### Install Tashaphyne Source: https://github.com/linuxscout/tashaphyne/blob/master/README.md Install the Tashaphyne library using pip. ```default pip install tashaphyne ``` -------------------------------- ### Example of extract_root and get_starword Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Demonstrates how to use the ArabicLightStemmer to get the stemmed word (with non-root letters as jokers) and the extracted root of a given Arabic word. ```python ArListem = ArabicLightStemmer() word = u'أفتصربونني' stem = ArListem.light_stem(word) print ArListem.get_starword() أفت***ونني print ArListem.get_root() ضرب ``` -------------------------------- ### Arabic Light Stemming and Component Extraction Source: https://github.com/linuxscout/tashaphyne/blob/master/README.rst Demonstrates how to use ArabicLightStemmer to stem a word and extract its root, stem, prefix, and suffix. Includes examples for getting positional indices and formatted affix outputs. ```python import pyarabic.arabrepr from tashaphyne.stemming import ArabicLightStemmer arepr = pyarabic.arabrepr.ArabicRepr() repr = arepr.repr ArListem = ArabicLightStemmer() word = u'أفتضاربانني' # stemming word stem = ArListem.light_stem(word) # extract stem print ArListem.get_stem() # extract root print ArListem.get_root() # get prefix position index print ArListem.get_left() # get prefix print ArListem.get_prefix() # get prefix with a specific index print ArListem.get_prefix(2) # get suffix position index print ArListem.get_right() # get suffix print ArListem.get_suffix() # get suffix with a specific index print ArListem.get_suffix(10) # get affix print ArListem.get_affix() # get affix tuple print repr(ArListem.get_affix_tuple()) # star words print ArListem.get_starword() # get star stem print ArListem.get_starstem() # get unvocalized word print ArListem.get_unvocalized() ``` -------------------------------- ### Get Affix Tuple from ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Returns a dictionary containing the prefix, suffix, stem, and root of a word. It utilizes other get methods to compute these values based on provided indices. ```python def get_affix_tuple(self, prefix_index=-1, suffix_index=0): """ return the affix tuple of the treated word by the stemmer. Example: >>> ArListem = ArabicLightStemmer() >>> word = u'أفتضاربانني' >>> stem = ArListem.light_stem(word) >>> print ArListem.get_affix_tuple() {'prefix': u'أفت', 'root': u'ضرب', 'suffix': u'انني', 'stem': u'ضارب'} @param prefix_index: indicate the left stemming position if = -1: not cosidered, and take the default word prefix lentgh. @type prefix_index:integer. @param suffix_index:indicate the right stemming position. if = -1: not cosidered, and take the default word suffix position. @type suffix_index: integer. @return: affix tuple. @rtype: dict. """ return { 'prefix':self.get_prefix(prefix_index), 'suffix':self.get_suffix(suffix_index), 'stem':self.get_stem(prefix_index, suffix_index), 'root':self.get_root(prefix_index, suffix_index), } ``` -------------------------------- ### ArabicLightStemmer.lookup_prefixes Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Looks up for prefixes in a given word and returns their starting positions. ```APIDOC ## lookup_prefixes(self, word) ### Description Looks up for prefixes in the given word and returns a list of their starting positions. ### Parameters #### Path Parameters - **word** (unicode) - The word to look for prefixes in. ### Return Value - **list of prefixes starts positions** (list of int) - A list of integers representing the starting positions of found prefixes. ``` -------------------------------- ### Instantiate ArabicLightStemmer Source: https://context7.com/linuxscout/tashaphyne/llms.txt Instantiate the main class to load default Arabic prefix/suffix lists and build the finite-state automaton. No additional setup is required. ```python from tashaphyne.stemming import ArabicLightStemmer stemmer = ArabicLightStemmer() # ready to use immediately — no additional setup required ``` -------------------------------- ### Get Prefix List - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Retrieves the set of prefixes used by the stemmer. Defaults to DEFAULT_PREFIX_LIST. ```python return self.prefix_list ``` -------------------------------- ### Get Stemming Left Position - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Returns the starting index of the stem within the original word. This indicates the end of the prefix. ```python >>> ArListem = ArabicLightStemmer() >>> word = u'أفتصربونني' >>> stem = ArListem .light_stem(word) >>> print ArListem.get_starword() أفت***ونني >>> print ArListem.get_left() 3 ``` -------------------------------- ### Get Segmentation List in ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Retrieves the list of segmentation positions (left, right) previously computed for the word. Includes an example of usage. ```python return self.segment_list ``` -------------------------------- ### ArabicLightStemmer Usage Example Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Demonstrates the basic usage of the ArabicLightStemmer class, including stemming a word and extracting various linguistic components like stem, root, prefixes, suffixes, and normalized forms. ```python ARLISTEM = ArabicLightStemmer() WORD = u'أفتضاربانني' # stemming word ARLISTEM.light_stem(WORD) # extract stem print(ARLISTEM.get_stem()) # extract root print(ARLISTEM.get_root()) # get prefix position index print(ARLISTEM.get_left()) # get prefix print(ARLISTEM.get_prefix()) # get prefix with a specific index print(ARLISTEM.get_prefix(2)) # get suffix position index print(ARLISTEM.get_right()) # get suffix print(ARLISTEM.get_suffix()) # get suffix with a specific index print(ARLISTEM.get_suffix(10)) # get affix tuple print(repr(ARLISTEM.get_affix_tuple())) # star words print(ARLISTEM.get_starword()) # get star stem print(ARLISTEM.get_starstem()) # get normalized word print(ARLISTEM.get_normalized()) # get unvocalized word print(ARLISTEM.get_unvocalized()) # Detect all possible segmentation print(ARLISTEM.segment(WORD)) print(ARLISTEM.get_segment_list()) # get affix list print(ARLISTEM.get_affix_list()) ``` -------------------------------- ### Lookup Prefixes in ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Searches for known prefixes within a given word using the pre-built prefix tree. Returns a list of possible prefix start positions. ```python branch = self.prefixes_tree lefts = [0, ] i = 0 while i < len(word) and word[i] in branch: if "#" in branch: # if branch['#'].has_key(word[:i]): lefts.append(i) if word[i] in branch: branch = branch[word[i]] else: # i += 1 break i += 1 if i < len(word) and "#" in branch: lefts.append(i) return lefts ``` -------------------------------- ### Get Stemming Right Position - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Returns the ending index of the stem within the original word. This indicates the start of the suffix. ```python >>> ArListem = ArabicLightStemmer() >>> word = u'أفتصربونني' >>> stem = ArListem .light_stem(word) >>> print ArListem.get_starword() أفت***ونني >>> print ArListem.get_right() 6 ``` -------------------------------- ### segment(word) Source: https://context7.com/linuxscout/tashaphyne/llms.txt Enumerates all possible segmentation positions for a given Arabic word. It returns a set of (left, right) integer tuples, where 'left' is the index marking the end of the prefix and the start of the stem, and 'right' is the index marking the end of the stem and the start of the suffix. ```APIDOC ## segment(word) ### Description Enumerates all valid segmentation positions for the given Arabic word. Returns a `set` of `(left, right)` integer tuples representing every valid prefix/suffix split point. `left` is the index where the prefix ends (stem starts); `right` is the index where the stem ends (suffix starts). ### Method `segment(word: str) -> set` ### Parameters #### Path Parameters - **word** (str) - Required - The Arabic word to segment. ### Request Example ```python from tashaphyne.stemming import ArabicLightStemmer stemmer = ArabicLightStemmer() word = 'فتضربين' positions = stemmer.segment(word) print(positions) # Retrieve the same result later without re-running print(stemmer.get_segment_list()) ``` ### Response #### Success Response (set) - **positions** (set) - A set of tuples, where each tuple contains two integers (left, right) representing segmentation boundaries. #### Response Example ``` {(0, 7), (1, 5), (2, 5)} {(0, 7), (1, 5), (2, 5)} ``` ``` -------------------------------- ### Get Affix Tuple for Stemming Results Source: https://context7.com/linuxscout/tashaphyne/llms.txt Retrieves a dictionary containing prefix, suffix, stem, starstem, and root for a given word's segmentation. Requires an initialized ArabicLightStemmer instance. ```python from tashaphyne.stemming import ArabicLightStemmer stemmer = ArabicLightStemmer() stemmer.light_stem('أفتضاربانني') result = stemmer.get_affix_tuple() print(result) # { # 'prefix' : 'أفت', # 'suffix' : 'انني', # 'stem' : 'ضارب', # 'starstem': '*ا**', # 'root' : 'ضرب' # } ``` -------------------------------- ### Lookup Suffixes in ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Searches for known suffixes within a given word using the pre-built suffix tree. Returns a list of possible suffix start positions. ```python branch = self.suffixes_tree suffix = '' # rights = [len(word)-1, ] rights = [] i = len(word)-1 while i >= 0 and word[i] in branch: suffix = word[i]+suffix if '#' in branch: # if branch['#'].has_key(word[i:]): # rights.append(i) rights.append(i+1) if word[i] in branch: branch = branch[word[i]] else: # i -= 1 break i -= 1 if i >= 0 and "#" in branch:#and branch['#'].has_key(word[i+1:]): rights.append(i+1) return rights ``` -------------------------------- ### Get Affix Tuple of Arabic Word Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Returns a dictionary containing the prefix, root, suffix, and stem of a treated Arabic word. This provides a comprehensive breakdown of the word's components after stemming. ```python >>> ArListem = ArabicLightStemmer() >>> word = u'أفتضاربانني' >>> stem = ArListem .light_stem(word) >>> print ArListem.get_affix_tuple() {'prefix': u'أفت', 'root': u'ضرب', 'suffix': u'انني', 'stem': u'ضارب'} ``` -------------------------------- ### Min Stem Length Configuration Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Methods to get and set the minimum length of the stem considered by the stemmer. ```APIDOC ## get_min_stem_length ### Description Returns the constant for the minimum length of the stem used by the stemmer. Defaults to DEFAULT_MIN_STEM_LENGTH. ### Method `get_min_stem_length(self)` ### Return Value - **integer**: The current minimum stem length. ## set_min_stem_length ### Description Sets the constant for the minimum length of the stem used by the stemmer. ### Method `set_min_stem_length(self, new_min_stem_length)` ### Parameters #### Path Parameters - **new_min_stem_length** (integer) - Required - The new minimum stem length constant. ``` -------------------------------- ### get_right Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Returns the right position of stemming (suffix start position) in the treated word. ```APIDOC ## get_right ### Description Returns the right position of stemming (suffix start position) in the treated word by the stemmer. ### Method `get_right(self)` ``` -------------------------------- ### Get Affix List with Tashaphyne Source: https://github.com/linuxscout/tashaphyne/blob/master/README.rst Retrieves the list of affixes (prefixes and suffixes) currently used by the stemmer. This can be useful for understanding the stemmer's internal configuration. ```python >>> print repr(custom_stemmer.get_affix_list()) [{'prefix': u'ب', 'root': u'المدرستين', 'stem': u'المدرستين', 'suffix': u''}, {'prefix': u'بال', 'root': u'مدرستين', 'stem': u'مدرستين', 'suffix': u''}, {'prefix': u'', 'root': u'بالمدرستين', 'stem': u'بالمدرستين', 'suffix': u''}] ``` -------------------------------- ### Get Affix from ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Combines the prefix and suffix of a stemmed word. It uses the get_prefix and get_suffix methods to retrieve these parts. Default values for indices are -1. ```python def get_affix(self, prefix_index=-1, suffix_index=-1): """ return the affix of the treated word by the stemmer. Example: >>> ArListem = ArabicLightStemmer() >>> word = u'أفتكاتبانني' >>> stem = ArListem.light_stem(word) >>> print ArListem.get_affix() أفت-انني @param prefix_index: indicate the left stemming position if = -1: not cosidered, and take the default word prefix lentgh. @type prefix_index:integer. @param suffix_index:indicate the right stemming position. if = -1: not cosidered, and take the default word suffix position. @type suffix_index: in4teger. @return: suffixe. @rtype: unicode. """ return "-".join([self.get_prefix(prefix_index), \ self.get_suffix(suffix_index)]) ``` -------------------------------- ### Get Affix List Source: https://github.com/linuxscout/tashaphyne/blob/master/docs/source/README.md Use `get_affix_list()` to extract a list of all potential affixes (prefix, root, stem, suffix) for the treated word. This is useful for detailed morphological analysis. ```python >>> # get affix list ... print repr(ArListem.get_affix_list() ) [{'prefix': u'أف', 'root': u'ضرب', 'stem': u'تضارب', 'suffix': u'انني'}, {'prefix': u'أفت', 'root': u'ضرب', 'stem': u'ضاربا', 'suffix': u'نني'}, {'prefix': u'', 'root': u'أفضرب', 'stem': u'أفتضاربا', 'suffix': u'نني'}, {'prefix': u'أف', 'root': u'ضربن', 'stem': u'تضاربان', 'suffix': u'ني'}, {'prefix': u'أف', 'root': u'ضرب', 'stem': u'تضاربا', 'suffix': u'نني'}, {'prefix': u'أفت', 'root': u'ضربنن', 'stem': u'ضاربانن', 'suffix': u'ي'}, ...] ``` -------------------------------- ### Segment Word in ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Generates all possible segmentation positions (left, right) for a given word by combining prefix and suffix lookups. Includes an example of usage. ```python self.word = word self.unvocalized = araby.strip_tashkeel(word) # word, harakat = araby.separate(word) word = re.sub(ur"[%s]"%(araby.ALEF_MADDA), araby.HAMZA+araby.ALEF, word) # get all lefts position of prefixes lefts = self.lookup_prefixes(word) # get all rights position of suffixes rights = self.lookup_suffixes(word) if lefts: self.left = max(lefts) else: self.left = -1 if rights: self.right = min(rights) else: self.right = -1 #~ ln = len(word) self.segment_list = set([(0, len(word))]) # print lefts, rights for i in lefts: for j in rights: if j >= i+2: self.segment_list.add((i, j)) return self.segment_list ``` -------------------------------- ### Getting Affix List Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Retrieves a list of dictionaries, where each dictionary contains the prefix, root, suffix, and the stemmed word. This is obtained after performing a segmentation. ```python ArListem = ArabicLightStemmer() word = u'فتضربين' ArListem.segment(word) print ArListem.get_affix_list() ``` -------------------------------- ### Max Prefix Length Configuration Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Methods to get and set the maximum length of the prefix considered by the stemmer. ```APIDOC ## get_max_prefix_length ### Description Returns the constant for the maximum length of the prefix used by the stemmer. Defaults to DEFAULT_MAX_PREFIX_LENGTH. ### Method `get_max_prefix_length(self)` ### Return Value - **integer**: The current maximum prefix length. ## set_max_prefix_length ### Description Sets the constant for the maximum length of the prefix used by the stemmer. ### Method `set_max_prefix_length(self, new_max_prefix_length)` ### Parameters #### Path Parameters - **new_max_prefix_length** (integer) - Required - The new maximum prefix length constant. ``` -------------------------------- ### Perform Light Stemming and Extract Components Source: https://context7.com/linuxscout/tashaphyne/llms.txt Use `light_stem` to get the lightest stem of an Arabic word. Intermediate results like root, prefix, suffix, and positions are stored on the instance for retrieval. ```python from tashaphyne.stemming import ArabicLightStemmer stemmer = ArabicLightStemmer() word = 'أفتضاربانني' stem = stemmer.light_stem(word) print('stem :', stemmer.get_stem()) print('root :', stemmer.get_root()) print('prefix :', stemmer.get_prefix()) print('suffix :', stemmer.get_suffix()) print('affix :', stemmer.get_affix()) print('left :', stemmer.get_left()) print('right :', stemmer.get_right()) print('starword:', stemmer.get_starword()) print('starstem:', stemmer.get_starstem()) print('unvoc :', stemmer.get_unvocalized()) ``` -------------------------------- ### Get All Segmentations as Structured Dictionaries Source: https://context7.com/linuxscout/tashaphyne/llms.txt After calling `segment()`, `get_affix_list()` returns a list of dictionaries, each detailing a valid segmentation with its prefix, stem, suffix, starstem, and root. ```python from tashaphyne.stemming import ArabicLightStemmer stemmer = ArabicLightStemmer() stemmer.segment('فتضربين') for entry in stemmer.get_affix_list(): print(entry) ``` -------------------------------- ### Get Stem - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Retrieves the core stem of the word. Optional prefix and suffix indices can be provided to customize the stem extraction. ```python >>> ArListem = ArabicLightStemmer() >>> word = u'أفتكاتبانني' >>> stem = ArListem .light_stem(word) >>> print ArListem.get_stem() كاتب ``` -------------------------------- ### Extract Root with Stemming Examples Source: https://context7.com/linuxscout/tashaphyne/llms.txt Use `get_root()` to extract the trilateral or quadrilateral Arabic root. The function uses a built-in dictionary and heuristics to select the most plausible root. ```python from tashaphyne.stemming import ArabicLightStemmer stemmer = ArabicLightStemmer() for word in ['أفتضاربانني', 'بالمكتبة', 'يستريحون', 'مزدهرة']: stemmer.light_stem(word) print(f'{word} → root: {stemmer.get_root()}, stem: {stemmer.get_stem()}') ``` -------------------------------- ### ArabicLightStemmer.__init__ Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/identifier-index.html Initializes the ArabicLightStemmer. ```APIDOC ## __init__() ### Description Initializes the ArabicLightStemmer. ### Method (Not specified, likely a constructor) ### Endpoint (Not applicable, Python method) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ``` -------------------------------- ### Get Stem of Word Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Retrieves the stem of the treated word after applying the light stemming algorithm. Optional prefix and suffix indices can be provided to specify the exact stemming boundaries. ```python ArListem = ArabicLightStemmer() word = u'أفتكاتبانني' stem = ArListem .light_stem(word) print ArListem.get_stem() ``` -------------------------------- ### Get Right Stemming Position Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Returns the integer representing the start position of the suffix in the stemmed word. This indicates how much of the end of the original word was considered a suffix. ```python ArListem = ArabicLightStemmer() word = u'أفتصربونني' stem = ArListem .light_stem(word) print ArListem.get_starword() print ArListem.get_right() ``` -------------------------------- ### ArabicLightStemmer Constructor Source: https://context7.com/linuxscout/tashaphyne/llms.txt Instantiate the main class of the library. This loads default Arabic prefix/suffix lists and builds the internal finite-state automaton trees, making the stemmer ready for immediate use. ```APIDOC ## ArabicLightStemmer Constructor ### Description Instantiates the main class of the library. This loads the default Arabic prefix/suffix lists and builds the internal finite-state automaton trees. ### Usage ```python from tashaphyne.stemming import ArabicLightStemmer stemmer = ArabicLightStemmer() # The stemmer is ready to use immediately. ``` ``` -------------------------------- ### Get Word - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Returns the last word that was processed by the stemmer. ```python return self.word ``` -------------------------------- ### ArabicLightStemmer._create_prefix_tree Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/identifier-index.html Internal method to create the prefix tree for the ArabicLightStemmer. ```APIDOC ## _create_prefix_tree() ### Description Internal method to create the prefix tree for the ArabicLightStemmer. ### Method (Not specified, likely a private method call) ### Endpoint (Not applicable, Python method) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ``` -------------------------------- ### Word Transformation Functions Source: https://github.com/linuxscout/tashaphyne/blob/master/docs/source/README.md Functions to get stemmed words and unvocalized forms. ```APIDOC ## get_starword() ### Description Get stared word, radical letters replaced by “*”. ### Method `get_starword()` ## get_starstem() ### Description Get stared stem, radical letters replaced by “*”. ### Method `get_starstem()` ## get_unvocalized() ### Description Returns the unvocalized form of the treated word by the stemmer. Harakat are striped. ### Method `get_unvocalized()` ``` -------------------------------- ### Segment Word with Tashaphyne Source: https://github.com/linuxscout/tashaphyne/blob/master/README.rst Demonstrates how to segment a word using the `segment` method of the `ArabicLightStemmer`. The output represents possible segmentation points. ```python >>> custom_stemmer.segment(word) set([(1, 10), (3, 10), (0, 10)]) ``` -------------------------------- ### Create Prefix Tree in ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Builds a tree structure to store prefixes of words. Used internally by the stemmer. ```python if char not in branch: branch[char] = {} branch = branch[char] # branch['#'] = '#' # the hash # as an end postion if '#' in branch: branch['#'][prefix] = "#" else: branch['#'] = {prefix:"#", } self.prefixes_tree = prefixestree return self.prefixes_tree ``` -------------------------------- ### get_right Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Retrieves the leftmost position of the suffix (start of the suffix) in the treated word. ```APIDOC ## get_right() ### Description Returns the right position of stemming (suffix start position) in the treated word. ### Example ```python ArListem = ArabicLightStemmer() word = u'أفتصربونني' stem = ArListem.light_stem(word) print ArListem.get_starword() # Output: أفت***ونني print ArListem.get_right() # Output: 6 ``` ### Returns - integer: The right position of stemming. ``` -------------------------------- ### ArabicLightStemmer Initialization Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Initializes an instance of the ArabicLightStemmer class. This is the entry point for using the stemmer's functionalities. ```APIDOC ## __init__ ### Description Initializes the ArabicLightStemmer. ### Method __init__ ### Parameters - **self** (object) - The instance of the class. ``` -------------------------------- ### Get Suffix List - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Retrieves the set of suffixes used by the stemmer. Defaults to DEFAULT_SUFFIX_LIST. ```python return self.suffix_list ``` -------------------------------- ### Stem Text with Tashaphyne and Pyarabic Source: https://github.com/linuxscout/tashaphyne/blob/master/README.rst Shows how to stem all words in an Arabic text using Tashaphyne's `ArabicLightStemmer` in conjunction with `pyarabic.araby.tokenize`. This process involves tokenizing the text first, then applying the stemmer to each token. ```python >>> import pyarabic.araby as araby >>> from tashaphyne.stemming import ArabicLightStemmer >>> stemmer = ArabicLightStemmer() >>> text = "الأطفال يستريحون في المكتبة للمطالعة" >>> tokens = araby.tokenize(text) >>> tokens ['الأطفال', 'يستريحون', 'في', 'المكتبة', 'للمطالعة'] >>> for tok in tokens: ... stem = stemmer.light_stem(tok) ... print(tok, stem) ... الأطفال أطفال يستريحون يستريح في في المكتبة مكتب للمطالعة مطالع ``` -------------------------------- ### ArabicLightStemmer.set_prefix_list Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/identifier-index.html Sets the list of prefixes for the ArabicLightStemmer. ```APIDOC ## set_prefix_list() ### Description Sets the list of prefixes for the ArabicLightStemmer. ### Method (Not specified, likely a method call) ### Endpoint (Not applicable, Python method) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ``` -------------------------------- ### Get Unvocalized - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Returns the unvocalized form of the treated word, with Harakat (vowel marks) removed. ```python return self.unvocalized ``` -------------------------------- ### get_affix_list Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Returns a list of affix dictionaries for the treated word. Each dictionary contains prefix, root, suffix, and stem information. ```APIDOC ## get_affix_list ### Description Returns a list of affix dictionaries for the treated word. Each dictionary contains prefix, root, suffix, and stem information. ### Method GET ### Endpoint `/get_affix_list` ### Parameters None ### Response #### Success Response (200) - **affix_list** (list of dict) - A list where each dictionary details the prefix, root, suffix, and stem of a word segment. ### Response Example ```json { "affix_list": [ { "prefix": "ف", "root": "ضرب", "suffix": "ين", "stem": "تضرب" }, { "prefix": "فت", "root": "ضرب", "suffix": "ين", "stem": "ضرب" }, { "prefix": "", "root": "فضربن", "suffix": "", "stem": "فتضربين" } ] } ``` ``` -------------------------------- ### Create Suffix Tree in ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Builds a tree structure to store suffixes of words. Used internally by the stemmer. ```python suffixestree = {} for suffix in suffixes: # print (u"'%s'"%suffix).encode('utf8') branch = suffixestree #reverse a string for char in suffix[::-1]: if char not in branch: branch[char] = {} branch = branch[char] # branch['#'] = '#' # the hash # as an end postion if "#" in branch: branch['#'][suffix] = "#" else: branch['#'] = {suffix:"#", } self.suffixes_tree = suffixestree return self.suffixes_tree ``` -------------------------------- ### Max Suffix Length Configuration Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Methods to get and set the maximum length of the suffix considered by the stemmer. ```APIDOC ## get_max_suffix_length ### Description Returns the constant for the maximum length of the suffix used by the stemmer. Defaults to DEFAULT_MAX_SUFFIX_LENGTH. ### Method `get_max_suffix_length(self)` ### Return Value - **integer**: The current maximum suffix length. ## set_max_suffix_length ### Description Sets the constant for the maximum length of the suffix used by the stemmer. ### Method `set_max_suffix_length(self, new_max_suffix_length)` ### Parameters #### Path Parameters - **new_max_suffix_length** (integer) - Required - The new maximum suffix length constant. ``` -------------------------------- ### Joker Character Configuration Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Methods to get and set the joker character used by the stemmer. This character can represent a wildcard. ```APIDOC ## get_joker ### Description Returns the joker character used by the stemmer. Defaults to DEFAULT_JOKER. ### Method `get_joker(self)` ### Return Value - **unicode**: The current joker character. ## set_joker ### Description Sets the joker character for the stemmer. If a string longer than one character is provided, only the first character is used. ### Method `set_joker(self, new_joker)` ### Parameters #### Path Parameters - **new_joker** (unicode) - Required - The new joker character to set. ``` -------------------------------- ### Get Segmentation List - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Retrieves the list of segmentations for a treated word. This is useful for understanding how the stemmer has broken down the word. ```python print ArListem.get_segment_list() ``` -------------------------------- ### ArabicLightStemmer._create_suffix_tree Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/identifier-index.html Internal method to create the suffix tree for the ArabicLightStemmer. ```APIDOC ## _create_suffix_tree() ### Description Internal method to create the suffix tree for the ArabicLightStemmer. ### Method (Not specified, likely a private method call) ### Endpoint (Not applicable, Python method) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ``` -------------------------------- ### Get Starword - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Returns the starlike representation of the treated word, where non-affix letters are replaced by a joker character (default '*'). ```python return self.starword ``` -------------------------------- ### ArabicLightStemmer.tokenize Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/identifier-index.html Tokenizes the input word using the ArabicLightStemmer. ```APIDOC ## tokenize() ### Description Tokenizes the input word using the ArabicLightStemmer. ### Method (Not specified, likely a method call) ### Endpoint (Not applicable, Python method) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ``` -------------------------------- ### Infix Letters Configuration Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Methods to get and set the infixation letters used by the stemmer. These are characters to be stripped from the middle of a word. ```APIDOC ## get_infix_letters ### Description Returns the infixation letters used by the stemmer. Defaults to DEFAULT_INFIX_LETTERS. ### Method `get_infix_letters(self)` ### Return Value - **unicode**: The current infixation letters. ## set_infix_letters ### Description Sets the infixation letters for the stemmer. These are characters to be stripped from the middle of a word. ### Method `set_infix_letters(self, new_infix_letters)` ### Parameters #### Path Parameters - **new_infix_letters** (unicode) - Required - The new infixation letters to set (e.g., u"أوي"). ``` -------------------------------- ### Customize Affixes with set_prefix_list and set_suffix_list Source: https://context7.com/linuxscout/tashaphyne/llms.txt Allows replacement of default prefix and suffix lists to create domain-specific stemmers. Rebuilds internal automaton trees upon modification. Use for focused stemming without code changes. ```python import tashaphyne.stemming CUSTOM_PREFIX_LIST = [ '', 'ال', 'ب', 'بال', 'ف', 'فال', 'و', 'وال', 'ك', 'كال', 'ل', 'لل', 'أ', 'أل', 'أف', 'أفب', 'أفبال', ] CUSTOM_SUFFIX_LIST = ['', 'ه', 'ها', 'هم', 'هن', 'هما', 'ك', 'كم', 'كن', 'كما', 'نا', 'ي'] default_stemmer = tashaphyne.stemming.ArabicLightStemmer() custom_stemmer = tashaphyne.stemming.ArabicLightStemmer() custom_stemmer.set_prefix_list(CUSTOM_PREFIX_LIST) custom_stemmer.set_suffix_list(CUSTOM_SUFFIX_LIST) word = 'بالمدرستين' default_stemmer.segment(word) print('default segments:', len(default_stemmer.get_segment_list())) # many possibilities custom_stemmer.segment(word) print('custom segments :', len(custom_stemmer.get_segment_list())) # fewer, more focused for entry in custom_stemmer.get_affix_list(): print(entry['prefix'], '|', entry['stem'], '|', entry['suffix']) # ب | المدرستين | # بال | مدرستين | # | بالمدرستين| ``` -------------------------------- ### tokenize Source: https://context7.com/linuxscout/tashaphyne/llms.txt Splits Arabic text into word tokens, preparing it for per-word stemming. ```APIDOC ## tokenize(text) ### Description Splits an Arabic text string on non-word characters (punctuation, whitespace, digits) and returns a list of word tokens, ready for per-word stemming. ### Parameters #### Path Parameters - **text** (str) - Required - The Arabic text string to tokenize. ### Response #### Success Response (200) - **tokens** (list) - A list of word tokens extracted from the text. ### Request Example ```python from tashaphyne.stemming import ArabicLightStemmer import pyarabic.araby as araby stemmer = ArabicLightStemmer() text = 'الأطفال يستريحون في المكتبة للمطالعة' tokens = araby.tokenize(text) results = [] for tok in tokens: stemmer.light_stem(tok) results.append({ 'word' : tok, 'stem' : stemmer.get_stem(), 'root' : stemmer.get_root(), 'prefix': stemmer.get_prefix(), 'suffix': stemmer.get_suffix(), }) for r in results: print(r['word'], '->', r['stem'], '(root:', r['root'] + ')') ``` ### Response Example ```json [ "الأطفال", "يستريحون", "في", "المكتبة", "للمطالعة" ] ``` ### Example Usage with Stemming Results ``` الأطفال -> أطفال (root: طفل) يستريحون -> يستريح (root: روح) في -> في (root: في) المكتبة -> مكتب (root: كتب) للمطالعة -> مطالع (root: طلع) ``` ``` -------------------------------- ### Suffix Letters Configuration Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Methods to get and set the suffixation letters used by the stemmer. These are characters to be stripped from the end of a word. ```APIDOC ## get_suffix_letters ### Description Returns the suffixation letters used by the stemmer. Defaults to DEFAULT_SUFFIX_LETTERS. ### Method `get_suffix_letters(self)` ### Return Value - **unicode**: The current suffixation letters. ## set_suffix_letters ### Description Sets the suffixation letters for the stemmer. These are characters to be stripped from the end of a word. ### Method `set_suffix_letters(self, new_suffix_letters)` ### Parameters #### Path Parameters - **new_suffix_letters** (unicode) - Required - The new suffixation letters to set (e.g., u"ةون"). ``` -------------------------------- ### Create prefix tree Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Builds a tree structure from a list of prefixes. This is used internally to efficiently manage and search for prefixes during the stemming process. ```python prefixestree = {} for prefix in prefixes: # print prefix.encode('utf8') branch = prefixestree for char in prefix: ``` -------------------------------- ### Get Unvocalized Word - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Retrieves the unvocalized version of the word after stemming. This is useful for seeing the base word without diacritics. ```python >>> word = u"الْعَرَبِيّةُ" >>> ArListem = ArabicLightStemmer() >>> stem = ArListem .light_stem(word) >>> print ArListem.get_unvocalized() العربية ``` -------------------------------- ### Get Normalized - ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Returns the normalized form of the treated word, converting certain letters like Hamzat to their standard forms. ```python return self.normalized ``` -------------------------------- ### Access and Configure Stemmer Constraints Source: https://context7.com/linuxscout/tashaphyne/llms.txt Provides accessors to inspect default stemmer constraints like max prefix/suffix length and min stem length. Constraints can be tightened using setters, which take effect immediately and rebuild FSA trees for prefix/suffix list setters. ```python from tashaphyne.stemming import ArabicLightStemmer stemmer = ArabicLightStemmer() # inspect defaults print('max prefix length :', stemmer.get_max_prefix_length()) # 4 print('max suffix length :', stemmer.get_max_suffix_length()) # 6 print('min stem length :', stemmer.get_min_stem_length()) # 2 print('joker char :', stemmer.get_joker()) # * # tighten constraints for a specific domain stemmer.set_max_prefix_length(2) stemmer.set_max_suffix_length(3) stemmer.set_min_stem_length(3) ``` -------------------------------- ### get_affix_list Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Returns a list of affix tuples of the treated word by the stemmer. ```APIDOC ## get_affix_list ### Description Return a list of affix tuple of the treated word by the stemmer. ### Method N/A (Method of ArabicLightStemmer class) ### Parameters None. ### Returns - A list of dictionaries, where each dictionary represents an affix (structure not specified). ``` -------------------------------- ### ArabicLightStemmer light_stem method Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Performs light stemming on an Arabic word. It processes the word by removing tashkeel, substituting specific characters, and identifying potential prefixes, stems, and suffixes based on defined rules and lists. The result is a 'starword' representation and stemming boundaries. ```python self.word = word word = araby.[strip_tashkeel](# "tashaphyne.normalize.strip_tashkeel")(word) # word, harakat = araby.separate(word) self.unvocalized = word word = re.sub(ur"[%s]"%(araby.ALEF_MADDA), araby.HAMZA+araby.ALEF, word) word = re.sub(ur"[^%s%s]"%(self.prefix_letters, self.suffix_letters), \ self.joker, word) #~ ln = len(word) left = word.find(self.joker) right = word.rfind(self.joker) if left >= 0: left = min(left, self.max_prefix_length-1) right = max(right+1, len(word)-self.max_suffix_length) prefix = word[:left] stem = word[left:right] suffix = word[right:] prefix = re.sub(ur"[^%s]"%self.prefix_letters, self.joker, prefix) # avoid null infixes if self.infix_letters: stem = re.sub(ur"[^%s]"%self.infix_letters, self.joker, stem) suffix = re.sub(ur"[^%s]"%self.suffix_letters, self.joker, suffix) word = prefix+stem+suffix left = word.find(self.joker) right = word.rfind(self.joker) # prefix_list = self.PREFIX_LIST # suffix_list = self.SUFFIX_LIST if left < 0: left = min(self.max_prefix_length, len(word)-2) if left >= 0: prefix = word[:left] while prefix != "" and prefix not in self.prefix_list: prefix = prefix[:-1] if right < 0: right = max(len(prefix), len(word)-self.max_suffix_length) suffix = word[right:] while suffix != "" and suffix not in self.suffix_list: suffix = suffix[1:] left = len(prefix) right = len(word)-len(suffix) stem = word[left:right] # convert stem into stars. # a stem must starts with alef, or end with alef. # any other infixes letter isnt infixe at the border of the stem. #substitute all non infixes letters if self.infix_letters != "": stem = re.sub(ur"[^%s]"%self.infix_letters, self.joker, stem) # substitube teh in infixes the teh mst be in the first # or second place, all others, are converted # # stem = stem[:2]+re.sub(TEH, self.joker, stem[2:]) word = prefix+stem+suffix # store result self.left = left self.right = right self.starword = word self.[extract_root](# "tashaphyne.stemming.ArabicLightStemmer.extract_root")() # return starword, left, right position of stem return (word, left, right) ``` -------------------------------- ### Get Suffix from ArabicLightStemmer Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming-pysrc.html Retrieves the suffix of a word after stemming. If suffix_index is -1, it uses the default suffix position. Otherwise, it uses the provided index. ```python def get_suffix(self, suffix_index=-1): """ return the suffix of the treated word by the stemmer. Example: >>> ArListem = ArabicLightStemmer() >>> word = u'أفتكاتبانني' >>> stem = ArListem.light_stem(word) >>> print ArListem.get_suffix() انني @param suffix_index:indicate the right stemming position. if = -1: not cosidered, and take the default word suffix position. @type suffix_index: integer. @return: suffixe. @rtype: unicode. """ if suffix_index < 0: return self.unvocalized[self.right:] else: return self.unvocalized[suffix_index:] ``` -------------------------------- ### _create_prefix_tree Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Creates a prefixes tree from a given list of prefixes. ```APIDOC ## _create_prefix_tree ### Description Create a prefixes tree from given prefixes list. ### Method N/A (Private method of ArabicLightStemmer class) ### Parameters - **prefixes** (list): A list of prefixes to build the tree from. ### Returns Tree structure (type not specified). ``` -------------------------------- ### Get Unvocalized Word Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Retrieves the unvocalized form of the treated word by stripping Harakat (vowel marks). This is useful for processing text where vocalization is not relevant. ```python word = u"الْعَرَبِيّةُ" ArListem = ArabicLightStemmer() stem = ArListem .light_stem(word) print ArListem.get_unvocalized() ``` -------------------------------- ### Get Starword Representation Source: https://github.com/linuxscout/tashaphyne/blob/master/doc/html/tashaphyne.stemming.ArabicLightStemmer-class.html Retrieves the starlike representation of the treated word, where non-affix letters are replaced by a joker character. This is useful for visualizing the stemming process. ```python ArListem = ArabicLightStemmer() word = u'أفتصربونني' stem = ArListem .light_stem(word) print ArListem.get_starword() ```