clarinsi / classla

CLASSLA Fork of the Official Stanford NLP Python Library for Many Human Languages
https://www.clarin.si/info/k-centre/
Other
38 stars 19 forks source link

Converting classla Document or classla CONNLU to Python object #7

Closed RatkoNikolic closed 3 years ago

RatkoNikolic commented 3 years ago

Hi, I can't manage to convert the output of Serbian non-standard lemmatization to any Python object. I tried using stanza for converting classla Document or CoNLLFile to dictionary, but I got the following errors:

'Document' object has no attribute 'to_dict' or 'CoNLLFile' object is not iterable.

Thanks in advance.

nljubesi commented 3 years ago

Hi, could you share your full code in future issues?

If you use the Serbian non-standard example from the README, then the resulting doc object can be iterated for lemmas it the following way (same as stanza):

for sentence in doc.sentences:
    for word in sentence.words:
        print(word.lemma)

the output being

ne
moći
da
verovati
kakav
biti
zezanje
biti
prošli
godina
u
Zagreb
.
RatkoNikolic commented 3 years ago

Thank you! Iterating for lemmas solved it for me. I was just experimenting, so, for now, I have no coherent code to share.