flexicon.code.Parser package¶
Submodules¶
flexicon.code.Parser.ParserOperations module¶
- flexicon.code.Parser.ParserOperations.REQUIRED_MEMBERS = ('HCParser(LcmCache)', 'Update()', 'Reset()', 'IsUpToDate()', 'ParseWord(string)', 'ParseWordXml(string)', 'TraceWordXml(string, IEnumerable<int>)')¶
Every member this facade calls, rendered the way the C# source spells it. Verified against the real installed component by tier A2 (tests/test_parser_reflective.py) BEFORE any of the behaviour below was written – Constitution Principle I. Reset() and IsUpToDate() had never been verified anywhere, in either repository, before that tier.
Deliberately NOT the same list as FlexToolsMCP’s src/flextoolsmcp/server/parser_probe.py. The two diverge in both directions and neither is a superset of the other: that module additionally requires the filing member, which is the write spine and which this read facade never binds; this list additionally requires the reset and currency members, which that module does not cover. Each check probes what its OWN surface binds, and CP2a changes zero lines of the other one (FR-041, Decision D1).
- class flexicon.code.Parser.ParserOperations.ParserAvailability(available: bool, reason: str, version: str | None = None)[source]¶
Bases:
objectWhether this project can reach the parser, and why not if it cannot.
Returned, never raised. Asking whether the parser is reachable succeeds on every machine, in every condition – a missing component, a component from another FieldWorks install, a component whose surface has moved, a permissions error on the directory, a pythonnet failure. That is SC-001, and it is the single property tier A1 exists to test.
This is the first degrading-with-reason return in flexicon. The package otherwise has exactly two behaviours, raise or silently become None, and neither is right here: a script that wants to know whether it can parse should be able to ask without guarding the question in a try block.
- Variables:
available (bool) – Whether the parser operations may be called.
reason (str) – Why not, when available is False. Empty when available. States WHAT WAS CHECKED and nothing more.
version (str or None) – The detected component version, or None when the component was never loaded. Reported, never compared.
Notes
version is REPORTED AND NEVER COMPARED AGAINST A MINIMUM (FR-006). A version floor is the check that looks reasonable in review and then refuses to run on the one machine whose FieldWorks build number sorts the wrong way. The gate is the two checks below, neither of which reads a number: same-installation, and the bound surface exists. A standing AST test on each side of the repository boundary asserts zero comparisons (tests/test_parser_structure.py, A1.2).
The same-installation check is DIRECTORY EQUALITY ONLY. See GetAvailability for the limit of what that proves.
Example
>>> status = project.Parser.GetAvailability() >>> if not status.available: ... print(f"No parser: {status.reason}") ... else: ... print(f"Parser {status.version} ready") Parser 9.3.10 ready
See also
ParserOperations.GetAvailability
- available: bool¶
- reason: str¶
- version: str | None = None¶
- class flexicon.code.Parser.ParserOperations.ParserOperations(project)[source]¶
Bases:
BaseOperationsREAD-ONLY access to the FieldWorks morphological parser.
Reached as
project.Parser. Ask a word whether it parses, get the parser’s structured answer, or trace an attempt to see why it failed.THIS SURFACE IS READ-ONLY BY CONSTRUCTION, AND THAT IS LOAD-BEARING. There is no operation here that records, files or otherwise writes a parse result back into the project, and there is no transaction and no write-enable check anywhere in this module – because there is nothing to guard. If you are about to add a method that persists a parse, stop: the read-only safety claim made by every caller of this surface rests on that absence, and a standing test enumerates the public surface by set equality to keep it true (tests/test_parser_offline.py, A1.4). Persisting a parse is a later checkpoint’s work and arrives with its own guards.
THE EXACT LIMIT OF THAT CLAIM, since a caller is entitled to know where it stops. “Read-only” covers everything this class ADDS – all six methods above. It does not extend to the generic reordering helpers every Operations class inherits from BaseOperations. Four of them (Sort, MoveUp, MoveDown, MoveToIndex) are inert here because they route through _GetSequence, which this class deliberately does not override. The rest – Swap, MoveBefore, MoveAfter, ApplySyncableProperties – take their targets as arguments and WILL write if you hand them writable objects. None of them can record a parse result, and this class adds no new reach, but project.Parser.Swap(a, b) is not a no-op and should not be read as one.
DEGRADES, DOES NOT EXPLODE. On a machine where the parser component is missing, relocated, or from a different FieldWorks installation, importing flexicon still works and
GetAvailability()answers with a reason. Only CALLING an operation raises, and it raises with that same reason. Ask first if you are not sure:status = project.Parser.GetAvailability() if not status.available: report.Warning(status.reason)
ONE GRAMMAR, AND ITS CURRENCY IS ASKED, NEVER ASSUMED. At most one loaded grammar is held at a time, for the project in use; switching projects releases the previous one. Before every parse the parser is ASKED whether its grammar is current, and a stale grammar is reloaded before the word is parsed – never after, and never from a local flag that this class maintains, because a local flag is exactly what goes stale when something else changes the model.
Usage:
from flexicon import FLExProject project = FLExProject() project.OpenProject("IndonesianHC-Complete", writeEnabled=False) status = project.Parser.GetAvailability() if status.available: result = project.Parser.ParseWord("mengambil") trace = project.Parser.TraceWordXml("mengambil") project.CloseProject()
See also
ParserAvailability
- GetAvailability(*args, **kwargs)¶
Automatically instantiate and call the method.
- ParseWord(*args, **kwargs)¶
Automatically instantiate and call the method.
- ParseWordXml(*args, **kwargs)¶
Automatically instantiate and call the method.
- TraceWordXml(*args, **kwargs)¶
Automatically instantiate and call the method.
- Reload(*args, **kwargs)¶
Automatically instantiate and call the method.
- IsUpToDate(*args, **kwargs)¶
Automatically instantiate and call the method.