From c8bf1fb097163c50a433376b5b2d260fff020d46 Mon Sep 17 00:00:00 2001 From: karvindass Date: Sat, 28 May 2016 17:10:24 +0700 Subject: [PATCH 1/7] Updated Command List Includes Coin Flip --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 264d1a7..5b3d971 100644 --- a/README.md +++ b/README.md @@ -21,5 +21,8 @@ We all want a friendly drink `Time in` + "Name of Major City" * Looks up time in city +`flip` [or synonyms] + `coin` (order insignificant) +* Flips a coin for the user, returning the result and a corresponding ASCII image + # References [Parts of Speech (POS) Tags](https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html) - Used for NLTK From 2b06ee888de32df43594424a807d849ec6719451 Mon Sep 17 00:00:00 2001 From: karvindass Date: Sun, 29 May 2016 20:36:47 +0700 Subject: [PATCH 2/7] Case Changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User’s name is saved in title case, entered strings are saved in lower case --- friendly-drink.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/friendly-drink.py b/friendly-drink.py index 336a415..cbbae29 100644 --- a/friendly-drink.py +++ b/friendly-drink.py @@ -42,7 +42,7 @@ def intro(): # Gets name of user def getName(): reveal("What's your name?") - userData['userName'] = raw_input('> ') # input stored in user data dictionary + userData['userName'] = raw_input('> ').title() # input stored in user data dictionary reveal("Hey there %s, it's nice to meet you" % userData['userName']) # function to print time of a location from user input using Dataset @@ -137,6 +137,7 @@ def flipCoin(): # tokenizes string to determine if user is asking to flip a coin def searchQ(sentence): + sentence = sentence.lower() tokens = nltk.word_tokenize(sentence) # Array of sentence usedWords = [] # Contains all the words used to make decisions on what response to make tags = nltk.pos_tag(tokens) # Array containing all words and POS tag From db8b6149d9e8475076b09bc9f76299a82a93468b Mon Sep 17 00:00:00 2001 From: karvindass Date: Wed, 1 Jun 2016 16:13:47 +0700 Subject: [PATCH 3/7] Birthday Query (#5) Set up RDFLib, SPARQL and DBpedia searching New coin flip option (heads or tails) Can determine birthdate of person provided 2 word length name (no exception for not found) New Methods: synonyms, get resource, get birthday --- README.md | 8 +- databanksearch.py | 116 +++++++++++++++++++++++++ friendly-drink.py => friendly_drink.py | 24 +++-- nltk/WordNetFunctions.py | 13 +++ 4 files changed, 153 insertions(+), 8 deletions(-) create mode 100644 databanksearch.py rename friendly-drink.py => friendly_drink.py (85%) create mode 100644 nltk/WordNetFunctions.py diff --git a/README.md b/README.md index 5b3d971..4615aff 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,13 @@ We all want a friendly drink - Make sure to run using Python 2 - Make sure to install NLTK packages - Not needed yet, but will at some point soon +- Install RDFLib + - `pip install rdflib` (use `sudo` if needed) # Python File Goals: * To achieve: - 1. Do NLTK to answer a simple question - * "Toss/flip/throw a coin" + 1. Toss a coin + * "heads or tails" as possible input 2. NLTK to get information about learning a concept * Find appropriate YouTube video/Wikipedia page * "I want to learn about integration" @@ -22,7 +24,9 @@ We all want a friendly drink * Looks up time in city `flip` [or synonyms] + `coin` (order insignificant) +* Alternately, `heads or tails` or `tails or heads` can be used * Flips a coin for the user, returning the result and a corresponding ASCII image + # References [Parts of Speech (POS) Tags](https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html) - Used for NLTK diff --git a/databanksearch.py b/databanksearch.py new file mode 100644 index 0000000..3da44d3 --- /dev/null +++ b/databanksearch.py @@ -0,0 +1,116 @@ +import nltk # Used for Natural Language Processing +from nltk.stem import WordNetLemmatizer # Used to lemmatize (find root word) +from nltk.tokenize import sent_tokenize, word_tokenize # Used to sentence and word tokenize + +import rdflib # Import for dbpedia usage +from rdflib import Graph, URIRef # Used to make dbpedia queries +from rdflib import RDFS # Used to get label name in dbpedia + +# Get Birthday of resource +def getBirthday(rdfFile): + g = Graph() # Creates graph object + g.parse(rdfFile) # Parses through rdfFile + generator = g.objects(predicate = RDFS.label) # Creates object of all labels given in all languages + + for stmt in g.subject_objects(URIRef("http://dbpedia.org/ontology/birthDate")): # finds subjects and objects with predicate of birthDate + return stmt[1] # Returns first value found + +# Find label function +# Determine's label name based on resource given +def getLabel(rdfFile): + g = Graph() # Creates graph object + g.parse(rdfFile) # Parses through rdfFile + + generator = g.objects(predicate = RDFS.label) # Creates object of all labels given in all languages + + for stmt in generator: # loops through all labels in all languages + if stmt.language == "en": + return stmt # Returns the English name for the resource + +# Gen Resource string +# Should find the link to the object of the interested thing +# e.g. Kanye +def getResource(resName): + resName = resName.title() + tokens = nltk.word_tokenize(resName) + qString = "http://dbpedia.org/resource/" + tokens[0] + for i in range(1, len(tokens)): + qString += "_" + tokens[i] + + return qString + +# Parse question, identify what is asked and return results +def parseQuestion(fullString): + sentenceArray = sent_tokenize(fullString) + + for sentence in sentenceArray: + qIndex = qQuestion(sentence) # return index of question type + if qIndex == 3: # 'When' question + whenQuestion(word_tokenize(sentence)) + +# Identifies what kind of question it is asking (Who/What/Where/When/What/How) +def qQuestion(querySentence): + wordsInSentence = word_tokenize(querySentence) + qWords = ['who','what','where','when','what','how'] + + for word in wordsInSentence: + if word in qWords: + # Proceed if question word is found + return qWords.index(word) + +# When question +# Carried out when 'when' is identified as the question word +def whenQuestion(sentenceArray): + # search for time frame + qDict = {'question': 'when'} # Dict containing all useful information used + timeFrames = {} # Future Dict for searching for time frames + for word in sentenceArray: + if word == 'born': + # Proceed if asking about birthday + qDict['timeQuestion'] = 'birth' + subject = idObject(sentenceArray) + stringToBe = subject[0] + + for word in range(len(subject)): + if word != 0: + stringToBe += " " + subject[word] + qDict['subject'] = stringToBe + break + + RDFlink = getResource(qDict['subject']) + if qDict['timeQuestion'] == 'birth': + timeValue = getBirthday(RDFlink) # get's the value requested, in birth case - date + print ("%s was born on %s" % (qDict['subject'].title(), timeValue)) + +# Object identifier +# identifies object asked about in sentence +# input is full sentence +def idObject(sentenceArray): + h = {} + # Let's assume for ease of use that only the phrase 'When was X Y born?' + h[0] = sentenceArray[2] + h[1] = sentenceArray[3] + # POS_tagged_sentence = nltk.pos_tag(sentenceArray) + # print POS_tagged_sentence + # for index in range(len(POS_tagged_sentence)-1): + # print index + " " + POS_tagged_sentence[index][1] + # if POS_tagged_sentence[index][1] == 'NNP': + # h[0] = sentenceArray[index] + # if POS_tagged_sentence[index+1][1] == 'NNP': + # h[1] = sentenceArray[index+1] + # if POS_tagged_sentence[index + 2][1] == 'NNP': + # h[2] = sentenceArray[index+2] + # break + # else: + # break + # else: + # break + return h + + +def searchDemo(qString): + print getLabel("http://dbpedia.org/resource/Elvis_Presley") + +def search(qString): + # searchDemo(qString) + parseQuestion(qString) diff --git a/friendly-drink.py b/friendly_drink.py similarity index 85% rename from friendly-drink.py rename to friendly_drink.py index cbbae29..cd1e970 100644 --- a/friendly-drink.py +++ b/friendly_drink.py @@ -7,6 +7,7 @@ from random import randint # Used to generate random integer import ASCII_Store +import databanksearch as dbsearch # file containing db query searches # Dictionary containing information about user userData = {} @@ -108,9 +109,11 @@ def checkToFlipCoin(POS_tagged_sentence): flipSynonyms = findSynonyms("flip") + findSynonyms("toss") for word in POS_tagged_sentence: - if word[1] == 'NN': # Checks if word is a noun + # print WordNetLemmatizer().lemmatize(word[0]) + # print word[1] + if word[1] == 'NN' or word[1] == 'NNS': # Checks if word is a noun(or pl.) if WordNetLemmatizer().lemmatize(word[0]) == 'coin': - # Proceed if 'coin' is in setence + # Proceed if 'coin' is in sentence for words in POS_tagged_sentence: if words[1] == 'VB' or words[1] == 'NN' or words[1] == 'IN': # Proceed if a word is base verb, preposition or singular noun @@ -119,6 +122,14 @@ def checkToFlipCoin(POS_tagged_sentence): if syns == words[0]: # If word is a synonym, return True return True + elif WordNetLemmatizer().lemmatize(word[0]) == 'head': + # Proceed if 'head' is in sentence + for word in POS_tagged_sentence: + # iterates through other nouns in sentence + if word[1] == 'NN' or word[1] == 'NNS': + if WordNetLemmatizer().lemmatize(word[0]) == 'tail': + # Proceeds if sentence contains 'tail' + return True # Flips coin, prints string showing answer def flipCoin(): @@ -136,16 +147,17 @@ def flipCoin(): # tokenizes string to determine if user is asking to flip a coin -def searchQ(sentence): - sentence = sentence.lower() +def searchQ(inString): + sentence = inString.lower() tokens = nltk.word_tokenize(sentence) # Array of sentence usedWords = [] # Contains all the words used to make decisions on what response to make tags = nltk.pos_tag(tokens) # Array containing all words and POS tag - flipCheck = checkToFlipCoin(tags) - if flipCheck: + if checkToFlipCoin(tags): usedWords.extend(['flip','coin']) flipCoin() + else: + dbsearch.search(inString) def start(): sTime = time.time() # time from program start diff --git a/nltk/WordNetFunctions.py b/nltk/WordNetFunctions.py new file mode 100644 index 0000000..f924134 --- /dev/null +++ b/nltk/WordNetFunctions.py @@ -0,0 +1,13 @@ +import nltk # Used for natural language recoginition +from nltk.corpus import wordnet # Wordnet for finding synonyms + +# Finds synonyms of word - returns array of synonyms +def findSynonyms(entryWord): + # Array which will contain synonyms + synonyms = [] + for syn in wordnet.synsets(entryWord): + # Iterates through synonyms + for l in syn.lemmas(): + # Iterates through possible lemmas, appends to synonyms array + synonyms.append(l.name()) + return synonyms From ffb64b7eef52b9451a069abfb87cf622e1d693e2 Mon Sep 17 00:00:00 2001 From: karvindass Date: Wed, 1 Jun 2016 17:29:47 +0700 Subject: [PATCH 4/7] Updated README Updates to packages required, file goals and possible inputs --- README.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4615aff..af782ab 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,24 @@ We all want a friendly drink - Not needed yet, but will at some point soon - Install RDFLib - `pip install rdflib` (use `sudo` if needed) +- Install Wikipedia (Github repo used for Wikipedia interfacing) + - `pip install wikipedia` (use `sudo` if needed) # Python File Goals: * To achieve: - 1. Toss a coin - * "heads or tails" as possible input - 2. NLTK to get information about learning a concept + 1. Alternate entries + * Asking for time + * Asking birthday + 1. Intelligent suggestions + * For page names + * e.g. `Barack Obama` from `brack Obama` + * For resource names + * e.g. `dbo:headquarter` from `headquarters` + * LATER `dbo:parent` from `parent company` + 1. NLTK to get information about learning a concept * Find appropriate YouTube video/Wikipedia page * "I want to learn about integration" - 3. Do NLTK on page to get information from Wikipedia page + 2. Do NLTK on page to get information from Wikipedia page * E.g. DOB, gender * "What is the DOB of Kanye West?"" @@ -27,6 +36,9 @@ We all want a friendly drink * Alternately, `heads or tails` or `tails or heads` can be used * Flips a coin for the user, returning the result and a corresponding ASCII image +`when was` + `` + `` + `born` + (optional) `?` +* Searches wikipedia for birthdate of queried individual + # References [Parts of Speech (POS) Tags](https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html) - Used for NLTK From 12e5bf387e118e8ebd807109243fa75114869d9c Mon Sep 17 00:00:00 2001 From: karvindass Date: Thu, 2 Jun 2016 18:45:34 +0700 Subject: [PATCH 5/7] Death in the QueryFile (#6) Set up Wikipedia module, day of death retrieval, files rearranged Now can convert RDFlib returned literals into Python objects New Methods: get death day, suggest page name, new get RDF function --- ASCII_Store.py => exec/ASCII_Store.py | 0 exec/Datasets/__init__.py | 1 + .../Datasets}/timezonedb/country.csv | 0 .../Datasets}/timezonedb/readme.txt | 0 .../Datasets}/timezonedb/timezone.csv | 0 .../Datasets}/timezonedb/zone.csv | 0 {nltk => exec}/WordNetFunctions.py | 0 databanksearch.py => exec/databanksearch.py | 56 ++++++++++++------- friendly_drink.py => exec/friendly_drink.py | 0 exec/wikiFunctions.py | 27 +++++++++ 10 files changed, 64 insertions(+), 20 deletions(-) rename ASCII_Store.py => exec/ASCII_Store.py (100%) create mode 100644 exec/Datasets/__init__.py rename {Datasets => exec/Datasets}/timezonedb/country.csv (100%) rename {Datasets => exec/Datasets}/timezonedb/readme.txt (100%) rename {Datasets => exec/Datasets}/timezonedb/timezone.csv (100%) rename {Datasets => exec/Datasets}/timezonedb/zone.csv (100%) rename {nltk => exec}/WordNetFunctions.py (100%) rename databanksearch.py => exec/databanksearch.py (72%) rename friendly_drink.py => exec/friendly_drink.py (100%) create mode 100644 exec/wikiFunctions.py diff --git a/ASCII_Store.py b/exec/ASCII_Store.py similarity index 100% rename from ASCII_Store.py rename to exec/ASCII_Store.py diff --git a/exec/Datasets/__init__.py b/exec/Datasets/__init__.py new file mode 100644 index 0000000..b6e690f --- /dev/null +++ b/exec/Datasets/__init__.py @@ -0,0 +1 @@ +from . import * diff --git a/Datasets/timezonedb/country.csv b/exec/Datasets/timezonedb/country.csv similarity index 100% rename from Datasets/timezonedb/country.csv rename to exec/Datasets/timezonedb/country.csv diff --git a/Datasets/timezonedb/readme.txt b/exec/Datasets/timezonedb/readme.txt similarity index 100% rename from Datasets/timezonedb/readme.txt rename to exec/Datasets/timezonedb/readme.txt diff --git a/Datasets/timezonedb/timezone.csv b/exec/Datasets/timezonedb/timezone.csv similarity index 100% rename from Datasets/timezonedb/timezone.csv rename to exec/Datasets/timezonedb/timezone.csv diff --git a/Datasets/timezonedb/zone.csv b/exec/Datasets/timezonedb/zone.csv similarity index 100% rename from Datasets/timezonedb/zone.csv rename to exec/Datasets/timezonedb/zone.csv diff --git a/nltk/WordNetFunctions.py b/exec/WordNetFunctions.py similarity index 100% rename from nltk/WordNetFunctions.py rename to exec/WordNetFunctions.py diff --git a/databanksearch.py b/exec/databanksearch.py similarity index 72% rename from databanksearch.py rename to exec/databanksearch.py index 3da44d3..7731441 100644 --- a/databanksearch.py +++ b/exec/databanksearch.py @@ -6,15 +6,27 @@ from rdflib import Graph, URIRef # Used to make dbpedia queries from rdflib import RDFS # Used to get label name in dbpedia +import wikiFunctions as wiki # import functions needed for dbpedia queries + # Get Birthday of resource def getBirthday(rdfFile): g = Graph() # Creates graph object g.parse(rdfFile) # Parses through rdfFile - generator = g.objects(predicate = RDFS.label) # Creates object of all labels given in all languages for stmt in g.subject_objects(URIRef("http://dbpedia.org/ontology/birthDate")): # finds subjects and objects with predicate of birthDate return stmt[1] # Returns first value found +# Get Deathday of resource +def getDeathday(rdfFile): + g = Graph() # Creates graph object + g.parse(rdfFile) + + for stmt in g.subject_objects(URIRef("http://dbpedia.org/ontology/deathDate")): #finds subjects and objects with predicate of deathDate + return stmt[1] + + # Control flow when no deathDate found + return "not found, are you sure they have died?" # Returned if deathDate not found + # Find label function # Determine's label name based on resource given def getLabel(rdfFile): @@ -27,18 +39,6 @@ def getLabel(rdfFile): if stmt.language == "en": return stmt # Returns the English name for the resource -# Gen Resource string -# Should find the link to the object of the interested thing -# e.g. Kanye -def getResource(resName): - resName = resName.title() - tokens = nltk.word_tokenize(resName) - qString = "http://dbpedia.org/resource/" + tokens[0] - for i in range(1, len(tokens)): - qString += "_" + tokens[i] - - return qString - # Parse question, identify what is asked and return results def parseQuestion(fullString): sentenceArray = sent_tokenize(fullString) @@ -77,10 +77,31 @@ def whenQuestion(sentenceArray): qDict['subject'] = stringToBe break - RDFlink = getResource(qDict['subject']) + elif word == 'die': + # Proceed if asking about deathday + qDict['timeQuestion'] = 'death' + subject = idObject(sentenceArray) + stringToBe = subject[0] + + for word in range(len(subject)): + if word != 0: + stringToBe += " " + subject[word] + qDict['subject'] = stringToBe + break + + RDFlink = wiki.suggestRDFPage(qDict['subject']) if qDict['timeQuestion'] == 'birth': timeValue = getBirthday(RDFlink) # get's the value requested, in birth case - date - print ("%s was born on %s" % (qDict['subject'].title(), timeValue)) + dateRetrieved = timeValue.toPython() + # Consider if date not found - maybe person is dead + dateString = dateRetrieved.strftime("%d %b, %Y") + print ("%s was born on %s" % (qDict['subject'].title(), dateString)) + elif qDict['timeQuestion'] == 'death': + timeValue = getDeathday(RDFlink) + dateRetrieved = timeValue.toPython() + # Consider if date not found - maybe person is alive + dateString = dateRetrieved.strftime("%d %b, %Y") + print ("%s died on %s" % (qDict['subject'].title(), dateString)) # Object identifier # identifies object asked about in sentence @@ -107,10 +128,5 @@ def idObject(sentenceArray): # break return h - -def searchDemo(qString): - print getLabel("http://dbpedia.org/resource/Elvis_Presley") - def search(qString): - # searchDemo(qString) parseQuestion(qString) diff --git a/friendly_drink.py b/exec/friendly_drink.py similarity index 100% rename from friendly_drink.py rename to exec/friendly_drink.py diff --git a/exec/wikiFunctions.py b/exec/wikiFunctions.py new file mode 100644 index 0000000..fe7645f --- /dev/null +++ b/exec/wikiFunctions.py @@ -0,0 +1,27 @@ +import wikipedia # Used for wikipedia stuff + +# Natural language processing +import nltk +from nltk.tokenize import word_tokenize + +# Recommends a page name +def suggestPage(qString): + return wikipedia.search(qString)[0] + # Returns string of recommended name + +# Gets RDF DBPedia Link for specific page +def getRDFLink(pageTitle): + tokens = nltk.word_tokenize(pageTitle) + qString = "http://dbpedia.org/resource/" + tokens[0] + for i in range(1, len(tokens)): + qString += "_" + tokens[i] + + return qString + # Returns string of web address + +# Gets RDF Link from provided topic (possibly incorrect entry) +def suggestRDFPage(topic): + suggestedPage = suggestPage(topic) + var = getRDFLink(suggestedPage) + return var + # returns string of web address From 4b1713ebe46380c1313ad55c58b06c5b86171b80 Mon Sep 17 00:00:00 2001 From: Sagar Mandal Date: Fri, 17 Jun 2016 20:26:48 -0400 Subject: [PATCH 6/7] Fine tuned the state of mind and separated find synonyms --- exec/findsynonyms.py | 16 ++++++++++ exec/friendly_drink.py | 69 +++++------------------------------------- exec/location.py | 1 + exec/stateofmind.py | 63 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 61 deletions(-) create mode 100644 exec/findsynonyms.py create mode 100644 exec/stateofmind.py diff --git a/exec/findsynonyms.py b/exec/findsynonyms.py new file mode 100644 index 0000000..17cdbd3 --- /dev/null +++ b/exec/findsynonyms.py @@ -0,0 +1,16 @@ +import nltk # Used for natural language recognition +from nltk.stem import WordNetLemmatizer # Used to lemmatize (find root word) +from nltk.corpus import wordnet # Wordnet for finding synonyms +from nltk.tokenize import sent_tokenize, word_tokenize + + +# Finds synonyms of word - returns array of synonyms +def findSynonyms(entryWord): + # Array which will contain synonyms + synonyms = [] + for syn in wordnet.synsets(entryWord): + # Iterates through synonyms + for l in syn.lemmas(): + # Iterates through possible lemmas, appends to synonyms array + synonyms.append(l.name()) + return synonyms diff --git a/exec/friendly_drink.py b/exec/friendly_drink.py index 6de2a8b..ef0d6fe 100644 --- a/exec/friendly_drink.py +++ b/exec/friendly_drink.py @@ -5,8 +5,9 @@ from nltk.corpus import wordnet # Wordnet for finding synonyms from nltk.tokenize import sent_tokenize, word_tokenize +from findsynonyms import findSynonyms from location import lctnwthrgt - +from stateofmind import fnchk from random import randint # Used to generate random integer import ASCII_Store @@ -73,51 +74,14 @@ def stateofmind(): usedWords = [] # Contains all the words used to make decisions on what response to make wrdarr = word_tokenize(tempstore['sttofmnd']) # Array of sentence tokens= nltk.pos_tag(wrdarr) - fnchk(tokens) - if sombin==1: + + if fnchk(tokens): reveal ("That is Amazing.") - elif sombin==2: + sombin=1 + else: reveal ("I hope you feel better") - - -def fnchk(sentence): - fnSynonyms= findSynonyms("fine")+ findSynonyms("good") - ntSynonyms= findSynonyms("not") - sdSynonyms= findSynonyms("sad")+findSynonyms("sick")+findSynonyms("bad") - for i in range (0, (len(sentence)-1)): - ki=0; - if sentence[i][1]=='JJ': - for syns in fnSynonyms: - if syns.lower() == sentence[i][0].lower(): - ki=ki+1 - if i==0: - sombin=1 - else: - if sentence[i-1][0].lower()=="not": - sombin=0 - else: - for ntsyns in ntSynonyms: - if sentence[i-1][0].lower()==ntsyns.lower(): - sombin=0 - else: - sombin=1 - - if ki!=0: - for syns in sdSynonyms: - if syns.lower() == sentence[i][0].lower(): - if i==0: - sombin=0 - else: - if sentence[i-1][0].lower()=="not": - sombin=1 - else: - for ntsyns in ntSynonyms: - if sentence[i-1][0].lower()==ntsyns.lower(): - sombin=1 - else: - sombin=0 - return + sombin=0 @@ -167,16 +131,6 @@ def getTime(locale): reveal("The time in %s, %s is:" % (searchParam.title(), countryName)) reveal(time.strftime("%H:%M:%S, %a, %d %b %Y ", time.gmtime(checkTime))) -# Finds synonyms of word - returns array of synonyms -def findSynonyms(entryWord): - # Array which will contain synonyms - synonyms = [] - for syn in wordnet.synsets(entryWord): - # Iterates through synonyms - for l in syn.lemmas(): - # Iterates through possible lemmas, appends to synonyms array - synonyms.append(l.name()) - return synonyms # Checks if asking to flip a coin def checkToFlipCoin(POS_tagged_sentence): @@ -205,10 +159,6 @@ def checkToFlipCoin(POS_tagged_sentence): if WordNetLemmatizer().lemmatize(word[0]) == 'tail': # Proceeds if sentence contains 'tail' return True -<<<<<<< HEAD:exec/friendly_drink.py -======= - ->>>>>>> My-Branch:exec/friendly_drink.py # Flips coin, prints string showing answer def flipCoin(): @@ -229,7 +179,7 @@ def weathercheck(sentence): return True def weatherout(): - weather='The temperature in %s is %5.2f with wind speed of %i' %(userData['city'], userData['temperature'], userData['wndspd']) + weather='The temperature in %s is %5.2f with wind speed of %4.1f' %(userData['city'], userData['temperature'], userData['wndspd']) reveal(weather) # tokenizes string to determine if user is asking to flip a coin @@ -242,11 +192,8 @@ def searchQ(inString): if checkToFlipCoin(tags): usedWords.extend(['flip','coin']) flipCoin() -<<<<<<< HEAD:exec/friendly_drink.py -======= elif weathercheck(tags): weatherout() ->>>>>>> My-Branch:exec/friendly_drink.py else: dbsearch.search(inString) diff --git a/exec/location.py b/exec/location.py index b3f45ea..f93d689 100644 --- a/exec/location.py +++ b/exec/location.py @@ -21,6 +21,7 @@ def lctnwthrgt (): return (temperature, wnd['speed'], sky['id'], str(location['city']) ) + #weatherid: #20X thunder storm stuff #30X drizzle diff --git a/exec/stateofmind.py b/exec/stateofmind.py new file mode 100644 index 0000000..2a50693 --- /dev/null +++ b/exec/stateofmind.py @@ -0,0 +1,63 @@ +import nltk # Used for natural language recognition +from nltk.stem import WordNetLemmatizer # Used to lemmatize (find root word) +from nltk.corpus import wordnet # Wordnet for finding synonyms +from nltk.tokenize import sent_tokenize, word_tokenize + +from findsynonyms import findSynonyms + +def fnchk(sentence): + stom=0 + fnSynonyms= findSynonyms("fine")+ findSynonyms("good")+findSynonyms("happy") + ntSynonyms= findSynonyms("not") + sdSynonyms= findSynonyms("sad")+findSynonyms("sick")+findSynonyms("bad") + + for i in range (0, (len(sentence))): + ki=0 + if (len(sentence))==1: + li=0 + for syns in fnSynonyms: + li=1 + if sentence[i][0].lower()==syns: + return True + break + if li==0: + for syns in sdSynonyms: + if sentence[i][0].lower()==syns: + return False + break + + elif sentence[i][1]=='JJ': + for syns in fnSynonyms: + if syns == sentence[i][0].lower(): + ki=1 + if i==0: + return True + else: + if sentence[i-1][0].lower()=="not": + return False + else: + for ntsyns in ntSynonyms: + if sentence[i-1][0].lower()==ntsyns: + return False + else: + return True + break + + break + if ki==0: + for syns in sdSynonyms: + if syns == sentence[i][0]: + if i==0: + return False + else: + if sentence[i-1][0].lower()=="not": + return True + else: + for ntsyns in ntSynonyms: + if sentence[i-1][0].lower()==ntsyns: + return True + else: + return False + break + + break From 548ac9141e57933011308e6f959e2e546f785d5d Mon Sep 17 00:00:00 2001 From: Sagar Mandal Date: Wed, 22 Jun 2016 15:45:37 -0400 Subject: [PATCH 7/7] Merge branch 'My-Branch' # Conflicts: # exec/friendly_drink.py Fixed State of Mind to make it more accurate but code became bulkier. --- exec/friendly_drink.py | 1 + exec/stateofmind.py | 34 +++++++++++++--------------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/exec/friendly_drink.py b/exec/friendly_drink.py index ef0d6fe..0f4b269 100644 --- a/exec/friendly_drink.py +++ b/exec/friendly_drink.py @@ -192,6 +192,7 @@ def searchQ(inString): if checkToFlipCoin(tags): usedWords.extend(['flip','coin']) flipCoin() + elif weathercheck(tags): weatherout() else: diff --git a/exec/stateofmind.py b/exec/stateofmind.py index 2a50693..0bcd310 100644 --- a/exec/stateofmind.py +++ b/exec/stateofmind.py @@ -33,16 +33,12 @@ def fnchk(sentence): if i==0: return True else: - if sentence[i-1][0].lower()=="not": - return False - else: - for ntsyns in ntSynonyms: - if sentence[i-1][0].lower()==ntsyns: - return False - else: - return True - break - + for k in range (0, (i)): + if (sentence[k][0].lower()=="not" or sentence[k][0].lower()=="non"): + return False + else: + continue + return True break if ki==0: for syns in sdSynonyms: @@ -50,14 +46,10 @@ def fnchk(sentence): if i==0: return False else: - if sentence[i-1][0].lower()=="not": - return True - else: - for ntsyns in ntSynonyms: - if sentence[i-1][0].lower()==ntsyns: - return True - else: - return False - break - - break + for k in range (0, (i)): + if (sentence[k][0].lower()=="not" or sentence[k][0].lower()=="non"): + return True + else: + continue + return False + break