flexlibs library¶
FLExProject
class¶
- class flexlibs.FLExProject[source]¶
This class provides convenience methods for accessing a FieldWorks project by hiding some of the complexity of LCM. For functionality that isn’t provided here, LCM data and methods can be used directly via FLExProject.project, FLExProject.lp and FLExProject.lexDB; However, for long term use, new methods should be added to this class.
Usage:
from SIL.LCModel.Core.KernelInterfaces import ITsString, ITsStrBldr from SIL.LCModel.Core.Text import TsStringUtils fp = FLExProject() try: fp.OpenProject("my project", writeEnabled = True/False) except: #"Failed to open project" del fp WSHandle = fp.WSHandle('en') # Traverse the whole lexicon for lexEntry in fp.LexiconAllEntries(): headword = fp.LexiconGetHeadword(lexEntry) # Use get_String() and set_String() with text fields: lexForm = lexEntry.LexemeFormOA lexEntryValue = ITsString(lexForm.Form.get_String(WSHandle)).Text newValue = convert_headword(lexEntryValue) mkstr = TsStringUtils.MakeString(newValue, WSHandle) lexForm.Form.set_String(WSHandle, mkstr)
- BestStr(stringObj)[source]¶
Generic string extraction function returning the best Analysis or Vernacular string.
- BuildGotoURL(objectOrGuid)[source]¶
Builds a URL that can be used with os.startfile() to jump to the object in Fieldworks. This method currently supports:
Lexical Entries
Reversal Entries
Wordforms
Texts
- GetAllAnalysisWSs()[source]¶
Returns a set of language tags for all analysis writing systems used in this project.
- GetAllSemanticDomains(flat=False)[source]¶
Returns a nested or flat list of all Semantic Domains defined in this project. The list is ordered.
Return items are objects with properties/methods:
Hvo - ID (value not the same across projects)
Guid - Global Unique ID (same across all projects)
ToString() - String representation of the semantic domain.
- GetAllVernacularWSs()[source]¶
Returns a set of language tags for all vernacular writing systems used in this project.
- GetCustomFieldValue(senseOrEntryOrHvo, fieldID, languageTagOrHandle=None)[source]¶
Returns the field value for String, MultiString and Integer fields. Returns None for other field types. languageTagOrHandle only applies to MultiStrings; if None the best Analysis or Venacular string is returned.
Note: if the field is a vernacular WS field, then the languageTagOrHandle must be specified.
- GetDefaultVernacularWS()[source]¶
Returns the Default Vernacular Writing System: (Language-tag, Name)
- GetWritingSystems()[source]¶
Returns the Writing Systems that are active in this project as a list of tuples: (Name, Language-tag, Handle, IsVernacular). Use the Language-tag when specifying Writing System to other functions.
- LexiconAddTagToField(senseOrEntryOrHvo, fieldID, tag)[source]¶
Appends the tag string to the end of the given field in the sense or entry inserting a semicolon between tags. If the tag is already in the field then it isn’t added.
- LexiconAllEntries()[source]¶
Returns an iterator over all entries in the lexicon.
Each entry is of type:
SIL.LCModel.ILexEntry, which contains: - HomographNumber :: integer - HomographForm :: string - LexemeFormOA :: SIL.LCModel.Ling.MoForm - Form :: SIL.LCModel.MultiUnicodeAccessor - GetAlternative : Get String for given WS type - SetAlternative : Set string for given WS type - SensesOS :: Ordered collection of SIL.LCModel.Ling.LexSense - Gloss :: SIL.LCModel.MultiUnicodeAccessor - Definition :: SIL.LCModel.MultiStringAccessor - SenseNumber :: string - ExamplesOS :: Ordered collection of LexExampleSentence - Example :: MultiStringAccessor
- LexiconClearField(senseOrEntryOrHvo, fieldID)[source]¶
Clears the string field or all of the strings (writing systems) in a multi-string field. Can be used to clear out a custom field.
- LexiconEntryAnalysesCount(entry)[source]¶
Returns a count of the occurences of the entry in the text corpus.
NOTE: As of Fieldworks 8.0.10 this calculation can be slightly off (the same analysis in the same text segment is only counted once), but is the same as reported in Fieldworks in the Number of Analyses column. See LT-13997.
- LexiconFieldIsStringType(fieldID)[source]¶
Returns True if the given field is a simple string type suitable for use with LexiconAddTagToField(), otherwise returns False.
- LexiconGetCitationForm(entry, languageTagOrHandle=None)[source]¶
Returns the citation form for the entry in the Default Vernacular WS or other WS as specified by languageTagOrHandle.
- LexiconGetEntryCustomFieldNamed(fieldName)[source]¶
Return the entry-level field ID given its name.
NOTE: fieldName is case-sensitive.
- LexiconGetEntryCustomFields()[source]¶
Returns a list of the custom fields defined at Entry level. Each item in the list is a tuple of (flid, label)
- LexiconGetExample(example, languageTagOrHandle=None)[source]¶
Returns the example text in the Default Vernacular WS or other WS as specified by languageTagOrHandle.
- LexiconGetExampleTranslation(translation, languageTagOrHandle=None)[source]¶
Returns the translation of an example in the Default Analysis WS or other WS as specified by languageTagOrHandle.
NOTE: Analysis language translations of example sentences are stored as a collection (list). E.g.:
for translation in example.TranslationsOC: print (project.LexiconGetExampleTranslation(translation))
- LexiconGetFieldText(senseOrEntryOrHvo, fieldID, languageTagOrHandle=None)[source]¶
Return the text value for the given entry/sense and field ID. Provided for use with custom fields. Returns the empty string if the value is null. languageTagOrHandle only applies to MultiStrings; if None the default Analysis writing system is returned.
Note: if the field is a vernacular WS field, then the languageTagOrHandle must be specified.
For normal fields the object can be used directly with get_String(). E.g.:
lexForm = lexEntry.LexemeFormOA lexEntryValue = ITsString(lexForm.Form.get_String(WSHandle)).Text
- LexiconGetLexemeForm(entry, languageTagOrHandle=None)[source]¶
Returns the lexeme form for the entry in the Default Vernacular WS or other WS as specified by languageTagOrHandle.
- LexiconGetPronunciation(pronunciation, languageTagOrHandle=None)[source]¶
Returns the Form for the Pronunciation in the Default Vernacular WS or other WS as specified by languageTagOrHandle.
- LexiconGetSenseCustomFieldNamed(fieldName)[source]¶
Return the sense-level field ID given its name.
NOTE: fieldName is case-sensitive.
- LexiconGetSenseCustomFields()[source]¶
Returns a list of the custom fields defined at Sense level. Each item in the list is a tuple of (flid, label)
- LexiconGetSenseDefinition(sense, languageTagOrHandle=None)[source]¶
Returns the definition for the sense in the Default Analysis WS or other WS as specified by languageTagOrHandle.
- LexiconGetSenseGloss(sense, languageTagOrHandle=None)[source]¶
Returns the gloss for the sense in the Default Analysis WS or other WS as specified by languageTagOrHandle.
- LexiconGetSenseSemanticDomains(sense)[source]¶
Returns a list of Semantic Domain objects belonging to the sense. ToString() and Hvo are available.
- LexiconSetExample(example, newString, languageTagOrHandle=None)[source]¶
Set the Default Vernacular string for the given Example:
newString must be unicode.
languageTagOrHandle specifies a different writing system.
NOTE: using this function will lose any formatting that might have been present in the example string.
- LexiconSetFieldInteger(senseOrEntryOrHvo, fieldID, integer)[source]¶
Set the integer value for the given entry/sense and field ID. Provided for use with custom fields.
- LexiconSetFieldText(senseOrEntryOrHvo, fieldID, text, languageTagOrHandle=None)[source]¶
Set the text value for the given entry/sense and field ID. Provided for use with custom fields.
NOTE: writes the string in one writing system only (defaults to the default analysis WS.)
For normal fields the object can be used directly with set_String(). E.g.:
lexForm = lexEntry.LexemeFormOA mkstr = TsStringUtils.MakeString("text to write", WSHandle) lexForm.Form.set_String(WSHandle, mkstr)
- LexiconSetSenseGloss(sense, gloss, languageTagOrHandle=None)[source]¶
Set the Default Analysis gloss for the given sense:
gloss must be unicode.
languageTagOrHandle specifies a different writing system.
- ObjectCountFor(repository)[source]¶
Returns the number of objects in the given repository. repository is specified by the interface class, such as:
ITextRepository
ILexEntryRepository
(All repository names can be viewed by opening a project in LCMBrowser, which can be launched via the Help menu.)
- ObjectsIn(repository)[source]¶
Returns an iterator over all the objects in the given repository. repository is specified by the interface class, such as:
ITextRepository
ILexEntryRepository
Open a project in LCMBrowser to identify other repository names.
- OpenProject(projectName, writeEnabled=False)[source]¶
Open a project. The project must be closed with CloseProject() to save any changes, and release the lock.
- projectName:
Either the full path including “.fwdata” suffix, or
The name only, to open from the default project location.
- writeEnabled:
Enables changes to be written to the project, which will be saved on a call to CloseProject(). LCM will raise an exception if changes are attempted without opening the project in this mode.
- Note:
A call to OpenProject() may fail with a FP_FileLockedError exception if the project is open in Fieldworks (or another application). To avoid this, project sharing can be enabled within the Fieldworks Project Properties dialog. In the Sharing tab, turn on the option “Share project contents with programs on this computer”.
- ReversalEntries(languageTag)[source]¶
Returns an iterator for the reversal entries for the given language tag (eg ‘en’). Returns None if there is no reversal index for that writing system.
- ReversalGetForm(entry, languageTagOrHandle=None)[source]¶
Returns the citation form for the reversal entry in the Default Vernacular WS or other WS as specified by languageTagOrHandle.
- ReversalIndex(languageTag)[source]¶
Returns the ReversalIndex that matches the given languageTag string (eg ‘en’). Returns None if there is no reversal index for that writing system.
- ReversalSetForm(entry, form, languageTagOrHandle=None)[source]¶
Set the Default Analysis reversal form for the given reversal entry:
form must be unicode.
languageTagOrHandle can be used to specify a different writing system.
- TextsGetAll(supplyName=True, supplyText=True)[source]¶
A Generator that returns tuples of (Name, Text) where:
Name is the best vernacular or analysis name.
Text is a string with newlines separating paragraphs.
Passing supplyName/Text=False returns only the texts or names.
- UnpackNestedPossibilityList(possibilityList, flat=False)[source]¶
Returns a nested or flat list of a Fieldworks Possibility List.
- Return items are objects with properties/methods:
Hvo - ID (value not the same across projects)
Guid - Global Unique ID (same across all projects)
ToString() - String representation.