diff --git a/tenet/febTransduction/net/atom_property_net.py b/tenet/febTransduction/net/atom_property_net.py index c7bbcdfe499268e5004c2741c1dcb8aadf0d2fca..c029b52c158a40f07362e3d883bd45d31dc995da 100644 --- a/tenet/febTransduction/net/atom_property_net.py +++ b/tenet/febTransduction/net/atom_property_net.py @@ -53,7 +53,10 @@ class AtomPropertyNet(PropertyNet): @core_role.setter def core_role(self, new_value): - self._core_role = new_value + if isinstance(self._core_role, list): + self._core_role.append(new_value) + else: + self._core_role = new_value @property def target_argument_node(self): @@ -62,7 +65,10 @@ class AtomPropertyNet(PropertyNet): @target_argument_node.setter def target_argument_node(self, new_value): - self._target_argument_node = new_value + if isinstance(self._target_argument_node, list): + self._target_argument_node.append(new_value) + else: + self._target_argument_node = new_value @property def property_type(self): @@ -71,7 +77,10 @@ class AtomPropertyNet(PropertyNet): @property_type.setter def property_type(self, new_value): - self._property_type = new_value + if isinstance(self._property_type, list): + self._property_type.append(new_value) + else: + self._property_type = new_value @property def property_name01(self): @@ -80,7 +89,10 @@ class AtomPropertyNet(PropertyNet): @property_name01.setter def property_name01(self, new_value): - self._property_name01 = new_value + if isinstance(self._property_name01, list): + self._property_name01.append(new_value) + else: + self._property_name01 = new_value @property def property_name10(self): @@ -89,7 +101,10 @@ class AtomPropertyNet(PropertyNet): @property_name10.setter def property_name10(self, new_value): - self._property_name10 = new_value + if isinstance(self._property_name10, list): + self._property_name10.append(new_value) + else: + self._property_name10 = new_value @property def property_name12(self): @@ -98,4 +113,7 @@ class AtomPropertyNet(PropertyNet): @property_name12.setter def property_name12(self, new_value): - self._property_name12 = new_value \ No newline at end of file + if isinstance(self._property_name12, list): + self._property_name12.append(new_value) + else: + self._property_name12 = new_value \ No newline at end of file diff --git a/tenet/febTransduction/net/class_net.py b/tenet/febTransduction/net/class_net.py index d1fbe6675041b67d9ee7b0756a7e9a58bc265e1a..c030589686b1b898935919294c7d23e253a10440 100644 --- a/tenet/febTransduction/net/class_net.py +++ b/tenet/febTransduction/net/class_net.py @@ -47,4 +47,7 @@ class ClassNet(Net): @class_name.setter def class_name(self, new_value): - self._class_name = new_value \ No newline at end of file + if isinstance(self._class_name, list): + self._class_name.append(new_value) + else: + self._class_name = new_value \ No newline at end of file diff --git a/tenet/febTransduction/net/composite_class_net.py b/tenet/febTransduction/net/composite_class_net.py index 484fef40c0c5df1302acb36c81cbefc5fc866b53..374e050f8e8337b4dcac56c1275ea012e0785726 100644 --- a/tenet/febTransduction/net/composite_class_net.py +++ b/tenet/febTransduction/net/composite_class_net.py @@ -33,9 +33,9 @@ class CompositeClassNet(ClassNet): self.type_uri = f'net:{self.type_id}' # -- Net Attributes - self.mother_class_net = None - self.restriction = [] - self.restriction01 = [] + self._mother_class_net = None + self._restriction = [] + self._restriction01 = [] #-------------------------------------------------------------------------- @@ -49,7 +49,10 @@ class CompositeClassNet(ClassNet): @mother_class_net.setter def mother_class_net(self, new_value): - self._mother_class_net = new_value + if isinstance(self._mother_class_net, list): + self._mother_class_net.append(new_value) + else: + self._mother_class_net = new_value @property def restriction(self): @@ -58,7 +61,10 @@ class CompositeClassNet(ClassNet): @restriction.setter def restriction(self, new_value): - self._restriction = new_value + if isinstance(self._restriction, list): + self._restriction.append(new_value) + else: + self._restriction = new_value @property def restriction01(self): @@ -67,4 +73,7 @@ class CompositeClassNet(ClassNet): @restriction01.setter def restriction01(self, new_value): - self._restriction01 = new_value \ No newline at end of file + if isinstance(self._restriction01, list): + self._restriction01.append(new_value) + else: + self._restriction01 = new_value \ No newline at end of file diff --git a/tenet/febTransduction/net/composite_property_net.py b/tenet/febTransduction/net/composite_property_net.py index 8629d93fe90de11528eea4d4f1e42eb9dbf4e4cb..7a2f969db8e9d3aa77f13539dc209cea8cc1fe80 100644 --- a/tenet/febTransduction/net/composite_property_net.py +++ b/tenet/febTransduction/net/composite_property_net.py @@ -50,7 +50,10 @@ class CompositePropertyNet(PropertyNet): @core_role.setter def core_role(self, new_value): - self._core_role = new_value + if isinstance(self._core_role, list): + self._core_role.append(new_value) + else: + self._core_role = new_value @property def target_argument_node(self): @@ -59,7 +62,10 @@ class CompositePropertyNet(PropertyNet): @target_argument_node.setter def target_argument_node(self, new_value): - self._target_argument_node = new_value + if isinstance(self._target_argument_node, list): + self._target_argument_node.append(new_value) + else: + self._target_argument_node = new_value @property def property_type(self): @@ -68,7 +74,10 @@ class CompositePropertyNet(PropertyNet): @property_type.setter def property_type(self, new_value): - self._property_type = new_value + if isinstance(self._property_type, list): + self._property_type.append(new_value) + else: + self._property_type = new_value @property def restriction(self): @@ -77,4 +86,7 @@ class CompositePropertyNet(PropertyNet): @restriction.setter def restriction(self, new_value): - self._restriction = new_value \ No newline at end of file + if isinstance(self._restriction, list): + self._restriction.append(new_value) + else: + self._restriction = new_value \ No newline at end of file diff --git a/tenet/febTransduction/net/individual_net.py b/tenet/febTransduction/net/individual_net.py index 504ddb422e1f5f15712fe7792042a9590e804429..7088754625d3823a5cc598f19b84d05d4410ee1c 100644 --- a/tenet/febTransduction/net/individual_net.py +++ b/tenet/febTransduction/net/individual_net.py @@ -33,9 +33,9 @@ class IndividualNet(Net): self.type_uri = f'net:{self.type_id}' # -- Net Attributes - self.base_class_name = None - self.mother_class_net = [] - self.individual_label = None + self._base_class_name = None + self._mother_class_net = [] + self._individual_label = None #-------------------------------------------------------------------------- @@ -49,7 +49,10 @@ class IndividualNet(Net): @base_class_name.setter def base_class_name(self, new_value): - self._base_class_name = new_value + if isinstance(self._base_class_name, list): + self._base_class_name.append(new_value) + else: + self._base_class_name = new_value @property def mother_class_net(self): @@ -58,7 +61,10 @@ class IndividualNet(Net): @mother_class_net.setter def mother_class_net(self, new_value): - self._mother_class_net = new_value + if isinstance(self._mother_class_net, list): + self._mother_class_net.append(new_value) + else: + self._mother_class_net = new_value @property def individual_label(self): @@ -67,4 +73,7 @@ class IndividualNet(Net): @individual_label.setter def individual_label(self, new_value): - self._individual_label = new_value \ No newline at end of file + if isinstance(self._individual_label, list): + self._individual_label.append(new_value) + else: + self._individual_label = new_value \ No newline at end of file diff --git a/tenet/febTransduction/net/net.py b/tenet/febTransduction/net/net.py index 3753c204ea392783f02afe9f1af6d0876d7fbf96..42f824f13d861b462f12036edc9c920c0de90705 100644 --- a/tenet/febTransduction/net/net.py +++ b/tenet/febTransduction/net/net.py @@ -44,6 +44,7 @@ class Net: self._naming = None + #-------------------------------------------------------------------------- # Accessor Base Methods #-------------------------------------------------------------------------- @@ -91,7 +92,16 @@ class Net: return res + def set_attribute_value(self, **attr): + for attr_key, attr_value in attr.items(): + if isinstance(attr_key, list): + self.attr_key.append(attr_value) + print(f'{attr_key} | {attr_value} | {self.attr_key} | {self._base_node}') + else: + self.attr_key = attr_value + print(f'{attr_key} | {attr_value} | {self.attr_key} | {self._base_node}') + #-------------------------------------------------------------------------- # Accessors for Net URI #-------------------------------------------------------------------------- @@ -104,6 +114,7 @@ class Net: def uri(self, new_value): self._uri = new_value + #-------------------------------------------------------------------------- # Accessors for Net Attributes @@ -116,7 +127,10 @@ class Net: @node.setter def node(self, new_value): - self._node = new_value + if isinstance(self._node, list): + self._node.append(new_value) + else: + self._node = new_value @property def base_node(self): @@ -125,7 +139,10 @@ class Net: @base_node.setter def base_node(self, new_value): - self._base_node = new_value + if isinstance(self._base_node, list): + self._base_node.append(new_value) + else: + self._base_node = new_value @property def structure(self): @@ -134,7 +151,10 @@ class Net: @structure.setter def structure(self, new_value): - self._structure = new_value + if isinstance(self._structure, list): + self._structure.append(new_value) + else: + self._structure = new_value @property def naming(self): @@ -143,4 +163,25 @@ class Net: @naming.setter def naming(self, new_value): - self._naming = new_value \ No newline at end of file + if isinstance(self._naming, list): + self._naming.append(new_value) + else: + self._naming = new_value + + + + #-------------------------------------------------------------------------- + # Composition Method + #-------------------------------------------------------------------------- + + def compose(self, *nets): + + assert len(nets) > 0, 'at least one net is needed to compose a new net' + + # -- Base Node and Structure Setting + self.base_node = nets[0].base_node + self.structure = nets[0].structure + + # -- Node(s) Setting + for n in nets: + self.node = n.node \ No newline at end of file diff --git a/tenet/febTransduction/net/phenomena_net.py b/tenet/febTransduction/net/phenomena_net.py index 6780eda3fd016693c68746725798317d5641f179..096109848bbf4e36a99bdc90fc3f4cd2de936020 100644 --- a/tenet/febTransduction/net/phenomena_net.py +++ b/tenet/febTransduction/net/phenomena_net.py @@ -33,8 +33,8 @@ class PhenomenaNet(Net): self.type_uri = f'net:{self.type_id}' # -- Net Attributes - self.phenomena_type = None - self.phenomena_ref = None + self._phenomena_type = None + self._phenomena_ref = None #-------------------------------------------------------------------------- @@ -48,7 +48,10 @@ class PhenomenaNet(Net): @phenomena_type.setter def phenomena_type(self, new_value): - self._phenomena_type = new_value + if isinstance(self._phenomena_type, list): + self._phenomena_type.append(new_value) + else: + self._phenomena_type = new_value @property def phenomena_ref(self): @@ -57,4 +60,7 @@ class PhenomenaNet(Net): @phenomena_ref.setter def phenomena_ref(self, new_value): - self._phenomena_ref = new_value \ No newline at end of file + if isinstance(self._phenomena_ref, list): + self._phenomena_ref.append(new_value) + else: + self._phenomena_ref = new_value \ No newline at end of file diff --git a/tenet/febTransduction/net/property_net.py b/tenet/febTransduction/net/property_net.py index 9caa07b061467066ff55186278683ad99dba2469..2da29dc3677eed229aea01f15d5c7d90aaf20258 100644 --- a/tenet/febTransduction/net/property_net.py +++ b/tenet/febTransduction/net/property_net.py @@ -47,4 +47,7 @@ class PropertyNet(Net): @property_name.setter def property_name(self, new_value): - self._property_name = new_value \ No newline at end of file + if isinstance(self._property_name, list): + self._property_name.append(new_value) + else: + self._property_name = new_value \ No newline at end of file diff --git a/tenet/febTransduction/net/restriction_net.py b/tenet/febTransduction/net/restriction_net.py index c9dde4bd2f5b5f825036e5b968dcdbb8df215693..a60709087ded56f0e486cd6bc552f18d5f043183 100644 --- a/tenet/febTransduction/net/restriction_net.py +++ b/tenet/febTransduction/net/restriction_net.py @@ -33,9 +33,9 @@ class RestrictionNet(Net): self.type_uri = f'net:{self.type_id}' # -- Net Attributes - self.target_node = [] - self.restriction_property = None - self.restriction_net_value = None + self._target_node = [] + self._restriction_property = None + self._restriction_net_value = None #-------------------------------------------------------------------------- @@ -49,7 +49,10 @@ class RestrictionNet(Net): @target_node.setter def target_node(self, new_value): - self._target_node = new_value + if isinstance(self._target_node, list): + self._target_node.append(new_value) + else: + self._target_node = new_value @property def restriction_property(self): @@ -58,7 +61,10 @@ class RestrictionNet(Net): @restriction_property.setter def restriction_property(self, new_value): - self._restriction_property = new_value + if isinstance(self._restriction_property, list): + self._restriction_property.append(new_value) + else: + self._restriction_property = new_value @property def restriction_net_value(self): @@ -67,4 +73,7 @@ class RestrictionNet(Net): @restriction_net_value.setter def restriction_net_value(self, new_value): - self._restriction_net_value = new_value \ No newline at end of file + if isinstance(self._restriction_net_value, list): + self._restriction_net_value.append(new_value) + else: + self._restriction_net_value = new_value \ No newline at end of file diff --git a/tenet/febTransduction/net/value_net.py b/tenet/febTransduction/net/value_net.py index 570b298c6e298d87a98eca6a977c9579401d8fa3..7971e411d3a5beff76d46708dceed9f7ae5dd61d 100644 --- a/tenet/febTransduction/net/value_net.py +++ b/tenet/febTransduction/net/value_net.py @@ -33,7 +33,7 @@ class ValueNet(Net): self.type_uri = f'net:{self.type_id}' # -- Net Attributes - self.value_label = None + self._value_label = None #-------------------------------------------------------------------------- @@ -47,4 +47,7 @@ class ValueNet(Net): @value_label.setter def value_label(self, new_value): - self._value_label = new_value \ No newline at end of file + if isinstance(self._value_label, list): + self._value_label.append(new_value) + else: + self._value_label = new_value diff --git a/tests/test_tenet_rule.py b/tests/test_rule.py similarity index 100% rename from tests/test_tenet_rule.py rename to tests/test_rule.py diff --git a/tests/test_tenet_scheme.py b/tests/test_scheme.py similarity index 100% rename from tests/test_tenet_scheme.py rename to tests/test_scheme.py diff --git a/tests/test_semantic_net_1.py b/tests/test_semantic_net_1.py new file mode 100644 index 0000000000000000000000000000000000000000..a8a77f3b6dabc3b87078e9ca5539c04b7b20d4aa --- /dev/null +++ b/tests/test_semantic_net_1.py @@ -0,0 +1,148 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Semantic Net Class Test +#------------------------------------------------------------------------------ +# Script to test the semantic net classes +#============================================================================== + +import subprocess, os +from rdflib import Graph +from rdflib import Namespace +from rdflib.namespace import NamespaceManager + +FILE_PATH = f'{os.path.dirname(os.path.abspath(__file__))}' +INPUT_DIR_PATH = f'{FILE_PATH}/input/' +OUTPUT_DIR_PATH = f'{FILE_PATH}/output/' +TEST_GRAPH = f'{INPUT_DIR_PATH}testGraph1.ttl' + +from context import tenet + +from tenet.febTransduction.net import Net + +from tenet.febTransduction.net import ClassNet +from tenet.febTransduction.net import AtomClassNet +from tenet.febTransduction.net import CompositeClassNet + +from tenet.febTransduction.net import PropertyNet +from tenet.febTransduction.net import AtomPropertyNet +from tenet.febTransduction.net import CompositePropertyNet + +from tenet.febTransduction.net import IndividualNet + +from tenet.febTransduction.net import ValueNet + +from tenet.febTransduction.net import PhenomenaNet + +from tenet.febTransduction.net import RestrictionNet + + + +#============================================================================== +# Utilities +#============================================================================== + +def test_attribute_access(net, *attr_set): + print(f'\n *** Net attributes ({net.type_id})) ***') + for attr in attr_set: + print(f' ----- {attr}: {eval(attr)}') + + + +#============================================================================== +# Development Test +#============================================================================== + +print('\n' + ' *** Development Test ***') +print('\n *** TEST: Semantic Net Getters ***') + +print(f'\n -- Test Graph Loading') +graph = Graph() +graph.bind('net', Namespace('https://tenet.tetras-libre.fr/semantic-net#')) +graph.parse(TEST_GRAPH) +print(f" ----- Graph Loaded ({len(graph)})") + +print('\n -- Net') +net = Net(graph, uri='net:atomClass_sun_s2') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming') + +print('\n -- Class Net') +net = ClassNet(graph, uri='net:atomClass_sun_s2') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.class_name') + +print('\n -- Atom Class Net') +net = AtomClassNet(graph, uri='net:atomClass_sun_s2') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.class_name') + +print('\n -- Composite Class Net (1)') +net = CompositeClassNet(graph, uri='net:compositeClass_orbit-hasManner-conjunction-OR_o2') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.class_name', + 'net.mother_class_net', 'net.restriction', 'net.restriction01') + +print('\n -- Composite Class Net (2)') +net = CompositeClassNet(graph, uri='net:compositeClass_system-hasPart-sun-and-object_s') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.class_name', + 'net.mother_class_net', 'net.restriction', 'net.restriction01') + +print('\n -- Property Net') +net = PropertyNet(graph, uri='net:atomProperty_orbit_o2') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.property_name') + +print('\n -- Atom Property Net') +net = AtomPropertyNet(graph, uri='net:atomProperty_orbit_o2') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.property_name', + 'net.core_role', 'net.target_argument_node', 'net.property_type', + 'net.property_name01', 'net.property_name10', 'net.property_name12') + +print('\n -- Composite Property Net') +net = CompositePropertyNet(graph, uri='net:compositeProperty_not-direct_d2') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.property_name', + 'net.core_role', 'net.target_argument_node', 'net.property_type', 'net.restriction') + +print('\n -- Individual Net') +net = IndividualNet(graph, uri='net:individual_system_SolarSystem') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.base_class_name', 'net.mother_class_net', 'net.individual_label') + +print('\n -- Value Net') +net = ValueNet(graph, uri='net:value_SolarSystem_blankNode') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.value_label') + +print('\n -- Phenomena Net (1)') +net = PhenomenaNet(graph, uri='net:phenomena_conjunction-AND_a') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.phenomena_type', 'net.phenomena_ref') + +print('\n -- Phenomena Net (1)') +net = PhenomenaNet(graph, uri='net:phenomena_conjunction-OR_o3') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.phenomena_type', 'net.phenomena_ref') + +print('\n -- Restriction Net') +net = RestrictionNet(graph, uri='net:restriction_hasPart_sun') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.target_node', 'net.restriction_property', 'net.restriction_net_value') + +print('\n' + ' *** - ***') \ No newline at end of file diff --git a/tests/test_semantic_net_2.py b/tests/test_semantic_net_2.py new file mode 100644 index 0000000000000000000000000000000000000000..5b6d42bb9634a6a90c072743d4d36b2356fe3a5e --- /dev/null +++ b/tests/test_semantic_net_2.py @@ -0,0 +1,188 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Semantic Net Class Test +#------------------------------------------------------------------------------ +# Script to test the semantic net classes +#============================================================================== + +import subprocess, os +from rdflib import Graph +from rdflib import Namespace +from rdflib.namespace import NamespaceManager + +FILE_PATH = f'{os.path.dirname(os.path.abspath(__file__))}' +INPUT_DIR_PATH = f'{FILE_PATH}/input/' +OUTPUT_DIR_PATH = f'{FILE_PATH}/output/' +TEST_GRAPH = f'{INPUT_DIR_PATH}testGraph1.ttl' + +from context import tenet + +from tenet.febTransduction.net import Net + +from tenet.febTransduction.net import ClassNet +from tenet.febTransduction.net import AtomClassNet +from tenet.febTransduction.net import CompositeClassNet + +from tenet.febTransduction.net import PropertyNet +from tenet.febTransduction.net import AtomPropertyNet +from tenet.febTransduction.net import CompositePropertyNet + +from tenet.febTransduction.net import IndividualNet + +from tenet.febTransduction.net import ValueNet + +from tenet.febTransduction.net import PhenomenaNet + +from tenet.febTransduction.net import RestrictionNet + + + +#============================================================================== +# Utilities +#============================================================================== + +def test_attribute_access(net, *attr_set): + print(f'\n *** Net attributes ({net.type_id})) ***') + for attr in attr_set: + print(f' ----- {attr}: {eval(attr)}') + + + +#============================================================================== +# Development Test +#============================================================================== + +print('\n' + ' *** Development Test ***') +print('\n *** TEST: Semantic Net Setters ***') + +print(f'\n -- Test Graph Loading') +graph = Graph() +graph.bind('net', Namespace('https://tenet.tetras-libre.fr/semantic-net#')) +graph.parse(TEST_GRAPH) +print(f" ----- Graph Loaded ({len(graph)})") + +print('\n -- Net') +net = Net(graph, uri='net:atomClass_sun_s2') +print('\n /// before setting') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming') +net.base_node = ' *** node_a ***' +net.node = ' *** node_a ***' +net.structure = ' *** test-structure ***' +net.naming = ' *** test-naming ***' +print('\n /// after setting') +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming') + +print('\n -- Class Net') +net = ClassNet(graph, uri='net:atomClass_sun_s2') +net.class_name = ' *** test-class-name (1) ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.class_name') + +print('\n -- Atom Class Net') +net = AtomClassNet(graph, uri='net:atomClass_sun_s2') +net.class_name = ' *** test-class-name (2) ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.class_name') + +print('\n -- Composite Class Net (1)') +net = CompositeClassNet(graph, uri='net:compositeClass_orbit-hasManner-conjunction-OR_o2') +net.mother_class_net = ' *** test-value ***' +net.restriction = ' *** test-value ***' +net.restriction01 = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.class_name', + 'net.mother_class_net', 'net.restriction', 'net.restriction01') + +print('\n -- Composite Class Net (2)') +net = CompositeClassNet(graph, uri='net:compositeClass_system-hasPart-sun-and-object_s') +net.mother_class_net = ' *** test-value ***' +net.restriction = ' *** test-value ***' +net.restriction01 = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.class_name', + 'net.mother_class_net', 'net.restriction', 'net.restriction01') + +print('\n -- Property Net') +net = PropertyNet(graph, uri='net:atomProperty_orbit_o2') +net.property_name = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.property_name') + +print('\n -- Atom Property Net') +net = AtomPropertyNet(graph, uri='net:atomProperty_orbit_o2') +net.property_name = ' *** test-value ***' +net.core_role = ' *** test-value ***' +net.target_argument_node = ' *** test-value ***' +net.property_type = ' *** test-value ***' +net.property_name01 = ' *** test-value ***' +net.property_name10 = ' *** test-value ***' +net.property_name12 = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.property_name', + 'net.core_role', 'net.target_argument_node', 'net.property_type', + 'net.property_name01', 'net.property_name10', 'net.property_name12') + +print('\n -- Composite Property Net') +net = CompositePropertyNet(graph, uri='net:compositeProperty_not-direct_d2') +net.property_name = ' *** test-value ***' +net.core_role = ' *** test-value ***' +net.target_argument_node = ' *** test-value ***' +net.property_type = ' *** test-value ***' +net.restriction = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.property_name', + 'net.core_role', 'net.target_argument_node', 'net.property_type', 'net.restriction') + +print('\n -- Individual Net') +net = IndividualNet(graph, uri='net:individual_system_SolarSystem') +net.base_class_name = ' *** test-value ***' +net.mother_class_net = ' *** test-value ***' +net.individual_label = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.base_class_name', 'net.mother_class_net', 'net.individual_label') + +print('\n -- Value Net') +net = ValueNet(graph, uri='net:value_SolarSystem_blankNode') +net.value_label = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.value_label') + +print('\n -- Phenomena Net (1)') +net = PhenomenaNet(graph, uri='net:phenomena_conjunction-AND_a') +net.phenomena_type = ' *** test-value ***' +net.phenomena_ref = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.phenomena_type', 'net.phenomena_ref') + +print('\n -- Phenomena Net (1)') +net = PhenomenaNet(graph, uri='net:phenomena_conjunction-OR_o3') +net.phenomena_type = ' *** test-value ***' +net.phenomena_ref = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.phenomena_type', 'net.phenomena_ref') + +print('\n -- Restriction Net') +net = RestrictionNet(graph, uri='net:restriction_hasPart_sun') +net.target_node = ' *** test-value ***' +net.restriction_property = ' *** test-value ***' +net.restriction_net_value = ' *** test-value ***' +test_attribute_access(net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming', + 'net.target_node', 'net.restriction_property', 'net.restriction_net_value') + +print('\n' + ' *** - ***') \ No newline at end of file diff --git a/tests/test_semantic_net_3.py b/tests/test_semantic_net_3.py new file mode 100644 index 0000000000000000000000000000000000000000..61fa60748eff806b451c7baf6af5510b79377669 --- /dev/null +++ b/tests/test_semantic_net_3.py @@ -0,0 +1,86 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# TENET: Semantic Net Class Test +#------------------------------------------------------------------------------ +# Script to test the semantic net classes +#============================================================================== + +import subprocess, os +from rdflib import Graph +from rdflib import Namespace +from rdflib.namespace import NamespaceManager + +FILE_PATH = f'{os.path.dirname(os.path.abspath(__file__))}' +INPUT_DIR_PATH = f'{FILE_PATH}/input/' +OUTPUT_DIR_PATH = f'{FILE_PATH}/output/' +TEST_GRAPH = f'{INPUT_DIR_PATH}testGraph1.ttl' + +from context import tenet + +from tenet.febTransduction.net import Net + +from tenet.febTransduction.net import ClassNet +from tenet.febTransduction.net import AtomClassNet +from tenet.febTransduction.net import CompositeClassNet + +from tenet.febTransduction.net import PropertyNet +from tenet.febTransduction.net import AtomPropertyNet +from tenet.febTransduction.net import CompositePropertyNet + +from tenet.febTransduction.net import IndividualNet + +from tenet.febTransduction.net import ValueNet + +from tenet.febTransduction.net import PhenomenaNet + +from tenet.febTransduction.net import RestrictionNet + + + +#============================================================================== +# Utilities +#============================================================================== + +def test_attribute_access(net, *attr_set): + print(f'\n *** Net attributes ({net.type_id})) ***') + for attr in attr_set: + print(f' ----- {attr}: {eval(attr)}') + + + +#============================================================================== +# Development Test +#============================================================================== + +print('\n' + ' *** Development Test ***') +print('\n *** TEST: Semantic Net Composition ***') + +print(f'\n -- Test Graph Loading') +graph = Graph() +graph.bind('net', Namespace('https://tenet.tetras-libre.fr/semantic-net#')) +graph.parse(TEST_GRAPH) +print(f" ----- Graph Loaded ({len(graph)})") + +print('\n -- Nets to compose') +net_1 = AtomClassNet(graph, uri='net:atomClass_object_o') +print(f' ----- net_1: {net_1.uri} ({net_1.naming})') +net_2 = PropertyNet(graph, uri='net:atomProperty_orbit_o2') +print(f' ----- net_2: {net_2.uri} ({net_2.naming})') +net_3 = AtomClassNet(graph, uri='net:atomClass_sun_s2') +print(f' ----- net_3: {net_3.uri} ({net_3.naming})') + +print('\n -- New Net constructed by composition') +new_net = CompositeClassNet(graph) +print('\n /// before composition') +test_attribute_access(new_net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming') + +new_net.compose(net_1, net_2, net_3) + +print('\n /// after composition') +test_attribute_access(new_net, 'net.uri', + 'net.node', 'net.base_node', 'net.structure', 'net.naming') + +print('\n' + ' *** - ***') \ No newline at end of file diff --git a/tests/test_tenet_semantic_net.py b/tests/test_tenet_semantic_net.py deleted file mode 100644 index 587bf70f49a02a0f5b273cc7004074ce1551fdb6..0000000000000000000000000000000000000000 --- a/tests/test_tenet_semantic_net.py +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/python3.10 -# -*-coding:Utf-8 -* - -#============================================================================== -# TENET: Semantic Net Class Test -#------------------------------------------------------------------------------ -# Script to test the semantic net classes -#============================================================================== - -import subprocess, os -from rdflib import Graph -from rdflib import Namespace -from rdflib.namespace import NamespaceManager - -FILE_PATH = f'{os.path.dirname(os.path.abspath(__file__))}' -INPUT_DIR_PATH = f'{FILE_PATH}/input/' -OUTPUT_DIR_PATH = f'{FILE_PATH}/output/' -TEST_GRAPH = f'{INPUT_DIR_PATH}testGraph1.ttl' - -from context import tenet - -from tenet.febTransduction.net import Net - -from tenet.febTransduction.net import ClassNet -from tenet.febTransduction.net import AtomClassNet -from tenet.febTransduction.net import CompositeClassNet - -from tenet.febTransduction.net import PropertyNet -from tenet.febTransduction.net import AtomPropertyNet -from tenet.febTransduction.net import CompositePropertyNet - -from tenet.febTransduction.net import IndividualNet - -from tenet.febTransduction.net import ValueNet - -from tenet.febTransduction.net import PhenomenaNet - -from tenet.febTransduction.net import RestrictionNet - - - -#============================================================================== -# Test Methods -#============================================================================== - -def test_base_attribute_access(net): - print(f'\n *** Base attributes ({net.type_id})) ***') - print(f' ----- uri: {net.uri}') - print(f' ----- node: {net.node}') - print(f' ----- base_node: {net.base_node}') - print(f' ----- structure: {net.structure}') - print(f' ----- naming: {net.naming}') - - -def test_class_attribute_access(net): - print(f'\n *** Class attributes ({net.type_id})) ***') - print(f' ----- class_name: {net.class_name}') - -def test_composite_class_attribute_access(net): - print(f'\n *** Composite Class attributes ({net.type_id})) ***') - print(f' ----- mother_class_net: {net.mother_class_net}') - print(f' ----- restriction: {net.restriction}') - print(f' ----- restriction01: {net.restriction01}') - -def test_property_attribute_access(net): - print(f'\n *** Property attributes ({net.type_id})) ***') - print(f' ----- property_name: {net.property_name}') - -def test_atom_property_attribute_access(net): - print(f'\n *** Atom Property attributes ({net.type_id})) ***') - print(f' ----- core_role: {net.core_role}') - print(f' ----- target_argument_node: {net.target_argument_node}') - print(f' ----- property_type: {net.property_type}') - print(f' ----- property_name01: {net.property_name01}') - print(f' ----- property_name10: {net.property_name10}') - print(f' ----- property_name12: {net.property_name12}') - -def test_composite_property_attribute_access(net): - print(f'\n *** Composite Property attributes ({net.type_id})) ***') - print(f' ----- core_role: {net.core_role}') - print(f' ----- target_argument_node: {net.target_argument_node}') - print(f' ----- property_type: {net.property_type}') - print(f' ----- restriction: {net.restriction}') - - -def test_restriction_attribute_access(net): - print(f'\n *** Restriction attributes ({net.type_id})) ***') - print(f' ----- target_node: {net.target_node}') - print(f' ----- restriction_property: {net.restriction_property}') - print(f' ----- restriction_net_value: {net.restriction_net_value}') - - -def test_individual_attribute_access(net): - print(f'\n *** Individual attributes ({net.type_id})) ***') - print(f' ----- base_class_name: {net.base_class_name}') - print(f' ----- mother_class_net: {net.mother_class_net}') - print(f' ----- individual_label: {net.individual_label}') - - -def test_value_attribute_access(net): - print(f'\n *** Value attributes ({net.type_id})) ***') - print(f' ----- value_label: {net.value_label}') - - -def test_phenomena_attribute_access(net): - print(f'\n *** Phenomena attributes ({net.type_id})) ***') - print(f' ----- phenomena_type: {net.phenomena_type}') - print(f' ----- phenomena_ref: {net.phenomena_ref}') - - -#============================================================================== -# Development Test -#============================================================================== - -print('\n' + ' *** Development Test ***') - -print(f'\n -- Test Graph Loading') -graph = Graph() -graph.bind('net', Namespace('https://tenet.tetras-libre.fr/semantic-net#')) -graph.parse(TEST_GRAPH) -print(f" ----- Graph Loaded ({len(graph)})") - -print('\n -- Net') -net = Net(graph, uri='net:atomClass_sun_s2') -test_base_attribute_access(net) - -print('\n -- Class Net') -net = ClassNet(graph, uri='net:atomClass_sun_s2') -test_base_attribute_access(net) -test_class_attribute_access(net) - -print('\n -- Atom Class Net') -net = AtomClassNet(graph, uri='net:atomClass_sun_s2') -test_base_attribute_access(net) -test_class_attribute_access(net) - -print('\n -- Composite Class Net (1)') -net = CompositeClassNet(graph, uri='net:compositeClass_orbit-hasManner-conjunction-OR_o2') -test_base_attribute_access(net) -test_class_attribute_access(net) -test_composite_class_attribute_access(net) - -print('\n -- Composite Class Net (2)') -net = CompositeClassNet(graph, uri='net:compositeClass_system-hasPart-sun-and-object_s') -test_base_attribute_access(net) -test_class_attribute_access(net) -test_composite_class_attribute_access(net) - -print('\n -- Property Net') -net = AtomPropertyNet(graph, uri='net:atomProperty_orbit_o2') -test_base_attribute_access(net) -test_property_attribute_access(net) - -print('\n -- Atom Property Net') -net = AtomPropertyNet(graph, uri='net:atomProperty_orbit_o2') -test_base_attribute_access(net) -test_property_attribute_access(net) -test_atom_property_attribute_access(net) - -print('\n -- Composite Property Net') -net = CompositePropertyNet(graph, uri='net:compositeProperty_not-direct_d2') -test_base_attribute_access(net) -test_property_attribute_access(net) -test_composite_property_attribute_access(net) - -print('\n -- Individual Net') -net = IndividualNet(graph, uri='net:individual_system_SolarSystem') -test_individual_attribute_access(net) - -print('\n -- Value Net') -net = ValueNet(graph, uri='net:value_SolarSystem_blankNode') -test_value_attribute_access(net) - -print('\n -- Phenomena Net (1)') -net = PhenomenaNet(graph, uri='net:phenomena_conjunction-AND_a') -test_phenomena_attribute_access(net) - -print('\n -- Phenomena Net (1)') -net = PhenomenaNet(graph, uri='net:phenomena_conjunction-OR_o3') -test_phenomena_attribute_access(net) - -print('\n -- Restriction Net') -net = RestrictionNet(graph, uri='net:restriction_hasPart_sun') -test_restriction_attribute_access(net) - -print('\n' + ' *** - ***') \ No newline at end of file