Skip to content
Snippets Groups Projects
Commit 9374e4f8 authored by Aurélien Lamercerie's avatar Aurélien Lamercerie
Browse files

Fix bug: Incorrect individual generation

parent 63033820
No related branches found
No related tags found
No related merge requests found
Showing
with 8136 additions and 2111 deletions
......@@ -38,6 +38,14 @@ def __search_pattern_2(graph):
return rule_pattern_set
def __search_pattern_3(graph):
select_data_list = ['?property_net']
clause_list = [(f'?property_net a net:Predefined_Property_Net.')]
query_code = generate_select_query(graph, select_data_list, clause_list)
rule_pattern_set = graph.query(query_code)
return rule_pattern_set
def __get_atom_property_net_list(graph):
# -- Atom Property List
......@@ -62,6 +70,18 @@ def __get_composite_property_net_list(graph):
return composite_property_net_list
def __get_predefined_property_net_list(graph):
# -- Atom Property List
predefined_property_net_list = []
predefined_property_set = __search_pattern_3(graph)
for selection in predefined_property_set:
property_net = net.PropertyNet(graph, uri=selection.property_net)
predefined_property_net_list.append(property_net)
return predefined_property_net_list
def __get_mother_property_net_list(atom_property_net_list, composite_property_net_list):
# -- URI List
......@@ -86,7 +106,7 @@ def __get_mother_property_net_list(atom_property_net_list, composite_property_ne
def __is_property_to_generate(property_net):
check_1 = property_net.is_deprecated()
if is_instance(property_net.mother_property_net, list):
if isinstance(property_net.mother_property_net, list):
check_2 = len(property_net.mother_property_net) > 0
else:
check_2 = False
......@@ -125,6 +145,9 @@ def __generate_owl_taxonomic_relation(graph, new_property_uri, net):
relation = produce_uriref(graph, 'rdfs:subPropertyOf')
predicat = None
if net.type_id == 'Property_Net':
predicat = produce_uriref(graph, 'base-out:Out_ObjectProperty')
if net.type_id == 'Atom_Property_Net':
predicat = produce_uriref(graph, 'base-out:Out_ObjectProperty')
......@@ -163,7 +186,7 @@ def __generate_owl_triple_definition(graph, net):
#==============================================================================
# Main Method: analyze_phenomena_or_1
# Main Method
#==============================================================================
def generate_owl_property(graph):
......@@ -175,11 +198,15 @@ def generate_owl_property(graph):
# -- Get property net listings
atom_property_net_list = __get_atom_property_net_list(graph)
composite_property_net_list = __get_composite_property_net_list(graph)
predefined_property_net_list = __get_predefined_property_net_list(graph)
mother_property_net_list = __get_mother_property_net_list(atom_property_net_list,
composite_property_net_list)
# -- Triple Definition for 'not deprecated property net'
for property_net in (atom_property_net_list + composite_property_net_list):
property_net_list = (atom_property_net_list +
composite_property_net_list +
predefined_property_net_list)
for property_net in property_net_list:
if not property_net.is_deprecated():
rule_triple_list += __generate_owl_triple_definition(graph, property_net)
......
......@@ -11,8 +11,17 @@ from rdflib import Graph
import transduction
from transduction import net
from transduction.query_builder import generate_select_query
from transduction.naming_computer import define_individual_naming, define_relation_naming
from transduction.query_builder import (
generate_select_query,
generate_ask_query
)
from transduction.naming_computer import (
define_individual_naming,
define_relation_naming
)
#==============================================================================
# Pattern Search:
......@@ -20,12 +29,12 @@ from transduction.naming_computer import define_individual_naming, define_relati
#==============================================================================
def __search_pattern(graph):
select_data_list = ['?subject_class_net', '?predicate_property_net', '?object_class_net']
select_data_list = ['?subject_class_net', '?predicate_property_net', '?object_net']
clause_list = [
'?subject_class_net a net:Composite_Class_Net.',
'?subject_class_net net:hasRestriction ?restriction_net.',
'?restriction_net a net:Restriction_Net.',
'?restriction_net net:hasRestrictionNetValue ?object_class_net.',
'?restriction_net net:hasRestrictionNetValue ?object_net.',
'?restriction_net net:hasRestrictionOnProperty ?predicate_property_net.'
]
query_code = generate_select_query(graph, select_data_list, clause_list)
......@@ -67,6 +76,37 @@ def __search_subclass_of_class_net(graph, class_net_uri):
return result_set
#==============================================================================
# Methods to ask about net (using SPARQL ASK query)
#==============================================================================
def is_class_net(graph, net_uri):
# SPARQL query construction
clause_list = ['?classUri a [rdfs:subClassOf* net:Class_Net].']
query_code = generate_ask_query(graph, clause_list)
# SPARQL query execution
result = graph.query(query_code, initBindings={'classUri': net_uri})
# Result (True or False)
return bool(result)
def is_individual_net(graph, net_uri):
# SPARQL query construction
clause_list = ['?classUri a [rdfs:subClassOf* net:Individual_Net].']
query_code = generate_ask_query(graph, clause_list)
# SPARQL query execution
result = graph.query(query_code, initBindings={'classUri': net_uri})
# Result (True or False)
return bool(result)
#==============================================================================
# Useful Computation Method(s)
#==============================================================================
......@@ -152,29 +192,51 @@ def __construct_relation_net(graph, subject_net, predicate_net, object_net):
#==============================================================================
# Main Method
# Processing Method for two specific cases
#==============================================================================
def deduce_individual_and_relation_from_restriction(graph):
def deduce_relation_for_object_individual(graph, pattern):
rule_triple_list = []
# -- Rule Initialization
rule_label = 'deduce individual and relation from restriction'
# Useful Nets
subject_class_net = net.ClassNet(graph, uri=pattern.subject_class_net)
predicate_property_net = net.PropertyNet(graph, uri=pattern.predicate_property_net)
object_individual_net = net.ClassNet(graph, uri=pattern.object_net)
# -- Search for patterns
_, pattern_set = __search_pattern(graph)
# -- Check for existing (subject) Individual
existing_subject_individuals = list(__search_individual_from_class(graph, pattern.subject_class_net))
# -- Selection Analyzing (1)
# If either a subject or an object individual exists, then proceed
if existing_subject_individuals:
# Handle subject individual
if existing_subject_individuals:
subject_individual_net = net.IndividualNet(graph, uri=existing_subject_individuals[0].individual_net)
else:
subject_individual_net, subject_individual_triple_list = __construct_individual_net(graph, subject_class_net)
rule_triple_list += subject_individual_triple_list
# Create the relation
new_relation_net, relation_triple_list = __construct_relation_net(
graph, subject_individual_net, predicate_property_net, object_individual_net)
rule_triple_list += relation_triple_list
return rule_triple_list
def deduce_relation_for_object_class(graph, pattern):
rule_triple_list = []
for pattern in pattern_set:
# Useful Nets
subject_class_net = net.ClassNet(graph, uri=pattern.subject_class_net)
predicate_property_net = net.PropertyNet(graph, uri=pattern.predicate_property_net)
object_class_net = net.ClassNet(graph, uri=pattern.object_class_net)
object_class_net = net.ClassNet(graph, uri=pattern.object_net)
# -- Check for existing (subject) Individual
existing_subject_individuals = list(__search_individual_from_class(graph, pattern.subject_class_net))
# -- Check for existing (object) Individual
existing_object_individuals = list(__search_individual_from_class(graph, pattern.object_class_net))
existing_object_individuals = list(__search_individual_from_class(graph, pattern.object_net))
# If either a subject or an object individual exists, then proceed
if existing_subject_individuals or existing_object_individuals:
......@@ -198,6 +260,31 @@ def deduce_individual_and_relation_from_restriction(graph):
graph, subject_individual_net, predicate_property_net, object_individual_net)
rule_triple_list += relation_triple_list
return rule_triple_list
#==============================================================================
# Main Method
#==============================================================================
def deduce_individual_and_relation_from_restriction(graph):
# -- Rule Initialization
rule_label = 'deduce individual and relation from restriction'
# -- Search for patterns
_, pattern_set = __search_pattern(graph)
# -- Selection Analyzing (1)
rule_triple_list = []
for pattern in pattern_set:
if is_individual_net(graph, pattern.object_net):
rule_triple_list += deduce_relation_for_object_individual(graph, pattern)
if is_class_net(graph, pattern.object_net):
rule_triple_list += deduce_relation_for_object_class(graph, pattern)
return rule_label, rule_triple_list
......
......@@ -14,12 +14,12 @@ from rdflib import Graph
import transduction
from transduction import net
from transduction.query_builder import generate_select_query
from transduction.naming_computer import define_axiom_naming
from transduction.naming_computer import define_composite_naming_2
from transduction.rdfterm_computer import produce_uriref, produce_literal
ENTITY_CLASS_TYPE = 'base-out:Entity'
FEATURE_CLASS_TYPE = 'base-out:Feature'
FEATURE_PROPERTY_URI = 'base-out:hasFeature'
FEATURE_PROPERTY_NET_URI = 'net:predefinedProperty_hasFeature'
#==============================================================================
......@@ -88,7 +88,7 @@ def __construct_feature_restriction_net(graph, individual_net):
restriction_net.compose(individual_net)
# -- Data Computation
restriction_net.restriction_property = FEATURE_PROPERTY_URI
restriction_net.restriction_property = produce_uriref(graph, FEATURE_PROPERTY_NET_URI)
restriction_net.restriction_net_value = individual_net.uri
# -- Relation Propagation: None
......
......@@ -336,6 +336,11 @@ net:Phenomena_Net rdf:type owl:Class ;
rdfs:subClassOf net:Net .
### https://tenet.tetras-libre.fr/semantic-net#Predefined_Property_Net
net:Predefined_Property_Net rdf:type owl:Class ;
rdfs:subClassOf net:Property_Net .
### https://tenet.tetras-libre.fr/semantic-net#Property_Axiom_Net
net:Property_Axiom_Net rdf:type owl:Class ;
rdfs:subClassOf net:Axiom_Net .
......@@ -383,4 +388,12 @@ net:inverse_direction rdf:type owl:NamedIndividual .
net:normal_direction rdf:type owl:NamedIndividual .
### https://tenet.tetras-libre.fr/semantic-net#predefinedProperty_hasFeature
net:predefinedProperty_hasFeature a net:Predefined_Property_Net ;
net:hasNaming "hasFeature" ;
net:hasPropertyName "hasFeature" ;
net:hasPropertyType owl:ObjectProperty ;
net:hasStructure "predefinedProperty" .
### Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi
......@@ -34,11 +34,10 @@ class AtomPropertyNet(PropertyNet):
self.type_uri = produce_uriref(self.support_graph, f'net:{self.type_id}')
# -- Net Attributes
self.attr_list += ['core_role', 'target_argument_node', 'property_type',
self.attr_list += ['core_role', 'target_argument_node',
'property_name01', 'property_name10', 'property_name12']
self._core_role = None
self._target_argument_node = []
self._property_type = None
#self._property_name = None
self._property_name01 = None
self._property_name10 = None
......@@ -72,17 +71,6 @@ class AtomPropertyNet(PropertyNet):
self._target_argument_node = self.set_attribute_value_list(new_value, produce_uriref)
@property
def property_type(self):
if self._property_type is None:
self._property_type = self.get_value_list_from_graph('_property_type')
return self._property_type
@property_type.setter
def property_type(self, new_value):
self._property_type = self.set_attribute_value_list(new_value, produce_uriref)
@property
def property_name01(self):
if self._property_name01 is None:
......
......@@ -34,9 +34,10 @@ class PropertyNet(Net):
self.type_uri = produce_uriref(self.support_graph, f'net:{self.type_id}')
# -- Net Attributes
self.attr_list += ['property_name', 'property_uri']
self.attr_list += ['property_name', 'property_uri', 'property_type']
self._property_name = None
self._property_uri = None
self._property_type = None
#--------------------------------------------------------------------------
......@@ -63,3 +64,13 @@ class PropertyNet(Net):
@property_uri.setter
def property_uri(self, new_value):
self._property_uri = self.set_attribute_value_list(new_value, produce_uriref)
@property
def property_type(self):
if self._property_type is None:
self._property_type = self.get_value_list_from_graph('_property_type')
return self._property_type
@property_type.setter
def property_type(self, new_value):
self._property_type = self.set_attribute_value_list(new_value, produce_uriref)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -88,7 +88,7 @@ def test_search_pattern_deducer(graph):
result_str = f'>>> '
result_str += f'{row.subject_class_net.n3(graph.namespace_manager)}'
result_str += f' {row.predicate_property_net.n3(graph.namespace_manager)}'
result_str += f' {row.object_class_net.n3(graph.namespace_manager)}'
result_str += f' {row.object_net.n3(graph.namespace_manager)}'
print(result_str)
return pattern_set
......@@ -126,8 +126,13 @@ if __name__ == '__main__':
print('\n \n')
print('\n *** Unit Test ***')
test_rule_application_deducer(TEST_FILE_NAME_1, graph_1, test_rule_1.deduce_individual_and_relation_from_restriction)
test_rule_application_deducer(TEST_FILE_NAME_1, graph_1, test_rule_1.deduce_individual_and_relation_from_restriction_Recursively)
# test_rule_application_deducer(
# TEST_FILE_NAME_1, graph_1, test_rule_1.deduce_individual_and_relation_from_restriction)
test_rule_application_deducer(
TEST_FILE_NAME_2, graph_2, test_rule_1.deduce_individual_and_relation_from_restriction)
test_rule_application_deducer(
TEST_FILE_NAME_3, graph_3, test_rule_1.deduce_individual_and_relation_from_restriction)
# test_rule_application_deducer(TEST_FILE_NAME_1, graph_1, test_rule_1.deduce_individual_and_relation_from_restriction_Recursively)
print('\n \n')
print('\n *** - ***')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment