Created
March 9, 2017 20:30
-
-
Save pavelsterba/912da428bf1ec8b9fd4e68c036e5fe32 to your computer and use it in GitHub Desktop.
MorphoDiTa example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
result = requests.get('http://lindat.mff.cuni.cz/services/morphodita/api/tag', params={ | |
'data': 'Zeman: Chci být znovu prezidentem a budu kandidovat', | |
'output': 'json', | |
'convert_tagset': 'strip_lemma_comment', | |
}).json() | |
def is_noun(tag): | |
return tag.startswith('NN') | |
def clear_lemma(lemma): | |
lemma_parts = lemma.split('-') | |
if lemma_parts[-1].isdigit(): | |
lemma_parts = lemma_parts[:-1] | |
return '-'.join(lemma_parts) | |
for sentence in result['result']: | |
for word in sentence: | |
if is_noun(word['tag']): | |
print(clear_lemma(word['lemma'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment