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
def __init__(self): self._query_extractor = _qe.QueryExtractor()
def __init__(self): #print "inside QueryAnalyzer" self._query_extractor = _qe.QueryExtractor()