File size: 1,577 Bytes
3a1020a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from zemberek import TurkishMorphology
from typing import List
from functools import lru_cache

morphology = TurkishMorphology.create()
# Initialize the Turkish morphology analyzer as a global constant
MORPHOLOGY = TurkishMorphology.create_with_default_resources()

@lru_cache(maxsize=1000)  # Cache results for better performance
def is_verb_or_verbform_zemberek(word: str) -> bool:
    """

    Check if a word is a verb or verbform using Zemberek analysis.

    

    Args:

        word (str): The word to analyze

        

    Returns:

        bool: True if the word is a verb or verbform, False otherwise

    """
    try:
        # Get the analysis result for the word
        result = MORPHOLOGY.analyze(word)
        
        # Return True if there's at least one analysis and it's a verb
        return bool(result and "Verb" in result[0].primary_pos.value)
    except Exception as e:
        print(f"Error analyzing word '{word}': {str(e)}")
        return False

def filter_verbs(words: List[str]) -> List[str]:
    """

    Filter a list of words to keep only verbs and verbforms.

    

    Args:

        words (List[str]): List of words to filter

        

    Returns:

        List[str]: List containing only verbs and verbforms

    """
    return [word for word in words if is_verb_or_verbform_zemberek(word)]

def main():
    # Example usage
    words = ["geliyor", "gitti", "yapmak", "kitap"]
    filtered_words = filter_verbs(words)
    print(f"Verbs found: {filtered_words}")

if __name__ == "__main__":
    main()