Beispiel #1
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 #2
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 #3
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 #4
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")
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)
model.with_documents(list_of_documents)
model.create()

# 5- Wait to finish
Beispiel #6
0
 def test_name_type(self):
     name = 123
     vocabulary = Vocabulary()
     with self.assertRaises(QtArgumentError):
         vocabulary.name(name)
Beispiel #7
0
 def test_name_name(self):
     name = "some name"
     vocabulary = Vocabulary()
     vocabulary.name(name)
     self.assertEqual(name, vocabulary.temp_vocabulary["name"])
Beispiel #8
0
 def test_create_miss_entry(self):
     name = "some name"
     voc = Vocabulary()
     voc.name(name)
     with self.assertRaises(QtVocabularyError):
         voc.create()
Beispiel #9
0
API_KEY = "YOUR-API-KEY"
FILE_NAME = "resources/revenue.tsv"

# Initialise with api key
Qt.init(API_KEY)

vocabulary = Vocabulary()

# Create entries of vocabulary
vocabulary.add_entry("Apple Inc.", "AAPL")
vocabulary.add_entry("Amazon.com", "AMZN")
vocabulary.entries({"str": "Alphabet Inc.", "category": "GOOG"})

# Create Vocabulary
try:
    vocabulary.name("some name").add_entry("Apple Inc.", "AAPL").create()
except Exception as e:
    print(e)

# Fetch from current object
print("Fetch vocabulary")
print(vocabulary.fetch(vocabulary.get_id()))

# Create list of vocabularies from tsv file
print("Create list of the vocabularies from TSV file")
tsv_voc = Vocabulary()
tsv_voc.name("revenue")
tsv_voc.source(FILE_NAME)
try:
    tsv_voc.create()
except Exception as e: