### Install belmorph Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Install the library via npm. ```bash npm install belmorph ``` -------------------------------- ### Build the Dictionary Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Initializes submodules and compiles the dictionary files required for the library. ```bash git submodule update --init npm run build:dict ``` -------------------------------- ### Run Tests Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Commands to execute the test suite either once or in watch mode. ```bash npm test # Run tests once npm run test:watch # Run tests in watch mode ``` -------------------------------- ### Initialize Analyzer via HTTP Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Initialize the analyzer by pointing to a static dictionary directory or CDN. ```typescript import { MorphAnalyzer } from 'belmorph'; // Serve the dict/ folder as static files and point to it: const morph = await MorphAnalyzer.init('/dict/'); // or from a CDN: const morph = await MorphAnalyzer.init('https://cdn.example.com/dict/'); const results = morph.parse('горад'); ``` -------------------------------- ### MorphAnalyzer Initialization Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Methods for initializing the MorphAnalyzer instance in different environments. ```APIDOC ## MorphAnalyzer Initialization ### Methods - `new MorphAnalyzer(dict)`: Construct from a pre-loaded `DictData` object. - `MorphAnalyzer.init(baseUrl?)`: Async factory that fetches and decompresses dictionary files over HTTP. Default base URL is '/dict/'. - `loadDict(dir?)` (Node.js only): Synchronous filesystem load. Defaults to the bundled `dict/` directory. ``` -------------------------------- ### Configure Tokenizer Options Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Enables or disables specific token recognition features during Tokenizer initialization. ```typescript const tz = new Tokenizer({ hashtags: true, // recognize #hashtags mentions: true, // recognize @mentions emails: true, // recognize emails links: true, // recognize URLs }); ``` -------------------------------- ### Analyze and Inflect Words in Node.js Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Initialize the analyzer using the bundled dictionary and perform morphological analysis or inflection. ```typescript import { MorphAnalyzer } from 'belmorph'; import { loadDict } from 'belmorph/node'; const morph = new MorphAnalyzer(loadDict()); // uses bundled dict/ const results = morph.parse('горад'); console.log(results[0].lemma); // 'горад' console.log(results[0].tags.pos); // 'N' (noun) // Inflect to different forms results[0].inflect({ case: 'I', number: 'P' })?.word; // 'гарадамі' // Full names and short codes are interchangeable results[0].inflect({ case: 'instrumental', number: 'plural' })?.word; // 'гарадамі' // Get all forms const lexeme = results[0].lexeme; console.log(lexeme.map(r => r.word)); ``` -------------------------------- ### Tokenize Belarusian Text Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Demonstrates one-shot and streaming tokenization, as well as filtering tokens by type. ```typescript import { Tokenizer, only, TokenType } from 'belmorph/tokens'; // One-shot tokenization const tokens = Tokenizer.tokenize('Прывітанне, свет! #мова'); console.log(tokens.map(t => t.toString())); // Streaming (for large documents) const tz = new Tokenizer(); tz.append('Прывіта'); tz.append('нне, свет!'); const tokens = tz.done(); // Filter by type const words = only(tokens, TokenType.WORD); console.log(words.map(w => w.toString())); // ['Прывітанне', 'свет'] ``` -------------------------------- ### Analyze text with TextAnalyzer Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Initializes the morphological analyzer and uses TextAnalyzer to parse text and extract lemmas from words. ```typescript import { TextAnalyzer, MorphAnalyzer } from 'belmorph'; const morph = await MorphAnalyzer.init('/dict/'); const analyzer = new TextAnalyzer(morph); const result = analyzer.analyze('Горад прыгожы!'); // [{ token: Token("Горад"), parse: { lemma: "горад", tags: { pos: "N", ... } } }, // { token: Token(" "), parse: null }, // { token: Token("прыгожы"), parse: { lemma: "прыгожы", tags: { pos: "A", ... } } }, // { token: Token("!"), parse: null }] // Words only const words = analyzer.words('кніга і тавар'); words.map(w => w.parse!.lemma); // ['кніга', 'тавар'] ``` -------------------------------- ### Tokenizer Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md The Tokenizer class provides methods for one-shot and streaming tokenization of Belarusian text. ```APIDOC ## Tokenizer ### Description Utility for splitting text into tokens (words, numbers, punctuation, spaces, hashtags, mentions, emails, and links). ### Methods - **Tokenizer.tokenize(text: string)**: Performs one-shot tokenization on the provided string. - **new Tokenizer(options?: TokenizerOptions)**: Initializes a new tokenizer instance. - **Tokenizer.append(chunk: string)**: Appends a chunk of text for streaming tokenization. - **Tokenizer.done()**: Finalizes the streaming process and returns the collected tokens. ### Tokenizer Options - **hashtags** (boolean) - Optional - Recognize #hashtags - **mentions** (boolean) - Optional - Recognize @mentions - **emails** (boolean) - Optional - Recognize emails - **links** (boolean) - Optional - Recognize URLs ### Token Types - **WORD**: Cyrillic or Latin word - **NUMBER**: Integer or decimal number - **PUNCT**: Punctuation mark - **SPACE**: Whitespace - **NEWLINE**: Line break - **EMAIL**: Email address - **LINK**: URL - **HASHTAG**: #hashtag - **MENTION**: @mention ``` -------------------------------- ### Pluralizing words with numeral agreement Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Demonstrates using the pluralize method to handle Belarusian numeral agreement rules for different counts and cases. ```typescript const book = morph.parse('кніга')[0]; book.pluralize(1)!.word; // 'кніга' (1 кніга) book.pluralize(2)!.word; // 'кнігі' (2 кнігі) book.pluralize(5)!.word; // 'кніг' (5 кніг) // Oblique government, e.g. "давяраю пяці кнігам" (dative, governed by the verb) book.pluralize(5, 'D')!.word; // 'кнігам' ``` -------------------------------- ### MorphAnalyzer.parse(word) Source: https://github.com/alesdrobysh/belmorph/blob/main/README.md Parses a word and returns an array of ParseResult objects containing grammatical information and inflection methods. ```APIDOC ## MorphAnalyzer.parse(word) ### Description Parses the provided word and returns an array of `ParseResult` objects. ### ParseResult Properties - `word` (string): The inflected word form. - `lemma` (string): The dictionary form. - `tags` (Grammeme): Grammatical properties. - `predicted` (boolean): Whether the analysis was predicted. - `lexeme` (Array): All forms of the word. ### Methods - `inflect(target)`: Returns the form matching the given grammemes, or `null`. - `pluralize(count, targetCase = 'N')`: Returns the form agreeing with `count` based on Belarusian numeral agreement rules. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.