antimoda1 commited on
Commit ·
46895ea
1
Parent(s): cc9523c
more fixes
Browse files- lemmatizer.py +1 -1
- vocabulary/parse_vocabulary.py +13 -7
lemmatizer.py
CHANGED
|
@@ -29,7 +29,7 @@ class RussianLemmatizer:
|
|
| 29 |
"""Компонент для исправления лемм терминов и их форм"""
|
| 30 |
for token in doc:
|
| 31 |
lemma_lower = token.lemma_.lower()
|
| 32 |
-
canonical = VOCABULARY_MANAGER.
|
| 33 |
if canonical:
|
| 34 |
token.lemma_ = canonical.lower()
|
| 35 |
return doc
|
|
|
|
| 29 |
"""Компонент для исправления лемм терминов и их форм"""
|
| 30 |
for token in doc:
|
| 31 |
lemma_lower = token.lemma_.lower()
|
| 32 |
+
canonical = VOCABULARY_MANAGER.find_word_in_terms(lemma_lower)
|
| 33 |
if canonical:
|
| 34 |
token.lemma_ = canonical.lower()
|
| 35 |
return doc
|
vocabulary/parse_vocabulary.py
CHANGED
|
@@ -107,6 +107,16 @@ class ParserVocabulary:
|
|
| 107 |
self.vocabulary[pattern.lemma().lower()] = definition
|
| 108 |
self.patterns.append(pattern)
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
def find_terms(self, text: str) -> set[str]:
|
| 111 |
"""Возвращает список терминов в тексте (учитывая словоформы)
|
| 112 |
|
|
@@ -122,13 +132,9 @@ class ParserVocabulary:
|
|
| 122 |
words = re.findall(r'\b\w+(?:[.-]\w+)*\b', text.lower())
|
| 123 |
|
| 124 |
for word in words:
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
lemma = pattern.lemma().lower()
|
| 129 |
-
assert lemma in self.vocabulary, breakpoint()
|
| 130 |
-
found_lemmas.add(lemma)
|
| 131 |
-
break # Слово найдено, переходим к следующему
|
| 132 |
return found_lemmas
|
| 133 |
|
| 134 |
def wrap_prompt(self, retrieved_text: str, query_text: str):
|
|
|
|
| 107 |
self.vocabulary[pattern.lemma().lower()] = definition
|
| 108 |
self.patterns.append(pattern)
|
| 109 |
|
| 110 |
+
def find_word_in_terms(self, word: str) -> Optional[str]:
|
| 111 |
+
"""Проверяет, является ли слово термином (учитывая словоформы).
|
| 112 |
+
Если да, возвращает лемму термина, иначе None.
|
| 113 |
+
"""
|
| 114 |
+
word = word.lower()
|
| 115 |
+
for pattern in self.patterns:
|
| 116 |
+
if pattern.matches(word):
|
| 117 |
+
return pattern.lemma().lower()
|
| 118 |
+
return None
|
| 119 |
+
|
| 120 |
def find_terms(self, text: str) -> set[str]:
|
| 121 |
"""Возвращает список терминов в тексте (учитывая словоформы)
|
| 122 |
|
|
|
|
| 132 |
words = re.findall(r'\b\w+(?:[.-]\w+)*\b', text.lower())
|
| 133 |
|
| 134 |
for word in words:
|
| 135 |
+
res = self.find_word_in_terms(word)
|
| 136 |
+
if res:
|
| 137 |
+
found_lemmas.add(res)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
return found_lemmas
|
| 139 |
|
| 140 |
def wrap_prompt(self, retrieved_text: str, query_text: str):
|