diff --git a/shacler.py b/shacler.py index 71a388e94d6114c31a91d76175f3c771fa49c393..55a67c86bbbb522899e9959ac22c3c265b2ed03d 100644 --- a/shacler.py +++ b/shacler.py @@ -412,8 +412,47 @@ def retrieveValuesetRestrictions(graph, class_element, exceptionsByClass, inters valueset = list(graph.objects(sub_rest, OWL.hasValue)) ex = dictRangeRestriction(props, class_element, valueset, subclassesNotAllowed, onlyDirectSubclassesAllowed, propPipeline=prop, RangeConsistsOfIndividuals=True) else: - valueset = list(graph.objects(sub_rest, OWL.someValuesFrom)) - ex = dictRangeRestriction(props, class_element, valueset, subclassesNotAllowed, onlyDirectSubclassesAllowed, propPipeline=prop, RangeConsistsOfIndividuals=False) + # Fourth level of owl:someValuesFrom + for sub_sub_rest in list(graph.objects(sub_rest, OWL.someValuesFrom)): + if (sub_sub_rest, RDF.type, OWL.Class) in graph: + for sub_restriction in graph.objects(sub_sub_rest, OWL.unionOf): + sub_collection = list(Collection(graph, sub_restriction)) + valueset = [] + for sub_node in sub_collection: + prop_pipeline = list(graph.objects(sub_node, OWL.onProperty)) + if bool(prop_pipeline): + if list(graph.objects(sub_node, OWL.hasValue)): + value = list(graph.objects(sub_node, OWL.hasValue)) + else: + value = list(graph.objects(sub_node, OWL.someValuesFrom)) + valueset.append(value[0]) + for pn in graph.objects(sub_node, OWL.onProperty): + pn = pn + else: + pn = "" + valueset.append(sub_node) + if bool(pn): + prop.append(pn) + ex = dictRangeRestriction(props, class_element, valueset, subclassesNotAllowed, onlyDirectSubclassesAllowed, propPipeline=prop, RangeConsistsOfIndividuals=True) + else: + ex = dictRangeRestriction(props, class_element, valueset, subclassesNotAllowed, onlyDirectSubclassesAllowed, propPipeline=prop) + + exceptionsByClass[str(class_element)].append(ex) + elif (sub_sub_rest, RDF.type, OWL.Restriction) in graph: + for p in graph.objects(sub_sub_rest, OWL.onProperty): + p = p + prop.append(p) + if list(graph.objects(sub_sub_rest, OWL.hasValue)): + valueset = list(graph.objects(sub_sub_rest, OWL.hasValue)) + ex = dictRangeRestriction(props, class_element, valueset, subclassesNotAllowed, onlyDirectSubclassesAllowed, propPipeline=prop, RangeConsistsOfIndividuals=True) + else: + valueset = list(graph.objects(sub_sub_rest, OWL.someValuesFrom)) + ex = dictRangeRestriction(props, class_element, valueset, subclassesNotAllowed, onlyDirectSubclassesAllowed, propPipeline=prop, RangeConsistsOfIndividuals=False) + exceptionsByClass[str(class_element)].append(ex) + else: + valueset = [sub_sub_rest] + ex = dictRangeRestriction(props, class_element, valueset, subclassesNotAllowed, onlyDirectSubclassesAllowed, propPipeline=prop, RangeConsistsOfIndividuals=False) + exceptionsByClass[str(class_element)].append(ex) exceptionsByClass[str(class_element)].append(ex) else: valueset = [sub_rest]