### Set up Local Development Environment Source: https://github.com/obulat/zeyrek/blob/main/CONTRIBUTING.rst Install the trLemmer project into a virtual environment for local development using setup.py develop. ```shell mkvirtualenv trLemmer cd trLemmer/ python setup.py develop ``` -------------------------------- ### Install Zeyrek Source: https://github.com/obulat/zeyrek/blob/main/docs/index.md Install the Zeyrek library using pip. This command should be run in your terminal to add Zeyrek to your Python environment. ```shell $ pip install zeyrek ``` -------------------------------- ### Initialize MorphAnalyzer in Python Source: https://github.com/obulat/zeyrek/blob/main/README.md Instantiate the MorphAnalyzer class to begin analyzing Turkish words. No specific setup is required beyond importing the library. ```python import zeyrek analyzer = zeyrek.MorphAnalyzer() ``` -------------------------------- ### Analyze Turkish Words with Zeyrek Source: https://github.com/obulat/zeyrek/blob/main/README.md Use the analyze method to get all possible morphological analyses for a given Turkish word or text. Each analysis includes the original word, lemma, part of speech, morphemes, and a formatted string. ```python print(analyzer.analyze('benim')) ``` -------------------------------- ### Analyze Turkish Words Source: https://github.com/obulat/zeyrek/blob/main/docs/index.md Use the `analyze` method to get all possible morphological parses for a given Turkish word. Each parse includes the original word, its lemma, part of speech, morphemes, and a formatted representation. ```shell >>> for parse in analyzer.analyze('benim')[0]: ... print(parse) Parse(word='benim', lemma='ben', pos='Noun', morphemes=['Noun', 'A3sg', 'P1sg'], formatted='[ben:Noun] ben:Noun+A3sg+im:P1sg') Parse(word='benim', lemma='ben', pos='Pron', morphemes=['Pron', 'A1sg', 'Gen'], formatted='[ben:Pron,Pers] ben:Pron+A1sg+im:Gen') Parse(word='benim', lemma='ben', pos='Verb', morphemes=['Noun', 'A3sg', 'Zero', 'Verb', 'Pres', 'A1sg'], formatted='[ben:Noun] ben:Noun+A3sg|Zero→Verb+Pres+im:A1sg') Parse(word='benim', lemma='ben', pos='Verb', morphemes=['Pron', 'A1sg', 'Zero', 'Verb', 'Pres', 'A1sg'], formatted='[ben:Pron,Pers] ben:Pron+A1sg|Zero→Verb+Pres+im:A1sg') ``` -------------------------------- ### Lemmatize a Single Word Source: https://context7.com/obulat/zeyrek/llms.txt Get the base (dictionary) form of a single word using the `lemmatize` method. By default, it returns a list containing a single best lemma. ```python import zeyrek # Default: returns list of single lemma strings analyzer = zeyrek.MorphAnalyzer() result = analyzer.lemmatize('benim') print(result) # ['ben'] ``` -------------------------------- ### MorphAnalyzer Initialization and Usage Source: https://github.com/obulat/zeyrek/blob/main/README.md Demonstrates how to initialize the MorphAnalyzer and use its analyze and lemmatize methods. ```APIDOC ## MorphAnalyzer ### Description The `MorphAnalyzer` class is the main entry point for performing morphological analysis and lemmatization on Turkish words and texts. ### Initialization To use Zeyrek, first create an instance of `MorphAnalyzer` class: ```python import zeyrek analyzer = zeyrek.MorphAnalyzer() ``` ### Methods #### analyze(text) Analyzes a word or text and returns all possible morphological analyses. ##### Parameters - **text** (str) - The word or text to analyze. ##### Request Example ```python print(analyzer.analyze('benim')) ``` ##### Response Example ``` Parse(word='benim', lemma='ben', pos='Noun', morphemes=['Noun', 'A3sg', 'P1sg'], formatted='[ben:Noun] ben:Noun+A3sg+im:P1sg') Parse(word='benim', lemma='ben', pos='Pron', morphemes=['Pron', 'A1sg', 'Gen'], formatted='[ben:Pron,Pers] ben:Pron+A1sg+im:Gen') Parse(word='benim', lemma='ben', pos='Verb', morphemes=['Noun', 'A3sg', 'Zero', 'Verb', 'Pres', 'A1sg'], formatted='[ben:Noun] ben:Noun+A3sg|Zero→Verb+Pres+im:A1sg') Parse(word='benim', lemma='ben', pos='Verb', morphemes=['Pron', 'A1sg', 'Zero', 'Verb', 'Pres', 'A1sg'], formatted='[ben:Pron,Pers] ben:Pron+A1sg|Zero→Verb+Pres+im:A1sg') ``` #### lemmatize(text) Lemmatizes a word or text, returning a list of possible base forms (lemmas). ##### Parameters - **text** (str) - The word or text to lemmatize. ##### Request Example ```python print(analyzer.lemmatize('benim')) ``` ##### Response Example ``` [('benim', ['ben'])] ``` ``` -------------------------------- ### Initialize MorphAnalyzer Source: https://github.com/obulat/zeyrek/blob/main/docs/index.md Instantiate the MorphAnalyzer class to begin using Zeyrek's analysis capabilities. This is the first step before performing any morphological analysis. ```shell >>> import zeyrek >>> analyzer = zeyrek.MorphAnalyzer() ``` -------------------------------- ### Create MorphAnalyzer Instance Source: https://context7.com/obulat/zeyrek/llms.txt Instantiate the `MorphAnalyzer` class. Options include using built-in dictionaries, returning all possible lemmas, or using the Universal Dependencies formatter. ```python import zeyrek # Default analyzer using built-in Turkish dictionaries analyzer = zeyrek.MorphAnalyzer() # Analyzer that returns all possible lemmas (not just the first) analyzer_all = zeyrek.MorphAnalyzer(return_all_lemmas=True) # Analyzer with Universal Dependencies (UD) formatter analyzer_ud = zeyrek.MorphAnalyzer(formatter="UD") ``` -------------------------------- ### Clone the trLemmer Repository Source: https://github.com/obulat/zeyrek/blob/main/CONTRIBUTING.rst Clone your forked repository locally to begin development. ```shell $ git clone git@github.com:your_name_here/trLemmer.git ``` -------------------------------- ### Deploying trLemmer Source: https://github.com/obulat/zeyrek/blob/main/CONTRIBUTING.rst Steps for maintainers to deploy new versions, including version bumping and pushing tags. ```shell bumpversion patch # possible: major / minor / patch git push git push --tags ``` -------------------------------- ### Run Tests and Linting Source: https://github.com/obulat/zeyrek/blob/main/CONTRIBUTING.rst Ensure your changes pass flake8 linting and all tests, including cross-version compatibility with tox. ```shell flake8 trLemmer tests python setup.py test or py.test tox ``` -------------------------------- ### Create a New Branch for Development Source: https://github.com/obulat/zeyrek/blob/main/CONTRIBUTING.rst Create a new branch for your bugfix or feature before making local changes. ```shell git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### Commit and Push Changes Source: https://github.com/obulat/zeyrek/blob/main/CONTRIBUTING.rst Add, commit, and push your local changes to your GitHub fork. ```shell git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### MorphAnalyzer - Create an Analyzer Instance Source: https://context7.com/obulat/zeyrek/llms.txt Instantiate the MorphAnalyzer class to create a Turkish morphological analyzer. You can customize it with an optional lexicon, formatter, and a flag to return all possible lemmas. ```APIDOC ## MorphAnalyzer ### Description The `MorphAnalyzer` class is the primary entry point for morphological analysis and lemmatization. It uses a rule-based analyzer backed by the Turkish morphotactics engine and a built-in root lexicon. ### Initialization ```python import zeyrek # Default analyzer using built-in Turkish dictionaries analyzer = zeyrek.MorphAnalyzer() # Analyzer that returns all possible lemmas (not just the first) analyzer_all = zeyrek.MorphAnalyzer(return_all_lemmas=True) # Analyzer with Universal Dependencies (UD) formatter analyzer_ud = zeyrek.MorphAnalyzer(formatter="UD") ``` ### Parameters - **lexicon** (str, optional): Path to a custom dictionary file. Defaults to None. - **formatter** (str, optional): Output formatter. Can be 'Default' or 'UD'. Defaults to 'Default'. - **return_all_lemmas** (bool, optional): If True, returns all possible lemmas. Defaults to False. ``` -------------------------------- ### Run a Subset of Tests Source: https://github.com/obulat/zeyrek/blob/main/CONTRIBUTING.rst Execute a specific subset of tests using py.test for targeted testing. ```shell py.test tests.test_trLemmer ``` -------------------------------- ### Lemmatize with All Possible Lemmas Source: https://context7.com/obulat/zeyrek/llms.txt When `return_all_lemmas=True` is set during `MorphAnalyzer` instantiation, the `lemmatize` method returns a list of tuples, where each tuple contains the original word and a list of all its possible lemmas. ```python import zeyrek # With return_all_lemmas=True: returns list of (word, [lemmas]) tuples analyzer_all = zeyrek.MorphAnalyzer(return_all_lemmas=True) result = analyzer_all.lemmatize('beyazlaştı') print(result) # [('beyazlaştı', ['beyaz'])] result = analyzer_all.lemmatize("Bunu okuyabiliyorum") print(result) # [('Bunu', ['bu']), ('okuyabiliyorum', ['oku'])] ``` -------------------------------- ### Build Custom Lexicon from Lines Source: https://context7.com/obulat/zeyrek/llms.txt Constructs a custom lexicon programmatically from a list of strings. This is useful for testing or targeted analysis without external files. ```python from zeyrek.morphology import MorphAnalyzer from zeyrek.lexicon import RootLexicon # Build lexicon from word lines lexicon = RootLexicon.from_lines(["adak", "elma", "beyaz [P:Adj]", "meyve"]) # Use custom lexicon in analyzer analyzer = MorphAnalyzer(lexicon=lexicon, return_all_lemmas=True) print(analyzer.analyze('elma')) # [[Parse(word='elma', lemma='elma', pos='Noun', ...)]] print(analyzer.lemmatize('beyazlaştı')) # [('beyazlaştı', ['beyaz'])] print(analyzer.lemmatize('meyvesiz')) # [('meyvesiz', ['meyve'])] ``` -------------------------------- ### Use UDFormatter for Universal Dependencies Output Source: https://context7.com/obulat/zeyrek/llms.txt Configures MorphAnalyzer to use the UDFormatter for outputting morphological features in the Universal Dependencies format. ```python import zeyrek # Use UD formatter analyzer = zeyrek.MorphAnalyzer(formatter="UD") results = analyzer.analyze('kitabım') for parse in results[0]: print(parse.formatted) # Case=Nom|Number=Sing|Number[psor]=Sing|Person=3|Person[psor]=1 results = analyzer.analyze('geliyorum') for parse in results[0]: print(parse.formatted) # Aspect=Prog|Mood=Ind|Number=Sing|Person=1|Polarity=Pos|Polite=Infm|Tense=Pres ``` -------------------------------- ### Lemmatize Turkish Words with Zeyrek Source: https://github.com/obulat/zeyrek/blob/main/README.md Call the lemmatize method to retrieve only the base form (lemma) of Turkish words. It returns a list of tuples, where each tuple contains the original word and a list of its possible lemmas. ```python print(analyzer.lemmatize('benim')) ``` -------------------------------- ### Morphological Analysis of a Text File Source: https://context7.com/obulat/zeyrek/llms.txt Analyze the content of a text file. Ensure the file is opened with UTF-8 encoding and NLTK's tokenizer is downloaded for Turkish. ```python import zeyrek import nltk nltk.download('punkt') with open('text.txt', encoding='utf-8') as f: text = f.read() results = analyzer.analyze(text) for word_result in results: print(word_result[0].word) for parse in word_result: print(parse.formatted) print() ``` -------------------------------- ### Understand Root Word Attributes Source: https://context7.com/obulat/zeyrek/llms.txt Lists common RootAttribute enumerations used for morphophonological properties in custom dictionary entries and internal analysis. ```python from zeyrek.attributes import RootAttribute # Common attributes used in dictionary entries print(RootAttribute.Voicing) # Voicing: consonant mutation (p→b, k→ğ, etc.) print(RootAttribute.InverseHarmony) # InverseHarmony: vowel harmony exceptions (e.g., loan words) print(RootAttribute.NoVoicing) # NoVoicing: explicitly suppress voicing print(RootAttribute.LastVowelDrop) # LastVowelDrop: vowel drops before suffix (e.g., ağız → ağza) print(RootAttribute.Doubling) # Doubling: last letter doubled before vowel suffix (e.g., hat → hattı) # Example: mark a word with InverseHarmony in custom dictionary # Dictionary line: "alkol [P:Noun; A:InverseHarmony]" ``` -------------------------------- ### Add Custom Dictionary to Analyzer Source: https://context7.com/obulat/zeyrek/llms.txt Extends the MorphAnalyzer's lexicon with words from a user-supplied text file. Each line can contain a word, optional part-of-speech, and root attribute annotations. ```python import zeyrek analyzer = zeyrek.MorphAnalyzer() # custom_words.txt contents: # biyomedikal [P:Adj; A:InverseHarmony] # yazılım # veri [P:Noun] analyzer.add_dictionary('/path/to/custom_words.txt') # Now the analyzer can handle the custom words result = analyzer.analyze('biyomedikal') print(result[0][0].formatted) ``` -------------------------------- ### Enumerate Primary and Secondary POS Tags Source: https://context7.com/obulat/zeyrek/llms.txt Demonstrates accessing the enumeration values for PrimaryPos and SecondaryPos, which are used in Parse.pos and DictionaryItem attributes. ```python from zeyrek.attributes import PrimaryPos, SecondaryPos # PrimaryPos values (used in Parse.pos) print([p.value for p in PrimaryPos]) # ['Noun', 'Adj', 'Adv', 'Conj', 'Interj', 'Verb', 'Pron', 'Num', # 'Det', 'Postp', 'Ques', 'Dup', 'Punc', 'Unk'] # SecondaryPos values (subtypes for pronouns, numerals, etc.) print(SecondaryPos.ProperNoun.value) # 'Prop' print(SecondaryPos.Abbreviation.value) # 'Abbrv' print(SecondaryPos.PersonalPron.value) # 'Pers' # Filtering proper nouns from analysis import zeyrek analyzer = zeyrek.MorphAnalyzer() parses = analyzer.analyze('Ankara')[0] for p in parses: print(p.lemma, p.pos) # Ankara Noun (ProperNoun) ``` -------------------------------- ### Analyze Text and Inspect Parse Object Source: https://context7.com/obulat/zeyrek/llms.txt Analyzes input text and iterates through the morphological parses. Demonstrates accessing word, lemma, part-of-speech, morphemes, formatted output, and checking for specific morpheme IDs. ```python import zeyrek analyzer = zeyrek.MorphAnalyzer() parses = analyzer.analyze('kitabım')[0] for parse in parses: print(f"word : {parse.word}") print(f"lemma : {parse.lemma}") print(f"pos : {parse.pos}") print(f"morphemes: {parse.morphemes}") print(f"formatted: {parse.formatted}") print(f"num morphemes: {len(parse)}") # Membership test: check if a specific morpheme is present if 'P1sg' in parse: print(" -> First person singular possessive detected") print() # Example output: # word : kitabım # lemma : kitap # pos : Noun # morphemes: ['Noun', 'A3sg', 'P1sg'] # formatted: [kitap:Noun] kitap:Noun+A3sg+ım:P1sg # num morphemes: 3 # -> First person singular possessive detected ``` -------------------------------- ### Morphological Analysis of a Single Word Source: https://context7.com/obulat/zeyrek/llms.txt Analyze a single Turkish word using the `analyze` method. The output is a list of `Parse` objects, each representing a possible morphological breakdown. ```python import zeyrek analyzer = zeyrek.MorphAnalyzer() # Analyze a single word results = analyzer.analyze('benim') for parse in results[0]: print(parse) # Parse(word='benim', lemma='ben', pos='Noun', morphemes=['Noun', 'A3sg', 'P1sg'], formatted='[ben:Noun] ben:Noun+A3sg+im:P1sg') # Parse(word='benim', lemma='ben', pos='Pron', morphemes=['Pron', 'A1sg', 'Gen'], formatted='[ben:Pron,Pers] ben:Pron+A1sg+im:Gen') # Parse(word='benim', lemma='ben', pos='Verb', morphemes=['Noun', 'A3sg', 'Zero', 'Verb', 'Pres', 'A1sg'], formatted='[ben:Noun] ben:Noun+A3sg|Zero→Verb+Pres+im:A1sg') # Parse(word='benim', lemma='ben', pos='Verb', morphemes=['Pron', 'A1sg', 'Zero', 'Verb', 'Pres', 'A1sg'], formatted='[ben:Pron,Pers] ben:Pron+A1sg|Zero→Verb+Pres+im:A1sg') ``` -------------------------------- ### Morphological Analysis of a Sentence Source: https://context7.com/obulat/zeyrek/llms.txt Analyze a sentence using the `analyze` method. The results are structured as a list of lists, where each inner list contains the parses for a single token. ```python import zeyrek analyzer = zeyrek.MorphAnalyzer() # Analyze a multi-word sentence sentence_results = analyzer.analyze('Bunu okuyabiliyorum') for word_parses in sentence_results: print(word_parses[0].word, '->', word_parses[0].formatted) # Bunu -> [bu:Pron,Demons] bu:Pron+A3sg+nu:Acc # okuyabiliyorum -> [oku:Verb] oku:Verb+yabil:Able|iyor:Prog1+um:A1sg ``` -------------------------------- ### MorphAnalyzer.lemmatize Source: https://context7.com/obulat/zeyrek/llms.txt Extract the base (dictionary) form of words from the input text. This method simplifies words to their root lemmas. ```APIDOC ## MorphAnalyzer.lemmatize ### Description Returns the base (dictionary) form of each word in the input text. By default, uses proper noun filtering and returns a single best lemma per word. With `return_all_lemmas=True`, returns all possible lemmas. ### Method `lemmatize(text: str, return_all_lemmas: bool = False)` ### Parameters - **text** (str): The input text to lemmatize. - **return_all_lemmas** (bool, optional): If True, returns all possible lemmas for each word. Defaults to False. ### Returns - If `return_all_lemmas` is False: `list[str]` - A list of lemma strings for each word. - If `return_all_lemmas` is True: `list[tuple[str, list[str]]]` - A list of tuples, where each tuple contains the original word and a list of its possible lemmas. ### Request Example ```python import zeyrek # Default: returns list of single lemma strings analyzer = zeyrek.MorphAnalyzer() result = analyzer.lemmatize('benim') print(result) # Sentence lemmatization result = analyzer.lemmatize("Şu dünyadaki sevilen kişi sevmeyi bilendir.") print(result) # Compound word lemmatization result = analyzer.lemmatize("Zeytinyağlı") print(result) # With return_all_lemmas=True: returns list of (word, [lemmas]) tuples analyzer_all = zeyrek.MorphAnalyzer(return_all_lemmas=True) result = analyzer_all.lemmatize('beyazlaştı') print(result) ``` ### Response Example ``` ['ben'] ['şu', 'dünya', 'sevmek', 'kişi', 'sevmek', 'bilmek', '.'] ['zeytinyağı'] [('beyazlaştı', ['beyaz'])] [('Bunu', ['bu']), ('okuyabiliyorum', ['oku'])] ``` ``` -------------------------------- ### Lemmatize Turkish Words Source: https://github.com/obulat/zeyrek/blob/main/docs/index.md Call the `lemmatize` method to obtain the base (non-inflected) forms of Turkish words. It returns a list of tuples, where each tuple contains the original word and a list of its possible lemmas. ```shell >>> print(analyzer.lemmatize('benim')) [('benim', ['ben'])] ``` -------------------------------- ### MorphAnalyzer.analyze Source: https://context7.com/obulat/zeyrek/llms.txt Perform morphological analysis on input text. This method breaks down each word into its constituent morphemes and provides detailed parse information. ```APIDOC ## MorphAnalyzer.analyze ### Description Analyzes each word in the given text and returns all possible morphological parses. Returns a `list[list[Parse]]` — one inner list per token, each containing `Parse` named-tuples. ### Method `analyze(text: str)` ### Parameters - **text** (str): The input text to analyze. ### Returns - `list[list[Parse]]`: A list where each inner list corresponds to a token in the input text and contains `Parse` named-tuples representing possible morphological analyses. ### Parse Named-Tuple - **word** (str): The original word. - **lemma** (str): The base (dictionary) form of the word. - **pos** (str): The part of speech. - **morphemes** (list[str]): A list of morphemes. - **formatted** (str): A human-readable formatted string of the parse. ### Request Example ```python import zeyrek analyzer = zeyrek.MorphAnalyzer() # Analyze a single word results = analyzer.analyze('benim') for parse in results[0]: print(parse) # Analyze a multi-word sentence sentence_results = analyzer.analyze('Bunu okuyabiliyorum') for word_parses in sentence_results: print(word_parses[0].word, '->', word_parses[0].formatted) ``` ### Response Example ``` Parse(word='benim', lemma='ben', pos='Noun', morphemes=['Noun', 'A3sg', 'P1sg'], formatted='[ben:Noun] ben:Noun+A3sg+im:P1sg') Parse(word='benim', lemma='ben', pos='Pron', morphemes=['Pron', 'A1sg', 'Gen'], formatted='[ben:Pron,Pers] ben:Pron+A1sg+im:Gen') Parse(word='benim', lemma='ben', pos='Verb', morphemes=['Noun', 'A3sg', 'Zero', 'Verb', 'Pres', 'A1sg'], formatted='[ben:Noun] ben:Noun+A3sg|Zero→Verb+Pres+im:A1sg') Parse(word='benim', lemma='ben', pos='Verb', morphemes=['Pron', 'A1sg', 'Zero', 'Verb', 'Pres', 'A1sg'], formatted='[ben:Pron,Pers] ben:Pron+A1sg|Zero→Verb+Pres+im:A1sg') Bunu -> [bu:Pron,Demons] bu:Pron+A3sg+nu:Acc okuyabiliyorum -> [oku:Verb] oku:Verb+yabil:Able|iyor:Prog1+um:A1sg ``` ``` -------------------------------- ### Lemmatize a Sentence Source: https://context7.com/obulat/zeyrek/llms.txt Lemmatize all words in a Turkish sentence. The `lemmatize` method returns a list of base forms. ```python import zeyrek analyzer = zeyrek.MorphAnalyzer() # Sentence lemmatization result = analyzer.lemmatize("Şu dünyadaki sevilen kişi sevmeyi bilendir.") print(result) # ['şu', 'dünya', 'sevmek', 'kişi', 'sevmek', 'bilmek', '.'] ``` -------------------------------- ### Lemmatize Compound Words Source: https://context7.com/obulat/zeyrek/llms.txt Lemmatize compound Turkish words. The `lemmatize` method correctly identifies the base form of compound nouns. ```python import zeyrek analyzer = zeyrek.MorphAnalyzer() # Compound word lemmatization result = analyzer.lemmatize("Zeytinyağlı") print(result) # ['zeytinyağı'] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.