Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Linguistitagger Help
-
How would I print the lexical class of each match in the 2nd for loop (for match in matches) where it says
lex
? It showsOtherWord
every iteration.<pre>
Outputs user-defined definitions of each word in the input text
import re
import console
import workflow
import editor
import linguistictaggerparams = 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))
</pre> -
My code has changed a bit for simplicity sake:
<pre>
import linguistictaggersentence = '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 entryfor item in dictionary_list:
#associations.append(item[0] + ': ' + item[1])
print item[0],item[1]
</pre>