Exemplo n.º 1
0
 def test_create(self, con):
     some_dict = {"id": "value"}
     some_response = "value, " \
                     "{'title': None, 'excludeUttWithoutEntities': True, 'numWorkers': 8, 'chunk': 'PAGE', " \
                     "'searchDictionaries': [{'searchMode': 'ORDERED_SPAN', 'analyzeStrategy': 'SIMPLE'}]}"
     model = Model()
     extractor = Extractor()
     model.add_extractor(extractor)
     response = Mock()
     response.json.return_value = some_dict
     con.return_value = response
     res = model.create()
     self.assertEqual(str(res), some_response)
vocabulary.add_entry("Quasi-Governments")
vocabulary.add_entry("Governments")
vocabulary.name("Allocations (%)").create()

# 3- Creator Extractor - Regex must have 1 capturing group
extractor = Extractor()
extractor.set_vocabulary(vocabulary.get_id())
extractor.set_validator("^ +(\\d[\\d\\.\\,]+\\d)")
extractor.set_type(Type.DOUBLE)

# 4- Run
model = Model()
model.set_description("test data process")
model.add_extractor(extractor)
model.with_documents(list_of_documents)
model.create()

# 5- Wait to finish
model.wait_for_completion()

# 6- Export Field results
result = Result(model.get_id())
# print(result.read())
for item in result.read():
    field_value = item.get_values()[0]
    print(f"{item.get_str()} -> {field_value.get_str()}")

# 7- Export raw results to XLSX
result.result_xlsx_exporter("sample.xlsx")

# 8- Clean up
Exemplo n.º 3
0
 def test_create_empty_search_dict(self):
     model = Model()
     with self.assertRaises(QtModelError):
         model.create()