Wiki Process Flow

Getting Results from Wikipedia

Transformed Text is passed to wikiSearch flow to get the Summary from Wikipedia. By default Aryan gets 2 sentences from Wikipedia for the given Human query.

If Human explicitly mentions to get details about a particular topic, then Aryan gets 5 sentences from Wikipedia, This is achieved by passing a detailFlag as "Y" by the Speech Action flow which invokes Wikipedia flow.

Wikipedia is a Python library that makes it easy to access and parse data from Wikipedia.

Search Wikipedia, get article summaries, get data like links and images from a page, and more. Wikipedia wraps the MediaWiki API so you can focus on using Wikipedia data, not getting it.

'''When the detailFlag is set as Y then get the 5 sentences from Wikipedia, else get only 2 sentences per user request'''
if detailFlag == "Y":
    output = wikipedia.summary(query, sentences = 5)   
else:
    output = wikipedia.summary(query, sentences = 2)

Cleaning the Wikipedia Output

Once Aryan gets output from Wikipedia, Next step is to Clean the Wiki Result, Regular Expressions are used to parse the wiki data and clean it to make it usable for speaking and readability by Aryan. cleanWikiResult flow takes care of it

Below is an example of usage of the Regular Expressions to clean the output response of "Can you tell me about Queen Victoria?"

Wiki Raw Output:

Victoria (Alexandrina Victoria; 24 May 1819 – 22 January 1901) was Queen of the United Kingdom of Great Britain and Ireland from 20 June 1837 until her death in 1901. Known as the Victorian era, her reign of 63 years and seven months was longer than any previous British monarch.

Wiki Cleaned Output:

Victoria was Queen of the United Kingdom of Great Britain and Ireland from 20 June 1837 until her death in 1901. Known as the Victorian era, her reign of 63 years and seven months was longer than any previous British monarch.

updated_output = re.sub("[\(\[].*?[\)\]]", "", output)

Do you want to Know more?

By default, Aryan fetches 2 sentences from Wikipedia for the given query, Thus in this flow Aryan asks Human if they want to know more? wikiMoreDetailsCheck flow is executed to fulfill this task,

wikiMoreDetailsCheck(aifriend,query,updatedoutput)

It starts by asking the Human "Do you want to know more?",

  • In case Human says "yes", getMoreDetailsWiki flow is executed to fetch more information, i.e. 3 more sentences.

  • If Human says "no", Aryan triggers the NextStep flow to proceed with further execution.

  • In case of no response the Aryan worker thread exits and Aryan goes back to sleeping mode.

PrintText(aifriend,"Do you want to know more?")
SpeakText(aifriend,"Do you want to know more?")
    
DetailsCheck = TextTransformation(RawSpeechRecognization(aifriend)).lower().lstrip().rstrip()
 
if subStrCheck(DetailsCheck,"yes"):

    getMoreDetailsWiki(aifriend,query,updatedoutput)
    NextStep(aifriend) 

elif subStrCheck(DetailsCheck,"no") or subStrCheck(DetailsCheck, "thankyou") or subStrCheck(DetailsCheck, "thanks") or subStrCheck(DetailsCheck, "thank"):

    PrintText(aifriend, "Okay")
    SpeakText(aifriend,"Okay")
    NextStep(aifriend) 

else:
    PrintText(aifriend, "Didn't got a response")
    SpeakText(aifriend,"Didn't got a response")
    exit()

Get More Information from Wikipedia

In case the user wants to know more about a particular query then getMoreDetailsWiki flow is executed to get additional 3 sentences it is achieved by getting total 5 sentences and thereafter removing the sentences which is already communicated to our Human friend

output = wikipedia.summary(query, sentences = 5)
updatedoutputlong = cleanWikiResult(output)
moredetails = updatedoutputlong.replace(updatedoutputshort,"")

Wikipedia Disambiguation Error

In case for a user query, Aryan get's more then one topics from Wikipedia then disambiguation Error occurs, mentioning user to be more specific in their search as several options are present and flow fall backs to starting point of worker thread.

except wikipedia.exceptions.DisambiguationError as e:
    PrintText(aifriend,"Please be more specific, I have several options with same meaning")
    SpeakText(aifriend,"Please be more specific, I have several options with same meaning")
    ''' Revert the flow back to starting point'''
    TriggerAryanOnce(aifriend)

Wikipedia Exception Handling

Besides this, if for any topic Aryan is unable to get the response from Wiki, then Human is politely mentioned "Sorry could not get it" and Flow fall backs to starting point of worker thread.

except Exception as e:
    PrintText(aifriend, " Sorry could not get it")
    SpeakText(aifriend,"Sorry could not get it")
    PrintText("Exception",str(e))
    ''' Revert the flow back to starting point'''
    TriggerAryanOnce(aifriend)

Last updated