-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary_lookup.py
More file actions
36 lines (26 loc) · 1.29 KB
/
Copy pathdictionary_lookup.py
File metadata and controls
36 lines (26 loc) · 1.29 KB
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
import stanza
nlp = stanza.Pipeline(lang='uk', processors='tokenize,mwt,pos,lemma', tokenize_no_ssplit=True)
punctuation = [".", ",", "(", ")", "!", "?", ":", ";", "-"]
with open("anglicisms", 'r') as f:
en_dict = [x.lower() for x in f.read().split()]
with open("dictionary_sum_clean.txt", 'r') as f:
uk_dict = f.read().split()
def get_lemmas(text):
list_of_lemmas = []
for sent in nlp(text).sentences:
for word in sent.words:
lemma = word.lemma
if lemma not in list_of_lemmas and lemma not in punctuation and ("'" in lemma or lemma.isalpha()):
list_of_lemmas.append(lemma.lower())
return list_of_lemmas
def detect_neologisms(words):
anglicisms = []
new_words = []
for word in words:
if word in en_dict:
anglicisms.append(word)
if word not in uk_dict and word not in en_dict:
new_words.append(word)
return anglicisms, new_words
print(detect_neologisms(get_lemmas("""Сьогодні відбулися конкурсні випробування «Сам собі іміджмейкер» (захист постеру)
та «Публічний виступ у стилі TED». Чекаємо на презентації інших учасників і результати""")))