26 lines
684 B
Python
26 lines
684 B
Python
import spacy
|
|
|
|
class Imp:
|
|
action_s = ''
|
|
object_s = ''
|
|
|
|
nlp = spacy.load("pl_core_news_sm")
|
|
inputed_text = input('Podaj zdanie: ')
|
|
doc = nlp(inputed_text)
|
|
for token in doc:
|
|
print(token.text, token.pos_)
|
|
contains_imp = any(token.morph.get('Mood') == ['Imp'] for token in doc)
|
|
if not contains_imp:
|
|
print('Bye!')
|
|
else:
|
|
imp_list = []
|
|
index = -1
|
|
for token in doc:
|
|
if token.tag_ == 'IMPT':
|
|
imp_list.append(Imp())
|
|
index+=1
|
|
imp_list[index].action_s = token.text
|
|
else:
|
|
imp_list[index].object_s += token.text + " "
|
|
for imp in imp_list:
|
|
print('Action: '+imp.action_s+", Object: "+imp.object_s) |