streamlit-octostar-utils 2.11a6__tar.gz → 2.11a8__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.
Files changed (43) hide show
  1. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/PKG-INFO +1 -1
  2. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/pyproject.toml +1 -1
  3. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/fastapi.py +1 -1
  4. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/nifi.py +15 -14
  5. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/nlp/language.py +31 -9
  6. streamlit_octostar_utils-2.11a8/streamlit_octostar_utils/ontology/inheritance.py +15 -0
  7. streamlit_octostar_utils-2.11a6/streamlit_octostar_utils/ontology/inheritance.py +0 -2
  8. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/LICENSE +0 -0
  9. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/README.md +0 -0
  10. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/__init__.py +0 -0
  11. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/__init__.py +0 -0
  12. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/celery.py +0 -0
  13. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/__init__.py +0 -0
  14. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/combine_fields.py +0 -0
  15. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/entities_parser.py +0 -0
  16. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/generics.py +0 -0
  17. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/info.py +0 -0
  18. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/linkchart_functions.py +0 -0
  19. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/matches.py +0 -0
  20. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/parameters.py +0 -0
  21. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/rules.py +0 -0
  22. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/api_crafter/parser/signals.py +0 -0
  23. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/core/__init__.py +0 -0
  24. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/core/dict.py +0 -0
  25. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/core/filetypes.py +0 -0
  26. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/core/threading/__init__.py +0 -0
  27. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/core/threading/key_queue.py +0 -0
  28. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/core/timestamp.py +0 -0
  29. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/nlp/__init__.py +0 -0
  30. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/nlp/ner.py +0 -0
  31. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/octostar/__init__.py +0 -0
  32. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/octostar/client.py +0 -0
  33. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/octostar/context.py +0 -0
  34. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/octostar/permissions.py +0 -0
  35. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/ontology/__init__.py +0 -0
  36. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/ontology/expand_entities.py +0 -0
  37. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/ontology/validation.py +0 -0
  38. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/style/__init__.py +0 -0
  39. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/style/common.py +0 -0
  40. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/threading/__init__.py +0 -0
  41. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/threading/async_task_manager.py +0 -0
  42. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/threading/session_callback_manager.py +0 -0
  43. {streamlit_octostar_utils-2.11a6 → streamlit_octostar_utils-2.11a8}/streamlit_octostar_utils/threading/session_state_hot_swapper.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: streamlit-octostar-utils
3
- Version: 2.11a6
3
+ Version: 2.11a8
4
4
  Summary:
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -5,7 +5,7 @@ include = '\.pyi?$'
5
5
 
6
6
  [tool.poetry]
7
7
  name = "streamlit-octostar-utils"
8
- version = "2.11a6"
8
+ version = "2.11a8"
9
9
  description = ""
10
10
  license = "MIT"
11
11
  authors = ["Octostar"]
@@ -330,7 +330,7 @@ class DefaultErrorRoute:
330
330
  if len(message) > MAX_ERROR_MESSAGE_BYTES:
331
331
  message = message[-MAX_ERROR_MESSAGE_BYTES:]
332
332
  try:
333
- tcbk = traceback.format_exception(exc)
333
+ tcbk = "\n".join(traceback.format_exception(exc))
334
334
  if len(tcbk) > MAX_ERROR_TRACEBACK_BYTES:
335
335
  tcbk = tcbk[-MAX_ERROR_TRACEBACK_BYTES:]
336
336
  except:
@@ -23,7 +23,7 @@ from octostar.client import make_client
23
23
  from ..core.dict import recursive_update_dict, travel_dict, jsondict_hash
24
24
  from ..core.timestamp import now, string_to_datetime
25
25
  from .fastapi import DefaultErrorRoute, Route
26
- from ..ontology.inheritance import is_child_concept as is_child_concept_fn
26
+ from ..ontology.inheritance import is_child_concept as is_child_concept_fn, get_label_keys
27
27
  from ..ontology.expand_entities import expand_entities
28
28
 
29
29
  RELATIONSHIP_ENTITY_NAME = "os_relationship"
@@ -69,6 +69,7 @@ class NifiEntityModel(BaseModel):
69
69
  class OntologyInfoModel(BaseModel):
70
70
  parents: List[str]
71
71
  relationships: List[str]
72
+ label_keys: List[str]
72
73
 
73
74
  class ContentsPointerModel(BaseModel):
74
75
  location: NifiContentsPointerLocationModel
@@ -806,15 +807,8 @@ class NifiEntity(object):
806
807
 
807
808
  @property
808
809
  def label(self):
809
- if not self.context.ontology:
810
- return None
811
- label_fields = self.context.ontology["concepts"][
812
- self.record.get("os_concept") or self.record.get("entity_type")
813
- ]["labelKeys"]
814
- label_fields = [field for field in label_fields if field]
815
- label = " ".join(
816
- [(self.record.get(field) or "") for field in label_fields]
817
- ).strip()
810
+ label_keys = self.request["ontology_info"]["label_keys"]
811
+ label = " ".join([(self.record.get(field) or "") for field in label_keys]).strip()
818
812
  if not label:
819
813
  label = None
820
814
  return label
@@ -923,14 +917,21 @@ class NifiEntity(object):
923
917
  now_time = now()
924
918
  random_id = str(uuid.uuid4())
925
919
  username = self.jwt_data["username"]
920
+ if entity_type == self.record["entity_type"]:
921
+ ont_parents = self.request["ontology_info"]["parents"]
922
+ ont_relationships = self.request["ontology_info"]["relationships"]
923
+ ont_label_keys = self.request["ontology_info"]["label_keys"]
924
+ else:
925
+ ont_parents = self.context.ontology["concepts"][entity_type]["parents"]
926
+ ont_relationships = self.context.ontology["concepts"][entity_type]["relationships"]
927
+ ont_label_keys = get_label_keys(entity_type, self.context.ontology)
926
928
  child_request = {
927
929
  "jwt": self.request["jwt"],
928
930
  "ontology_name": self.request["ontology_name"],
929
931
  "ontology_info": {
930
- "parents": self.context.ontology["concepts"][entity_type]["parents"],
931
- "relationships": self.context.ontology["concepts"][entity_type][
932
- "relationships"
933
- ],
932
+ "parents": ont_parents,
933
+ "relationships": ont_relationships,
934
+ "label_keys": ont_label_keys,
934
935
  },
935
936
  "entity_timestamp": None,
936
937
  "sync_params": {},
@@ -1,7 +1,9 @@
1
1
  import re
2
+ from typing import Optional
3
+
2
4
  import py3langid as langid
3
5
 
4
- from iso639 import Lang
6
+ from iso639 import Lang, NonExistentLanguageError
5
7
 
6
8
  FLAIR_MODELS = {
7
9
  "en": "flair/ner-english-large",
@@ -31,7 +33,7 @@ def language_to_alpha2(language_name: str) -> str:
31
33
  if not language_name:
32
34
  raise ValueError("Language name must be a non-empty string.")
33
35
 
34
- name = re.sub(r'\b\w+', lambda m: m.group(0).capitalize(), name)
36
+ name = re.sub(r'\b\w+', lambda m: m.group(0).capitalize(), language_name)
35
37
  return Lang(name).pt1
36
38
 
37
39
 
@@ -46,19 +48,39 @@ def detect_language(text, min_confidence=None):
46
48
  return detected_lang, confidence
47
49
 
48
50
 
51
+ def is_language_available(language: Optional[str], type: str) -> bool:
52
+ if not language:
53
+ return False
54
+
55
+ try:
56
+ lang_code = language_to_alpha2(language)
57
+
58
+ except NonExistentLanguageError:
59
+ lang_code = language
60
+
61
+ match type:
62
+ case "spacy":
63
+ return SPACY_MODELS.get(lang_code, None) is not None
64
+
65
+ case "flair":
66
+ return FLAIR_MODELS.get(lang_code, None) is not None
67
+
68
+
49
69
  def load_language_model(language, type):
50
70
  from flair.models import SequenceTagger
51
71
  from spacy_download import load_spacy
52
72
 
53
- model = None
54
-
55
73
  match type:
56
74
  case "spacy":
57
- model_name = SPACY_MODELS.get(language_to_alpha2(language), SPACY_MODELS["en"])
58
- model = load_spacy(model_name)
75
+ if is_language_available(language, "spacy"):
76
+ model_name = SPACY_MODELS.get(language_to_alpha2(language), SPACY_MODELS["en"])
77
+ return load_spacy(model_name)
78
+
79
+ raise Exception(f"SpaCy model for language '{language}' is not available.")
59
80
 
60
81
  case "flair":
61
- model_name = FLAIR_MODELS.get(language, "flair/ner-multi")
62
- model = SequenceTagger.load(model_name)
82
+ if is_language_available(language, "flair"):
83
+ model_name = FLAIR_MODELS.get(language, "flair/ner-multi")
84
+ return SequenceTagger.load(model_name)
63
85
 
64
- return model
86
+ raise Exception(f"Flair model for language '{language}' is not available.")
@@ -0,0 +1,15 @@
1
+ def is_child_concept(type, parent_type, ontology):
2
+ return type == parent_type or parent_type in ontology["concepts"][type]["parents"]
3
+
4
+ def get_label_keys(type, ontology):
5
+ parents = set(ontology["concepts"][type]["parents"])
6
+ parents.add(type)
7
+ parents = list(parents)
8
+ parents.reverse()
9
+ label_keys = {} # for guaranteed insertion order
10
+ for parent in parents:
11
+ for label_key in ontology["concepts"][parent]["labelKeys"]:
12
+ if not label_key:
13
+ continue
14
+ label_keys[label_key] = None
15
+ return list(label_keys.keys())
@@ -1,2 +0,0 @@
1
- def is_child_concept(type, parent_type, ontology):
2
- return type == parent_type or parent_type in ontology["concepts"][type]["parents"]