Beispiel #1
0
 def test_add_entry_value_none(self):
     key = "test"
     value = None
     list_entries = [{"str": key}]
     vocabulary = Vocabulary()
     vocabulary.add_entry(key, value)
     self.assertEqual(list_entries, vocabulary.temp_vocabulary['entries'])
Beispiel #2
0
 def test_add_entry(self):
     key = "New York"
     value = "Knicks"
     list_entries = [{"str": key, "category": value}]
     vocabulary = Vocabulary()
     vocabulary.add_entry(key, value)
     self.assertEqual(list_entries, vocabulary.temp_vocabulary['entries'])
Beispiel #3
0
 def test_delete_false(self, con):
     some_id = 'some id'
     voc = Vocabulary()
     response = Mock()
     response.status_code = 200
     response.ok = False
     con.return_value = response
     res = voc.delete(some_id)
     self.assertEqual(res, False)
Beispiel #4
0
 def test_read(self, con):
     voc = Vocabulary()
     some_json = [{"key": "value"}]
     response = Mock()
     response.status_code = 200
     response.json.return_value = some_json
     con.return_value = response
     res = voc.read()
     self.assertEqual(res, some_json)
Beispiel #5
0
 def test_entries_vocabulary_len_3(self):
     test_vocabulary = {
         "str": "str",
         "category": "category",
         "some_key": "some_value"
     }
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.entries(test_vocabulary)
Beispiel #6
0
 def test_fetch(self, con):
     some_id = 'some id'
     some_json = {
         "id": "some id",
         "name": "some name",
         "entries": "some entries"
     }
     voc = Vocabulary()
     response = Mock()
     response.json.return_value = some_json
     con.return_value = response
     res = voc.fetch(some_id)
     self.assertEqual(str(res), str(some_json))
Beispiel #7
0
 def test_update_name(self):
     vocabulary_id = "string"
     entries = {"str": "str", "category": "category"}
     vocabulary = Vocabulary()
     vocabulary.entries(entries)
     with self.assertRaises(QtVocabularyError):
         vocabulary.update(vocabulary_id)
Beispiel #8
0
 def test_update_entries(self):
     vocabulary_id = "string"
     name = "name"
     vocabulary = Vocabulary()
     vocabulary.name(name)
     with self.assertRaises(QtVocabularyError):
         vocabulary.update(vocabulary_id)
Beispiel #9
0
 def test_create_input_stream(self, con):
     name = "some name"
     some_tsv_file = 'test.tsv'
     with open(some_tsv_file, "w") as f:
         f.write("Delete me!")
     some_dict = {
         "id": "some value",
         'name': 'some name',
         'entries': [{
             'str': 'some entry'
         }]
     }
     some_entry = "some entry"
     voc = Vocabulary()
     voc.name(name)
     voc.add_entry(some_entry)
     voc.source(some_tsv_file)
     response = Mock()
     response.json.return_value = some_dict
     con.return_value = response
     res = voc.create()
     self.assertEqual(str(res), str(some_dict))
     os.remove("test.tsv")
Beispiel #10
0
 def test_create_input_stream_none(self, con):
     name = "some name"
     some_dict = {
         "id": "some value",
         'name': 'some name',
         'entries': [{
             'str': 'some entry'
         }]
     }
     some_entry = "some entry"
     voc = Vocabulary()
     voc.name(name)
     voc.add_entry(some_entry)
     response = Mock()
     response.json.return_value = some_dict
     con.return_value = response
     res = voc.create()
     self.assertEqual(str(res), str(some_dict))
Beispiel #11
0
 def test_update(self, con):
     some_id = "some id"
     some_name = 'some name'
     some_key = 'some key'
     some_dict = {
         "id": None,
         'name': 'some name',
         'entries': [{
             'str': 'some entry'
         }]
     }
     voc = Vocabulary()
     voc.name(some_name)
     voc.add_entry(some_key)
     response = Mock()
     response.json.return_value = some_dict
     con.return_value = response
     res = voc.update(some_id)
     self.assertEqual(str(res), str(some_dict))
Beispiel #12
0
 def test_entries_vocabulary_len_0(self):
     test_vocabulary = {}
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.entries(test_vocabulary)
Beispiel #13
0
 def test_get_entries(self):
     vocabulary = Vocabulary()
     some_entry = []
     self.assertEqual(vocabulary.temp_vocabulary["entries"], some_entry)
Beispiel #14
0
 def test_entries_type(self):
     test_vocabulary = "string"
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.entries(test_vocabulary)
Beispiel #15
0
 def test_get_name(self):
     vocabulary = Vocabulary()
     some_name = None
     self.assertEqual(vocabulary.temp_vocabulary["name"], some_name)
Beispiel #16
0
 def test_name_type(self):
     name = 123
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.name(name)
Beispiel #17
0
 def test_create_miss_name(self):
     entries = {"str": "str", "category": "category"}
     vocabulary = Vocabulary()
     vocabulary.entries(entries)
     with self.assertRaises(QtVocabularyError):
         vocabulary.create()
Beispiel #18
0
 def test_set_id_arg_err(self):
     vocabulary = Vocabulary()
     some_id = 123
     with self.assertRaises(QtArgumentError):
         vocabulary.set_id(some_id)
Beispiel #19
0
 def test_name_name(self):
     name = "some name"
     vocabulary = Vocabulary()
     vocabulary.name(name)
     self.assertEqual(name, vocabulary.temp_vocabulary["name"])
Beispiel #20
0
 def test_delete_arg(self):
     vocabulary_id = 123
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.delete(vocabulary_id)
Beispiel #21
0
 def test_update_arg_type(self):
     vocabulary_id = 123
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.update(vocabulary_id)
Beispiel #22
0
 def test_source_arg_file_type(self):
     file = 123
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.source(file)
Beispiel #23
0
 def test_create_miss_entry(self):
     name = "some name"
     voc = Vocabulary()
     voc.name(name)
     with self.assertRaises(QtVocabularyError):
         voc.create()
Beispiel #24
0
 def test_set_id(self):
     vocabulary = Vocabulary()
     some_id = 'some id'
     vocabulary.set_id(some_id)
     self.assertEqual(vocabulary.id, some_id)
Beispiel #25
0
 def test_entries_vocabulary_content_2(self):
     test_vocabulary = {"str": "str", "test": "category"}
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.entries(test_vocabulary)
Beispiel #26
0
 def test_fetch_arg(self):
     vocabulary_id = 123
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.fetch(vocabulary_id)
Beispiel #27
0
 def test_entries_category(self):
     test_vocabulary = {"str": "str"}
     vocabulary = Vocabulary()
     vocabulary.entries(test_vocabulary)
     self.assertEqual([test_vocabulary],
                      vocabulary.temp_vocabulary['entries'])
Beispiel #28
0
 def test_source_file_exist(self):
     file = "path.tsv"
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.source(file)
from qtcurate.document import Document
from qtcurate.result import Result

API_KEY = "YOUR-API-KEY"
DOCUMENT = "resources/sample.pdf"

# Initialise with api key
Qt.init(API_KEY)

# 1- Upload the sample document for processing
list_of_documents = []
document = Document()
doc = document.create(DOCUMENT)
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)
Beispiel #30
0
 def test_add_entry_value_type(self):
     key = "test"
     value = ["Knicks"]
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.add_entry(key, value)