def test_simple_sentence(self): input_text = "Donald Trump is the president of USA. He is a business man." expected = [ "Donald Trump is the president of USA.", "Donald Trump is a business man." ] substituted = substitute(*resolve(input_text)) self.assertEqual(expected, substituted)
def test_resolver_for_full_article_Paris(self): with open(os.path.join('examples', 'Paris.input.txt')) as i: text = i.read() self.assertIsNotNone(text) sentences, substitutions = resolve(text, "") self.assertIsNotNone(sentences) self.assertEquals(len(sentences), 657) self.assertIsNotNone(substitutions) self.assertGreater(len(substitutions), 100)
def resolve_text(): data = request.get_json() if data is None: return make_response(jsonify({'message': 'No data.'}), 400) text = data['text'] if not text: return make_response( jsonify({'message': '`text` field is mandatory.'}), 400) substituted = substitute(*resolve(text, '')) return jsonify({'text': '\n'.join(s for s in substituted)})
def resolve_wiki(): data = request.get_json() if data is None: return make_response(jsonify({'message': 'No data.'}), 400) text, uri = data['text'], data['uri'] if not text or not uri: return make_response( jsonify({'message': '`text` and `uri` fields are mandatory.'}), 400) substituted = substitute(*resolve(text, uri)) return jsonify({'text': substituted})
def test_resolver_for_article_BarackObama(self): with open(os.path.join('examples', 'Barack_Obama.input.txt')) as i: sentences = [l for l in i] self.assertIsNotNone(sentences) self.assertEquals(403, len(sentences)) text = "\n".join(sentences) sentences, substitutions = resolve(text, "") substituted = substitute(sentences, substitutions) with open(os.path.join('examples', 'Barack_Obama.expected.txt')) as i: expected = [l.strip() for l in i] substituted = [s.strip() for s in substituted] self.assertEquals(len(substituted), len(expected)) for s, e in zip(substituted, expected): self.assertEquals(s, e)