Skip to content

Commit

Permalink
Version 1.3.4 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gurudevrao committed Sep 3, 2018
1 parent dcc6ea8 commit 0b75a41
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
73 changes: 53 additions & 20 deletions gurunudi/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion gurunudi/config.py
Original file line number Diff line number Diff line change
@@ -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'}
Expand Down
5 changes: 4 additions & 1 deletion gurunudi/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b75a41

Please sign in to comment.