streamlit-octostar-utils 0.1.7a9__py3-none-any.whl → 0.1.7a11__py3-none-any.whl
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.
- streamlit_octostar_utils/api_crafter/fastapi.py +2 -2
- streamlit_octostar_utils/api_crafter/parser/entities_parser.py +76 -76
- {streamlit_octostar_utils-0.1.7a9.dist-info → streamlit_octostar_utils-0.1.7a11.dist-info}/METADATA +1 -1
- {streamlit_octostar_utils-0.1.7a9.dist-info → streamlit_octostar_utils-0.1.7a11.dist-info}/RECORD +6 -6
- {streamlit_octostar_utils-0.1.7a9.dist-info → streamlit_octostar_utils-0.1.7a11.dist-info}/LICENSE +0 -0
- {streamlit_octostar_utils-0.1.7a9.dist-info → streamlit_octostar_utils-0.1.7a11.dist-info}/WHEEL +0 -0
@@ -314,7 +314,7 @@ class DefaultErrorRoute:
|
|
314
314
|
},
|
315
315
|
}
|
316
316
|
|
317
|
-
def format_error(exc, body=
|
317
|
+
def format_error(exc, body=b"", debug=False, excs_to_status_codes=DEFAULT_STATUS_CODE_MAPPINGS):
|
318
318
|
"""Generic Error Handler"""
|
319
319
|
status_code = 500
|
320
320
|
for exc_type, handler in excs_to_status_codes.items():
|
@@ -355,7 +355,7 @@ class DefaultErrorRoute:
|
|
355
355
|
silenced_excs = DefaultErrorRoute.DEFAULT_SILENCED_EXCEPTIONS
|
356
356
|
|
357
357
|
async def _async_handle_error(request: Request, exc: Exception):
|
358
|
-
return await DefaultErrorRoute.handle_error(
|
358
|
+
return await DefaultErrorRoute.handle_error(b"", exc, debug, excs_to_status_codes)
|
359
359
|
|
360
360
|
# Added all three since FastAPI seems to intercept some exceptions before Exception
|
361
361
|
fs_app.add_exception_handler(RequestValidationError, _async_handle_error)
|
@@ -60,29 +60,23 @@ class EntitiesInvalidReason(Enum):
|
|
60
60
|
INVALID_REL_TYPE = 20
|
61
61
|
UNKNOWN_UUID = 21
|
62
62
|
WRONG_SOURCE_OR_TARGET_TYPE = 22
|
63
|
+
|
64
|
+
|
65
|
+
EntityDict = dict
|
66
|
+
InvalidErrorDict = dict
|
63
67
|
|
64
68
|
|
65
69
|
class EntitiesParser(object):
|
66
|
-
def __init__(self, parse_rulesets,
|
70
|
+
def __init__(self, parse_rulesets, ontology=None):
|
67
71
|
self.concepts = dict()
|
68
72
|
self.ruleset = dict()
|
69
|
-
self.ontology =
|
70
|
-
self.os_client = client
|
73
|
+
self.ontology = ontology
|
71
74
|
if not isinstance(parse_rulesets, list):
|
72
75
|
parse_rulesets = [parse_rulesets]
|
73
76
|
for parse_ruleset in parse_rulesets:
|
74
77
|
self.ruleset = parse_ruleset.load(self.ruleset, self)
|
75
78
|
self._reset_parsing_vars()
|
76
79
|
|
77
|
-
def _get_ontology(self):
|
78
|
-
if not self.ontology:
|
79
|
-
from octostar.utils.ontology import fetch_ontology_data
|
80
|
-
|
81
|
-
try:
|
82
|
-
self.ontology = fetch_ontology_data.sync(client=self.os_client)
|
83
|
-
except:
|
84
|
-
self.ontology = None
|
85
|
-
|
86
80
|
def _reset_parsing_vars(self):
|
87
81
|
self.curr_entries = list()
|
88
82
|
self.curr_entities = list()
|
@@ -127,13 +121,13 @@ class EntitiesParser(object):
|
|
127
121
|
def _cull_entities(self, entities, relationships):
|
128
122
|
removed_ids = list()
|
129
123
|
for entity in entities:
|
130
|
-
if "extra_fields" in entity.fields:
|
131
|
-
if not entity.fields["extra_fields"]:
|
132
|
-
del entity.fields["extra_fields"]
|
124
|
+
if "#extra_fields" in entity.fields:
|
125
|
+
if not entity.fields["#extra_fields"]:
|
126
|
+
del entity.fields["#extra_fields"]
|
133
127
|
else:
|
134
|
-
for extra_field in list(entity.fields["extra_fields"].keys()):
|
135
|
-
if not entity.fields["extra_fields"][extra_field]:
|
136
|
-
del entity.fields["extra_fields"][extra_field]
|
128
|
+
for extra_field in list(entity.fields["#extra_fields"].keys()):
|
129
|
+
if not entity.fields["#extra_fields"][extra_field]:
|
130
|
+
del entity.fields["#extra_fields"][extra_field]
|
137
131
|
for field in list(entity.fields.keys()):
|
138
132
|
if not entity.fields[field]:
|
139
133
|
del entity.fields[field]
|
@@ -244,11 +238,11 @@ class EntitiesParser(object):
|
|
244
238
|
if root_entity:
|
245
239
|
root_entity = root_entity[0]
|
246
240
|
unused_fields = dict()
|
247
|
-
if "extra_fields" not in root_entity.fields:
|
248
|
-
root_entity.fields["extra_fields"] = dict()
|
241
|
+
if "#extra_fields" not in root_entity.fields:
|
242
|
+
root_entity.fields["#extra_fields"] = dict()
|
249
243
|
unused_fields = _find_extra_fields_recursive(entry.value)
|
250
|
-
root_entity.fields["extra_fields"] = {
|
251
|
-
**root_entity.fields["extra_fields"],
|
244
|
+
root_entity.fields["#extra_fields"] = {
|
245
|
+
**root_entity.fields["#extra_fields"],
|
252
246
|
**unused_fields,
|
253
247
|
}
|
254
248
|
|
@@ -544,32 +538,44 @@ class EntitiesParser(object):
|
|
544
538
|
"""
|
545
539
|
|
546
540
|
def validate_and_format_entities(self, entities, relationships):
|
547
|
-
self._get_ontology()
|
548
541
|
if not self.ontology:
|
549
|
-
raise RuntimeError("
|
542
|
+
raise RuntimeError("No ontology provided for validation!")
|
543
|
+
ontology = self.ontology
|
550
544
|
from streamlit_octostar_utils.ontology.validation import (
|
551
545
|
validate_and_format_timbr_type,
|
552
546
|
)
|
553
547
|
from streamlit_octostar_utils.ontology.inheritance import is_child_concept
|
554
548
|
|
555
549
|
processed_entities = []
|
556
|
-
|
550
|
+
processed_relationships = []
|
557
551
|
for entity in entities:
|
558
|
-
if entity.concept_name not in
|
559
|
-
processed_entities.append(
|
560
|
-
|
552
|
+
if entity.concept_name not in ontology["concepts"]:
|
553
|
+
processed_entities.append(
|
554
|
+
(
|
555
|
+
EntitiesInvalidReason.INVALID_TYPE,
|
556
|
+
entity,
|
557
|
+
{"error_message": f"{entity} has invalid concept name"},
|
558
|
+
)
|
559
|
+
)
|
561
560
|
entity_properties = [
|
562
|
-
k
|
561
|
+
k
|
562
|
+
for k in entity.fields.keys()
|
563
|
+
if not k.startswith("#")
|
563
564
|
]
|
564
565
|
ontology_properties = {
|
565
566
|
e["property_name"]: e
|
566
|
-
for e in
|
567
|
+
for e in ontology["concepts"][entity.concept_name]["allProperties"]
|
567
568
|
}
|
568
569
|
if any(prop not in ontology_properties for prop in entity_properties):
|
569
570
|
processed_entities.append(
|
570
|
-
(
|
571
|
+
(
|
572
|
+
EntitiesInvalidReason.INVALID_PROPERTIES,
|
573
|
+
entity,
|
574
|
+
{
|
575
|
+
"error_message": f"{entity} has invalid entity properties: {str(set(entity_properties) - set(ontology_properties))}"
|
576
|
+
},
|
577
|
+
)
|
571
578
|
)
|
572
|
-
continue
|
573
579
|
for prop in entity_properties:
|
574
580
|
try:
|
575
581
|
entity.fields[prop] = validate_and_format_timbr_type(
|
@@ -577,46 +583,66 @@ class EntitiesParser(object):
|
|
577
583
|
)
|
578
584
|
except:
|
579
585
|
processed_entities.append(
|
580
|
-
(
|
586
|
+
(
|
587
|
+
EntitiesInvalidReason.INVALID_PROPERTIES,
|
588
|
+
entity,
|
589
|
+
{
|
590
|
+
"error_message": f"{entity} has an invalid property type for property {prop}"
|
591
|
+
},
|
592
|
+
)
|
581
593
|
)
|
582
|
-
|
583
|
-
processed_entities.append((EntitiesInvalidReason.VALID, entity))
|
594
|
+
processed_entities.append((EntitiesInvalidReason.VALID, entity, {}))
|
584
595
|
ontology_relationships = {
|
585
|
-
r["relationship_name"]: r for r in
|
596
|
+
r["relationship_name"]: r for r in ontology["relationships"]
|
586
597
|
}
|
587
598
|
for rel in relationships:
|
588
599
|
if rel.name not in ontology_relationships.keys():
|
589
|
-
|
590
|
-
(
|
600
|
+
processed_relationships.append(
|
601
|
+
(
|
602
|
+
EntitiesInvalidReason.INVALID_REL_TYPE,
|
603
|
+
rel,
|
604
|
+
{"error_message": f"{rel} relationship name is invalid"},
|
605
|
+
)
|
591
606
|
)
|
592
|
-
|
593
|
-
entities_by_id = {e.unique_id: e for e in entities}
|
607
|
+
entities_by_id = {e[1].unique_id: e[1] for e in processed_entities}
|
594
608
|
if (
|
595
609
|
rel.concept_from not in entities_by_id.keys()
|
596
610
|
or rel.concept_to not in entities_by_id.keys()
|
597
611
|
):
|
598
|
-
|
599
|
-
(
|
612
|
+
processed_relationships.append(
|
613
|
+
(
|
614
|
+
EntitiesInvalidReason.UNKNOWN_UUID,
|
615
|
+
rel,
|
616
|
+
{
|
617
|
+
"error_message": f"for {rel}, source concept or target concept are invalid"
|
618
|
+
},
|
619
|
+
)
|
600
620
|
)
|
601
|
-
continue
|
602
621
|
ontology_relationship = ontology_relationships[rel.name]
|
603
622
|
rel_concept_types = (
|
604
623
|
entities_by_id[rel.concept_from].concept_name,
|
605
624
|
entities_by_id[rel.concept_to].concept_name,
|
606
625
|
)
|
607
626
|
if not is_child_concept(
|
608
|
-
rel_concept_types[0],
|
627
|
+
rel_concept_types[0],
|
628
|
+
ontology_relationship["concept"],
|
629
|
+
ontology,
|
609
630
|
) or not is_child_concept(
|
610
631
|
rel_concept_types[1],
|
611
632
|
ontology_relationship["target_concept"],
|
612
|
-
|
633
|
+
ontology,
|
613
634
|
):
|
614
|
-
|
615
|
-
(
|
635
|
+
processed_relationships.append(
|
636
|
+
(
|
637
|
+
EntitiesInvalidReason.WRONG_SOURCE_OR_TARGET_TYPE,
|
638
|
+
rel,
|
639
|
+
{
|
640
|
+
"error_message": f"for {rel}, type for source concept or for target concept is invalid"
|
641
|
+
},
|
642
|
+
)
|
616
643
|
)
|
617
|
-
|
618
|
-
|
619
|
-
return processed_entities, processsed_relationships
|
644
|
+
processed_relationships.append((EntitiesInvalidReason.VALID, rel, {}))
|
645
|
+
return processed_entities, processed_relationships
|
620
646
|
|
621
647
|
def replace_unique_id(self, id_from, id_to, entities, relationships):
|
622
648
|
for entity in entities:
|
@@ -628,32 +654,6 @@ class EntitiesParser(object):
|
|
628
654
|
if relationship.concept_to == id_from:
|
629
655
|
relationship.concept_to = id_to
|
630
656
|
|
631
|
-
def extra_fields_to_entities(self, source_entities, remove_fields_from_source=True):
|
632
|
-
new_entities = list()
|
633
|
-
new_relationships = list()
|
634
|
-
for entity in source_entities:
|
635
|
-
if (
|
636
|
-
entity.fields
|
637
|
-
and "extra_fields" in entity.fields
|
638
|
-
and entity.fields["extra_fields"]
|
639
|
-
):
|
640
|
-
new_entity = EntityInfo(
|
641
|
-
self._compute_deterministic_uuid(
|
642
|
-
entity.fields["extra_fields"], "json", False
|
643
|
-
),
|
644
|
-
"json",
|
645
|
-
entity.fields["extra_fields"],
|
646
|
-
)
|
647
|
-
if remove_fields_from_source:
|
648
|
-
del entity.fields["extra_fields"]
|
649
|
-
new_entities.append(new_entity)
|
650
|
-
new_relationships.append(
|
651
|
-
RelationshipInfo(
|
652
|
-
entity.unique_id, new_entity.unique_id, "has_unparsed_data"
|
653
|
-
)
|
654
|
-
)
|
655
|
-
return new_entities, new_relationships
|
656
|
-
|
657
657
|
def to_linkchart(self, entities, relationships, label_fn):
|
658
658
|
return_dict = {"records": list(), "relationships": list()}
|
659
659
|
for entity in entities:
|
{streamlit_octostar_utils-0.1.7a9.dist-info → streamlit_octostar_utils-0.1.7a11.dist-info}/RECORD
RENAMED
@@ -1,11 +1,11 @@
|
|
1
1
|
streamlit_octostar_utils/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
2
2
|
streamlit_octostar_utils/api_crafter/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
3
3
|
streamlit_octostar_utils/api_crafter/celery.py,sha256=bQq8P95j0XDWqx6Hdnm96PJL8kcp9ZcSKjveZUCQTVk,29874
|
4
|
-
streamlit_octostar_utils/api_crafter/fastapi.py,sha256=
|
4
|
+
streamlit_octostar_utils/api_crafter/fastapi.py,sha256=2bktT5Mwjs9XixWcOqUKMoLM_cgKl-cqZDUa2Imf4xA,14357
|
5
5
|
streamlit_octostar_utils/api_crafter/nifi.py,sha256=fQ5k9eZl2oSQZ2BexZYwKUiO05-FryUi7wnCd_56P9Y,44375
|
6
6
|
streamlit_octostar_utils/api_crafter/parser/__init__.py,sha256=YeYWF6sdQiCFV_RKNW2t9Vs6KJExE2pbXxWTe_DOayY,107
|
7
7
|
streamlit_octostar_utils/api_crafter/parser/combine_fields.py,sha256=ddc44xkajw8MU0peAX_263DL7rPXbTKbHUjpOhRgvyU,8790
|
8
|
-
streamlit_octostar_utils/api_crafter/parser/entities_parser.py,sha256=
|
8
|
+
streamlit_octostar_utils/api_crafter/parser/entities_parser.py,sha256=zOQoN-p1Gz6ZzxvoX4M1b4Fi3mfmQr5zaNUcp_8gCjw,30016
|
9
9
|
streamlit_octostar_utils/api_crafter/parser/generics.py,sha256=GefvTUWkqsICS_TdXA2p73_Uzh6041g88mWql3Fr9cY,1861
|
10
10
|
streamlit_octostar_utils/api_crafter/parser/info.py,sha256=L2cdtsmfIdFSkAnIXhGhQZG6YMZRtY1GgLXn-847avA,649
|
11
11
|
streamlit_octostar_utils/api_crafter/parser/linkchart_functions.py,sha256=WfHl-EfH4SWjpk8civS7HL11eIl4SAV5Dtwe8mTidrc,7163
|
@@ -37,7 +37,7 @@ streamlit_octostar_utils/threading/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzp
|
|
37
37
|
streamlit_octostar_utils/threading/async_task_manager.py,sha256=q7N6YZwUvIYMzkSHmsJNheNVCv93c03H6Hyg9uH8pvk,4747
|
38
38
|
streamlit_octostar_utils/threading/session_callback_manager.py,sha256=LvZVP4g6tvKtYmI13f2j1sX_7hm61Groqp5xJine9_k,3973
|
39
39
|
streamlit_octostar_utils/threading/session_state_hot_swapper.py,sha256=6eeCQI6A42hp4DmW2NQw2rbeR-k9N8DhfBKQdN_fbLU,811
|
40
|
-
streamlit_octostar_utils-0.1.
|
41
|
-
streamlit_octostar_utils-0.1.
|
42
|
-
streamlit_octostar_utils-0.1.
|
43
|
-
streamlit_octostar_utils-0.1.
|
40
|
+
streamlit_octostar_utils-0.1.7a11.dist-info/LICENSE,sha256=dkwVPyV03fPHHtERnF6RnvRXcll__tud9gWca1RcgnQ,1073
|
41
|
+
streamlit_octostar_utils-0.1.7a11.dist-info/METADATA,sha256=sh4TvXiQ_9cxohuhsa_MuY8kcqGJZ2GnVBNCVRXpbpc,2268
|
42
|
+
streamlit_octostar_utils-0.1.7a11.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
43
|
+
streamlit_octostar_utils-0.1.7a11.dist-info/RECORD,,
|
{streamlit_octostar_utils-0.1.7a9.dist-info → streamlit_octostar_utils-0.1.7a11.dist-info}/LICENSE
RENAMED
File without changes
|
{streamlit_octostar_utils-0.1.7a9.dist-info → streamlit_octostar_utils-0.1.7a11.dist-info}/WHEEL
RENAMED
File without changes
|