flexicon.code.Grammar package¶
Submodules¶
flexicon.code.Grammar.EnvironmentOperations module¶
- class flexicon.code.Grammar.EnvironmentOperations.EnvironmentOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing phonological environments in a FieldWorks project.
Phonological environments specify the context in which phonological rules apply. They describe what precedes and follows a segment, using notation like V_V (between vowels), #_ (word-initially), _# (word-finally), etc.
Usage:
from flexlibs2 import FLExProject, EnvironmentOperations project = FLExProject() project.OpenProject("my project", writeEnabled=True) envOps = EnvironmentOperations(project) # Get all environments for env in envOps.GetAll(): name = envOps.GetName(env) notation = envOps.GetStringRepresentation(env) print(f"{name}: {notation}") # Create a new environment word_initial = envOps.Create("Word Initial", "At the beginning of a word") envOps.SetStringRepresentation(word_initial, "#_") # Create more environments between_vowels = envOps.Create("Between Vowels") envOps.SetStringRepresentation(between_vowels, "V_V") project.CloseProject()
- GetAll(**kwargs)¶
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetStringRepresentation(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetStringRepresentation(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetLeftContextPattern(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetRightContextPattern(*args, **kwargs)¶
Automatically instantiate and call the method.
- Duplicate(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- ApplySyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.GramCatOperations module¶
- class flexicon.code.Grammar.GramCatOperations.GramCatOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing Grammatical Categories in a FieldWorks project.
Grammatical categories are used to classify and describe grammatical properties such as person, number, gender, tense, aspect, mood, case, and other morphosyntactic features used in linguistic analysis.
Usage:
from flexlibs2 import FLExProject, GramCatOperations project = FLExProject() project.OpenProject("my project", writeEnabled=True) gramCatOps = GramCatOperations(project) # Get all grammatical categories for cat in gramCatOps.GetAll(): print(gramCatOps.GetName(cat)) # Create a new category person = gramCatOps.Create("person") # Create subcategories first = gramCatOps.Create("1st person", parent=person) second = gramCatOps.Create("2nd person", parent=person) third = gramCatOps.Create("3rd person", parent=person) # Navigate hierarchy parent = gramCatOps.GetParent(first) subcats = gramCatOps.GetSubcategories(person) project.CloseProject()
- GetAll(**kwargs)¶
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSubcategories(**kwargs)¶
- GetParent(*args, **kwargs)¶
Automatically instantiate and call the method.
- Duplicate(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- ApplySyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.InflectionFeatureOperations module¶
- class flexicon.code.Grammar.InflectionFeatureOperations.InflectionFeatureOperations(project)[source]¶
Bases:
BaseOperations,CatalogBackedMixinThis class provides operations for managing inflection classes, feature structures, and features in a FieldWorks project.
Inflection classes group lexical items that inflect similarly (e.g., Latin noun declensions, Spanish verb conjugations). Feature structures and features represent grammatical properties like person, number, gender, tense, aspect, mood, etc.
Usage:
from flexlibs2 import FLExProject, InflectionFeatureOperations project = FLExProject() project.OpenProject("my project", writeEnabled=True) inflOps = InflectionFeatureOperations(project) # Get all inflection classes for ic in inflOps.InflectionClassGetAll(): name = inflOps.InflectionClassGetName(ic) print(f"Inflection Class: {name}") # Create a new inflection class first_decl = inflOps.InflectionClassCreate("First Declension") # Work with features for feature in inflOps.FeatureGetAll(): print(f"Feature: {feature}") project.CloseProject()
- CATALOG_FILE = 'EticGlossList.xml'¶
- CATALOG_SUBDIR = 'Language Explorer/MGA/GlossLists'¶
- static CATALOG_PARSER(path)¶
Parse a PhonFeatsEticGlossList-shaped catalog (root <eticGlossList>) into a flat list of feature CatalogEntry objects.
- Items have type=”group” | “fsType” | “feature” | “value”:
“group” entries are organizational only (not representable in LCM). They are skipped at every level, but the parser recurses INTO them so any features they contain still get returned.
“fsType” entries are agreement-category containers (e.g.
tCommonAgrholds the Bantu number featuresfBantuSg,fBantuPl,fBantuMany). Like “group” they are organizational and are not themselves CatalogEntry items, but the parser recurses INTO them so the features they hold get returned. (issue #192)“feature” entries become CatalogEntry items in the returned list. Each feature’s value children are attached to its .children list.
“value” entries become CatalogEntry children of their parent feature entry.
- Parameters:
path (str) – Absolute path to e.g. PhonFeatsEticGlossList.xml.
- Returns:
Flat list of feature entries with their value entries attached as .children. Group structure is flattened away.
- Return type:
list[CatalogEntry]
- Raises:
ValueError – If the root element is not <eticGlossList>.
- CATALOG_PREFIX_WRITE = None¶
- DOMAIN_LABEL = 'inflection feature'¶
- InflectionClassGetAll(*args, **kwargs)¶
Automatically instantiate and call the method.
- InflectionClassCreate(*args, **kwargs)¶
Automatically instantiate and call the method.
- InflectionClassDelete(*args, **kwargs)¶
Automatically instantiate and call the method.
- InflectionClassGetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- InflectionClassSetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- FeatureStructureGetAll(*args, **kwargs)¶
Automatically instantiate and call the method.
- FeatureStructureCreate(*args, **kwargs)¶
Automatically instantiate and call the method.
- FeatureStructureDelete(*args, **kwargs)¶
Automatically instantiate and call the method.
- FeatureGetAll(*args, **kwargs)¶
Automatically instantiate and call the method.
- Find(*args, **kwargs)¶
Automatically instantiate and call the method.
- Exists(*args, **kwargs)¶
Automatically instantiate and call the method.
- TypeFind(*args, **kwargs)¶
Automatically instantiate and call the method.
- TypeCreate(*args, **kwargs)¶
Automatically instantiate and call the method.
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- CreateValue(*args, **kwargs)¶
Automatically instantiate and call the method.
- CreateClosedFeatureWithValues(*args, **kwargs)¶
Automatically instantiate and call the method.
- MakeFeatStruc(*args, **kwargs)¶
Automatically instantiate and call the method.
- FeatureCreate(*args, **kwargs)¶
Automatically instantiate and call the method.
- FeatureDelete(*args, **kwargs)¶
Automatically instantiate and call the method.
- FeatureGetValues(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetFeatures(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetFeatureConstraints(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetTypes(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- ApplySyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.MorphRuleOperations module¶
- class flexicon.code.Grammar.MorphRuleOperations.MorphRuleOperations(project)[source]¶
Bases:
BaseOperationsOperations for managing morphological rules in a FieldWorks project.
Morphological rules are distributed across the LCM data model:
Compound rules (MoMorphData.CompoundRulesOS): Define compound word formation patterns (endocentric and exocentric).
Affix templates (PartOfSpeech.AffixTemplatesOS): Define inflectional affix template morphology per part of speech.
Ad hoc co-prohibitions (MoMorphData.AdhocCoProhibitionsOC): Define morpheme co-occurrence restrictions (separate property interface).
Usage:
from flexlibs2 import FLExProject, MorphRuleOperations project = FLExProject() project.OpenProject("my project", writeEnabled=True) ruleOps = MorphRuleOperations(project) # Get all compound rules for rule in ruleOps.GetAllCompoundRules(): print(ruleOps.GetName(rule), rule.ClassName) # Get all affix templates across all parts of speech for template in ruleOps.GetAllAffixTemplates(): print(ruleOps.GetName(template)) # Get affix templates for a specific POS verb = posOps.Find("Verb") for template in ruleOps.GetAllAffixTemplatesForPOS(verb): print(ruleOps.GetName(template)) # Create a compound rule rule = ruleOps.CreateCompoundRule("Noun-Noun Compound") # Create an affix template on a POS template = ruleOps.CreateAffixTemplate(verb, "Verb Inflection") project.CloseProject()
- GetAll(**kwargs)¶
- GetAllCompoundRules(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAllAffixTemplates(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAllAffixTemplatesForPOS(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAllAdhocCoProhibitions(*args, **kwargs)¶
Automatically instantiate and call the method.
- CreateCompoundRule(*args, **kwargs)¶
Automatically instantiate and call the method.
- CreateAffixTemplate(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetStratum(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetStratum(*args, **kwargs)¶
Automatically instantiate and call the method.
- IsDisabled(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDisabled(*args, **kwargs)¶
Automatically instantiate and call the method.
- Duplicate(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- ApplySyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.NaturalClassOperations module¶
- class flexicon.code.Grammar.NaturalClassOperations.NaturalClassOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing natural classes in a FieldWorks project.
Natural classes are groups of phonemes that share common phonological features and pattern together in phonological rules. For example, voiceless stops {/p/, /t/, /k/} or vowels {/a/, /e/, /i/, /o/, /u/}.
Usage:
from flexlibs2 import FLExProject project = FLExProject() project.OpenProject("my project", writeEnabled=True) # Get all natural classes for nc in project.NaturalClasses.GetAll(): name = project.NaturalClasses.GetName(nc) abbr = project.NaturalClasses.GetAbbreviation(nc) phonemes = project.NaturalClasses.GetPhonemes(nc) print(f"{name} ({abbr}): {len(phonemes)} phonemes") # Create a new natural class stops = project.NaturalClasses.Create("Voiceless Stops", "VLS") # Add phonemes to the class p_phoneme = project.Phonemes.Find("/p/") if p_phoneme: project.NaturalClasses.AddPhoneme(stops, p_phoneme) project.CloseProject()
- GetAll(**kwargs)¶
- Find(*args, **kwargs)¶
Automatically instantiate and call the method.
- Exists(*args, **kwargs)¶
Automatically instantiate and call the method.
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*args, **kwargs)¶
Automatically instantiate and call the method.
- Duplicate(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAbbreviation(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetPhonemes(*args, **kwargs)¶
Automatically instantiate and call the method.
- AddPhoneme(*args, **kwargs)¶
Automatically instantiate and call the method.
- RemovePhoneme(*args, **kwargs)¶
Automatically instantiate and call the method.
- CreateFeatureBased(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetType(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetFeatures(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetFeatures(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- ApplySyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.POSOperations module¶
- class flexicon.code.Grammar.POSOperations.POSOperations(project)[source]¶
Bases:
BaseOperations,CatalogBackedMixinThis class provides operations for managing Parts of Speech in a FieldWorks project.
Parts of Speech are fundamental grammatical categories used in linguistic analysis (e.g., Noun, Verb, Adjective, etc.).
Usage:
from flexlibs2 import FLExProject, POSOperations project = FLExProject() project.OpenProject("my project", writeEnabled=True) posOps = POSOperations(project) # Get all parts of speech for pos in posOps.GetAll(): print(posOps.GetName(pos), posOps.GetAbbreviation(pos)) # Create a new POS noun = posOps.Create("Noun", "N") # Find and update verb = posOps.Find("Verb") if verb: posOps.SetAbbreviation(verb, "V") project.CloseProject()
- CATALOG_FILE = 'GOLDEtic.xml'¶
- CATALOG_SUBDIR = 'Templates'¶
- static CATALOG_PARSER(path)¶
Parse a GOLDEtic-shaped POS catalog XML file into a tree of CatalogEntry objects.
- Parameters:
path (str) – Absolute path to GOLDEtic.xml.
- Returns:
The top-level catalog entries. Nested sub-categories are reachable via each entry’s .children.
- Return type:
list[CatalogEntry]
Notes
The root element is <eticPOSList>; we walk its direct <item type=”category”> children and recurse from there.
Other root shapes are not supported by this function.
- CATALOG_PREFIX_WRITE = 'GOLD'¶
- DOMAIN_LABEL = 'POS'¶
- GetAll(**kwargs)¶
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*args, **kwargs)¶
Automatically instantiate and call the method.
- Exists(*args, **kwargs)¶
Automatically instantiate and call the method.
- Find(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAbbreviation(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetAbbreviation(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSubcategories(**kwargs)¶
- AddSubcategory(*args, **kwargs)¶
Automatically instantiate and call the method.
- RemoveSubcategory(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetCatalogSourceId(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetInflectionClasses(**kwargs)¶
- GetAffixSlots(**kwargs)¶
- GetEntryCount(*args, **kwargs)¶
Automatically instantiate and call the method.
- Duplicate(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- ApplySyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.PhonFeatureOperations module¶
- class flexicon.code.Grammar.PhonFeatureOperations.PhonFeatureOperations(project)[source]¶
Bases:
BaseOperations,CatalogBackedMixinThis class provides operations for managing phonological features and feature values in a FieldWorks project.
Phonological features are owned by
LangProject.PhFeatureSystemOA(anIFsFeatureSystem). Each feature is anIFsClosedFeaturewith one or moreIFsSymFeatValvalue children (typically+and-for binary features). Phonemes and natural classes attach anIFsFeatStrucwhoseFeatureSpecsOCreferences (feature, value) pairs.The MGA
PhonFeatsEticGlossList.xmlcatalog provides the canonical set of features and values with stable GUIDs;ImportCatalogandCreateFromCatalogpopulate the project from it.Usage:
from flexlibs2 import FLExProject project = FLExProject() project.OpenProject("my project", writeEnabled=True) phonFeats = project.PhonFeatures # Bulk-import the standard MGA feature set. result = phonFeats.ImportCatalog() print(f"Created {result.created_count}, " f"skipped {result.skipped_count}") # Or create a specific feature with its +/- values. cons = phonFeats.CreateFromCatalog("fPAConsonantal") # Compose a feature structure for a phoneme. plus = next(v for v in phonFeats.GetValues(cons) if phonFeats.GetAbbreviation(v) == "+") struct = phonFeats.MakeFeatStruc([(cons, plus)], owner=phoneme) project.CloseProject()
- CATALOG_FILE = 'PhonFeatsEticGlossList.xml'¶
- CATALOG_SUBDIR = 'Language Explorer/MGA/GlossLists'¶
- static CATALOG_PARSER(path)¶
Parse a PhonFeatsEticGlossList-shaped catalog (root <eticGlossList>) into a flat list of feature CatalogEntry objects.
- Items have type=”group” | “fsType” | “feature” | “value”:
“group” entries are organizational only (not representable in LCM). They are skipped at every level, but the parser recurses INTO them so any features they contain still get returned.
“fsType” entries are agreement-category containers (e.g.
tCommonAgrholds the Bantu number featuresfBantuSg,fBantuPl,fBantuMany). Like “group” they are organizational and are not themselves CatalogEntry items, but the parser recurses INTO them so the features they hold get returned. (issue #192)“feature” entries become CatalogEntry items in the returned list. Each feature’s value children are attached to its .children list.
“value” entries become CatalogEntry children of their parent feature entry.
- Parameters:
path (str) – Absolute path to e.g. PhonFeatsEticGlossList.xml.
- Returns:
Flat list of feature entries with their value entries attached as .children. Group structure is flattened away.
- Return type:
list[CatalogEntry]
- Raises:
ValueError – If the root element is not <eticGlossList>.
- CATALOG_PREFIX_WRITE = None¶
- DOMAIN_LABEL = 'feature'¶
- GetAll(**kwargs)¶
- GetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAbbreviation(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetValues(**kwargs)¶
- Find(*args, **kwargs)¶
Automatically instantiate and call the method.
- Exists(*args, **kwargs)¶
Automatically instantiate and call the method.
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetAbbreviation(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*args, **kwargs)¶
Automatically instantiate and call the method.
- CreateValue(*args, **kwargs)¶
Automatically instantiate and call the method.
- DeleteValue(*args, **kwargs)¶
Automatically instantiate and call the method.
- MakeFeatStruc(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.PhonemeOperations module¶
- class flexicon.code.Grammar.PhonemeOperations.PhonemeOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing Phonemes in a FieldWorks project.
Phonemes are the minimal distinctive units of sound in a language. For example, in English, /p/ and /b/ are distinct phonemes because they distinguish words like “pat” and “bat”.
Usage:
from flexlibs2 import FLExProject, PhonemeOperations project = FLExProject() project.OpenProject("my project", writeEnabled=True) phonemeOps = PhonemeOperations(project) # Get all phonemes for phoneme in phonemeOps.GetAll(): print(phonemeOps.GetRepresentation(phoneme)) # Create a new phoneme p_phoneme = phonemeOps.Create("/p/") phonemeOps.SetDescription(p_phoneme, "voiceless bilabial stop") # Find and update b_phoneme = phonemeOps.Find("/b/") if b_phoneme: phonemeOps.SetDescription(b_phoneme, "voiced bilabial stop") project.CloseProject()
- GetAll(**kwargs)¶
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*args, **kwargs)¶
Automatically instantiate and call the method.
- Duplicate(*args, **kwargs)¶
Automatically instantiate and call the method.
- Exists(*args, **kwargs)¶
Automatically instantiate and call the method.
- Find(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetRepresentation(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetRepresentation(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetFeatures(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetCodes(*args, **kwargs)¶
Automatically instantiate and call the method.
- AddCode(*args, **kwargs)¶
Automatically instantiate and call the method.
- RemoveCode(*args, **kwargs)¶
Automatically instantiate and call the method.
- FindCode(*args, **kwargs)¶
Automatically instantiate and call the method.
- ReplaceCode(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetBasicIPASymbol(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetBasicIPASymbol(*args, **kwargs)¶
Automatically instantiate and call the method.
- IsVowel(*args, **kwargs)¶
Automatically instantiate and call the method.
- IsConsonant(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- ApplySyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
- ImportCatalog(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.PhonologicalRuleOperations module¶
- class flexicon.code.Grammar.PhonologicalRuleOperations.PhonologicalRuleOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing phonological rules in a FieldWorks project.
Phonological rules define systematic sound changes that apply in specific phonological environments. They consist of input specifications, output specifications, and contextual conditions.
Usage:
from flexlibs2 import FLExProject, PhonologicalRuleOperations project = FLExProject() project.OpenProject("my project", writeEnabled=True) phonRuleOps = PhonologicalRuleOperations(project) # Get all phonological rules for rule in phonRuleOps.GetAll(): name = phonRuleOps.GetName(rule) desc = phonRuleOps.GetDescription(rule) print(f"{name}: {desc}") # Create a new phonological rule rule = phonRuleOps.Create("Voicing Assimilation") phonRuleOps.SetDescription(rule, "Obstruents become voiced before vowels") # Wire the rule via WireRule (the supported composer). # SetLeftContext / SetRightContext are refused with # NotImplementedError (they wrote to the wrong owner -- see #142). from flexlibs2 import Seg, NC phonRuleOps.WireRule(rule, input_pattern=[Seg(phoneme_t)], output_change=[Seg(phoneme_d)], right_context=[NC(vowel_class)], ) project.CloseProject()
- GetAll(**kwargs)¶
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*args, **kwargs)¶
Automatically instantiate and call the method.
- Exists(*args, **kwargs)¶
Automatically instantiate and call the method.
- Find(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetStratum(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetStratum(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDirection(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDirection(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetLeftContext(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetRightContext(*args, **kwargs)¶
Automatically instantiate and call the method.
- MakeConstraint(*args, **kwargs)¶
Automatically instantiate and call the method.
- DeleteConstraint(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetConstraints(*args, **kwargs)¶
Automatically instantiate and call the method.
- WireRule(*args, **kwargs)¶
Automatically instantiate and call the method.
- Duplicate(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- ApplySyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.StratumOperations module¶
- class flexicon.code.Grammar.StratumOperations.StratumOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing morphological strata in a FieldWorks project.
Strata are ordered layers in the morphology/phonology that organise affix templates, MSAs, compound rules, and phonological rules. They live on
LangProject.MorphologicalDataOA.StrataOSand are referenced viaStratumRAfromIMoInflAffixTemplate,IMoDerivAffMsa,IMoStemMsa,IMoCompoundRuleandIPhPhonologicalRule.Usage:
from flexlibs2 import FLExProject project = FLExProject() project.OpenProject("my project", writeEnabled=True) # Enumerate strata for stratum in project.Strata.GetAll(): name = project.Strata.GetName(stratum) print(name) # Create a new stratum new_stratum = project.Strata.Create("Stem", abbreviation="stem") project.CloseProject()
- GetAll(**kwargs)¶
- Find(*args, **kwargs)¶
Automatically instantiate and call the method.
- Exists(*args, **kwargs)¶
Automatically instantiate and call the method.
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAbbreviation(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetSyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- ApplySyncableProperties(*args, **kwargs)¶
Automatically instantiate and call the method.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.Grammar.adhoc_prohibition module¶
Wrapper class for ad hoc morphosyntactic prohibition objects.
This module provides AdhocProhibition, a wrapper class that transparently handles the three concrete types of morphosyntactic prohibitions: - MoAdhocProhibGr: Grammatical feature prohibitions - MoAdhocProhibMorph: Morpheme co-occurrence prohibitions - MoAdhocProhibAllomorph: Allomorph co-occurrence prohibitions
The wrapper exposes a unified interface for accessing common properties and provides convenience methods for checking type-specific capabilities without exposing the underlying ClassName or casting complexity.
- Problem:
Morphosyntactic prohibitions have different properties depending on their concrete type: - MoAdhocProhibGr: Feature-based restrictions - MoAdhocProhibMorph: Morpheme-based restrictions - MoAdhocProhibAllomorph: Allomorph-based restrictions
All have GUID and ClassName, but differ in restriction properties.
Users working with mixed collections need to check ClassName and cast to access type-specific properties, which is error-prone and verbose.
- Solution:
AdhocProhibition wrapper provides: - Simple properties for common features (guid, prohibition_type) - Capability check properties (is_grammatical_prohibition, etc.) - Property access that works across all types - Human-readable description of the prohibition
Example:
from flexlibs2.code.Grammar.adhoc_prohibition import AdhocProhibition
# Wrap a prohibition from GetAllAdhocCoProhibitions()
prohib = morphRuleOps.GetAllAdhocCoProhibitions()[0]
wrapped = AdhocProhibition(prohib)
# Access common properties
print(wrapped.guid) # Works for all prohibition types
print(wrapped.prohibition_type) # "Grammatical", "Morpheme", or "Allomorph"
# Check capabilities
if wrapped.is_morpheme_prohibition:
# Access morpheme-specific properties
morpheme = wrapped.MorphemeRA
prohibited = wrapped.ProhibitedMorphemeRA
# Optional: Advanced users can access concrete types
if wrapped.as_morpheme_prohibition():
concrete = wrapped.as_morpheme_prohibition()
# Use concrete interface for advanced operations
- class flexicon.code.Grammar.adhoc_prohibition.AdhocProhibition(lcm_obj)[source]¶
Bases:
LCMObjectWrapperWrapper for ad hoc morphosyntactic prohibition objects.
Handles the three concrete types of prohibitions (MoAdhocProhibGr, MoAdhocProhibMorph, MoAdhocProhibAllomorph) transparently, providing common properties and capability checks without exposing ClassName or casting.
- Variables:
_obj – The base interface object (IMoAdhocProhib)
_concrete – The concrete type object (IMoAdhocProhibGr, IMoAdhocProhibMorph, or IMoAdhocProhibAllomorph)
Example:
prohib = morphRuleOps.GetAllAdhocCoProhibitions()[0] wrapped = AdhocProhibition(prohib) print(wrapped.prohibition_type) if wrapped.is_grammatical_prohibition: print("This is a grammatical feature prohibition")
- property guid¶
Get the GUID of this prohibition.
- Returns:
The GUID as a string.
- Return type:
str
Example:
prohib_id = wrapped.guid
- property prohibition_type¶
Get a human-readable type identifier for this prohibition.
Returns the prohibition type as a friendly string: - “Grammatical” for MoAdhocProhibGr - “Morpheme” for MoAdhocProhibMorph - “Allomorph” for MoAdhocProhibAllomorph - “Unknown” if type is not recognized
- Returns:
Human-readable type name.
- Return type:
str
Example:
print(wrapped.prohibition_type) # "Morpheme"
- property is_grammatical_prohibition¶
Check if this is a grammatical feature prohibition.
Grammatical prohibitions restrict which feature values can combine.
- Returns:
True if this is a MoAdhocProhibGr, False otherwise.
- Return type:
bool
Example:
if wrapped.is_grammatical_prohibition: feature = wrapped.FeatureRA
- property is_morpheme_prohibition¶
Check if this is a morpheme co-occurrence prohibition.
Morpheme prohibitions restrict which morphemes can combine together.
- Returns:
True if this is a MoAdhocProhibMorph, False otherwise.
- Return type:
bool
Example:
if wrapped.is_morpheme_prohibition: morph = wrapped.MorphemeRA prohibited = wrapped.ProhibitedMorphemeRA
- property is_allomorph_prohibition¶
Check if this is an allomorph variant prohibition.
Allomorph prohibitions restrict which allomorph variants can combine.
- Returns:
True if this is a MoAdhocProhibAllomorph, False otherwise.
- Return type:
bool
Example:
if wrapped.is_allomorph_prohibition: allo = wrapped.AllomorphRA prohibited = wrapped.ProhibitedAllomorphRA
- as_grammatical_prohibition()[source]¶
Cast to grammatical prohibition type if applicable.
For advanced users who need to access grammatical-specific properties directly via the C# interface.
- Returns:
- The concrete interface if this is a grammatical
prohibition, None otherwise.
- Return type:
IMoAdhocProhibGr
Example:
concrete = wrapped.as_grammatical_prohibition() if concrete: feature = concrete.FeatureRA feature_value = concrete.FeatureValueRA
- as_morpheme_prohibition()[source]¶
Cast to morpheme prohibition type if applicable.
For advanced users who need to access morpheme-specific properties directly via the C# interface.
- Returns:
- The concrete interface if this is a morpheme
prohibition, None otherwise.
- Return type:
IMoAdhocProhibMorph
Example:
concrete = wrapped.as_morpheme_prohibition() if concrete: morpheme = concrete.MorphemeRA prohibited = concrete.ProhibitedMorphemeRA
- as_allomorph_prohibition()[source]¶
Cast to allomorph prohibition type if applicable.
For advanced users who need to access allomorph-specific properties directly via the C# interface.
- Returns:
- The concrete interface if this is an
allomorph prohibition, None otherwise.
- Return type:
IMoAdhocProhibAllomorph
Example:
concrete = wrapped.as_allomorph_prohibition() if concrete: allo = concrete.AllomorphRA prohibited = concrete.ProhibitedAllomorphRA
flexicon.code.Grammar.affix_template module¶
Wrapper class for affix template objects with unified interface.
This module provides AffixTemplate, a wrapper class that transparently handles affix template objects (MoInflAffixTemplate) providing convenient access to template properties and slots.
- Problem:
Affix templates contain multiple slot collections and properties that require navigation through the LCM object hierarchy. Users working with templates need convenient access to: - Basic properties (name, description, stratum, disabled) - Slot collections (prefix, suffix, proclitic, enclitic) - Convenience properties (slot counts, capabilities)
- Solution:
AffixTemplate wrapper provides: - Simple properties for common features (name, description, stratum) - Direct access to slot collections - Convenience properties for slot counts and checks - Capability check properties (has_prefix_slots, etc.) - Property access that works transparently
Example:
from flexlibs2.code.Grammar.affix_template import AffixTemplate
# Wrap a template from GetAll()
template = morphRuleOps.GetAllAffixTemplates()[0]
wrapped = AffixTemplate(template)
# Access common properties
print(wrapped.name) # Template name
print(wrapped.description) # Template description
print(wrapped.stratum) # Stratum reference
# Check capabilities
if wrapped.has_prefix_slots:
print(f"Template has {wrapped.prefix_slot_count} prefix slots")
# Access slots directly
for slot in wrapped.prefix_slots:
print(f"Slot: {slot.Name}")
- class flexicon.code.Grammar.affix_template.AffixTemplate(lcm_template)[source]¶
Bases:
LCMObjectWrapperWrapper for affix template objects providing unified interface access.
Handles MoInflAffixTemplate objects transparently, providing common properties and convenience methods without exposing ClassName or casting.
- Variables:
_obj – The base interface object (IMoInflAffixTemplate)
_concrete – The concrete type object (IMoInflAffixTemplate)
Example:
template = morphRuleOps.GetAllAffixTemplates()[0] wrapped = AffixTemplate(template) print(wrapped.name) print(wrapped.prefix_slot_count) if wrapped.has_suffix_slots: print(f"Has {wrapped.suffix_slot_count} suffix slots")
- property name: str¶
Get the template’s name.
- Returns:
The template name, or empty string if not set.
- Return type:
str
Example:
print(f"Template: {wrapped.name}")
- property description¶
Get the template’s description.
- Returns:
The template description, or empty string if not set.
- Return type:
str
Example:
print(f"Description: {wrapped.description}")
- property stratum¶
Get the template’s stratum reference.
- Returns:
The phonological stratum that owns this template, or None if not set.
- Return type:
IMoStratum or None
Example:
if wrapped.stratum: print(f"Stratum: {wrapped.stratum.Name}")
- property disabled¶
Check if the template is disabled.
- Returns:
True if the template is disabled, False otherwise.
- Return type:
bool
Example:
if wrapped.disabled: print("Template is disabled")
- property prefix_slots: list[object]¶
Get the prefix slots collection.
- Returns:
List or collection of prefix slot objects, or empty list if none.
Example:
for slot in wrapped.prefix_slots: print(f"Prefix slot: {slot.Name}")
Notes
Access via PrefixSlotsRS from the concrete interface
Returns empty list if slots not available
- property suffix_slots¶
Get the suffix slots collection.
- Returns:
List or collection of suffix slot objects, or empty list if none.
Example:
for slot in wrapped.suffix_slots: print(f"Suffix slot: {slot.Name}")
Notes
Access via SuffixSlotsRS from the concrete interface
Returns empty list if slots not available
- property proclitic_slots¶
Get the proclitic slots collection.
- Returns:
List or collection of proclitic slot objects, or empty list if none.
Example:
for slot in wrapped.proclitic_slots: print(f"Proclitic slot: {slot.Name}")
Notes
Access via ProcliticSlotsRS from the concrete interface
Returns empty list if slots not available
- property enclitic_slots¶
Get the enclitic slots collection.
- Returns:
List or collection of enclitic slot objects, or empty list if none.
Example:
for slot in wrapped.enclitic_slots: print(f"Enclitic slot: {slot.Name}")
Notes
Access via EncliticSlotsRS from the concrete interface
Returns empty list if slots not available
- property prefix_slot_count¶
Get the number of prefix slots.
- Returns:
Number of prefix slots (0 if none).
- Return type:
int
Example:
print(f"Prefix slots: {wrapped.prefix_slot_count}")
- property suffix_slot_count¶
Get the number of suffix slots.
- Returns:
Number of suffix slots (0 if none).
- Return type:
int
Example:
print(f"Suffix slots: {wrapped.suffix_slot_count}")
- property proclitic_slot_count¶
Get the number of proclitic slots.
- Returns:
Number of proclitic slots (0 if none).
- Return type:
int
Example:
print(f"Proclitic slots: {wrapped.proclitic_slot_count}")
- property enclitic_slot_count¶
Get the number of enclitic slots.
- Returns:
Number of enclitic slots (0 if none).
- Return type:
int
Example:
print(f"Enclitic slots: {wrapped.enclitic_slot_count}")
- property total_slots¶
Get the total number of slots across all types.
Returns the sum of prefix, suffix, proclitic, and enclitic slots.
- Returns:
Total slot count (0 if no slots).
- Return type:
int
Example:
print(f"Total slots: {wrapped.total_slots}")
- property owner_pos¶
Get the owner Part of Speech for this template.
Convenience property to access the POS that owns this template.
- Returns:
The owner POS, or None if not available.
- Return type:
IPartOfSpeech or None
Example:
if wrapped.owner_pos: print(f"Template for POS: {wrapped.owner_pos.Name}")
- property has_prefix_slots¶
Check if this template has prefix slots.
- Returns:
True if template has at least one prefix slot.
- Return type:
bool
Example:
if wrapped.has_prefix_slots: print(f"Template has {wrapped.prefix_slot_count} prefix slots")
- property has_suffix_slots¶
Check if this template has suffix slots.
- Returns:
True if template has at least one suffix slot.
- Return type:
bool
Example:
if wrapped.has_suffix_slots: print(f"Template has {wrapped.suffix_slot_count} suffix slots")
- property has_proclitic_slots¶
Check if this template has proclitic slots.
- Returns:
True if template has at least one proclitic slot.
- Return type:
bool
Example:
if wrapped.has_proclitic_slots: print(f"Template has {wrapped.proclitic_slot_count} proclitic slots")
- property has_enclitic_slots¶
Check if this template has enclitic slots.
- Returns:
True if template has at least one enclitic slot.
- Return type:
bool
Example:
if wrapped.has_enclitic_slots: print(f"Template has {wrapped.enclitic_slot_count} enclitic slots")
- property has_any_slots¶
Check if this template has any slots at all.
- Returns:
True if template has at least one slot of any type.
- Return type:
bool
Example:
if wrapped.has_any_slots: print(f"Template has {wrapped.total_slots} total slots")
- property concrete¶
Get the raw concrete interface object.
For advanced users who need to access the underlying C# interface directly without going through wrapper properties.
- Returns:
The concrete interface object (IMoInflAffixTemplate).
Example:
# Direct access to concrete interface concrete = template_obj.concrete prefix_slots = concrete.PrefixSlotsRS
Notes
For power users only
Bypasses the wrapper’s abstraction
Normal users should prefer wrapper properties like has_prefix_slots, prefix_slot_count, etc.
flexicon.code.Grammar.affix_template_collection module¶
Smart collection class for affix templates.
This module provides AffixTemplateCollection, a smart collection that manages affix templates while supporting unified operations and convenient filtering.
- Problem:
GetAll() returns multiple templates from different parts of speech. Users need to: - See how many templates are in the collection - Filter by common criteria (name, stratum, slot availability) - Work with templates without manual casting or checking
- Solution:
AffixTemplateCollection provides: - __str__() showing template summary - filter() for common criteria (name_contains, stratum) - Convenience methods (with_prefix_slots, with_suffix_slots, etc.) - Chainable filtering: templates.with_prefix_slots().filter(name_contains=’Verb’) - where() for custom predicates
Example:
from flexlibs2.code.Grammar.affix_template_collection import AffixTemplateCollection
# GetAll() now returns AffixTemplateCollection
templates = morphRuleOps.GetAllAffixTemplates()
print(templates) # Shows collection summary
# Filter by slots
prefix_templates = templates.with_prefix_slots()
print(f"Templates with prefix slots: {len(prefix_templates)}")
# Filter by name
verb_templates = templates.filter(name_contains='Verb')
# Chain filters
verb_prefix = templates.with_prefix_slots().filter(name_contains='Verb')
# Iterate
for template in templates:
print(template.name)
- class flexicon.code.Grammar.affix_template_collection.AffixTemplateCollection(items=None)[source]¶
Bases:
SmartCollectionSmart collection for affix templates with filtering capabilities.
Manages collections of affix templates (AffixTemplate wrapper objects) with type-aware display and filtering capabilities. Supports filtering by common properties (name, stratum, slot availability).
- Variables:
_items – List of AffixTemplate wrapper objects
Example:
templates = morphRuleOps.GetAllAffixTemplates() print(templates) # Shows collection summary prefix = templates.with_prefix_slots() # Filter to templates with prefixes verb = templates.filter(name_contains='Verb') # Name filter both = templates.with_prefix_slots().filter(name_contains='Verb') # Chain
- filter(name_contains=None, stratum=None, where=None)[source]¶
Filter the collection by common template properties.
Supports filtering by properties that work across all templates (name, stratum). For complex filtering, use where().
- Parameters:
name_contains (str, optional) – Filter to templates whose name contains this string (case-sensitive).
stratum (str, optional) – Filter by stratum name or reference.
where (callable, optional) – Custom predicate function. If provided, other criteria are ignored.
- Returns:
New collection with filtered items.
- Return type:
Example:
# Filter by name verb_templates = templates.filter(name_contains='Verb') # Filter by stratum stratum1 = templates.filter(stratum='Stratum1') # Custom filtering with_slots = templates.where(lambda t: t.has_any_slots) # Chain filters verb_stratum = templates.filter(name_contains='Verb').filter(stratum='Stratum1')
Notes
name_contains is case-sensitive
All criteria are AND-ed together unless only one is provided
where() takes precedence over other criteria
Returns new collection (doesn’t modify original)
Use where() for complex custom filtering
- where(predicate)[source]¶
Filter using a custom predicate function.
For filtering by complex criteria or properties not supported by filter().
- Parameters:
predicate (callable) – Function that takes an AffixTemplate and returns True to include it in the result.
- Returns:
New collection with items matching the predicate.
- Return type:
Example:
# Complex predicate: templates with both prefix and suffix slots full_templates = templates.where( lambda t: t.has_prefix_slots and t.has_suffix_slots ) # Combining conditions complex_filter = templates.where( lambda t: t.has_any_slots and (t.name or "").startswith('Verb') ) # Capability checking prefix_templates = templates.where(lambda t: t.has_prefix_slots)
Notes
Predicate receives each AffixTemplate object
Return True to include in result, False to exclude
For simple filters (name, stratum), use filter() instead
- with_prefix_slots()[source]¶
Get only the templates that have prefix slots.
Convenience method for filtering to templates with prefix slots.
- Returns:
New collection with templates that have prefix slots.
- Return type:
Example:
prefix_templates = templates.with_prefix_slots() print(f"Found {len(prefix_templates)} templates with prefix slots") # Chain with other filters verb_prefix = templates.with_prefix_slots().filter(name_contains='Verb')
Notes
Equivalent to where(lambda t: t.has_prefix_slots)
Use has_prefix_slots on individual templates to check
- with_suffix_slots()[source]¶
Get only the templates that have suffix slots.
Convenience method for filtering to templates with suffix slots.
- Returns:
New collection with templates that have suffix slots.
- Return type:
Example:
suffix_templates = templates.with_suffix_slots() print(f"Found {len(suffix_templates)} templates with suffix slots") # Chain with other filters verb_suffix = templates.with_suffix_slots().filter(name_contains='Verb')
Notes
Equivalent to where(lambda t: t.has_suffix_slots)
Use has_suffix_slots on individual templates to check
- with_proclitic_slots()[source]¶
Get only the templates that have proclitic slots.
Convenience method for filtering to templates with proclitic slots.
- Returns:
New collection with templates that have proclitic slots.
- Return type:
Example:
proclitic_templates = templates.with_proclitic_slots() print(f"Found {len(proclitic_templates)} templates with proclitic slots")
Notes
Equivalent to where(lambda t: t.has_proclitic_slots)
Use has_proclitic_slots on individual templates to check
- with_enclitic_slots()[source]¶
Get only the templates that have enclitic slots.
Convenience method for filtering to templates with enclitic slots.
- Returns:
New collection with templates that have enclitic slots.
- Return type:
Example:
enclitic_templates = templates.with_enclitic_slots() print(f"Found {len(enclitic_templates)} templates with enclitic slots")
Notes
Equivalent to where(lambda t: t.has_enclitic_slots)
Use has_enclitic_slots on individual templates to check
- with_slots(slot_type)[source]¶
Get only the templates that have slots of a specific type.
Convenience method for filtering to specific slot types.
- Parameters:
slot_type (str) – Type of slots to filter by: ‘prefix’, ‘suffix’, ‘proclitic’, or ‘enclitic’.
- Returns:
New collection with templates that have the specified slots.
- Return type:
Example:
# Get templates with prefix slots prefix_templates = templates.with_slots('prefix') # Get templates with suffix slots suffix_templates = templates.with_slots('suffix') # Get templates with proclitic slots proclitic_templates = templates.with_slots('proclitic')
Notes
slot_type must be one of: ‘prefix’, ‘suffix’, ‘proclitic’, ‘enclitic’
Returns empty collection if slot_type is not recognized
- with_any_slots()[source]¶
Get only the templates that have any slots.
Convenience method for filtering to templates with at least one slot.
- Returns:
New collection with templates that have slots.
- Return type:
Example:
templates_with_slots = templates.with_any_slots() print(f"Found {len(templates_with_slots)} templates with slots")
Notes
Equivalent to where(lambda t: t.has_any_slots)
- full_templates()[source]¶
Get only the templates that have all four slot types.
Convenience method for filtering to templates with prefix, suffix, proclitic, and enclitic slots.
- Returns:
New collection with full-featured templates.
- Return type:
Example:
full_templates = templates.full_templates() print(f"Found {len(full_templates)} templates with all slot types")
Notes
Equivalent to:
where(lambda t: all([ t.has_prefix_slots, t.has_suffix_slots, t.has_proclitic_slots, t.has_enclitic_slots ]))
- for_pos(pos_name_or_object)[source]¶
Get only the templates for a specific part of speech.
Convenience method for filtering templates by their owner POS.
- Parameters:
pos_name_or_object – Either a POS name (str) or a POS object.
- Returns:
New collection with templates for the specified POS.
- Return type:
Example:
# Filter by POS name verb_templates = templates.for_pos('Verb') # Filter by POS object verb_pos = posOps.Find('Verb') verb_templates = templates.for_pos(verb_pos)
Notes
If pos_name_or_object is a string, looks for POS names containing the string
Returns empty collection if no templates found for the POS
flexicon.code.Grammar.compound_rule module¶
Wrapper class for compound rule objects with unified interface.
This module provides CompoundRule, a wrapper class that transparently handles the two concrete types of compound rules: - MoEndoCompound: Head is internal to the compound - MoExoCompound: Head is external to the compound
The wrapper exposes a unified interface for accessing common properties and provides convenience methods for checking type-specific capabilities without exposing the underlying ClassName or casting complexity.
- Problem:
Compound rules have different properties depending on their concrete type:
MoEndoCompound and MoExoCompound both have LeftHeadDep, RightHeadDep, LeftContextOA, RightContextOA
Users working with mixed collections need to check ClassName and cast to access type-specific properties, which is error-prone and verbose.
- Solution:
CompoundRule wrapper provides:
Simple properties for common features (name, head_dependency, contexts)
Capability check properties (is_endo_compound, is_exo_compound)
Property access that works across all types
Optional: Methods for advanced users who know C# types
Example:
from flexlibs2.code.Grammar.compound_rule import CompoundRule
# Wrap a rule from GetAll()
rule = morphRuleOps.GetAll()[0] # Typed as IMoCompoundRule
wrapped = CompoundRule(rule)
# Access common properties
print(wrapped.name) # Works for all rule types
if wrapped.left_head_dep:
print(f"Left head dependency: {wrapped.left_head_dep}")
# Check type
if wrapped.is_endo_compound:
print("Head is internal to the compound")
# Optional: Advanced users can access concrete types
if wrapped.as_endo_compound():
concrete = wrapped.as_endo_compound()
# Use concrete interface for advanced operations
- class flexicon.code.Grammar.compound_rule.CompoundRule(lcm_rule)[source]¶
Bases:
LCMObjectWrapperWrapper for compound rule objects providing unified interface access.
Handles the two concrete types of compound rules (MoEndoCompound, MoExoCompound) transparently, providing common properties and capability checks without exposing ClassName or casting.
- Variables:
_obj – The base interface object (IMoCompoundRule)
_concrete – The concrete type object (IMoEndoCompound or IMoExoCompound)
Example:
rule = morphRuleOps.GetAll()[0] wrapped = CompoundRule(rule) print(wrapped.name) print(wrapped.is_endo_compound) if wrapped.left_head_dep: print(wrapped.left_head_dep)
- property name: str¶
Get the rule’s name.
- Returns:
The rule name, or empty string if not set.
- Return type:
str
Example:
print(f"Rule: {wrapped.name}")
- property left_head_dep¶
Get the left head dependency.
- Returns:
The left head dependency value, or None if not set.
- Return type:
int or None
Example:
if wrapped.left_head_dep: print(f"Left head dep: {wrapped.left_head_dep}")
Notes
Available on both MoEndoCompound and MoExoCompound
Use head_dependency for generic access
- property right_head_dep¶
Get the right head dependency.
- Returns:
The right head dependency value, or None if not set.
- Return type:
int or None
Example:
if wrapped.right_head_dep: print(f"Right head dep: {wrapped.right_head_dep}")
Notes
Available on both MoEndoCompound and MoExoCompound
Use head_dependency for generic access
- property head_dependency¶
Get the primary head dependency (convenience property).
Returns the first non-None head dependency (left takes precedence).
- Returns:
The head dependency value, or None if neither set.
- Return type:
int or None
Example:
if wrapped.head_dependency: print(f"Head dependency: {wrapped.head_dependency}")
Notes
Tries left_head_dep first, then right_head_dep
Use left_head_dep or right_head_dep for specific access
- property left_context¶
Get the left context.
- Returns:
The left context object, or None if not set.
- Return type:
IMoPhonContext or None
Example:
if wrapped.left_context: print(f"Left context: {wrapped.left_context}")
Notes
Available on both MoEndoCompound and MoExoCompound
Use contexts property for generic access
- property right_context¶
Get the right context.
- Returns:
The right context object, or None if not set.
- Return type:
IMoPhonContext or None
Example:
if wrapped.right_context: print(f"Right context: {wrapped.right_context}")
Notes
Available on both MoEndoCompound and MoExoCompound
Use contexts property for generic access
- property contexts¶
Get both left and right contexts as a tuple.
- Returns:
(left_context, right_context) where each can be None.
- Return type:
tuple
Example:
left_ctx, right_ctx = wrapped.contexts if left_ctx: print(f"Left: {left_ctx}") if right_ctx: print(f"Right: {right_ctx}")
Notes
Convenience property for accessing both contexts
Use left_context or right_context for individual access
- property is_endo_compound¶
Check if this is an endocentric compound rule.
- Returns:
True if this is MoEndoCompound (head is internal).
- Return type:
bool
Example:
if wrapped.is_endo_compound: print("Head is internal to the compound")
Notes
MoEndoCompound has the head inside the compound structure
Mutually exclusive with is_exo_compound
- property is_exo_compound¶
Check if this is an exocentric compound rule.
- Returns:
True if this is MoExoCompound (head is external).
- Return type:
bool
Example:
if wrapped.is_exo_compound: print("Head is external to the compound")
Notes
MoExoCompound has the head outside the compound structure
Mutually exclusive with is_endo_compound
- as_endo_compound()[source]¶
Cast to IMoEndoCompound if this is an endo compound rule.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not an MoEndoCompound.
- Returns:
- The concrete interface if this is an
MoEndoCompound, None otherwise.
- Return type:
IMoEndoCompound or None
Example:
if rule_obj.as_endo_compound(): concrete = rule_obj.as_endo_compound() # Can now access IMoEndoCompound-specific methods/properties # Advanced operations...
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like is_endo_compound instead
Only useful if you need to call methods or access properties that aren’t exposed through the wrapper
- as_exo_compound()[source]¶
Cast to IMoExoCompound if this is an exo compound rule.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not an MoExoCompound.
- Returns:
- The concrete interface if this is an
MoExoCompound, None otherwise.
- Return type:
IMoExoCompound or None
Example:
if rule_obj.as_exo_compound(): concrete = rule_obj.as_exo_compound() # Can now access IMoExoCompound-specific methods/properties
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like is_exo_compound instead
- property concrete¶
Get the raw concrete interface object.
For advanced users who need to access the underlying C# interface directly without going through wrapper properties.
- Returns:
The concrete interface object (IMoEndoCompound or IMoExoCompound depending on the rule’s actual type).
Example:
# Direct access to concrete interface concrete = rule_obj.concrete left_dep = concrete.LeftHeadDep
Notes
For power users only
Bypasses the wrapper’s abstraction
Normal users should prefer wrapper properties like is_endo_compound, left_head_dep, etc.
flexicon.code.Grammar.compound_rule_collection module¶
Smart collection class for compound rules.
This module provides CompoundRuleCollection, a smart collection that manages compound rules while showing type diversity and supporting unified operations across the two concrete types: - MoEndoCompound - MoExoCompound
- Problem:
GetAll() returns objects with multiple concrete implementations. Users need to: - See which types are in the collection - Filter by type if they want to - Work with all types together without manual casting - Filter by common properties that work across all types
- Solution:
CompoundRuleCollection provides: - __str__() showing type breakdown - by_type() filtering to specific concrete types - filter() for common criteria (name_contains, head_dependency) - Convenience methods (endo_compounds(), exo_compounds()) - Chainable filtering: rules.endo_compounds().filter(name_contains=’V’) - where() for custom predicates
Example:
from flexlibs2.code.Grammar.compound_rule_collection import CompoundRuleCollection
# GetAll() now returns CompoundRuleCollection
rules = morphRuleOps.GetAll()
print(rules) # Shows type breakdown
# CompoundRuleCollection (8 total)
# MoEndoCompound: 5 (62%)
# MoExoCompound: 3 (38%)
# Filter by type
endo_only = rules.endo_compounds()
print(len(endo_only)) # 5
# Filter by name
verb_rules = rules.filter(name_contains='Verb')
# Chain filters
verb_endo = rules.endo_compounds().filter(name_contains='Verb')
# Iterate
for rule in rules:
print(rule.name)
- class flexicon.code.Grammar.compound_rule_collection.CompoundRuleCollection(items=None)[source]¶
Bases:
SmartCollectionSmart collection for compound rules with type-aware filtering.
Manages collections of compound rules (CompoundRule wrapper objects) with type-aware display and filtering capabilities. Supports filtering by common properties (name, head_dependency) and by concrete type.
- Variables:
_items – List of CompoundRule wrapper objects
Example:
rules = morphRuleOps.GetAll() # Returns CompoundRuleCollection print(rules) # Shows type breakdown endo = rules.endo_compounds() # Filter to MoEndoCompound verb = rules.filter(name_contains='Verb') # Name filter both = rules.endo_compounds().filter(name_contains='Verb') # Chain
- filter(name_contains=None, head_dependency=None, where=None)[source]¶
Filter the collection by common rule properties.
Supports filtering by properties that work across all rule types (name, head_dependency). For complex filtering, use where().
- Parameters:
name_contains (str, optional) – Filter to rules whose name contains this string (case-sensitive).
head_dependency (int, optional) – Filter by head dependency value.
where (callable, optional) – Custom predicate function. If provided, other criteria are ignored.
- Returns:
New collection with filtered items.
- Return type:
Example:
# Filter by name verb_rules = rules.filter(name_contains='Verb') # Filter by head dependency lhs_head = rules.filter(head_dependency=0) # Custom filtering with_contexts = rules.where(lambda r: r.left_context or r.right_context) # Chain filters verb_lhs = rules.filter(name_contains='Verb').filter(head_dependency=0)
Notes
name_contains is case-sensitive
All criteria are AND-ed together unless only one is provided
where() takes precedence over other criteria
Returns new collection (doesn’t modify original)
Use where() for complex custom filtering
- where(predicate)[source]¶
Filter using a custom predicate function.
For filtering by complex criteria or properties not supported by filter().
- Parameters:
predicate (callable) – Function that takes a CompoundRule and returns True to include it in the result.
- Returns:
New collection with items matching the predicate.
- Return type:
Example:
# Complex predicate: rules with both left and right contexts full_context = rules.where( lambda r: r.left_context is not None and r.right_context is not None ) # Combining conditions endo_with_context = rules.where( lambda r: r.is_endo_compound and (r.left_context or r.right_context) ) # Type checking combined with other criteria exo_rules = rules.where(lambda r: r.is_exo_compound)
Notes
Predicate receives each CompoundRule object
Return True to include in result, False to exclude
For simple filters (name, head_dependency), use filter() instead
- endo_compounds()[source]¶
Get only the endocentric (MoEndoCompound) rules from the collection.
Convenience method for filtering to MoEndoCompound objects only.
- Returns:
New collection with only MoEndoCompound objects.
- Return type:
Example:
endo = rules.endo_compounds() print(f"Found {len(endo)} endocentric rules") # Chain with other filters verb_endo = rules.endo_compounds().filter(name_contains='Verb')
Notes
Equivalent to by_type(‘MoEndoCompound’)
Endo compounds have head internal to the compound
Use is_endo_compound on individual rules to check type
- exo_compounds()[source]¶
Get only the exocentric (MoExoCompound) rules from the collection.
Convenience method for filtering to MoExoCompound objects only.
- Returns:
New collection with only MoExoCompound objects.
- Return type:
Example:
exo = rules.exo_compounds() print(f"Found {len(exo)} exocentric rules") # Chain with other filters noun_exo = rules.exo_compounds().filter(name_contains='Noun')
Notes
Equivalent to by_type(‘MoExoCompound’)
Exo compounds have head external to the compound
Use is_exo_compound on individual rules to check type
flexicon.code.Grammar.phonological_rule module¶
Wrapper class for phonological rule objects with unified interface.
This module provides PhonologicalRule, a wrapper class that transparently handles the three concrete types of phonological rules: - PhRegularRule: Standard rules with output specifications - PhMetathesisRule: Metathesis rules with swapped segments - PhReduplicationRule: Reduplication rules with repeated segments
The wrapper exposes a unified interface for accessing common properties and provides convenience methods for checking type-specific capabilities without exposing the underlying ClassName or casting complexity.
- Problem:
Phonological rules have different properties depending on their concrete type: - PhRegularRule has RightHandSidesOS (output specs) - PhMetathesisRule has LeftPartOfMetathesisOS, RightPartOfMetathesisOS - PhReduplicationRule has LeftPartOfReduplicationOS, RightPartOfReduplicationOS
All have StrucDescOS (input contexts), Name, Direction, etc.
Users working with mixed collections need to check ClassName and cast to access type-specific properties, which is error-prone and verbose.
- Solution:
PhonologicalRule wrapper provides: - Simple properties for common features (name, input_contexts) - Capability check properties (has_output_specs, has_metathesis_parts, etc.) - Property access that works across all types - Optional: Methods for advanced users who know C# types
Example:
from flexlibs2.code.Grammar.phonological_rule import PhonologicalRule
# Wrap a rule from GetAll()
rule = phonRuleOps.GetAll()[0] # Typed as IPhSegmentRule
wrapped = PhonologicalRule(rule)
# Access common properties
print(wrapped.name) # Works for all rule types
for context in wrapped.input_contexts:
print(context)
# Check capabilities
if wrapped.has_output_specs:
for spec in wrapped.output_specs:
print(f"Output: {spec}")
if wrapped.has_metathesis_parts:
print("This is a metathesis rule")
# Optional: Advanced users can access concrete types
if wrapped.as_regular_rule():
concrete = wrapped.as_regular_rule()
# Use concrete interface for advanced operations
- class flexicon.code.Grammar.phonological_rule.PhonologicalRule(lcm_rule)[source]¶
Bases:
LCMObjectWrapperWrapper for phonological rule objects providing unified interface access.
Handles the three concrete types of phonological rules (PhRegularRule, PhMetathesisRule, PhReduplicationRule) transparently, providing common properties and capability checks without exposing ClassName or casting.
- Variables:
_obj – The base interface object (IPhSegmentRule)
_concrete – The concrete type object (IPhRegularRule, IPhMetathesisRule, or IPhReduplicationRule)
Example:
rule = phonRuleOps.GetAll()[0] wrapped = PhonologicalRule(rule) print(wrapped.name) print(wrapped.input_contexts) if wrapped.has_output_specs: print(wrapped.output_specs)
- property name: str¶
Get the rule’s name.
- Returns:
The rule name, or empty string if not set.
- Return type:
str
Example:
print(f"Rule: {wrapped.name}")
- property direction: int¶
Get the direction of rule application.
- Returns:
- Direction value (0=left-to-right, 1=right-to-left,
2=simultaneous).
- Return type:
int
Example:
if wrapped.direction == 0: print("Left-to-right application")
- property stratum: object | None¶
Get the stratum this rule applies in.
- Returns:
The stratum object if set, None otherwise.
- Return type:
IMoStratum or None
Example:
if wrapped.stratum: print(f"Stratum: {wrapped.stratum.Name.BestAnalysisAlternative.Text}")
- property input_contexts: ContextCollection¶
Get the input contexts (structural description) for this rule.
- Returns:
- Smart collection of PhonologicalContext wrapper objects
representing the structural description (input) of this rule. Returns empty collection if none.
- Return type:
Example:
for context in wrapped.input_contexts: print(f"Input context: {context.context_name}") if context.is_simple_context_seg: segment = context.segment print(f"Segment: {segment}") # Filter contexts simple_contexts = wrapped.input_contexts.simple_contexts() boundaries = wrapped.input_contexts.boundary_contexts()
Notes
StrucDescOS contains the input specifications
Works on all rule types (regular, metathesis, reduplication)
Returns ContextCollection for convenient filtering and type checking
Contexts are wrapped in PhonologicalContext for unified interface
- property has_output_specs¶
Check if this rule has output specifications.
- Returns:
True if this is a PhRegularRule with RightHandSidesOS.
- Return type:
bool
Example:
if wrapped.has_output_specs: for spec in wrapped.output_specs: print(f"Output: {spec}")
Notes
Only PhRegularRule has output specifications
PhMetathesisRule and PhReduplicationRule have their own output representations
- property output_specs¶
Get the output specifications for this rule.
Only available on PhRegularRule. Returns empty list for other types.
- Returns:
List of IPhSegRuleRHS objects, or empty list if not available.
- Return type:
list
Example:
if wrapped.has_output_specs: for rhs in wrapped.output_specs: print(f"Output spec: {rhs}")
Notes
Only PhRegularRule has RightHandSidesOS
Use has_output_specs to check before accessing
- property has_metathesis_parts¶
Check if this rule is a metathesis rule.
- Returns:
True if this is a PhMetathesisRule with metathesis parts.
- Return type:
bool
Example:
if wrapped.has_metathesis_parts: left, right = wrapped.metathesis_parts print(f"Swap: {left} <-> {right}")
Notes
Only PhMetathesisRule objects have this capability
Use metathesis_parts to get the actual parts
- property metathesis_parts¶
Get the metathesis parts (left and right swapped segments).
- Returns:
- (left_parts, right_parts) where each is a list of contexts,
or ([], []) if not a metathesis rule.
- Return type:
tuple
Example:
if wrapped.has_metathesis_parts: left, right = wrapped.metathesis_parts for part in left: print(f"Left swapped part: {part}")
Notes
Only PhMetathesisRule has these parts
Use has_metathesis_parts to check before accessing
- property has_redup_parts¶
Check if this rule is a reduplication rule.
- Returns:
True if this is a PhReduplicationRule with reduplication parts.
- Return type:
bool
Example:
if wrapped.has_redup_parts: left, right = wrapped.redup_parts print(f"Reduplication: {left} <-> {right}")
Notes
Only PhReduplicationRule objects have this capability
Use redup_parts to get the actual parts
- property redup_parts¶
Get the reduplication parts (left and right repeated segments).
- Returns:
- (left_parts, right_parts) where each is a list of contexts,
or ([], []) if not a reduplication rule.
- Return type:
tuple
Example:
if wrapped.has_redup_parts: left, right = wrapped.redup_parts for part in left: print(f"Left reduplicated part: {part}")
Notes
Only PhReduplicationRule has these parts
Use has_redup_parts to check before accessing
- as_regular_rule()[source]¶
Cast to IPhRegularRule if this is a regular rule.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not a PhRegularRule.
- Returns:
- The concrete interface if this is a
PhRegularRule, None otherwise.
- Return type:
IPhRegularRule or None
Example:
if rule_obj.as_regular_rule(): concrete = rule_obj.as_regular_rule() # Can now access IPhRegularRule-specific methods/properties rhs = concrete.RightHandSidesOS # Advanced operations...
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like has_output_specs and output_specs instead
Only useful if you need to call methods or access properties that aren’t exposed through the wrapper
- as_metathesis_rule()[source]¶
Cast to IPhMetathesisRule if this is a metathesis rule.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not a PhMetathesisRule.
- Returns:
- The concrete interface if this is a
PhMetathesisRule, None otherwise.
- Return type:
IPhMetathesisRule or None
Example:
if rule_obj.as_metathesis_rule(): concrete = rule_obj.as_metathesis_rule() # Can now access IPhMetathesisRule-specific methods/properties
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like has_metathesis_parts and metathesis_parts instead
- as_reduplication_rule()[source]¶
Cast to IPhReduplicationRule if this is a reduplication rule.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not a PhReduplicationRule.
- Returns:
- The concrete interface if this is a
PhReduplicationRule, None otherwise.
- Return type:
IPhReduplicationRule or None
Example:
if rule_obj.as_reduplication_rule(): concrete = rule_obj.as_reduplication_rule() # Can now access IPhReduplicationRule-specific methods/properties
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like has_redup_parts and redup_parts instead
- property concrete¶
Get the raw concrete interface object.
For advanced users who need to access the underlying C# interface directly without going through wrapper properties.
- Returns:
The concrete interface object (IPhRegularRule, IPhMetathesisRule, or IPhReduplicationRule depending on the rule’s actual type).
Example:
# Direct access to concrete interface concrete = rule_obj.concrete rhs = concrete.RightHandSidesOS # PhRegularRule property
Notes
For power users only
Bypasses the wrapper’s abstraction
Normal users should prefer wrapper properties like has_output_specs, output_specs, etc.
flexicon.code.Grammar.prohibition_collection module¶
Smart collection class for ad hoc morphosyntactic prohibitions.
This module provides ProhibitionCollection, a smart collection that manages ad hoc prohibitions while showing type diversity and supporting unified operations across the three concrete types: - MoAdhocProhibGr (Grammatical feature prohibitions) - MoAdhocProhibMorph (Morpheme co-occurrence prohibitions) - MoAdhocProhibAllomorph (Allomorph co-occurrence prohibitions)
- Problem:
GetAllAdhocCoProhibitions() returns objects with multiple concrete implementations. Users need to:
See which types are in the collection
Filter by type if they want to
Work with all types together without manual casting
Filter by common properties that work across all types
- Solution:
ProhibitionCollection provides:
__str__() showing type breakdown
by_type() filtering to specific concrete types
filter() for filtering by prohibition type
grammatical_prohibitions(), morpheme_prohibitions(), allomorph_prohibitions() convenience filters
where() for custom filtering
Chainable filtering: prohibitions.morpheme_prohibitions()
Example:
from flexlibs2.code.Grammar.prohibition_collection import ProhibitionCollection
# GetAllAdhocCoProhibitions() now returns ProhibitionCollection
prohibitions = morphRuleOps.GetAllAdhocCoProhibitions()
print(prohibitions) # Shows type breakdown
# ProhibitionCollection (12 total)
# MoAdhocProhibGr: 5 (42%)
# MoAdhocProhibMorph: 4 (33%)
# MoAdhocProhibAllomorph: 3 (25%)
# Filter by type
morph_only = prohibitions.morpheme_prohibitions()
print(len(morph_only)) # 4
# Filter by custom predicate
named_prohibitions = prohibitions.where(lambda p: p.guid is not None)
# Chain filters
morph_with_guid = prohibitions.morpheme_prohibitions().where(
lambda p: p.guid is not None
)
# Iterate
for prohib in prohibitions:
print(prohib.prohibition_type)
- class flexicon.code.Grammar.prohibition_collection.ProhibitionCollection(items=None)[source]¶
Bases:
SmartCollectionSmart collection for ad hoc prohibitions with type-aware filtering.
Manages collections of AdhocProhibition wrapper objects with type-aware display and filtering capabilities. Supports filtering by prohibition type and custom predicates.
- Variables:
_items – List of AdhocProhibition wrapper objects
Example:
prohibitions = morphRuleOps.GetAllAdhocCoProhibitions() print(prohibitions) # Shows type breakdown morph = prohibitions.morpheme_prohibitions() # Type filter custom = prohibitions.where(lambda p: p.is_morpheme_prohibition)
- filter(prohibition_type=None, where=None)[source]¶
Filter the collection by prohibition type.
Supports filtering by prohibition type (grammatical, morpheme, allomorph). For complex filtering, use where().
- Parameters:
prohibition_type (str, optional) – Filter by type. Accepts: - “Grammatical” or “grammatical” - “Morpheme” or “morpheme” - “Allomorph” or “allomorph” - “Gr” (abbreviation for Grammatical) - “Morph” (abbreviation for Morpheme) - “Allo” (abbreviation for Allomorph)
where (callable, optional) – Custom predicate function. If provided, prohibition_type is ignored.
- Returns:
New collection with filtered items.
- Return type:
Example:
# Filter by type name morph_prohibitions = prohibitions.filter(prohibition_type="Morpheme") # Filter by abbreviation gr_prohibitions = prohibitions.filter(prohibition_type="Gr") # Custom filtering has_guid = prohibitions.where(lambda p: p.guid is not None) # Chain filters morph_with_guid = prohibitions.filter( prohibition_type="Morpheme" ).where(lambda p: p.guid is not None)
Notes
prohibition_type is case-insensitive
Abbreviations: “Gr”, “Morph”, “Allo”
where() takes precedence over prohibition_type
Returns new collection (doesn’t modify original)
Use where() for complex custom filtering
- where(predicate)[source]¶
Filter using a custom predicate function.
For filtering by complex criteria or properties not supported by filter().
- Parameters:
predicate (callable) – Function that takes an AdhocProhibition and returns True to include it in the result.
- Returns:
- New collection with items matching the
predicate.
- Return type:
Example:
# Prohibitions with non-empty GUID has_guid = prohibitions.where(lambda p: p.guid is not None) # Combining conditions morph_with_guid = prohibitions.where( lambda p: p.is_morpheme_prohibition and p.guid is not None ) # Type checking combined with other criteria non_grammatical = prohibitions.where( lambda p: p.class_type != "MoAdhocProhibGr" )
Notes
Predicate receives each AdhocProhibition object
Return True to include in result, False to exclude
For simple filters (type), use filter() instead
- grammatical_prohibitions()[source]¶
Get only the grammatical feature prohibitions from the collection.
Convenience method for filtering to MoAdhocProhibGr objects only.
- Returns:
- New collection with only MoAdhocProhibGr
objects.
- Return type:
Example:
grammatical = prohibitions.grammatical_prohibitions() print(f"Found {len(grammatical)} grammatical prohibitions") # Chain with other filters with_guid = prohibitions.grammatical_prohibitions().where( lambda p: p.guid is not None )
Notes
Equivalent to filter(prohibition_type=”Grammatical”)
Use is_grammatical_prohibition on individual items to check type
- morpheme_prohibitions()[source]¶
Get only the morpheme co-occurrence prohibitions from the collection.
Convenience method for filtering to MoAdhocProhibMorph objects only.
- Returns:
- New collection with only MoAdhocProhibMorph
objects.
- Return type:
Example:
morpheme = prohibitions.morpheme_prohibitions() print(f"Found {len(morpheme)} morpheme prohibitions") # Chain with other filters morph_subset = prohibitions.morpheme_prohibitions().where( lambda p: p.MorphemeRA is not None )
Notes
Equivalent to filter(prohibition_type=”Morpheme”)
Use is_morpheme_prohibition on individual items to check type
- allomorph_prohibitions()[source]¶
Get only the allomorph variant prohibitions from the collection.
Convenience method for filtering to MoAdhocProhibAllomorph objects only.
- Returns:
- New collection with only
MoAdhocProhibAllomorph objects.
- Return type:
Example:
allomorph = prohibitions.allomorph_prohibitions() print(f"Found {len(allomorph)} allomorph prohibitions") # Chain with other filters allo_subset = prohibitions.allomorph_prohibitions().where( lambda p: p.AllomorphRA is not None )
Notes
Equivalent to filter(prohibition_type=”Allomorph”)
Use is_allomorph_prohibition on individual items to check type
flexicon.code.Grammar.rule_collection module¶
Smart collection class for phonological rules.
This module provides RuleCollection, a smart collection that manages phonological rules while showing type diversity and supporting unified operations across the three concrete types: - PhRegularRule - PhMetathesisRule - PhReduplicationRule
- Problem:
GetAll() returns objects with multiple concrete implementations. Users need to: - See which types are in the collection - Filter by type if they want to - Work with all types together without manual casting - Filter by common properties that work across all types
- Solution:
RuleCollection provides: - __str__() showing type breakdown - by_type() filtering to specific concrete types - filter() for common criteria (name_contains, direction, stratum) - Convenience methods (regular_rules(), metathesis_rules(), redup_rules()) - Chainable filtering: rules.regular_rules().filter(name_contains=’voicing’)
Example:
from flexlibs2.code.Grammar.rule_collection import RuleCollection
# GetAll() now returns RuleCollection
rules = phonRuleOps.GetAll()
print(rules) # Shows type breakdown
# RuleCollection (12 total)
# PhRegularRule: 7 (58%)
# PhMetathesisRule: 3 (25%)
# PhReduplicationRule: 2 (17%)
# Filter by type
regular_only = rules.regular_rules()
print(len(regular_only)) # 7
# Filter by name
voicing_rules = rules.filter(name_contains='voicing')
# Chain filters
voicing_regular = rules.regular_rules().filter(name_contains='voicing')
# Iterate
for rule in rules:
print(rule.name)
- class flexicon.code.Grammar.rule_collection.RuleCollection(items=None)[source]¶
Bases:
SmartCollectionSmart collection for phonological rules with type-aware filtering.
Manages collections of phonological rules (PhonologicalRule wrapper objects) with type-aware display and filtering capabilities. Supports filtering by common properties (name, direction, stratum) and by concrete type.
- Variables:
_items – List of PhonologicalRule wrapper objects
Example:
rules = phonRuleOps.GetAll() # Returns RuleCollection print(rules) # Shows type breakdown regular = rules.regular_rules() # Filter to PhRegularRule voicing = rules.filter(name_contains='voicing') # Name filter both = rules.regular_rules().filter(name_contains='voicing') # Chain
- filter(name_contains=None, direction=None, stratum=None, where=None)[source]¶
Filter the collection by common rule properties.
Supports filtering by properties that work across all rule types (name, direction, stratum). For complex filtering, use where().
- Parameters:
name_contains (str, optional) – Filter to rules whose name contains this string (case-sensitive).
direction (int, optional) – Filter by direction (0=L-R, 1=R-L, 2=simultaneous).
stratum – Filter by stratum object or GUID. Can be an IMoStratum object or the stratum GUID as string.
where (callable, optional) – Custom predicate function. If provided, other criteria are ignored.
- Returns:
New collection with filtered items.
- Return type:
Example:
# Filter by name voicing_rules = rules.filter(name_contains='voicing') # Filter by direction ltr_rules = rules.filter(direction=0) # Filter by stratum stratum = project.lp.MorphologicalDataOA.StrataOS[0] stratum_rules = rules.filter(stratum=stratum) # Custom filtering high_rules = rules.where(lambda r: r.Direction == 0) # Chain filters voicing_ltr = rules.filter(name_contains='voicing').filter(direction=0)
Notes
name_contains is case-sensitive
All criteria are AND-ed together unless only one is provided
where() takes precedence over other criteria
Returns new collection (doesn’t modify original)
Use where() for complex custom filtering
- where(predicate)[source]¶
Filter using a custom predicate function.
For filtering by complex criteria or properties not supported by filter().
- Parameters:
predicate (callable) – Function that takes a PhonologicalRule and returns True to include it in the result.
- Returns:
New collection with items matching the predicate.
- Return type:
Example:
# Complex predicate: rules with more than 2 input contexts complex_rules = rules.where(lambda r: len(r.input_contexts) > 2) # Combining conditions regular_with_contexts = rules.where( lambda r: r.has_output_specs and len(r.input_contexts) > 1 ) # Type checking combined with other criteria non_regular = rules.where(lambda r: r.class_type != 'PhRegularRule')
Notes
Predicate receives each PhonologicalRule object
Return True to include in result, False to exclude
For simple filters (name, direction), use filter() instead
- regular_rules()[source]¶
Get only the regular (PhRegularRule) rules from the collection.
Convenience method for filtering to PhRegularRule objects only.
- Returns:
New collection with only PhRegularRule objects.
- Return type:
Example:
regular = rules.regular_rules() print(f"Found {len(regular)} regular rules") # Chain with other filters voicing_regular = rules.regular_rules().filter(name_contains='voicing')
Notes
Equivalent to by_type(‘PhRegularRule’)
Regular rules have RightHandSidesOS (output specifications)
Use has_output_specs on individual rules to check type
- metathesis_rules()[source]¶
Get only the metathesis (PhMetathesisRule) rules from the collection.
Convenience method for filtering to PhMetathesisRule objects only.
- Returns:
New collection with only PhMetathesisRule objects.
- Return type:
Example:
metathesis = rules.metathesis_rules() print(f"Found {len(metathesis)} metathesis rules") # Chain with other filters initial_metathesis = rules.metathesis_rules().filter(name_contains='initial')
Notes
Equivalent to by_type(‘PhMetathesisRule’)
Metathesis rules swap segments (left <-> right)
Use has_metathesis_parts on individual rules to check type
- redup_rules()[source]¶
Get only the reduplication (PhReduplicationRule) rules from the collection.
Convenience method for filtering to PhReduplicationRule objects only.
- Returns:
New collection with only PhReduplicationRule objects.
- Return type:
Example:
redup = rules.redup_rules() print(f"Found {len(redup)} reduplication rules") # Chain with other filters prefix_redup = rules.redup_rules().filter(name_contains='prefix')
Notes
Equivalent to by_type(‘PhReduplicationRule’)
Reduplication rules repeat segments
Use has_redup_parts on individual rules to check type