flexicon.code.System package¶
Submodules¶
flexicon.code.System.AnnotationDefOperations module¶
- class flexicon.code.System.AnnotationDefOperations.AnnotationDefOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing annotation type definitions in a FieldWorks project.
Annotation definitions specify the types and characteristics of annotations (notes, comments) that can be created in FLEx. They define properties such as name, help text, whether users can create instances, and whether multiple annotations of this type are allowed.
This class should be accessed via FLExProject.AnnotationDef property.
Usage:
from flexlibs2 import FLExProject project = FLExProject() project.OpenProject("my project", writeEnabled=True) # Get all annotation definitions for anno_def in project.AnnotationDef.GetAll(): name = project.AnnotationDef.GetName(anno_def) anno_type = project.AnnotationDef.GetAnnotationType(anno_def) print(f"{name}: {anno_type}") # Find a specific annotation definition todo_def = project.AnnotationDef.Find("To Do") if todo_def: # Get properties help_text = project.AnnotationDef.GetHelpString(todo_def) user_can_create = project.AnnotationDef.GetUserCanCreate(todo_def) print(f"Help: {help_text}") print(f"User creatable: {user_can_create}") # Create a new annotation definition custom_def = project.AnnotationDef.Create( "Review Required", CmAnnotationType.katGeneralNote, "en" ) project.AnnotationDef.SetHelpString(custom_def, "Mark entries that need review", "en") project.AnnotationDef.SetUserCanCreate(custom_def, True) # Get annotation definitions by type for note_def in project.AnnotationDef.FindByType( CmAnnotationType.katGeneralNote): name = project.AnnotationDef.GetName(note_def) print(f"Note type: {name}") project.CloseProject()
- GetAll(**kwargs)¶
- Create(*args, **kwargs)¶
Automatically instantiate and call the method.
- Delete(*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.
- GetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetHelpString(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetHelpString(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAnnotationType(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetInstanceOf(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetUserCanCreate(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetUserCanCreate(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetMultiple(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetMultiple(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetPrompt(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetPrompt(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetCopyCutPasteAllowed(*args, **kwargs)¶
Automatically instantiate and call the method.
- FindByType(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetUserCreatableTypes(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetGuid(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDateCreated(*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.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.System.CheckOperations module¶
- class flexicon.code.System.CheckOperations.CheckOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing consistency checks and validation in a FieldWorks project.
Consistency checks help identify data quality issues, missing information, and inconsistencies in lexical entries, texts, and other project data. Check types are managed as possibility list items.
This class should be accessed via FLExProject.Checks property.
Usage:
from flexlibs2 import FLExProject project = FLExProject() project.OpenProject("my project", writeEnabled=True) # Get all check types for check_type in project.Checks.GetAllCheckTypes(): name = project.Checks.GetName(check_type) enabled = project.Checks.IsEnabled(check_type) print(f"{name}: {'Enabled' if enabled else 'Disabled'}") # Create a custom check type check = project.Checks.CreateCheckType("Missing Gloss Check") project.Checks.SetDescription(check, "Verify all senses have glosses") project.Checks.EnableCheck(check) # Run a check and get results project.Checks.RunCheck(check) errors = project.Checks.GetErrorCount(check) warnings = project.Checks.GetWarningCount(check) print(f"Check found {errors} errors and {warnings} warnings") # Get items with issues items = project.Checks.FindItemsWithIssues(check) for item in items: issues = project.Checks.GetIssuesForObject(check, item) print(f"Issues: {len(issues)}") project.CloseProject()
- GetAllCheckTypes(*args, **kwargs)¶
Automatically instantiate and call the method.
- CreateCheckType(*args, **kwargs)¶
Automatically instantiate and call the method.
- DeleteCheckType(*args, **kwargs)¶
Automatically instantiate and call the method.
- FindCheckType(*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.
- RunCheck(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetCheckStatus(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetLastRun(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetCheckResults(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetErrorCount(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetWarningCount(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetEnabledChecks(*args, **kwargs)¶
Automatically instantiate and call the method.
- EnableCheck(*args, **kwargs)¶
Automatically instantiate and call the method.
- DisableCheck(*args, **kwargs)¶
Automatically instantiate and call the method.
- IsEnabled(*args, **kwargs)¶
Automatically instantiate and call the method.
- FindItemsWithIssues(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetIssuesForObject(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetGuid(*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.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.System.CustomFieldOperations module¶
- class flexicon.code.System.CustomFieldOperations.CustomFieldOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing custom fields in a FieldWorks project.
Custom fields extend the FLEx data model by allowing users to add additional fields to various object classes (entries, senses, examples, etc.). These fields can store strings, integers, dates, or references to lists/objects.
- Field Types:
String: Single-line text (one writing system)
MultiString: Multi-line text (multiple writing systems)
MultiUnicode: Unicode text (multiple writing systems)
Integer: Whole number (e.g., frequency counts)
GenDate: Date with flexible precision
ReferenceAtom: Single-select from predefined list (dropdown menu)
ReferenceCollection: Multi-select from predefined list (checkboxes)
This class should be accessed via FLExProject.CustomFields property.
Usage:
from flexlibs2 import FLExProject project = FLExProject() project.OpenProject("my project", writeEnabled=True) # Get all custom fields for entries entry_fields = project.CustomFields.GetAllFields("LexEntry") for field_id, label in entry_fields: print(f"Field: {label} (ID: {field_id})") # Create a new custom field field_id = project.CustomFields.CreateField( "LexEntry", "DialectVariant", "MultiString", "vernacular" ) # Get and set field values entry = project.LexEntry.Find("run") project.CustomFields.SetValue(entry, "DialectVariant", "runnin'", "en") value = project.CustomFields.GetValue(entry, "DialectVariant", "en") print(value) # "runnin'" project.CloseProject()
- GetAllFields(*args, **kwargs)¶
Automatically instantiate and call the method.
- CreateField(*args, **kwargs)¶
Automatically instantiate and call the method.
- DeleteField(*args, **kwargs)¶
Automatically instantiate and call the method.
- FindField(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetFieldType(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetFieldName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetFieldName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetValue(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetValue(*args, **kwargs)¶
Automatically instantiate and call the method.
- ClearValue(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetListValues(*args, **kwargs)¶
Automatically instantiate and call the method.
- AddListValue(*args, **kwargs)¶
Automatically instantiate and call the method.
- RemoveListValue(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetOwnerClass(*args, **kwargs)¶
Automatically instantiate and call the method.
- IsMultiString(*args, **kwargs)¶
Automatically instantiate and call the method.
- IsListType(*args, **kwargs)¶
Automatically instantiate and call the method.
- IsStringType(*args, **kwargs)¶
Automatically instantiate and call the method.
- ClearField(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetListFieldSingle(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetListFieldMultiple(*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.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.System.ProjectSettingsOperations module¶
- class flexicon.code.System.ProjectSettingsOperations.ProjectSettingsOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing project-level settings and configuration in a FieldWorks project.
Project settings include metadata (name, description), language settings (vernacular and analysis writing systems), interface preferences, default fonts, and file paths for external resources.
This class should be accessed via FLExProject.ProjectSettings property.
Usage:
from flexlibs2 import FLExProject project = FLExProject() project.OpenProject("my project", writeEnabled=True) # Get project information name = project.ProjectSettings.GetProjectName() description = project.ProjectSettings.GetDescription("en") print(f"Project: {name}") print(f"Description: {description}") # Set project metadata project.ProjectSettings.SetProjectName("My Linguistic Study") project.ProjectSettings.SetDescription( "Documentation of endangered language", "en" ) # Language settings vern_wss = project.ProjectSettings.GetVernacularWSs() anal_wss = project.ProjectSettings.GetAnalysisWSs() print(f"Vernacular WSs: {vern_wss}") print(f"Analysis WSs: {anal_wss}") # Set default writing systems project.ProjectSettings.SetDefaultVernacular("qaa-x-kal") project.ProjectSettings.SetDefaultAnalysis("en") # Configure default fonts project.ProjectSettings.SetDefaultFont("qaa-x-kal", "Charis SIL") project.ProjectSettings.SetDefaultFontSize("qaa-x-kal", 14) # External file paths linked_path = project.ProjectSettings.GetLinkedFilesRootDir() print(f"Linked files: {linked_path}") # Metadata created = project.ProjectSettings.GetDateCreated() modified = project.ProjectSettings.GetDateModified() print(f"Created: {created}") print(f"Last modified: {modified}") project.CloseProject()
- GetProjectName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetProjectName(*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.
- GetVernacularWSs(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAnalysisWSs(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDefaultVernacular(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDefaultAnalysis(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetInterfaceLanguage(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetInterfaceLanguage(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDefaultFont(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDefaultFont(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDefaultFontSize(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDefaultFontSize(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetLinkedFilesRootDir(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetLinkedFilesRootDir(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetExtLinkRootDir(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetExtLinkRootDir(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAnalysisWritingSystems(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetVernacularWritingSystems(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetProjectGuid(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetProjectDescription(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetExternalLink(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAnalysisWritingSystem(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetVernacularWritingSystem(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDateCreated(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDateModified(*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.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.System.WritingSystemOperations module¶
- class flexicon.code.System.WritingSystemOperations.WritingSystemOperations(project)[source]¶
Bases:
BaseOperationsThis class provides operations for managing writing systems in a FieldWorks project.
Writing systems define how text is displayed, including language, script, font settings, and directionality (left-to-right or right-to-left).
This class should be accessed via FLExProject.WritingSystems property.
Usage:
from flexlibs2 import FLExProject project = FLExProject() project.OpenProject("my project", writeEnabled=True) # Get all writing systems for ws in project.WritingSystems.GetAll(): name = project.WritingSystems.GetDisplayName(ws) tag = project.WritingSystems.GetLanguageTag(ws) print(f"{name} ({tag})") # Get vernacular and analysis writing systems vern_wss = project.WritingSystems.GetVernacular() anal_wss = project.WritingSystems.GetAnalysis() # Configure a writing system ws = list(vern_wss)[0] project.WritingSystems.SetFontName(ws, "Charis SIL") project.WritingSystems.SetFontSize(ws, 12) project.WritingSystems.SetRightToLeft(ws, False) # Check and set defaults default_vern = project.WritingSystems.GetDefaultVernacular() default_anal = project.WritingSystems.GetDefaultAnalysis() project.CloseProject()
- GetAll(**kwargs)¶
- GetVernacular(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetAnalysis(*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.
- GetFontName(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetFontName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetFontSize(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetFontSize(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetRightToLeft(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetRightToLeft(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDefaultVernacular(*args, **kwargs)¶
Automatically instantiate and call the method.
- SetDefaultAnalysis(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDefaultVernacular(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDefaultAnalysis(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetDisplayName(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetLanguageTag(*args, **kwargs)¶
Automatically instantiate and call the method.
- Exists(*args, **kwargs)¶
Automatically instantiate and call the method.
- GetBestString(*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.
- CompareTo(*args, **kwargs)¶
Automatically instantiate and call the method.
flexicon.code.System.context_collection module¶
Smart collection class for phonological contexts.
This module provides ContextCollection, a smart collection that manages phonological contexts while showing type diversity and supporting unified operations across the multiple concrete types: - PhSimpleContextSeg - PhSimpleContextNC - PhComplexContextSeg - PhComplexContextNC - PhBoundaryContext
- Problem:
GetAll() or input_contexts 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:
ContextCollection provides: - __str__() showing type breakdown - by_type() filtering to specific concrete types - filter() for common criteria (context_name, type) - Convenience methods (simple_contexts(), complex_contexts(), boundary_contexts()) - Chainable filtering: contexts.simple_contexts().filter(name_contains=’word’)
Example:
from flexlibs2.code.System.context_collection import ContextCollection
# Rule's input contexts now wrapped in ContextCollection
contexts = rule.input_contexts # Returns ContextCollection
print(contexts) # Shows type breakdown
# ContextCollection (8 total)
# PhSimpleContextSeg: 4 (50%)
# PhBoundaryContext: 3 (37%)
# PhSimpleContextNC: 1 (13%)
# Filter by type
simple_only = contexts.simple_contexts()
print(len(simple_only)) # 5
# Filter by name
word_contexts = contexts.filter(name_contains='word')
# Chain filters
simple_word = contexts.simple_contexts().filter(name_contains='word')
# Iterate
for context in contexts:
print(context.context_name)
- class flexicon.code.System.context_collection.ContextCollection(items=None)[source]¶
Bases:
SmartCollectionSmart collection for phonological contexts with type-aware filtering.
Manages collections of phonological contexts (PhonologicalContext wrapper objects) with type-aware display and filtering capabilities. Supports filtering by common properties (name, type) and by concrete type.
- Variables:
_items – List of PhonologicalContext wrapper objects
Example:
contexts = rule.input_contexts # Returns ContextCollection print(contexts) # Shows type breakdown simple = contexts.simple_contexts() # Filter to simple contexts word = contexts.filter(name_contains='word') # Name filter both = contexts.simple_contexts().filter(name_contains='word') # Chain
- filter(name_contains=None, where=None)[source]¶
Filter the collection by common context properties.
Supports filtering by properties that work across all context types (name). For complex filtering, use where().
- Parameters:
name_contains (str, optional) – Filter to contexts whose name contains this string (case-sensitive).
where (callable, optional) – Custom predicate function. If provided, other criteria are ignored.
- Returns:
New collection with filtered items.
- Return type:
Example:
# Filter by name word_contexts = contexts.filter(name_contains='word') # Custom filtering simple_word = contexts.where( lambda c: c.is_simple_context and 'word' in c.context_name ) # Chain filters simple_word = contexts.simple_contexts().filter(name_contains='word')
Notes
name_contains is case-sensitive
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 PhonologicalContext and returns True to include it in the result.
- Returns:
New collection with items matching the predicate.
- Return type:
Example:
# Complex predicate: simple segment contexts only simple_segs = contexts.where(lambda c: c.is_simple_context_seg) # Combining conditions simple_with_name = contexts.where( lambda c: c.is_simple_context and c.context_name )
Notes
Predicate receives each PhonologicalContext object
Return True to include in result, False to exclude
For simple filters (name), use filter() instead
- simple_contexts()[source]¶
Get only the simple contexts (segment or natural class).
Convenience method for filtering to simple contexts (either PhSimpleContextSeg or PhSimpleContextNC).
- Returns:
New collection with only simple context objects.
- Return type:
Example:
simple = contexts.simple_contexts() print(f"Found {len(simple)} simple contexts") # Chain with other filters simple_word = contexts.simple_contexts().filter(name_contains='word')
Notes
Includes both PhSimpleContextSeg and PhSimpleContextNC
Use simple_context_seg() or simple_context_nc() to distinguish
- simple_context_seg()[source]¶
Get only the simple segment contexts.
Convenience method for filtering to PhSimpleContextSeg objects only.
- Returns:
New collection with only simple segment contexts.
- Return type:
Example:
segs = contexts.simple_context_seg() for seg_ctx in segs: segment = seg_ctx.segment print(f"Segment: {segment}")
Notes
Simple segment contexts represent a single segment
Equivalent to by_type(‘PhSimpleContextSeg’)
- simple_context_nc()[source]¶
Get only the simple natural class contexts.
Convenience method for filtering to PhSimpleContextNC objects only.
- Returns:
New collection with only simple natural class contexts.
- Return type:
Example:
ncs = contexts.simple_context_nc() for nc_ctx in ncs: nc = nc_ctx.natural_class print(f"Natural Class: {nc}")
Notes
Simple natural class contexts represent a natural class
Equivalent to by_type(‘PhSimpleContextNC’)
- complex_contexts()[source]¶
Get only the complex contexts (segment or natural class).
Convenience method for filtering to complex contexts (either PhComplexContextSeg or PhComplexContextNC).
- Returns:
New collection with only complex context objects.
- Return type:
Example:
complex = contexts.complex_contexts() print(f"Found {len(complex)} complex contexts") # Chain with other filters complex_word = contexts.complex_contexts().filter(name_contains='word')
Notes
Includes both PhComplexContextSeg and PhComplexContextNC
Use complex_context_seg() or complex_context_nc() to distinguish
- complex_context_seg()[source]¶
Get only the complex segment contexts.
Convenience method for filtering to PhComplexContextSeg objects only.
- Returns:
New collection with only complex segment contexts.
- Return type:
Example:
segs = contexts.complex_context_seg() print(f"Found {len(segs)} complex segment contexts")
Notes
Equivalent to by_type(‘PhComplexContextSeg’)
Complex segment contexts have multiple segment specifications
- complex_context_nc()[source]¶
Get only the complex natural class contexts.
Convenience method for filtering to PhComplexContextNC objects only.
- Returns:
New collection with only complex natural class contexts.
- Return type:
Example:
ncs = contexts.complex_context_nc() print(f"Found {len(ncs)} complex natural class contexts")
Notes
Equivalent to by_type(‘PhComplexContextNC’)
Complex natural class contexts have multiple natural class specifications
- boundary_contexts()[source]¶
Get only the boundary contexts.
Convenience method for filtering to PhBoundaryContext objects only.
- Returns:
New collection with only boundary context objects.
- Return type:
Example:
boundaries = contexts.boundary_contexts() for bctx in boundaries: btype = bctx.boundary_type print(f"Boundary type: {btype}")
Notes
Boundary contexts represent word/morpheme boundaries
Equivalent to by_type(‘PhBoundaryContext’)
flexicon.code.System.phonological_context module¶
Wrapper class for phonological context objects with unified interface.
This module provides PhonologicalContext, a wrapper class that transparently handles the multiple concrete types of phonological contexts: - PhSimpleContextSeg: Simple context with single segment - PhSimpleContextNC: Simple context with natural class - PhComplexContextSeg: Complex context with segments - PhComplexContextNC: Complex context with natural class - PhBoundaryContext: Boundary context
All share a base interface IPhPhonContext or similar.
- Problem:
Phonological contexts have different properties depending on their concrete type: - PhSimpleContextSeg: Represents a single segment - PhSimpleContextNC: Represents a natural class - PhComplexContextSeg: Complex segment specifications - PhComplexContextNC: Complex natural class specifications - PhBoundaryContext: Word/morpheme boundaries
All have Name, Description, and other common properties.
Users working with mixed collections need to check ClassName and cast to access type-specific properties, which is error-prone and verbose.
- Solution:
PhonologicalContext wrapper provides: - Simple properties for common features (context_name, description) - Capability check properties (is_simple_context_seg, is_boundary, etc.) - Property access that works across all types - Optional: Methods for advanced users who know C# types
Example:
from flexlibs2.code.System.phonological_context import PhonologicalContext
# Wrap a context from a rule's input contexts
context = rule.input_contexts[0] # Typed as IPhPhonContext
wrapped = PhonologicalContext(context)
# Access common properties
print(wrapped.context_name) # Works for all context types
# Check capabilities
if wrapped.is_simple_context_seg:
print("This is a simple segment context")
if wrapped.is_boundary_context:
print("This is a boundary context")
# Optional: Advanced users can access concrete types
if wrapped.as_simple_context_seg():
concrete = wrapped.as_simple_context_seg()
# Use concrete interface for advanced operations
- class flexicon.code.System.phonological_context.PhonologicalContext(lcm_context)[source]¶
Bases:
LCMObjectWrapperWrapper for phonological context objects providing unified interface access.
Handles the multiple concrete types of phonological contexts transparently, providing common properties and capability checks without exposing ClassName or casting.
- Variables:
_obj – The base interface object (IPhPhonContext)
_concrete – The concrete type object (IPhSimpleContextSeg, IPhSimpleContextNC, IPhComplexContextSeg, IPhComplexContextNC, IPhBoundaryContext, etc.)
Example:
context = rule.input_contexts[0] wrapped = PhonologicalContext(context) print(wrapped.context_name) if wrapped.is_simple_context_seg: print("Simple segment context")
- property context_name: str¶
Get the context’s name or identifier.
- Returns:
The context name/identifier, or empty string if not set.
- Return type:
str
Example:
print(f"Context: {wrapped.context_name}")
Notes
For simple contexts, this may be the segment or natural class name
For boundary contexts, this identifies the boundary type
- property description: str¶
Get the context’s description if available.
- Returns:
The description, or empty string if not set.
- Return type:
str
Example:
print(f"Context: {wrapped.description}")
- property is_simple_context_seg¶
Check if this is a simple segment context.
- Returns:
True if this is a PhSimpleContextSeg.
- Return type:
bool
Example:
if wrapped.is_simple_context_seg: print("Simple segment context")
Notes
Simple segment contexts represent a single segment
Use segment property to access the actual segment
- property is_simple_context_nc¶
Check if this is a simple natural class context.
- Returns:
True if this is a PhSimpleContextNC.
- Return type:
bool
Example:
if wrapped.is_simple_context_nc: print("Simple natural class context")
Notes
Simple natural class contexts represent a natural class
Use natural_class property to access the actual natural class
- property is_simple_context¶
Check if this is any simple context (segment or natural class).
- Returns:
True if this is either PhSimpleContextSeg or PhSimpleContextNC.
- Return type:
bool
Example:
if wrapped.is_simple_context: print("This is a simple context")
Notes
Convenience property for checking if context is “simple”
Use is_simple_context_seg or is_simple_context_nc for type specificity
- property is_complex_context_seg¶
Check if this is a complex segment context.
- Returns:
True if this is a PhComplexContextSeg.
- Return type:
bool
Example:
if wrapped.is_complex_context_seg: print("Complex segment context")
Notes
Complex segment contexts have multiple segment specifications
- property is_complex_context_nc¶
Check if this is a complex natural class context.
- Returns:
True if this is a PhComplexContextNC.
- Return type:
bool
Example:
if wrapped.is_complex_context_nc: print("Complex natural class context")
Notes
Complex natural class contexts have multiple natural class specifications
- property is_complex_context¶
Check if this is any complex context (segment or natural class).
- Returns:
True if this is either PhComplexContextSeg or PhComplexContextNC.
- Return type:
bool
Example:
if wrapped.is_complex_context: print("This is a complex context")
Notes
Convenience property for checking if context is “complex”
Use is_complex_context_seg or is_complex_context_nc for type specificity
- property is_boundary_context¶
Check if this is a boundary context.
- Returns:
True if this is a PhBoundaryContext.
- Return type:
bool
Example:
if wrapped.is_boundary_context: print("Word/morpheme boundary context")
Notes
Boundary contexts represent word or morpheme boundaries
Different from other context types in purpose and properties
- property segment: object | None¶
Get the segment from a simple segment context.
- Returns:
The segment object if this is a PhSimpleContextSeg, None otherwise.
Example:
if wrapped.is_simple_context_seg: seg = wrapped.segment if seg: print(f"Segment: {seg.Name}")
Notes
Only meaningful for PhSimpleContextSeg
Returns None for other context types
- property natural_class: object | None¶
Get the natural class from a simple natural class context.
- Returns:
The natural class object if this is a PhSimpleContextNC, None otherwise.
Example:
if wrapped.is_simple_context_nc: nc = wrapped.natural_class if nc: print(f"Natural Class: {nc.Name}")
Notes
Only meaningful for PhSimpleContextNC
Returns None for other context types
- property boundary_type¶
Get the boundary type from a boundary context.
- Returns:
The boundary type (0=word, 1=morpheme, etc.), or -1 if not applicable.
- Return type:
int
Example:
if wrapped.is_boundary_context: btype = wrapped.boundary_type print(f"Boundary type: {btype}")
Notes
Only meaningful for PhBoundaryContext
Different boundary types have different values
- as_simple_context_seg()[source]¶
Cast to IPhSimpleContextSeg if this is a simple segment context.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not a PhSimpleContextSeg.
- Returns:
- The concrete interface if this is a
PhSimpleContextSeg, None otherwise.
- Return type:
IPhSimpleContextSeg or None
Example:
if context_obj.as_simple_context_seg(): concrete = context_obj.as_simple_context_seg() # Can now access IPhSimpleContextSeg-specific methods/properties segment = concrete.SegmentRA # Advanced operations...
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like is_simple_context_seg and segment instead
- as_simple_context_nc()[source]¶
Cast to IPhSimpleContextNC if this is a simple natural class context.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not a PhSimpleContextNC.
- Returns:
- The concrete interface if this is a
PhSimpleContextNC, None otherwise.
- Return type:
IPhSimpleContextNC or None
Example:
if context_obj.as_simple_context_nc(): concrete = context_obj.as_simple_context_nc() # Can now access IPhSimpleContextNC-specific methods/properties
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like is_simple_context_nc and natural_class instead
- as_complex_context_seg()[source]¶
Cast to IPhComplexContextSeg if this is a complex segment context.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not a PhComplexContextSeg.
- Returns:
The concrete interface if applicable.
- Return type:
IPhComplexContextSeg or None
Example:
if context_obj.as_complex_context_seg(): concrete = context_obj.as_complex_context_seg() # Advanced operations...
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like is_complex_context_seg instead
- as_complex_context_nc()[source]¶
Cast to IPhComplexContextNC if this is a complex natural class context.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not a PhComplexContextNC.
- Returns:
The concrete interface if applicable.
- Return type:
IPhComplexContextNC or None
Example:
if context_obj.as_complex_context_nc(): concrete = context_obj.as_complex_context_nc() # Advanced operations...
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like is_complex_context_nc instead
- as_boundary_context()[source]¶
Cast to IPhBoundaryContext if this is a boundary context.
For advanced users who need direct access to the C# concrete interface. Returns None if this is not a PhBoundaryContext.
- Returns:
- The concrete interface if this is a
PhBoundaryContext, None otherwise.
- Return type:
IPhBoundaryContext or None
Example:
if context_obj.as_boundary_context(): concrete = context_obj.as_boundary_context() # Can now access IPhBoundaryContext-specific methods/properties
Notes
For users who know C# interfaces and want advanced control
Most users should use properties like is_boundary_context and boundary_type 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 (IPhSimpleContextSeg, IPhSimpleContextNC, IPhComplexContextSeg, IPhComplexContextNC, IPhBoundaryContext, etc., depending on the context’s actual type).
Example:
# Direct access to concrete interface concrete = context_obj.concrete segment = concrete.SegmentRA # PhSimpleContextSeg property
Notes
For power users only
Bypasses the wrapper’s abstraction
Normal users should prefer wrapper properties like is_simple_context_seg, segment, etc.