Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
GroupD3/PartsOfSpeech.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
77 lines (50 sloc)
1.55 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#made by Ridvan Karaman | |
def responce(sentence): | |
resp = respond(sentence) | |
return resp | |
def find_pronoun(sent): | |
""" finds a preferred pronoun to respond with, given a sentence. returns none if no candidate""" | |
pronoun = None | |
for word, part_of_speech in sent.pos_tags: | |
if part_of_speech == 'PRP' and word.lower() == 'you': | |
pronoun = 'I' | |
elif part_of_speech == 'PRP' and word == 'I': | |
pronoun = 'You' | |
return pronoun | |
def find_verb(sent): | |
""" finds verb in a sentence""" | |
verb = None | |
pos = None | |
for word, part_of_speech in sent.pos_tags: | |
if part_of_speech.startswith('VB'): | |
verb = word | |
pos = part_of_speech | |
break | |
return verb, pos | |
def find_noun(sent): | |
""" finds the best candidate noun in a sentence""" | |
noun = None | |
if not noun: | |
for w,p in sent.pos_tags: | |
if p == 'NN' | |
noun = w | |
break | |
if noun: | |
print("Found noun: %s" + noun) | |
return noun | |
def find_adjective(sent): | |
adj = None | |
for w,p in sent.pos_tags: | |
if p == 'JJ': | |
adj = w | |
break | |
return adj | |
def construck_responce(pronoun,noun,verb): | |
resp = [] | |
if pronoun: | |
resp.append(pronoun) | |
if noun: | |
pronoun = "an" if vowell_check(noun) else "a" | |
resp.append(pronoun + " " + noun) | |
resp.append(random.choice(( "lol", "though", "somehow", ""))) | |
return " ".join(resp) | |