kodexa 7.0.1a8003211616__py3-none-any.whl → 7.0.1a9196667375__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.
File without changes
@@ -0,0 +1,126 @@
1
+ from typing import Optional, List
2
+
3
+ from pydantic import BaseModel, ConfigDict, Field
4
+ from kodexa.model.base import StandardDateTime
5
+ from kodexa.platform.client import EntityEndpoint, PageEndpoint, EntitiesEndpoint
6
+
7
+
8
+ class Product(BaseModel):
9
+ """
10
+
11
+ """
12
+ model_config = ConfigDict(
13
+ populate_by_name=True,
14
+ use_enum_values=True,
15
+ arbitrary_types_allowed=True,
16
+ protected_namespaces=("model_config",),
17
+ )
18
+ """
19
+ A product
20
+ """
21
+
22
+
23
+ id: Optional[str] = None
24
+ uuid: Optional[str] = None
25
+ change_sequence: Optional[int] = Field(None, alias="changeSequence")
26
+ created_on: Optional[StandardDateTime] = Field(None, alias="createdOn")
27
+ updated_on: Optional[StandardDateTime] = Field(None, alias="updatedOn")
28
+ name: str
29
+ description: Optional[str] = None
30
+ overview_markdown: Optional[str] = Field(None, alias="overviewMarkdown")
31
+
32
+
33
+ class ProductEndpoint(Product, EntityEndpoint):
34
+ """Handles the endpoint for a product
35
+
36
+ This class is a combination of DataException and EntityEndpoint. It is used
37
+ to manage the endpoint for data exceptions.
38
+
39
+ Methods:
40
+ get_type: Returns the type of the endpoint.
41
+ """
42
+
43
+ def get_type(self) -> str:
44
+ """Gets the type of the endpoint.
45
+
46
+ This method returns the type of the endpoint which is "exceptions".
47
+
48
+ Returns:
49
+ str: The type of the endpoint.
50
+ """
51
+ return "products"
52
+
53
+
54
+ class PageProduct(BaseModel):
55
+ """
56
+
57
+ """
58
+ model_config = ConfigDict(
59
+ populate_by_name=True,
60
+ use_enum_values=True,
61
+ arbitrary_types_allowed=True,
62
+ protected_namespaces=("model_config",),
63
+ )
64
+ total_pages: Optional[int] = Field(None, alias="totalPages")
65
+ total_elements: Optional[int] = Field(None, alias="totalElements")
66
+ size: Optional[int] = None
67
+ content: Optional[List[Product]] = None
68
+ number: Optional[int] = None
69
+
70
+ number_of_elements: Optional[int] = Field(None, alias="numberOfElements")
71
+ first: Optional[bool] = None
72
+ last: Optional[bool] = None
73
+ empty: Optional[bool] = None
74
+
75
+
76
+ class PageProductEndpoint(PageProduct, PageEndpoint):
77
+ def get_type(self) -> Optional[str]:
78
+ return "product"
79
+
80
+
81
+ class ProductsEndpoint(EntitiesEndpoint):
82
+ """Represents the products endpoint
83
+
84
+ This class is used to represent the products endpoint in the system.
85
+
86
+ Attributes:
87
+ object_dict: A dictionary containing the object data.
88
+ """
89
+
90
+ """Represents a assistants endpoint"""
91
+
92
+ def get_type(self) -> str:
93
+ """Get the type of the endpoint
94
+
95
+ This method is used to get the type of the endpoint.
96
+
97
+ Returns:
98
+ str: The type of the endpoint.
99
+ """
100
+ return "products"
101
+
102
+ def get_instance_class(self, object_dict=None):
103
+ """Get the instance class of the endpoint
104
+
105
+ This method is used to get the instance class of the endpoint.
106
+
107
+ Args:
108
+ object_dict (dict, optional): A dictionary containing the object data.
109
+
110
+ Returns:
111
+ AssistantEndpoint: The instance class of the endpoint.
112
+ """
113
+ return ProductEndpoint
114
+
115
+ def get_page_class(self, object_dict=None):
116
+ """Get the page class of the endpoint
117
+
118
+ This method is used to get the page class of the endpoint.
119
+
120
+ Args:
121
+ object_dict (dict, optional): A dictionary containing the object data.
122
+
123
+ Returns:
124
+ PageAssistantEndpoint: The page class of the endpoint.
125
+ """
126
+ return PageProductEndpoint
@@ -0,0 +1,122 @@
1
+ from typing import Optional, List
2
+
3
+ from pydantic import BaseModel, ConfigDict, Field
4
+
5
+ from kodexa.model.base import StandardDateTime
6
+ from kodexa.model.entities.product import Product
7
+ from kodexa.model.objects import Organization
8
+ from kodexa.platform.client import EntityEndpoint, PageEndpoint, EntitiesEndpoint
9
+
10
+
11
+ class ProductSubscription(BaseModel):
12
+ """
13
+ A product subscription
14
+ """
15
+ model_config = ConfigDict(
16
+ populate_by_name=True,
17
+ use_enum_values=True,
18
+ arbitrary_types_allowed=True,
19
+ protected_namespaces=("model_config",),
20
+ )
21
+
22
+ id: Optional[str] = Field(None)
23
+ uuid: Optional[str] = None
24
+ change_sequence: Optional[int] = Field(None, alias="changeSequence")
25
+ created_on: Optional[StandardDateTime] = Field(None, alias="createdOn")
26
+ updated_on: Optional[StandardDateTime] = Field(None, alias="updatedOn")
27
+ product: Optional[Product] = None
28
+ organization: Optional[Organization] = None
29
+
30
+
31
+ class ProductSubscriptionEndpoint(ProductSubscription, EntityEndpoint):
32
+ """Handles the endpoint for a product subscription
33
+
34
+ This class is a combination of ProductSubscription and EntityEndpoint. It is used
35
+ to manage the endpoint for product subscriptions.
36
+
37
+ Methods:
38
+ get_type: Returns the type of the endpoint.
39
+ """
40
+
41
+ def get_type(self) -> str:
42
+ """Gets the type of the endpoint.
43
+
44
+ This method returns the type of the endpoint which is "product_subscriptions".
45
+
46
+ Returns:
47
+ str: The type of the endpoint.
48
+ """
49
+ return "productSubscription"
50
+
51
+
52
+ class PageProductSubscription(BaseModel):
53
+ """
54
+ A page of product subscriptions
55
+ """
56
+ model_config = ConfigDict(
57
+ populate_by_name=True,
58
+ use_enum_values=True,
59
+ arbitrary_types_allowed=True,
60
+ protected_namespaces=("model_config",),
61
+ )
62
+ total_pages: Optional[int] = Field(None, alias="totalPages")
63
+ total_elements: Optional[int] = Field(None, alias="totalElements")
64
+ size: Optional[int] = None
65
+ content: Optional[List[ProductSubscription]] = None
66
+ number: Optional[int] = None
67
+
68
+ number_of_elements: Optional[int] = Field(None, alias="numberOfElements")
69
+ first: Optional[bool] = None
70
+ last: Optional[bool] = None
71
+ empty: Optional[bool] = None
72
+
73
+
74
+ class PageProductSubscriptionEndpoint(PageProductSubscription, PageEndpoint):
75
+ def get_type(self) -> Optional[str]:
76
+ return "productSubscription"
77
+
78
+
79
+ class ProductSubscriptionsEndpoint(EntitiesEndpoint):
80
+ """Represents the product subscriptions endpoint
81
+
82
+ This class is used to represent the product subscriptions endpoint in the system.
83
+
84
+ Attributes:
85
+ object_dict: A dictionary containing the object data.
86
+ """
87
+
88
+ def get_type(self) -> str:
89
+ """Get the type of the endpoint
90
+
91
+ This method is used to get the type of the endpoint.
92
+
93
+ Returns:
94
+ str: The type of the endpoint.
95
+ """
96
+ return "productSubscriptions"
97
+
98
+ def get_instance_class(self, object_dict=None):
99
+ """Get the instance class of the endpoint
100
+
101
+ This method is used to get the instance class of the endpoint.
102
+
103
+ Args:
104
+ object_dict (dict, optional): A dictionary containing the object data.
105
+
106
+ Returns:
107
+ ProductSubscriptionEndpoint: The instance class of the endpoint.
108
+ """
109
+ return ProductSubscriptionEndpoint
110
+
111
+ def get_page_class(self, object_dict=None):
112
+ """Get the page class of the endpoint
113
+
114
+ This method is used to get the page class of the endpoint.
115
+
116
+ Args:
117
+ object_dict (dict, optional): A dictionary containing the object data.
118
+
119
+ Returns:
120
+ PageProductSubscriptionEndpoint: The page class of the endpoint.
121
+ """
122
+ return PageProductSubscriptionEndpoint
kodexa/model/model.py CHANGED
@@ -8,8 +8,8 @@ import os
8
8
  import re
9
9
  import uuid
10
10
  from enum import Enum
11
- from typing import Any, List, Optional, Dict
12
-
11
+ from typing import Any, List, Optional
12
+ from addict import Dict
13
13
  import deepdiff
14
14
  import msgpack
15
15
  from pydantic import BaseModel, ConfigDict
@@ -67,6 +67,7 @@ class Ref:
67
67
 
68
68
  import addict
69
69
 
70
+
70
71
  class DocumentMetadata(addict.Dict):
71
72
  """A flexible dict based approach to capturing metadata for the document.
72
73
 
@@ -114,6 +115,7 @@ class ContentException(dict):
114
115
  exception_details: Optional[str] = None,
115
116
  node_uuid: Optional[str] = None,
116
117
  value: Optional[str] = None,
118
+ boolean_value: Optional[bool] = None,
117
119
  *args,
118
120
  **kwargs,
119
121
  ):
@@ -128,9 +130,10 @@ class ContentException(dict):
128
130
  self.severity = severity
129
131
  self.value = value
130
132
  self.exception_type_id = exception_type_id
133
+ self.boolean_value = boolean_value
131
134
 
132
135
 
133
- class Tag(dict):
136
+ class Tag(Dict):
134
137
  """A class to represent the metadata for a label that is applied as a feature on a content node.
135
138
 
136
139
  Attributes:
@@ -173,6 +176,8 @@ class Tag(dict):
173
176
  **kwargs,
174
177
  ):
175
178
  super().__init__(*args, **kwargs)
179
+
180
+ import uuid as uuid_gen
176
181
  self.start: Optional[int] = start
177
182
  """The start position (zero indexed) of the content within the node, if None then label is applied to the whole node"""
178
183
  self.end: Optional[int] = end
@@ -181,7 +186,7 @@ class Tag(dict):
181
186
  """A string representing the value that was labelled in the node"""
182
187
  self.data: Optional[Any] = data
183
188
  """Any data object (JSON serializable) that you wish to associate with the label"""
184
- self.uuid: Optional[str] = uuid or str(uuid.uuid4())
189
+ self.uuid: Optional[str] = uuid or str(uuid_gen.uuid4())
185
190
  """The UUID for this tag instance, this allows tags that are on different content nodes to be related through the same UUID"""
186
191
  self.confidence: Optional[float] = confidence
187
192
  """The confidence of the tag in a range of 0-1"""
@@ -798,6 +803,7 @@ class ContentNode(object):
798
803
  >>> document.get_root().select('//*[hasTag($tagName)]', {"tagName": "div"})
799
804
  [ContentNode]
800
805
  """
806
+
801
807
  if variables is None:
802
808
  variables = {}
803
809
  from kodexa.selectors import parse
@@ -2438,6 +2444,19 @@ class Document(object):
2438
2444
  for node in tag_instance.nodes:
2439
2445
  node.remove_tag(tag)
2440
2446
 
2447
+ def get_nodes_by_type(self, node_type: str) -> List[ContentNode]:
2448
+ """
2449
+ Get all the nodes of a specific type
2450
+
2451
+ Args:
2452
+ node_type: the type of the node
2453
+
2454
+ Returns:
2455
+ a list of nodes
2456
+
2457
+ """
2458
+ return self._persistence_layer.get_nodes_by_type(node_type)
2459
+
2441
2460
  def get_node_by_uuid(self, uuid: int) -> ContentNode:
2442
2461
  """
2443
2462
  Get a node by its uuid
@@ -2612,7 +2631,7 @@ class Document(object):
2612
2631
  return self
2613
2632
 
2614
2633
  @classmethod
2615
- def from_text(cls, text, separator=None):
2634
+ def from_text(cls, text, separator=None, inmemory=False):
2616
2635
  """Creates a new Document from the text provided.
2617
2636
 
2618
2637
  Args:
@@ -2623,7 +2642,7 @@ class Document(object):
2623
2642
  the document
2624
2643
 
2625
2644
  """
2626
- new_document = Document()
2645
+ new_document = Document(inmemory=inmemory)
2627
2646
  new_document.source.original_filename = f"text-{uuid.uuid4()}"
2628
2647
  new_document.content_node = new_document.create_node(node_type="text", index=0)
2629
2648
  if text:
@@ -2939,7 +2958,7 @@ class Document(object):
2939
2958
  )
2940
2959
  fp.write(source)
2941
2960
  fp.close()
2942
- return Document(kddb_path=fp.name, delete_on_close=True)
2961
+ return Document(kddb_path=fp.name, delete_on_close=True, inmemory=inmemory)
2943
2962
 
2944
2963
  @classmethod
2945
2964
  def from_file(cls, file, unpack: bool = False):