Last active
December 19, 2015 03:19
-
-
Save azenla/5889594 to your computer and use it in GitHub Desktop.
PyQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __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