TutorialDoctor
Nov 26, 2014 - 18:49
How would I print the lexical class of each match in the 2nd for loop (for match in matches) where it says lex? It shows OtherWord every iteration.
# Outputs user-defined definitions of each word in the input text
import re
import console
import workflow
import editor
import linguistictagger
params = workflow.get_parameters()
sentence = params['Text']
dictionary = {}
dictionary_list = []
associations = []
tags = linguistictagger.tag_string(sentence, linguistictagger.SCHEME_LEXICAL_CLASS)
print tags[0][0]
for tag in tags:
lex = tag[0]
#document_length = len(editor.get_text())
expression = re.compile('\w+')
matches = expression.findall(sentence)
for match in matches:
definition = raw_input("Defition of %s" % (match)) or "No definition"
dictionary.update({match:definition})
dictionary_list.append((match,dictionary[match]))
print match + ': ' + lex + dictionary[match]
for item in dictionary_list:
associations.append(item[0] + ': ' + item[1])
workflow.set_output('\n'.join(associations))