Skip to content

Instantly share code, notes, and snippets.

@jiansoo
Created February 27, 2019 13:56
Show Gist options
  • Save jiansoo/681bea31de0b08308a74f53903eebee2 to your computer and use it in GitHub Desktop.
Save jiansoo/681bea31de0b08308a74f53903eebee2 to your computer and use it in GitHub Desktop.
def imperative_pos_tag(sent):
return [(word, tag[:2]) if tag.startswith('VB') else (word,tag) for word, tag in nltk.pos_tag(['He']+sent)[1:]]
def find_verb(inp):
inp_token = nltk.word_tokenize(inp)
inp_tagged = imperative_pos_tag(inp_token)
print(inp_tagged)
for i in range(len(inp_tagged)):
if inp_tagged[i][1] == 'VB':
return(inp_tagged[i][0], inp, i)
def interpret_meaning(inp_v, inp, i):
global playing
span_generator = WhitespaceTokenizer().span_tokenize(inp)
spans = [span for span in span_generator]
verb_span = spans[i]
if inp_v == 'play':
rest_of_str = inp[(verb_span[1]+1):]
if rest_of_str == 'music' or rest_of_str == '':
spot.play()
playing = True
start_detection()
elif 'playlist' in rest_of_str:
ros_p = rest_of_str.replace('playlist ', '')
print(ros_p)
spot.search(ros_p, 'p')
start_detection()
else:
spot.search(rest_of_str, 't')
start_detection()
elif inp_v == 'stop' or inp_v == 'pause':
spot.pause()
playing = False
else:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment