Capital Process Flow

Identify the Country Name

getCapital flow is used to get the Capital of a Country. Once getCapital flow is invoked, Rawspeech is passed to the getCountryName flow to identify the Country Name.

getCountryName parses the RawSpeech against the list of country from pycountry and return the country name identified.

  • In case the country is not identified then default country name is returned.

  • This is for questions such as what is capital?, So no country is passed thus it default's the country and returns India in this example.

while i<len(pycountry.countries):
    if subStrCheck(rawspeech,(list(pycountry.countries)[i].name)):
        countryname = list(pycountry.countries)[i].name
        break
    i = i+1
    if i == len(pycountry.countries):
        countryname = "India" 

pycountry packages provides the ISO databases for the standards for Countries, Languages, Deleted Countries, Subdivisions of Countries, Currencies, Scripts.

Identify the Capital for the Country

Once the country name is identified then CountryInfo class from CountryInfo package is used to get the Country property i.e. Capital in this case.

countryname = getCountryName(rawspeech)
capital = CountryInfo(countryname).capital()

Thereafter, details are provided to user and Control is returned to NextStep flow.

Aryan provides the Capital the requested Country and flow is completed successfully. Control is passed to NextStep.

PrintText(aifriend,"Capital for " + countryname + " is " + capital)
SpeakText(aifriend,"Capital for " + countryname + " is " + capital )

Last updated