Skip to content

Instantly share code, notes, and snippets.

@NesrineSF
Last active March 31, 2021 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NesrineSF/a304e1fedb26dd879e58bc0f4683f828 to your computer and use it in GitHub Desktop.
Save NesrineSF/a304e1fedb26dd879e58bc0f4683f828 to your computer and use it in GitHub Desktop.
same word belonging to different lemma
living_from_live = "She's living her best life"
living_from_living = "What do you do for a living?"
language = 'en'
#Request to the API
output = client.specific_resource_analysis(
body={"document": {"text": living_from_live }},
params={'language': language, 'resource': 'disambiguation'
})
#Request to the API
output_2 = client.specific_resource_analysis(
body={"document": {"text": living_from_living }},
params={'language': language, 'resource': 'disambiguation'
})
#to print TOKEN, POS and ID (for the concept) in bold at the beginning of the output array:
print (f'\t \033[1mOuput of the first sentence : \033[0m \n')
print (f'\033[1m{"TOKEN":{20}} {"LEMMA":{15}} {"POS":{6}} \033[0m')
#Syncon stands for "Concept" that we refer to with an ID
for token in output.tokens:
print (f'{living_from_live [token.start:token.end]:{20}} {token.lemma:{15}} {token.pos:{6}} ')
print (f'\t \033[1mOuput of the second sentence : \033[0m \n')
print (f'\033[1m{"TOKEN":{20}} {"LEMMA":{15}} {"POS":{6}} \033[0m')
for token in output_2.tokens:
print (f'{living_from_living [token.start:token.end]:{20}} {token.lemma:{15}} {token.pos:{6}} ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment