I'm working some NLP experiments in Python and wanted to implement this function in Python 3.x though the lambda expansion here is giving me a hard time and I'm not sure how it'd be implemented in 3.x; any suggestions?
candidates = [' '.join(word for word, pos, chunk in group).lower()
for key, group in itertools.groupby(all_chunks, lambda (word,pos,chunk): chunk != 'O') if key]
The error I get is on this piece since sublist parameters are not supported in 3.x
lambda (word,pos,chunk)
The original source is the extract_candidate_words function here: http://bdewilde.github.io/blog/2014/09/23/intro-to-automatic-keyphrase-extraction/
The syntax in Python3 would be:
lambda word__pos__chunk: word__pos__chunk[2] != 'O'
A lambda function with a three item tuple (word, pos, chunk) gets converted to word__pos__chunk with positional arguments, word__pos__chunk[2] access the third item for example.
more information: pep-3113
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With