From 0b75a41abf7eba8a34500bccffcc35913a72ab93 Mon Sep 17 00:00:00 2001 From: Gurudev <1757254+gurudevrao@users.noreply.github.com> Date: Tue, 4 Sep 2018 00:27:38 +0530 Subject: [PATCH] Version 1.3.4 changes --- gurunudi/ai.py | 73 +++++++++++++++++++++++++++++++------------ gurunudi/config.py | 2 +- gurunudi/constants.py | 5 ++- 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/gurunudi/ai.py b/gurunudi/ai.py index 0a97024..7ffa885 100644 --- a/gurunudi/ai.py +++ b/gurunudi/ai.py @@ -12,6 +12,14 @@ class AI(object): Python class wrapper for Gurunudi AI methods """ + + def __init__(self,version=1): + """ + version (int): The API version to be used while querying Gurunudi Server + + """ + self.version='v'+str(version) + def autocorrect(self,text,lang=lang.ENGLISH): """ text (string): The text that has to be autocorrected @@ -117,16 +125,6 @@ def keywords(self,text,lang=lang.ENGLISH): return self.__call_api(constants.API_KEYWORDS,{constants.FIELD_TEXT:text,constants.FIELD_LANG:lang}) - def knowledge(self,text,lang=lang.ENGLISH): - """ - text (string): The knowledge query whose answer has to be fetched - lang (string): ISO3 language code of the text - returns: answer from Gurunudi Knowledge Graph - """ - - return self.__call_api(constants.API_KNOWLEDGE,{constants.FIELD_TEXT:text,constants.FIELD_LANG:lang}) - - def language(self,text): """ text (string): The text whose language has to be found @@ -135,6 +133,33 @@ def language(self,text): return self.__call_api(constants.API_LANGUAGE,{constants.FIELD_TEXT:text}) + def generate(self,intent,lang=lang.ENGLISH): + """ + intent (dict): The intent for which natural language text has to be generated + lang (string): ISO3 language code of the language in which the text has to be generated + returns: natural language text + """ + + return self.__call_api(constants.API_NLG,{constants.FIELD_TEXT:intent,constants.FIELD_LANG:lang}) + + def graph_query(self,data,lang=lang.ENGLISH): + """ + data (string): The structured info to query the Gurunudi Knowledge Graph + lang (string): ISO3 language code of the query data + returns: answer from Gurunudi Knowledge Graph + """ + + return self.__call_api(constants.API_GRAPH_QUERY,{constants.FIELD_TEXT:data,constants.FIELD_LANG:lang}) + + def inferences(self,text,lang=lang.ENGLISH): + """ + text (string): The text to be infered + lang (string): ISO3 language code of the language in which the text has to be infered + returns: list of inferences + """ + + return self.__call_api(constants.API_NLI,{constants.FIELD_TEXT:text,constants.FIELD_LANG:lang}) + def named_entities(self,text,lang=lang.ENGLISH): """ text (string): The text to find named entities in @@ -145,6 +170,23 @@ def named_entities(self,text,lang=lang.ENGLISH): return self.__call_api(constants.API_NAMED_ENTITIES,{constants.FIELD_TEXT:text,constants.FIELD_LANG:lang}) + def nlp(self,text,lang=lang.ENGLISH): + """ + text (string): The text to be processed + lang (string): ISO3 language code of the language in which the text has to be processed + returns: list of NLP data for each sentence in the text + """ + + return self.__call_api(constants.API_NLP,{constants.FIELD_TEXT:text,constants.FIELD_LANG:lang}) + + def query(self,text,lang=lang.ENGLISH): + """ + text (string): The natural language query whose answer has to be fetched + lang (string): ISO3 language code of the text + returns: answer from Gurunudi Knowledge Graph + """ + + return self.__call_api(constants.API_QUERY,{constants.FIELD_TEXT:text,constants.FIELD_LANG:lang}) def sentences(self,text,lang=lang.ENGLISH): """ @@ -207,15 +249,6 @@ def topics(self,text,lang=lang.ENGLISH): return self.__call_api(constants.API_TOPICS,{constants.FIELD_TEXT:text,constants.FIELD_LANG:lang}) - def nlg(self,intent,lang=lang.ENGLISH): - """ - intent (dict): The intent for which natural language text has to be generated - lang (string): ISO3 language code of the language in which the text has to be generated - returns: natural language text - """ - - return self.__call_api(constants.API_NLG,{constants.FIELD_TEXT:text,constants.FIELD_LANG:lang}) - def translate(self,text,target_lang,src_lang): """ @@ -243,7 +276,7 @@ def __call_api(self,api,data): print("Request Data",data) #call the API - url = config.API_URL.format(api) + url = config.API_URL.format(self.version,api) response = requests.post(url, json=data, headers=config.HEADERS) json=response.json() diff --git a/gurunudi/config.py b/gurunudi/config.py index 147995e..f88536f 100644 --- a/gurunudi/config.py +++ b/gurunudi/config.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """Generic URI of the Gurunudi AI API""" -API_URL = "https://www.gurunudi.com/api/v1/{}/" +API_URL = "https://www.gurunudi.com/api/{}/{}/" """Gurunudi AI API accepts and sents JSON content only""" HEADERS = {'Content-type': 'application/json; charset=utf-8', 'Accept': 'application/json','User-Agent':'Gurunudi Client'} diff --git a/gurunudi/constants.py b/gurunudi/constants.py index 5912e62..2d8043d 100644 --- a/gurunudi/constants.py +++ b/gurunudi/constants.py @@ -12,9 +12,12 @@ API_CHAT ='chat' #real time conversation and knowledge q&a - ideal for chatbots API_DEFINE ='define' #returns definition of word or noun or phrase API_CONTEXTQA ='contextqa' #answers based on given context -API_KNOWLEDGE ='knowledge' #answers using gurunudi knowledge graph API_FIX_CASE ='fixcase' #returns text after fixing any incorrect case issues +API_GRAPH_QUERY ='graph_query' #queries gurunudi knowledge graph in a structured way API_NLG ='nlg' #generates natural language text from given intent +API_NLI ='inferences' #generates inferences based on given text +API_NLP ='nlp' #sentence extraction + pos + dep + ner +API_QUERY ='query' #answers natural language query using gurunudi knowledge graph API_KEYWORDS ='keywords' #extracts keywords from a text document API_SENTENCES ='sentences' #extracts sentences in a text document API_INTENT ='intent' #extracts intent of a text document