def test_search_size_not_int_arg(self):
     model_id = "test"
     param_from = 5
     size = "test"
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.search(model_id, param_from, size)
 def test_get_extractor(self):
     some_dict = {'searchDictionaries': 'ab'}
     some_list = ['a', 'b']
     model = Model()
     model.get_extractor(some_dict)
     self.assertEqual(model.temp_dictionary['searchDictionaries'],
                      some_list)
 def test_search_pairs_arg(self):
     index = "test"
     param_from = 5
     size = 100
     model = Model()
     f1 = "string"
     with self.assertRaises(QtArgumentError):
         model.search(index, param_from, size, f1)
 def test_read(self, con):
     some_list = []
     model = Model()
     response = Mock()
     response.json.return_value = some_list
     con.return_value = response
     res = model.read()
     self.assertEqual(res, some_list)
 def test_delete_false(self, con):
     some_id = 'some id'
     model = Model()
     response = Mock()
     response.ok = False
     con.return_value = response
     res = model.delete(some_id)
     self.assertEqual(res, False)
 def test_search(self, con):
     some_id = 'some id'
     some_dict = {"key": "value"}
     model = Model()
     response = Mock()
     response.json.return_value = some_dict
     con.return_value = response
     res = model.search(some_id)
     self.assertEqual(res, some_dict)
 def test_set_returned_data(self):
     model = Model()
     some_dict = {
         'title': "some title",
         'excludeUttWithoutEntities': True,
         'searchDictionaries': [],
         'files': 'some files',
         'chunk': 'PAGE',
         'numWorkers': 8
     }
     model.set_returned_data(some_dict)
     self.assertEqual(model.temp_dictionary, some_dict)
 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)
 def test_fetch(self, con):
     some_id = 'some id'
     some_dict = {
         'title': "some title",
         'excludeUttWithoutEntities': True,
         'searchDictionaries': [],
         'files': 'some files',
         'chunk': 'PAGE',
         'numWorkers': 8
     }
     some_response = "some id, {'title': 'some title', 'excludeUttWithoutEntities': True, 'numWorkers': 8, " \
                     "'chunk': 'PAGE', 'searchDictionaries': [], 'files': 'some files'}"
     model = Model()
     response = Mock()
     response.json.return_value = some_dict
     con.return_value = response
     res = model.fetch(some_id)
     self.assertEqual(str(res), some_response)
    def test_add_extractor(self):
        ex = Extractor()
        ex.set_vocabulary('123')
        ex.set_type(Type.DATETIME)
        ex.set_mode(Mode.SIMPLE)
        ex.set_stop_word_list(['stop'])
        ex.set_synonym_list(['synonym'])
        ex.set_validator('val')
        some_list = [{
            'vocabId': '123',
            'vocabValueType': 'REGEX',
            'dataType': 'DATETIME',
            'searchMode': 'ORDERED_SPAN',
            'analyzeStrategy': 'SIMPLE',
            'stopwordList': ['stop'],
            'synonymList': ['synonym'],
            'phraseMatchingPattern': 'val'
        }]

        model = Model()
        model.add_extractor(ex)
        self.assertEqual(model.temp_dictionary["searchDictionaries"],
                         some_list)
 def test_set_workers_arg_err(self):
     value = '123'
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.set_workers(value)
 def test_exclude_utt(self):
     value = True
     model = Model()
     model.exclude_utt_without_entities(value)
     self.assertEqual(value,
                      model.temp_dictionary["excludeUttWithoutEntities"])
 def test_exclude_utt_arg_error(self):
     value = 12
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.exclude_utt_without_entities(value)
 def test_set_description(self):
     title = "some title"
     model = Model()
     model.set_description(title)
     self.assertEqual(title, model.temp_dictionary["title"])
 def test_set_description_arg_error(self):
     title = 12
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.set_description(title)
 def test_with_documents_arg_error(self):
     list_files = "string"
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.with_documents(list_files)
 def test_progress_argument_type_error(self):
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.progress(model_id=[])
 def test_set_chunk(self):
     model = Model()
     some_chunk = ChunkMode.SENTENCE
     model.set_chunk(some_chunk)
     self.assertEqual(model.temp_dictionary["chunk"], some_chunk.value)
 def test_clone_model_id_arg_err(self):
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.clone(model_id=[])
 def test_delete_argument_type_error(self):
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.delete(model_id=[])
 def test_clone_tag_files_empty(self):
     model = Model()
     mod_id = 'some id'
     with self.assertRaises(QtModelError):
         model.clone(mod_id)
 def test_search_size_range_arg(self):
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.search(model_id="some_model", param_from=5, size=201)
 def test_search_param_from_arg_error(self):
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.search(model_id="some_model", param_from="123")
 def test_search_model_id_arg(self):
     model = Model()
     with self.assertRaises(QtArgumentError):
         model.search(model_id=123)
 def test_set_workers(self):
     value = 123
     model = Model()
     model.set_workers(value)
     self.assertEqual(model.temp_dictionary["numWorkers"], value)
 def test_set_id(self):
     model = Model()
     model.set_id('some id')
     self.assertEqual(model.id, 'some id')
 def test_with_documents(self):
     list_files = ["file1", "file2"]
     model = Model()
     model.with_documents(list_files)
     self.assertEqual(list_files, model.temp_dictionary['files'])
 def test_get_uuid(self):
     model = Model()
     some_uuid = None
     self.assertEqual(model.get_uuid(), str(some_uuid))
list_of_documents.append(doc)
# 2- Create vocabulary
vocabulary = Vocabulary()
vocabulary.add_entry("Industrials")
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()}")
 def test_set_chunk_arg_err(self):
     model = Model()
     some_value = 'some value'
     with self.assertRaises(QtArgumentError):
         model.set_chunk(some_value)