Forum Archive

Linguistitagger Help

TutorialDoctor

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))
TutorialDoctor

My code has changed a bit for simplicity sake:

import linguistictagger

sentence = 'What is your last name'

words = sentence.split()

dictionary = {}
dictionary_list = []

for word in words:
    definition = raw_input("Defition of %s" % (word)) or "No definition"
    dictionary.update({word:definition})
    dictionary_list.append((word,dictionary[word]))
    entry = word + ': ' + dictionary[word]
    print entry

for item in dictionary_list:
    #associations.append(item[0] + ': ' + item[1])
    print item[0],item[1]