Quellcode durchsuchen

Primitive type services

Andrei Bondarenko vor 4 Jahren
Ursprung
Commit
3e2d0fb96a

+ 0 - 0
services/primitives/__init__.py


+ 19 - 0
services/primitives/boolean_type.py

@@ -0,0 +1,19 @@
+from uuid import UUID
+from state.base import State
+from services.bottom.V0 import Bottom
+
+
+class Boolean:
+    def __init__(self, model: UUID, state: State):
+        self.model = model
+        self.bottom = Bottom(state)
+        type_model_id_node, = self.bottom.read_outgoing_nodes(state.read_root(), "Boolean")
+        self.type_model = UUID(self.bottom.read_value(type_model_id_node))
+
+    def create(self, value: bool):
+        if "boolean" in self.bottom.read_keys(self.model):
+            instance, = self.bottom.read_outgoing_nodes(self.model, "boolean")
+            self.bottom.delete_element(instance)
+        _instance = self.bottom.create_edge(self.model, self.bottom.create_node(value), "boolean")
+        _type, = self.bottom.read_outgoing_nodes(self.type_model, "Boolean")
+        self.bottom.create_edge(_instance, _type, "Morphism")

+ 19 - 0
services/primitives/float_type.py

@@ -0,0 +1,19 @@
+from uuid import UUID
+from state.base import State
+from services.bottom.V0 import Bottom
+
+
+class Float:
+    def __init__(self, model: UUID, state: State):
+        self.model = model
+        self.bottom = Bottom(state)
+        type_model_id_node, = self.bottom.read_outgoing_nodes(state.read_root(), "Float")
+        self.type_model = UUID(self.bottom.read_value(type_model_id_node))
+
+    def create(self, value: float):
+        if "float" in self.bottom.read_keys(self.model):
+            instance, = self.bottom.read_outgoing_nodes(self.model, "float")
+            self.bottom.delete_element(instance)
+        _instance = self.bottom.create_edge(self.model, self.bottom.create_node(value), "float")
+        _type, = self.bottom.read_outgoing_nodes(self.type_model, "Float")
+        self.bottom.create_edge(_instance, _type, "Morphism")

+ 19 - 0
services/primitives/integer_type.py

@@ -0,0 +1,19 @@
+from uuid import UUID
+from state.base import State
+from services.bottom.V0 import Bottom
+
+
+class Integer:
+    def __init__(self, model: UUID, state: State):
+        self.model = model
+        self.bottom = Bottom(state)
+        type_model_id_node, = self.bottom.read_outgoing_nodes(state.read_root(), "Integer")
+        self.type_model = UUID(self.bottom.read_value(type_model_id_node))
+
+    def create(self, value: int):
+        if "string" in self.bottom.read_keys(self.model):
+            instance, = self.bottom.read_outgoing_nodes(self.model, "integer")
+            self.bottom.delete_element(instance)
+        _instance = self.bottom.create_edge(self.model, self.bottom.create_node(value), "integer")
+        _type, = self.bottom.read_outgoing_nodes(self.type_model, "Integer")
+        self.bottom.create_edge(_instance, _type, "Morphism")

+ 19 - 0
services/primitives/string_type.py

@@ -0,0 +1,19 @@
+from uuid import UUID
+from state.base import State
+from services.bottom.V0 import Bottom
+
+
+class String:
+    def __init__(self, model: UUID, state: State):
+        self.model = model
+        self.bottom = Bottom(state)
+        type_model_id_node, = self.bottom.read_outgoing_nodes(state.read_root(), "String")
+        self.type_model = UUID(self.bottom.read_value(type_model_id_node))
+
+    def create(self, value: str):
+        if "string" in self.bottom.read_keys(self.model):
+            instance, = self.bottom.read_outgoing_nodes(self.model, "string")
+            self.bottom.delete_element(instance)
+        _instance = self.bottom.create_edge(self.model, self.bottom.create_node(value), "string")
+        _type, = self.bottom.read_outgoing_nodes(self.type_model, "String")
+        self.bottom.create_edge(_instance, _type, "Morphism")

+ 19 - 0
services/primitives/type_type.py

@@ -0,0 +1,19 @@
+from uuid import UUID
+from state.base import State
+from services.bottom.V0 import Bottom
+
+
+class Integer:
+    def __init__(self, model: UUID, state: State):
+        self.model = model
+        self.bottom = Bottom(state)
+        type_model_id_node, = self.bottom.read_outgoing_nodes(state.read_root(), "Type")
+        self.type_model = UUID(self.bottom.read_value(type_model_id_node))
+
+    def create(self, value: tuple):
+        if "string" in self.bottom.read_keys(self.model):
+            instance, = self.bottom.read_outgoing_nodes(self.model, "type")
+            self.bottom.delete_element(instance)
+        _instance = self.bottom.create_edge(self.model, self.bottom.create_node(value), "type")
+        _type, = self.bottom.read_outgoing_nodes(self.type_model, "Type")
+        self.bottom.create_edge(_instance, _type, "Morphism")