Skip to content

Instantly share code, notes, and snippets.

@azenla
Last active December 19, 2015 03:19
Show Gist options
  • Select an option

  • Save azenla/5889594 to your computer and use it in GitHub Desktop.

Select an option

Save azenla/5889594 to your computer and use it in GitHub Desktop.
PyQ
__author__ = 'Kenneth Endfinger'
keywords = {
'Who': 'Person',
'What': 'Thing',
'Where': 'Thing'
}
def parseQuestion(question):
print('Parsing: ' + question)
array = str.split(question)
length = len(array) - 1
array[length] = array[length].replace('?', '')
start = 0
array[start] = array[start].lower().capitalize()
typeID = array[start]
count = 0
entityBegin = 1
entity = ''
for i in array:
if count > entityBegin:
if count is length:
entity += i
else:
entity += i + ' '
count += 1
if typeID not in keywords:
print('Unknown Type: ' + typeID)
else:
print('Type: ' + keywords.get(typeID))
print('Entity: ' + entity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment