예제 #1
0
 def predict(self, data):
     try:
         if "news" in data.lower() or "latest" in data.lower():
             # News query
             source, query = self._query_extractor.get_news_tokens(data)
             response = (_ga() if "guardian" in source else
                         _nyt()).get_news(query)
             if len(response) <= 0:
                 return {
                     "phrase": "Sorry, no relevant results were returned."
                 }, 500
             i, done = 0, media_aggregator.shorten_news(response[0])
             while (not done) and ((i + 1) < len(response)):
                 i += 1
                 done = shorten_news(response[i])
         else:
             # Knowledge query
             done = get_gkg(
                 self._query_extractor.get_knowledge_tokens(data))
         ret_val = {"urls": done}
         if not done:
             ret_val["phrase"] = "Sorry, no valid results were returned."
         return ret_val, done
     except:
         return {"phrase": "Sorry, something unexpected happened."}, False
예제 #2
0
 def predict(self, data):
     s=_qe.QueryExtractor()
     _classes, _datapropertiesValues, _dataProperties = InputsForQuery(data.lower())
     try:
         if _classes != "" and _datapropertiesValues == "" and _dataProperties == "":
             print("Information Question")
             print(_classes)
             # Query Classes 
             runQuery = SparqlQueriesClasses()
             Queryresponse = runQuery.search(_classes.capitalize())
             response = TemplateGeneratorInformation(_classes, Queryresponse)
             done = response
             if len(response) <= 0:
                 response = "Sorry, no relevant results were returned."
             i, done = 0, response
             while (not done) and ((i + 1) < len(response)):
                 i += 1
                 done = response 
         elif _classes != "" and _datapropertiesValues != "" and _dataProperties == "":
             print("List Question")
             print(_datapropertiesValues)
             print(_classes)
             # Query Names 
             runQuery = SparqlQueriesNames()
             Queryresponse = runQuery.search(_classes.capitalize(),_datapropertiesValues.capitalize())
             response = TemplateGeneratorList(_classes, _datapropertiesValues, Queryresponse)
             if len(response) <= 0:
                 response = "Sorry, no relevant results were returned."
             i, done = 0, response
             while (not done) and ((i + 1) < len(response)):
                 i += 1
                 done = response
         elif _dataProperties != "" and _datapropertiesValues != "" and _classes == "":
             print("Specific Question")
             print(_datapropertiesValues)
             print(_dataProperties)
             print("museums")
             runQuery = SparqlQueriesSpecific()
             Queryresponse = runQuery.search("Museums", _dataProperties.capitalize(), _datapropertiesValues.capitalize())
             response = TemplateGeneratorSpecific(_dataProperties, _datapropertiesValues, Queryresponse)
             if len(response) <= 0:
                 response = "Sorry, no relevant results were returned."
             i, done = 0, response
             while (not done) and ((i + 1) < len(response)):
                 i += 1
                 done = response
         else:
             # Knowledge query
             done = get_gkg(self._query_extractor.get_knowledge_tokens(data))
         ret_val = {"urls": done}
         if not done:
             ret_val["phrase"] = "Sorry, no valid results were returned."
         return ret_val, done
     except Exception as e:
         return {"phrase": "Sorry, something unexpected happened.", "original_exception": e.message}, False
예제 #3
0
 def predict(self, data):
     try:
         if "news" in data.lower() or "latest" in data.lower():
             # News query
             source, query = self._query_extractor.get_news_tokens(data)
             response = (_ga() if "guardian" in source else _nyt()).get_news(query)
             if len(response) <= 0:
                 return {"phrase": "Sorry, no relevant results were returned."}, 500
             i, done = 0, media_aggregator.shorten_news(response[0])
             while (not done) and ((i + 1) < len(response)):
                 i += 1
                 done = shorten_news(response[i])
         else:
             # Knowledge query
             done = get_gkg(self._query_extractor.get_knowledge_tokens(data))
         ret_val = {"urls": done}
         if not done:
             ret_val["phrase"] = "Sorry, no valid results were returned."
         return ret_val, done
     except Exception, e:
         return {"phrase": "Sorry, something unexpected happened.", "original_exception": e.message}, False