def get_input(text): display_text(text) choice = raw_input(">.. ") if choice == "end": exit(0) else: scan = lexicon.scan(choice) sentence = parser.parse_sentence(scan) while not sentence: text = """ You make no sense. \\n You can enter a sentence like 'Shoot the Gothon' or 'Hide in the doorway' \\n Try again """ display_text(text) choice = raw_input(">..") if choice == "end": exit(0) else: scan = lexicon.scan(choice) sentence = parser.parse_sentence(scan) return sentence
def index(): tags = None if request.method == 'GET': sentence = request.args.get("sentence", "") if sentence is None: tags = request.args.get("tags", "") else: sentence = request.get_json()['q'] result = parser.parse_sentence(sentence, tags, pos_tagger, dependency_parser) return Response(response=json.dumps(result, indent=2), status=200, content_type="application/json")
def index(): tags = None if request.method == 'GET': sentence = request.args.get("sentence", None) if sentence is None: tags = request.args.get("tags", None) else: if len(sentence) == 0: return Response(response="sentence can't be empty.", status=400) else: sentence = request.get_json()['q'] result = parser.parse_sentence(sentence, tags, pos_tagger, dependency_parser) return Response( response=json.dumps(result, indent=2), status=200, content_type="application/json")
def convert_number(s): try: return int(s) except ValueError: return None """inputted_word = words[0] inputted_word = Word(inputted_word) inputted_word.find_word_type() print inputted_word.word_type """ def scanner(): sentence = [] for each_word in words: each_word = Word(each_word) each_word.find_word_type() tuple = each_word.word_type, each_word.name sentence.append(tuple) return sentence scanned = lexicon.scan(stuff) parsed = parser.parse_sentence(scanned) print parsed.show()
def sentences(): pass y = parse_sentence([('noun','princess'),('verb','run'),('direction','away')]) return y
def test_Parser_Error_msg(): """test that the error message when a exception is raised is correct""" with pytest.raises(ParserError) as excinfo: x = parse_sentence([('noun','princess'),('verbs', 'go'),('direction','away')]) assert str(excinfo.value) == 'expected a verb next'
def test_raise_Parser_Error(): with pytest.raises(ParserError): x = parse_sentence([('noun','princess'),('obj', 'run'), ('direction','away')])
def test_parse_sentence(): """the same test as above without a fixture""" x = parse_sentence([('noun','princess'),('verb','run'),('direction','away')]) assert x.subject == 'princess' assert x.verb == 'run' assert x.obj == 'away'
def process_input(self, user_input): action = lexicon.scan(user_input) print(action) return parser.parse_sentence(action)