arkindex-base-worker 0.3.7rc4__tar.gz → 0.3.7rc6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/PKG-INFO +2 -2
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_base_worker.egg-info/PKG-INFO +2 -2
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_base_worker.egg-info/requires.txt +1 -1
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/classification.py +18 -18
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/pyproject.toml +1 -1
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/requirements.txt +1 -1
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_classifications.py +134 -137
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/LICENSE +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/README.md +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_base_worker.egg-info/SOURCES.txt +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_base_worker.egg-info/dependency_links.txt +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_base_worker.egg-info/top_level.txt +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/__init__.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/cache.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/image.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/models.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/utils.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/__init__.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/base.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/dataset.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/element.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/entity.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/metadata.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/task.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/training.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/transcription.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/version.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/docs-requirements.txt +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/setup.cfg +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/setup.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/__init__.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/conftest.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_base_worker.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_cache.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_dataset_worker.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_element.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/__init__.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_cli.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_dataset.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_elements.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_entities.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_metadata.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_task.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_training.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_transcriptions.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_elements_worker/test_worker.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_image.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_merge.py +0 -0
- {arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: arkindex-base-worker
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.7rc6
|
|
4
4
|
Summary: Base Worker to easily build Arkindex ML workflows
|
|
5
5
|
Author-email: Teklia <contact@teklia.com>
|
|
6
6
|
Maintainer-email: Teklia <contact@teklia.com>
|
|
@@ -41,7 +41,7 @@ Classifier: Topic :: Text Processing :: Linguistic
|
|
|
41
41
|
Requires-Python: >=3.10
|
|
42
42
|
Description-Content-Type: text/markdown
|
|
43
43
|
License-File: LICENSE
|
|
44
|
-
Requires-Dist: arkindex-client==1.0.
|
|
44
|
+
Requires-Dist: arkindex-client==1.0.15
|
|
45
45
|
Requires-Dist: peewee==3.17.0
|
|
46
46
|
Requires-Dist: Pillow==10.2.0
|
|
47
47
|
Requires-Dist: pymdown-extensions==10.7
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: arkindex-base-worker
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.7rc6
|
|
4
4
|
Summary: Base Worker to easily build Arkindex ML workflows
|
|
5
5
|
Author-email: Teklia <contact@teklia.com>
|
|
6
6
|
Maintainer-email: Teklia <contact@teklia.com>
|
|
@@ -41,7 +41,7 @@ Classifier: Topic :: Text Processing :: Linguistic
|
|
|
41
41
|
Requires-Python: >=3.10
|
|
42
42
|
Description-Content-Type: text/markdown
|
|
43
43
|
License-File: LICENSE
|
|
44
|
-
Requires-Dist: arkindex-client==1.0.
|
|
44
|
+
Requires-Dist: arkindex-client==1.0.15
|
|
45
45
|
Requires-Dist: peewee==3.17.0
|
|
46
46
|
Requires-Dist: Pillow==10.2.0
|
|
47
47
|
Requires-Dist: pymdown-extensions==10.7
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
ElementsWorker methods for classifications and ML classes.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from uuid import UUID
|
|
6
|
-
|
|
7
5
|
from apistar.exceptions import ErrorResponse
|
|
8
6
|
from peewee import IntegrityError
|
|
9
7
|
|
|
@@ -178,10 +176,14 @@ class ClassificationMixin:
|
|
|
178
176
|
Create multiple classifications at once on the given element through the API.
|
|
179
177
|
|
|
180
178
|
:param element: The element to create classifications on.
|
|
181
|
-
:param classifications:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
:param classifications: A list of dicts representing a classification each, with the following keys:
|
|
180
|
+
|
|
181
|
+
ml_class (str)
|
|
182
|
+
Required. Name of the MLClass to use.
|
|
183
|
+
confidence (float)
|
|
184
|
+
Required. Confidence score for the classification. Must be between 0 and 1.
|
|
185
|
+
high_confidence (bool)
|
|
186
|
+
Optional. Whether or not the classification is of high confidence.
|
|
185
187
|
|
|
186
188
|
:returns: List of created classifications, as returned in the ``classifications`` field by
|
|
187
189
|
the ``CreateClassifications`` API endpoint.
|
|
@@ -194,18 +196,10 @@ class ClassificationMixin:
|
|
|
194
196
|
), "classifications shouldn't be null and should be of type list"
|
|
195
197
|
|
|
196
198
|
for index, classification in enumerate(classifications):
|
|
197
|
-
|
|
199
|
+
ml_class = classification.get("ml_class")
|
|
198
200
|
assert (
|
|
199
|
-
|
|
200
|
-
), f"Classification at index {index} in classifications:
|
|
201
|
-
|
|
202
|
-
# Make sure it's a valid UUID
|
|
203
|
-
try:
|
|
204
|
-
UUID(ml_class_id)
|
|
205
|
-
except ValueError as e:
|
|
206
|
-
raise ValueError(
|
|
207
|
-
f"Classification at index {index} in classifications: ml_class_id is not a valid uuid."
|
|
208
|
-
) from e
|
|
201
|
+
ml_class and isinstance(ml_class, str)
|
|
202
|
+
), f"Classification at index {index} in classifications: ml_class shouldn't be null and should be of type str"
|
|
209
203
|
|
|
210
204
|
confidence = classification.get("confidence")
|
|
211
205
|
assert (
|
|
@@ -231,7 +225,13 @@ class ClassificationMixin:
|
|
|
231
225
|
body={
|
|
232
226
|
"parent": str(element.id),
|
|
233
227
|
"worker_run_id": self.worker_run_id,
|
|
234
|
-
"classifications":
|
|
228
|
+
"classifications": [
|
|
229
|
+
{
|
|
230
|
+
**classification,
|
|
231
|
+
"ml_class": self.get_ml_class_id(classification["ml_class"]),
|
|
232
|
+
}
|
|
233
|
+
for classification in classifications
|
|
234
|
+
],
|
|
235
235
|
},
|
|
236
236
|
)["classifications"]
|
|
237
237
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "arkindex-base-worker"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.7rc6"
|
|
8
8
|
description = "Base Worker to easily build Arkindex ML workflows"
|
|
9
9
|
license = { file = "LICENSE" }
|
|
10
10
|
dynamic = ["dependencies", "optional-dependencies"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import re
|
|
3
|
-
from uuid import UUID
|
|
3
|
+
from uuid import UUID
|
|
4
4
|
|
|
5
5
|
import pytest
|
|
6
6
|
from apistar.exceptions import ErrorResponse
|
|
@@ -325,9 +325,6 @@ def test_create_classification_create_ml_class(mock_elements_worker, responses):
|
|
|
325
325
|
)
|
|
326
326
|
|
|
327
327
|
# Check a class & classification has been created
|
|
328
|
-
for call in responses.calls:
|
|
329
|
-
print(call.request.url, call.request.body)
|
|
330
|
-
|
|
331
328
|
assert [
|
|
332
329
|
(call.request.url, json.loads(call.request.body))
|
|
333
330
|
for call in responses.calls[-2:]
|
|
@@ -506,12 +503,12 @@ def test_create_classifications_wrong_data(
|
|
|
506
503
|
"element": Element({"id": "12341234-1234-1234-1234-123412341234"}),
|
|
507
504
|
"classifications": [
|
|
508
505
|
{
|
|
509
|
-
"
|
|
506
|
+
"ml_class": "cat",
|
|
510
507
|
"confidence": 0.75,
|
|
511
508
|
"high_confidence": False,
|
|
512
509
|
},
|
|
513
510
|
{
|
|
514
|
-
"
|
|
511
|
+
"ml_class": "dog",
|
|
515
512
|
"confidence": 0.25,
|
|
516
513
|
"high_confidence": False,
|
|
517
514
|
},
|
|
@@ -523,86 +520,71 @@ def test_create_classifications_wrong_data(
|
|
|
523
520
|
|
|
524
521
|
|
|
525
522
|
@pytest.mark.parametrize(
|
|
526
|
-
("arg_name", "data", "error_message"
|
|
523
|
+
("arg_name", "data", "error_message"),
|
|
527
524
|
[
|
|
528
|
-
# Wrong classifications >
|
|
525
|
+
# Wrong classifications > ml_class
|
|
529
526
|
(
|
|
530
|
-
"
|
|
527
|
+
"ml_class",
|
|
531
528
|
DELETE_PARAMETER,
|
|
532
|
-
"
|
|
533
|
-
|
|
534
|
-
), # Updated
|
|
529
|
+
"ml_class shouldn't be null and should be of type str",
|
|
530
|
+
),
|
|
535
531
|
(
|
|
536
|
-
"
|
|
532
|
+
"ml_class",
|
|
537
533
|
None,
|
|
538
|
-
"
|
|
539
|
-
AssertionError,
|
|
534
|
+
"ml_class shouldn't be null and should be of type str",
|
|
540
535
|
),
|
|
541
536
|
(
|
|
542
|
-
"
|
|
537
|
+
"ml_class",
|
|
543
538
|
1234,
|
|
544
|
-
"
|
|
545
|
-
AssertionError,
|
|
546
|
-
),
|
|
547
|
-
(
|
|
548
|
-
"ml_class_id",
|
|
549
|
-
"not_an_uuid",
|
|
550
|
-
"ml_class_id is not a valid uuid.",
|
|
551
|
-
ValueError,
|
|
539
|
+
"ml_class shouldn't be null and should be of type str",
|
|
552
540
|
),
|
|
553
541
|
# Wrong classifications > confidence
|
|
554
542
|
(
|
|
555
543
|
"confidence",
|
|
556
544
|
DELETE_PARAMETER,
|
|
557
545
|
"confidence shouldn't be null and should be a float in [0..1] range",
|
|
558
|
-
AssertionError,
|
|
559
546
|
),
|
|
560
547
|
(
|
|
561
548
|
"confidence",
|
|
562
549
|
None,
|
|
563
550
|
"confidence shouldn't be null and should be a float in [0..1] range",
|
|
564
|
-
AssertionError,
|
|
565
551
|
),
|
|
566
552
|
(
|
|
567
553
|
"confidence",
|
|
568
554
|
"wrong confidence",
|
|
569
555
|
"confidence shouldn't be null and should be a float in [0..1] range",
|
|
570
|
-
AssertionError,
|
|
571
556
|
),
|
|
572
557
|
(
|
|
573
558
|
"confidence",
|
|
574
559
|
0,
|
|
575
560
|
"confidence shouldn't be null and should be a float in [0..1] range",
|
|
576
|
-
AssertionError,
|
|
577
561
|
),
|
|
578
562
|
(
|
|
579
563
|
"confidence",
|
|
580
564
|
2.00,
|
|
581
565
|
"confidence shouldn't be null and should be a float in [0..1] range",
|
|
582
|
-
AssertionError,
|
|
583
566
|
),
|
|
584
567
|
# Wrong classifications > high_confidence
|
|
585
568
|
(
|
|
586
569
|
"high_confidence",
|
|
587
570
|
"wrong high_confidence",
|
|
588
571
|
"high_confidence should be of type bool",
|
|
589
|
-
AssertionError,
|
|
590
572
|
),
|
|
591
573
|
],
|
|
592
574
|
)
|
|
593
575
|
def test_create_classifications_wrong_classifications_data(
|
|
594
|
-
arg_name, data, error_message,
|
|
576
|
+
arg_name, data, error_message, mock_elements_worker
|
|
595
577
|
):
|
|
596
578
|
all_data = {
|
|
597
579
|
"element": Element({"id": "12341234-1234-1234-1234-123412341234"}),
|
|
598
580
|
"classifications": [
|
|
599
581
|
{
|
|
600
|
-
"
|
|
582
|
+
"ml_class": "cat",
|
|
601
583
|
"confidence": 0.75,
|
|
602
584
|
"high_confidence": False,
|
|
603
585
|
},
|
|
604
586
|
{
|
|
605
|
-
"
|
|
587
|
+
"ml_class": "dog",
|
|
606
588
|
"confidence": 0.25,
|
|
607
589
|
"high_confidence": False,
|
|
608
590
|
# Overwrite with wrong data
|
|
@@ -614,7 +596,7 @@ def test_create_classifications_wrong_classifications_data(
|
|
|
614
596
|
del all_data["classifications"][1][arg_name]
|
|
615
597
|
|
|
616
598
|
with pytest.raises(
|
|
617
|
-
|
|
599
|
+
AssertionError,
|
|
618
600
|
match=re.escape(
|
|
619
601
|
f"Classification at index 1 in classifications: {error_message}"
|
|
620
602
|
),
|
|
@@ -623,6 +605,7 @@ def test_create_classifications_wrong_classifications_data(
|
|
|
623
605
|
|
|
624
606
|
|
|
625
607
|
def test_create_classifications_api_error(responses, mock_elements_worker):
|
|
608
|
+
mock_elements_worker.classes = {"cat": "0000", "dog": "1111"}
|
|
626
609
|
responses.add(
|
|
627
610
|
responses.POST,
|
|
628
611
|
"http://testserver/api/v1/classification/bulk/",
|
|
@@ -631,12 +614,12 @@ def test_create_classifications_api_error(responses, mock_elements_worker):
|
|
|
631
614
|
elt = Element({"id": "12341234-1234-1234-1234-123412341234"})
|
|
632
615
|
classes = [
|
|
633
616
|
{
|
|
634
|
-
"
|
|
617
|
+
"ml_class": "cat",
|
|
635
618
|
"confidence": 0.75,
|
|
636
619
|
"high_confidence": False,
|
|
637
620
|
},
|
|
638
621
|
{
|
|
639
|
-
"
|
|
622
|
+
"ml_class": "dog",
|
|
640
623
|
"confidence": 0.25,
|
|
641
624
|
"high_confidence": False,
|
|
642
625
|
},
|
|
@@ -660,57 +643,96 @@ def test_create_classifications_api_error(responses, mock_elements_worker):
|
|
|
660
643
|
]
|
|
661
644
|
|
|
662
645
|
|
|
663
|
-
def
|
|
664
|
-
|
|
665
|
-
portrait_uuid = str(uuid4())
|
|
666
|
-
landscape_uuid = str(uuid4())
|
|
667
|
-
mock_elements_worker_with_cache.classes = {
|
|
668
|
-
"portrait": portrait_uuid,
|
|
669
|
-
"landscape": landscape_uuid,
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
elt = CachedElement.create(id="12341234-1234-1234-1234-123412341234", type="thing")
|
|
673
|
-
classes = [
|
|
674
|
-
{
|
|
675
|
-
"ml_class_id": portrait_uuid,
|
|
676
|
-
"confidence": 0.75,
|
|
677
|
-
"high_confidence": False,
|
|
678
|
-
},
|
|
679
|
-
{
|
|
680
|
-
"ml_class_id": landscape_uuid,
|
|
681
|
-
"confidence": 0.25,
|
|
682
|
-
"high_confidence": False,
|
|
683
|
-
},
|
|
684
|
-
]
|
|
646
|
+
def test_create_classifications_create_ml_class(mock_elements_worker, responses):
|
|
647
|
+
elt = Element({"id": "12341234-1234-1234-1234-123412341234"})
|
|
685
648
|
|
|
649
|
+
# Automatically create a missing class!
|
|
650
|
+
responses.add(
|
|
651
|
+
responses.POST,
|
|
652
|
+
"http://testserver/api/v1/corpus/11111111-1111-1111-1111-111111111111/classes/",
|
|
653
|
+
status=201,
|
|
654
|
+
json={"id": "new-ml-class-1234"},
|
|
655
|
+
)
|
|
686
656
|
responses.add(
|
|
687
657
|
responses.POST,
|
|
688
658
|
"http://testserver/api/v1/classification/bulk/",
|
|
689
|
-
status=
|
|
659
|
+
status=201,
|
|
690
660
|
json={
|
|
691
661
|
"parent": str(elt.id),
|
|
692
662
|
"worker_run_id": "56785678-5678-5678-5678-567856785678",
|
|
693
663
|
"classifications": [
|
|
694
664
|
{
|
|
695
665
|
"id": "00000000-0000-0000-0000-000000000000",
|
|
696
|
-
"ml_class":
|
|
666
|
+
"ml_class": "new-ml-class-1234",
|
|
697
667
|
"confidence": 0.75,
|
|
698
668
|
"high_confidence": False,
|
|
699
669
|
"state": "pending",
|
|
700
670
|
},
|
|
701
|
-
{
|
|
702
|
-
"id": "11111111-1111-1111-1111-111111111111",
|
|
703
|
-
"ml_class": landscape_uuid,
|
|
704
|
-
"confidence": 0.25,
|
|
705
|
-
"high_confidence": False,
|
|
706
|
-
"state": "pending",
|
|
707
|
-
},
|
|
708
671
|
],
|
|
709
672
|
},
|
|
710
673
|
)
|
|
674
|
+
mock_elements_worker.classes = {"another_class": "0000"}
|
|
675
|
+
mock_elements_worker.create_classifications(
|
|
676
|
+
element=elt,
|
|
677
|
+
classifications=[
|
|
678
|
+
{
|
|
679
|
+
"ml_class": "a_class",
|
|
680
|
+
"confidence": 0.75,
|
|
681
|
+
"high_confidence": False,
|
|
682
|
+
}
|
|
683
|
+
],
|
|
684
|
+
)
|
|
711
685
|
|
|
712
|
-
|
|
713
|
-
|
|
686
|
+
# Check a class & classification has been created
|
|
687
|
+
assert len(responses.calls) == len(BASE_API_CALLS) + 2
|
|
688
|
+
assert [
|
|
689
|
+
(call.request.method, call.request.url) for call in responses.calls
|
|
690
|
+
] == BASE_API_CALLS + [
|
|
691
|
+
(
|
|
692
|
+
"POST",
|
|
693
|
+
"http://testserver/api/v1/corpus/11111111-1111-1111-1111-111111111111/classes/",
|
|
694
|
+
),
|
|
695
|
+
("POST", "http://testserver/api/v1/classification/bulk/"),
|
|
696
|
+
]
|
|
697
|
+
|
|
698
|
+
assert json.loads(responses.calls[-2].request.body) == {"name": "a_class"}
|
|
699
|
+
assert json.loads(responses.calls[-1].request.body) == {
|
|
700
|
+
"parent": "12341234-1234-1234-1234-123412341234",
|
|
701
|
+
"worker_run_id": "56785678-5678-5678-5678-567856785678",
|
|
702
|
+
"classifications": [
|
|
703
|
+
{
|
|
704
|
+
"ml_class": "new-ml-class-1234",
|
|
705
|
+
"confidence": 0.75,
|
|
706
|
+
"high_confidence": False,
|
|
707
|
+
}
|
|
708
|
+
],
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
def test_create_classifications(responses, mock_elements_worker):
|
|
713
|
+
mock_elements_worker.classes = {"portrait": "0000", "landscape": "1111"}
|
|
714
|
+
elt = Element({"id": "12341234-1234-1234-1234-123412341234"})
|
|
715
|
+
responses.add(
|
|
716
|
+
responses.POST,
|
|
717
|
+
"http://testserver/api/v1/classification/bulk/",
|
|
718
|
+
status=200,
|
|
719
|
+
json={"classifications": []},
|
|
720
|
+
)
|
|
721
|
+
|
|
722
|
+
mock_elements_worker.create_classifications(
|
|
723
|
+
element=elt,
|
|
724
|
+
classifications=[
|
|
725
|
+
{
|
|
726
|
+
"ml_class": "portrait",
|
|
727
|
+
"confidence": 0.75,
|
|
728
|
+
"high_confidence": False,
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
"ml_class": "landscape",
|
|
732
|
+
"confidence": 0.25,
|
|
733
|
+
"high_confidence": False,
|
|
734
|
+
},
|
|
735
|
+
],
|
|
714
736
|
)
|
|
715
737
|
|
|
716
738
|
assert len(responses.calls) == len(BASE_API_CALLS) + 1
|
|
@@ -723,52 +745,24 @@ def test_create_classifications(responses, mock_elements_worker_with_cache):
|
|
|
723
745
|
assert json.loads(responses.calls[-1].request.body) == {
|
|
724
746
|
"parent": str(elt.id),
|
|
725
747
|
"worker_run_id": "56785678-5678-5678-5678-567856785678",
|
|
726
|
-
"classifications":
|
|
748
|
+
"classifications": [
|
|
749
|
+
{
|
|
750
|
+
"confidence": 0.75,
|
|
751
|
+
"high_confidence": False,
|
|
752
|
+
"ml_class": "0000",
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
"confidence": 0.25,
|
|
756
|
+
"high_confidence": False,
|
|
757
|
+
"ml_class": "1111",
|
|
758
|
+
},
|
|
759
|
+
],
|
|
727
760
|
}
|
|
728
761
|
|
|
729
|
-
# Check that created classifications were properly stored in SQLite cache
|
|
730
|
-
assert list(CachedClassification.select()) == [
|
|
731
|
-
CachedClassification(
|
|
732
|
-
id=UUID("00000000-0000-0000-0000-000000000000"),
|
|
733
|
-
element_id=UUID(elt.id),
|
|
734
|
-
class_name="portrait",
|
|
735
|
-
confidence=0.75,
|
|
736
|
-
state="pending",
|
|
737
|
-
worker_run_id=UUID("56785678-5678-5678-5678-567856785678"),
|
|
738
|
-
),
|
|
739
|
-
CachedClassification(
|
|
740
|
-
id=UUID("11111111-1111-1111-1111-111111111111"),
|
|
741
|
-
element_id=UUID(elt.id),
|
|
742
|
-
class_name="landscape",
|
|
743
|
-
confidence=0.25,
|
|
744
|
-
state="pending",
|
|
745
|
-
worker_run_id=UUID("56785678-5678-5678-5678-567856785678"),
|
|
746
|
-
),
|
|
747
|
-
]
|
|
748
|
-
|
|
749
762
|
|
|
750
|
-
def
|
|
751
|
-
|
|
752
|
-
):
|
|
753
|
-
"""
|
|
754
|
-
CreateClassifications using ID that are not in `.classes` attribute.
|
|
755
|
-
Will load corpus MLClass to insert the corresponding name in Cache.
|
|
756
|
-
"""
|
|
757
|
-
portrait_uuid = str(uuid4())
|
|
758
|
-
landscape_uuid = str(uuid4())
|
|
763
|
+
def test_create_classifications_with_cache(responses, mock_elements_worker_with_cache):
|
|
764
|
+
mock_elements_worker_with_cache.classes = {"portrait": "0000", "landscape": "1111"}
|
|
759
765
|
elt = CachedElement.create(id="12341234-1234-1234-1234-123412341234", type="thing")
|
|
760
|
-
classes = [
|
|
761
|
-
{
|
|
762
|
-
"ml_class_id": portrait_uuid,
|
|
763
|
-
"confidence": 0.75,
|
|
764
|
-
"high_confidence": False,
|
|
765
|
-
},
|
|
766
|
-
{
|
|
767
|
-
"ml_class_id": landscape_uuid,
|
|
768
|
-
"confidence": 0.25,
|
|
769
|
-
"high_confidence": False,
|
|
770
|
-
},
|
|
771
|
-
]
|
|
772
766
|
|
|
773
767
|
responses.add(
|
|
774
768
|
responses.POST,
|
|
@@ -780,14 +774,14 @@ def test_create_classifications_not_in_cache(
|
|
|
780
774
|
"classifications": [
|
|
781
775
|
{
|
|
782
776
|
"id": "00000000-0000-0000-0000-000000000000",
|
|
783
|
-
"ml_class":
|
|
777
|
+
"ml_class": "0000",
|
|
784
778
|
"confidence": 0.75,
|
|
785
779
|
"high_confidence": False,
|
|
786
780
|
"state": "pending",
|
|
787
781
|
},
|
|
788
782
|
{
|
|
789
783
|
"id": "11111111-1111-1111-1111-111111111111",
|
|
790
|
-
"ml_class":
|
|
784
|
+
"ml_class": "1111",
|
|
791
785
|
"confidence": 0.25,
|
|
792
786
|
"high_confidence": False,
|
|
793
787
|
"state": "pending",
|
|
@@ -795,42 +789,45 @@ def test_create_classifications_not_in_cache(
|
|
|
795
789
|
],
|
|
796
790
|
},
|
|
797
791
|
)
|
|
798
|
-
responses.add(
|
|
799
|
-
responses.GET,
|
|
800
|
-
f"http://testserver/api/v1/corpus/{mock_elements_worker_with_cache.corpus_id}/classes/",
|
|
801
|
-
status=200,
|
|
802
|
-
json={
|
|
803
|
-
"count": 2,
|
|
804
|
-
"next": None,
|
|
805
|
-
"results": [
|
|
806
|
-
{
|
|
807
|
-
"id": portrait_uuid,
|
|
808
|
-
"name": "portrait",
|
|
809
|
-
},
|
|
810
|
-
{"id": landscape_uuid, "name": "landscape"},
|
|
811
|
-
],
|
|
812
|
-
},
|
|
813
|
-
)
|
|
814
792
|
|
|
815
793
|
mock_elements_worker_with_cache.create_classifications(
|
|
816
|
-
element=elt,
|
|
794
|
+
element=elt,
|
|
795
|
+
classifications=[
|
|
796
|
+
{
|
|
797
|
+
"ml_class": "portrait",
|
|
798
|
+
"confidence": 0.75,
|
|
799
|
+
"high_confidence": False,
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
"ml_class": "landscape",
|
|
803
|
+
"confidence": 0.25,
|
|
804
|
+
"high_confidence": False,
|
|
805
|
+
},
|
|
806
|
+
],
|
|
817
807
|
)
|
|
818
808
|
|
|
819
|
-
assert len(responses.calls) == len(BASE_API_CALLS) +
|
|
809
|
+
assert len(responses.calls) == len(BASE_API_CALLS) + 1
|
|
820
810
|
assert [
|
|
821
811
|
(call.request.method, call.request.url) for call in responses.calls
|
|
822
812
|
] == BASE_API_CALLS + [
|
|
823
813
|
("POST", "http://testserver/api/v1/classification/bulk/"),
|
|
824
|
-
(
|
|
825
|
-
"GET",
|
|
826
|
-
f"http://testserver/api/v1/corpus/{mock_elements_worker_with_cache.corpus_id}/classes/",
|
|
827
|
-
),
|
|
828
814
|
]
|
|
829
815
|
|
|
830
|
-
assert json.loads(responses.calls[-
|
|
816
|
+
assert json.loads(responses.calls[-1].request.body) == {
|
|
831
817
|
"parent": str(elt.id),
|
|
832
818
|
"worker_run_id": "56785678-5678-5678-5678-567856785678",
|
|
833
|
-
"classifications":
|
|
819
|
+
"classifications": [
|
|
820
|
+
{
|
|
821
|
+
"confidence": 0.75,
|
|
822
|
+
"high_confidence": False,
|
|
823
|
+
"ml_class": "0000",
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
"confidence": 0.25,
|
|
827
|
+
"high_confidence": False,
|
|
828
|
+
"ml_class": "1111",
|
|
829
|
+
},
|
|
830
|
+
],
|
|
834
831
|
}
|
|
835
832
|
|
|
836
833
|
# Check that created classifications were properly stored in SQLite cache
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/__init__.py
RENAMED
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/base.py
RENAMED
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/dataset.py
RENAMED
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/element.py
RENAMED
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/entity.py
RENAMED
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/metadata.py
RENAMED
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/task.py
RENAMED
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/training.py
RENAMED
|
File without changes
|
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/arkindex_worker/worker/version.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{arkindex-base-worker-0.3.7rc4 → arkindex-base-worker-0.3.7rc6}/tests/test_dataset_worker.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|