def test_parse_x_of_y_in_year(self): query = "what is the population of France in 2020" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual(output['template'], ['propclass', 'of', 'entity', 'in', 'datetime'])
def test_parse_wh_X_of_y(self): query = "who is the president of Ghana" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual(output['template'], ['propclass', 'of', 'entity'])
def test_parse_nn_pps2(self): query = "How many albums did the Beetles release" # query = "Ghana population" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual(output['template'], ['propclass', 'propclass'])
def test_parse_nn_pps(self): query = "Friends theme songs" # query = "Ghana population" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual(output['template'], ['propclass', 'propclass'])
def test_parse_entity_props(self): query = "sara bareilles songs" # query = "Ghana population" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual(output['template'], ['entity', 'propclass'])
def test_parse_wh_prop_obj(self): # query = "who is the president of Ghana" query = "who sang Infinite Things?" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual(output['template'], ['verb', 'propclass'])
def test_parse_prop_xx_of_y(self): query = "sang theme song of Friends" # query = "Ghana population" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual(output['template'], ['verb', 'propclass', 'of', 'propclass'])
def test_parse_prop_xx_of_entity(self): query = "composed the national anthem of Ghana" # query = "Ghana population" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual(output['template'], ['verb', 'propclass', 'of', 'entity'])
def test_parse_when(self): query = "When did Taylor Swift recorded Exile" # query = "Ghana population" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual(output['template'], ['when', 'entity', 'propclass', 'entity'])
def test_parse_when2(self): query = "When did Rembrandts sing the theme song of Friends" # query = "Ghana population" parser = frank.query_parser.parser.Parser() output = parser.getNextSuggestion(query) print(output) self.assertEqual( output['template'], ['when', 'entity', 'verb', 'propclass', 'of', 'propclass'])
def find_templates(querystring): parsedQuestion = {'alist': {}, 'templates': []} missing_field = False required_fields = [querystring] # check required fields for field in required_fields: if field is None: missing_field = True if not missing_field: if len(querystring.strip().split(' ')) >= 3: parser = frank.query_parser.parser.Parser() parsedQuestion = parser.getNextSuggestion(querystring) parsedQuestion['alist_string'] = json.dumps(parsedQuestion['alist']) return Response(response=json.dumps(parsedQuestion), status=200, mimetype="application/json")
def cli(query, context={}): session_id = uuid.uuid4().hex interactive = False answer = None if query: query_json = None else: print(f"\n{pcol.CYAN}FRANK CLI{pcol.RESETALL}") query = input(f"Enter question or alist query: \n {pcol.CYAN}>{pcol.RESETALL} ") context = input(f"Enter context: \n {pcol.CYAN}>{pcol.RESETALL} ") query_json = None interactive = True # check if input is question or alist if type(query) == str and '{' in query and '"' in query: query_json = json.loads(query) elif type(query) == dict: query_json = query else: parser = frank.query_parser.parser.Parser() parsedQuestion = parser.getNextSuggestion(query) query_json = parsedQuestion['alist'] if query_json: alist = Alist(**query_json) if context: context_json = json.loads(context) if type(context) == str else context alist.set(tt.CONTEXT, context_json) print(f"{pcol.YELLOW} ├── query alist:{json.dumps(alist.attributes)} {pcol.RESETALL}") print(f"{pcol.YELLOW} └── session id:{session_id} {pcol.RESETALL}\n") launch = Launcher() launch.start(alist, session_id, inference_graphs) if session_id in inference_graphs: answer = inference_graphs[session_id]['answer']['answer'] graph = inference_graphs[session_id]['graph'] graph.plot_plotly(query) if interactive: input("\npress any key to exit") else: print("\nCould not parse question. Please try again.") return answer