How gvlasov/inflectible works
Project type and purpose
• Inflectible is a Java library (template engine) for building grammatically correct, inflected natural-language strings.
• It uses ANTLR grammars to parse two domain‐specific markup languages—vocabulary markups and template markups—into ASTs and then into internal model objects.
High‐level architecture overview
The internal architecture can be thought of as a multi‐stage pipeline with the following logical layers:
a. Markup input (vocabulary definitions & template definitions)
b. ANTLR processing (lexer & parser)
c. Parsed AST model (org.tendiwa.inflectible.antlr.parsed)
d. Core model construction (org.tendiwa.inflectible core classes like BasicLexeme, BasicTemplate, BasicVocabulary, NativeSpeaker)
e. Language‐specific implementations (org.tendiwa.inflectible.implementations) & inflection logic (org.tendiwa.inflectible.inflection)
f. Application API (user interacts via NativeSpeaker.fillOut(...))
Main components
• ANTLR Grammars (src/main/antlr4):
– SharedLexer/SharedParser for shared tokens
– LexemeLexer/LexemeParser for vocabulary markups
– TemplateLexer/TemplateParser for template markups
• Generated Parser Classes (under src/main/java/org/tendiwa/inflectible/antlr)
• Parsed AST classes (package parsed/): hold parse‐tree wrappers for lexemes, templates, concepts, placeholders, etc.
• Core Model classes (org.tendiwa.inflectible): interfaces (Vocabulary, Template, Concept, NativeSpeaker), and basic implementations (BasicVocabulary, BasicTemplate, BasicLexeme, etc.)
• Inflection engine (package inflection): algorithms for selecting closest grammatical meaning, suppletive forms, etc.
• Language Implementations (package implementations): concrete languages (English, Russian) that supply grammemes, parts of speech, declension rules, built‐in vocabularies.
• User API: NativeSpeaker orchestrates parsing, vocabulary loading, template loading, and final text generation.
Relationships & data flow
1. User or build‐time plugin provides markup files (vocabulary + template).
2. ANTLR-generated lexer → parser reads markup → produces parse‐tree → mapped into Parsed AST objects.
3. Parsed AST → Core constructors translate AST into domain objects (Lexeme, Template, Vocabulary).
4. Core domain objects + Language implementations + Inflection engine → assembled into a NativeSpeaker instance.
5. Application calls nativeSpeaker.fillOut(templateName, Concept… ) → Core uses vocabulary, grammar rules, inflection logic → produces final string.
Architectural patterns & design principles
• Layered pipeline (parsing → AST → model → service)
• Strategy & plugin pattern for languages (implementations can be added)
• Clear separation of concerns: parsing vs. model vs. inflection logic vs. API
• Immutable model objects for thread‐safety
Putting it all together
[Markup files] → [ANTLR Grammars & Generated Parsers] → [Parsed AST classes] → [Core Model classes] ↔ [Language implementations & Inflection Engine] → [NativeSpeaker API] → [Final Text].