From 6aef9dd00cd271ef27f061b019a47a3d154910e6 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 24 Jun 2022 12:06:56 +0100 Subject: [PATCH 01/15] =?UTF-8?q?Add=20=E2=80=9Cno=20cover=E2=80=9D=20prag?= =?UTF-8?q?mas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rdflib/extras/infixowl.py | 66 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/rdflib/extras/infixowl.py b/rdflib/extras/infixowl.py index 08a59943e..d0d14f23f 100644 --- a/rdflib/extras/infixowl.py +++ b/rdflib/extras/infixowl.py @@ -201,7 +201,7 @@ def __matmul__(self, other): return self.function(other) def __call__(self, value1, value2): - return self.function(value1, value2) + return self.function(value1, value2) # pragma: no cover nsBinds = { # noqa: N816 @@ -400,8 +400,8 @@ def __init__(self, identifier=None, graph=None): self.identifier ) self.qname = ":".join([prefix, localName]) - except: # noqa: E722 - pass + except: # noqa: E722 # pragma: no cover + pass # pragma: no cover def clearInDegree(self): # noqa: N802 self.graph.remove((None, None, self.identifier)) @@ -444,7 +444,7 @@ def _delete_type(self): >>> len(list(b.type)) 0 """ - pass + pass # pragma: no cover type = property(_get_type, _set_type, _delete_type) @@ -473,8 +473,8 @@ def _set_identifier(self, i): try: prefix, uri, localName = self.graph.compute_qname(i) # noqa: N806 self.qname = ":".join([prefix, localName]) - except: # noqa: E722 - pass + except: # noqa: E722 # pragma: no cover + pass # pragma: no cover identifier = property(_get_identifier, _set_identifier) @@ -494,7 +494,7 @@ def _set_sameAs(self, term): # noqa: N802 @TermDeletionHelper(OWL.sameAs) def _delete_sameAs(self): # noqa: N802 - pass + pass # pragma: no cover sameAs = property(_get_sameAs, _set_sameAs, _delete_sameAs) # noqa: N815 @@ -576,7 +576,7 @@ def _set_comment(self, comment): @TermDeletionHelper(RDFS.comment) def _del_comment(self): - pass + pass # pragma: no cover comment = property(_get_comment, _set_comment, _del_comment) @@ -594,7 +594,7 @@ def _set_seeAlso(self, seeAlsos): # noqa: N802, N803 @TermDeletionHelper(RDFS.seeAlso) def _del_seeAlso(self): # noqa: N802 - pass + pass # pragma: no cover seeAlso = property(_get_seeAlso, _set_seeAlso, _del_seeAlso) # noqa: N815 @@ -623,7 +623,7 @@ def _delete_label(self): >>> len(list(b.label)) 0 """ - pass + pass # pragma: no cover label = property(_get_label, _set_label, _delete_label) @@ -655,7 +655,7 @@ def _set_imports(self, other): @TermDeletionHelper(OWL["imports"]) def _del_imports(self): - pass + pass # pragma: no cover imports = property(_get_imports, _set_imports, _del_imports) @@ -750,8 +750,8 @@ def ComponentTerms(cls): # noqa: N802 yield _c else: yield innerCls - except: # noqa: E722 - pass + except: # noqa: E722 # pragma: no cover + pass # pragma: no cover else: cls = CastClass(cls, Individual.factoryGraph) if isinstance(cls, BooleanClass): @@ -998,7 +998,7 @@ def _set_extent(self, other): @TermDeletionHelper(RDF.type) def _del_type(self): - pass + pass # pragma: no cover extent = property(_get_extent, _set_extent, _del_type) @@ -1012,7 +1012,7 @@ def _get_extentQuery(self): # noqa: N802 return (Variable("CLASS"), RDF.type, self.identifier) def _set_extentQuery(self, other): # noqa: N802 - pass + pass # pragma: no cover extentQuery = property(_get_extentQuery, _set_extentQuery) # noqa: N815 @@ -1097,7 +1097,7 @@ def _set_subClassOf(self, other): # noqa: N802 @TermDeletionHelper(RDFS.subClassOf) def _del_subClassOf(self): # noqa: N802 - pass + pass # pragma: no cover subClassOf = property( # noqa: N815 _get_subClassOf, _set_subClassOf, _del_subClassOf @@ -1119,7 +1119,7 @@ def _set_equivalentClass(self, other): # noqa: N802 @TermDeletionHelper(OWL.equivalentClass) def _del_equivalentClass(self): # noqa: N802 - pass + pass # pragma: no cover equivalentClass = property( # noqa: N815 _get_equivalentClass, _set_equivalentClass, _del_equivalentClass @@ -1139,7 +1139,7 @@ def _set_disjointWith(self, other): # noqa: N802 @TermDeletionHelper(OWL.disjointWith) def _del_disjointWith(self): # noqa: N802 - pass + pass # pragma: no cover disjointWith = property( # noqa: N815 _get_disjointWith, _set_disjointWith, _del_disjointWith @@ -1163,7 +1163,7 @@ def _set_complementOf(self, other): # noqa: N802 @TermDeletionHelper(OWL.complementOf) def _del_complementOf(self): # noqa: N802 - pass + pass # pragma: no cover complementOf = property( # noqa: N815 _get_complementOf, _set_complementOf, _del_complementOf @@ -1524,14 +1524,14 @@ class BooleanClass(OWLRDFListProxy, Class): @BooleanClassExtentHelper(OWL.intersectionOf) @Callable def getIntersections(): # type: ignore[misc] # noqa: N802 - pass + pass # pragma: no cover getIntersections = Callable(getIntersections) # noqa: N815 @BooleanClassExtentHelper(OWL.unionOf) @Callable def getUnions(): # type: ignore[misc] # noqa: N802 - pass + pass # pragma: no cover getUnions = Callable(getUnions) # noqa: N815 @@ -1634,7 +1634,7 @@ def AllDifferent(members): # noqa: N802 DisjointClasses(' description description { description } ')' """ - pass + pass # pragma: no cover class Restriction(Class): @@ -1775,7 +1775,7 @@ def _set_onProperty(self, prop): # noqa: N802 @TermDeletionHelper(OWL.onProperty) def _del_onProperty(self): # noqa: N802 - pass + pass # pragma: no cover onProperty = property( # noqa: N815 _get_onProperty, _set_onProperty, _del_onProperty @@ -1799,7 +1799,7 @@ def _set_allValuesFrom(self, other): # noqa: N802 @TermDeletionHelper(OWL.allValuesFrom) def _del_allValuesFrom(self): # noqa: N802 - pass + pass # pragma: no cover allValuesFrom = property( # noqa: N815 _get_allValuesFrom, _set_allValuesFrom, _del_allValuesFrom @@ -1823,7 +1823,7 @@ def _set_someValuesFrom(self, other): # noqa: N802 @TermDeletionHelper(OWL.someValuesFrom) def _del_someValuesFrom(self): # noqa: N802 - pass + pass # pragma: no cover someValuesFrom = property( # noqa: N815 _get_someValuesFrom, _set_someValuesFrom, _del_someValuesFrom @@ -1845,7 +1845,7 @@ def _set_hasValue(self, other): # noqa: N802 @TermDeletionHelper(OWL.hasValue) def _del_hasValue(self): # noqa: N802 - pass + pass # pragma: no cover hasValue = property(_get_hasValue, _set_hasValue, _del_hasValue) # noqa: N815 @@ -1865,7 +1865,7 @@ def _set_cardinality(self, other): @TermDeletionHelper(OWL.cardinality) def _del_cardinality(self): - pass + pass # pragma: no cover cardinality = property(_get_cardinality, _set_cardinality, _del_cardinality) @@ -1887,7 +1887,7 @@ def _set_maxCardinality(self, other): # noqa: N802 @TermDeletionHelper(OWL.maxCardinality) def _del_maxCardinality(self): # noqa: N802 - pass + pass # pragma: no cover maxCardinality = property( # noqa: N815 _get_maxCardinality, _set_maxCardinality, _del_maxCardinality @@ -1911,7 +1911,7 @@ def _set_minCardinality(self, other): # noqa: N802 @TermDeletionHelper(OWL.minCardinality) def _del_minCardinality(self): # noqa: N802 - pass + pass # pragma: no cover minCardinality = property( # noqa: N815 _get_minCardinality, _set_minCardinality, _del_minCardinality @@ -2148,7 +2148,7 @@ def _set_subPropertyOf(self, other): # noqa: N802 @TermDeletionHelper(RDFS.subPropertyOf) def _del_subPropertyOf(self): # noqa: N802 - pass + pass # pragma: no cover subPropertyOf = property( # noqa: N815 _get_subPropertyOf, _set_subPropertyOf, _del_subPropertyOf @@ -2165,7 +2165,7 @@ def _set_inverseOf(self, other): # noqa: N802 @TermDeletionHelper(OWL.inverseOf) def _del_inverseOf(self): # noqa: N802 - pass + pass # pragma: no cover inverseOf = property(_get_inverseOf, _set_inverseOf, _del_inverseOf) # noqa: N815 @@ -2184,7 +2184,7 @@ def _set_domain(self, other): @TermDeletionHelper(RDFS.domain) def _del_domain(self): - pass + pass # pragma: no cover domain = property(_get_domain, _set_domain, _del_domain) @@ -2203,7 +2203,7 @@ def _set_range(self, ranges): @TermDeletionHelper(RDFS.range) def _del_range(self): - pass + pass # pragma: no cover range = property(_get_range, _set_range, _del_range) From 9b53dc1b17a57cb291e9a21a78457cfe409155a2 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 24 Jun 2022 13:08:42 +0100 Subject: [PATCH 02/15] Addressing of non-API flake8 issues of function and variable naming. --- rdflib/extras/infixowl.py | 494 +++++++++++++++++++------------------- 1 file changed, 242 insertions(+), 252 deletions(-) diff --git a/rdflib/extras/infixowl.py b/rdflib/extras/infixowl.py index d0d14f23f..ae4335a97 100644 --- a/rdflib/extras/infixowl.py +++ b/rdflib/extras/infixowl.py @@ -257,34 +257,34 @@ def manchesterSyntax( # noqa: N802 liveChildren = iter(thing) # noqa: N806 children = [manchesterSyntax(child, store) for child in thing] else: - liveChildren = iter(Collection(store, thing)) # noqa: N806 + livechildren = iter(Collection(store, thing)) children = [ manchesterSyntax(child, store) for child in Collection(store, thing) ] if boolean == OWL.intersectionOf: - childList = [] # noqa: N806 + childlist = [] named = [] - for child in liveChildren: + for child in livechildren: if isinstance(child, URIRef): named.append(child) else: - childList.append(child) + childlist.append(child) if named: def castToQName(x): # noqa: N802 - prefix, uri, localName = store.compute_qname(x) # noqa: N806 - return ":".join([prefix, localName]) + prefix, uri, localname = store.compute_qname(x) + return ":".join([prefix, localname]) if len(named) > 1: prefix = "( " + " AND ".join(map(castToQName, named)) + " )" else: prefix = manchesterSyntax(named[0], store) - if childList: + if childlist: return ( str(prefix) + " THAT " + " AND ".join( - [str(manchesterSyntax(x, store)) for x in childList] + [str(manchesterSyntax(x, store)) for x in childlist] ) ) else: @@ -299,28 +299,24 @@ def castToQName(x): # noqa: N802 assert boolean == OWL.complementOf elif OWL.Restriction in store.objects(subject=thing, predicate=RDF.type): prop = list(store.objects(subject=thing, predicate=OWL.onProperty))[0] - prefix, uri, localName = store.compute_qname(prop) # noqa: N806 - propString = ":".join([prefix, localName]) # noqa: N806 + prefix, uri, localname = store.compute_qname(prop) + propstring = ":".join([prefix, localname]) label = first(store.objects(subject=prop, predicate=RDFS.label)) if label: - propString = "'%s'" % label # noqa: N806 - for onlyClass in store.objects( # noqa: N806 - subject=thing, predicate=OWL.allValuesFrom - ): - return "( %s ONLY %s )" % (propString, manchesterSyntax(onlyClass, store)) + propstring = "'%s'" % label + for onlyclass in store.objects(subject=thing, predicate=OWL.allValuesFrom): + return "( %s ONLY %s )" % (propstring, manchesterSyntax(onlyclass, store)) for val in store.objects(subject=thing, predicate=OWL.hasValue): - return "( %s VALUE %s )" % (propString, manchesterSyntax(val, store)) - for someClass in store.objects( # noqa: N806 - subject=thing, predicate=OWL.someValuesFrom - ): - return "( %s SOME %s )" % (propString, manchesterSyntax(someClass, store)) - cardLookup = { # noqa: N806 + return "( %s VALUE %s )" % (propstring, manchesterSyntax(val, store)) + for someclass in store.objects(subject=thing, predicate=OWL.someValuesFrom): + return "( %s SOME %s )" % (propstring, manchesterSyntax(someclass, store)) + cardlookup = { OWL.maxCardinality: "MAX", OWL.minCardinality: "MIN", OWL.cardinality: "EQUALS", } - for s, p, o in store.triples_choices((thing, list(cardLookup.keys()), None)): - return "( %s %s %s )" % (propString, cardLookup[p], o) + for s, p, o in store.triples_choices((thing, list(cardlookup.keys()), None)): + return "( %s %s %s )" % (propstring, cardlookup[p], o) compl = list(store.objects(subject=thing, predicate=OWL.complementOf)) if compl: return "( NOT %s )" % (manchesterSyntax(compl[0], store)) @@ -332,14 +328,12 @@ def castToQName(x): # noqa: N802 + "?bool rdf:first ?foo }" ) initb = {Variable("?class"): thing} - for boolProp, col in store.query( # noqa: N806 - qstr, processor="sparql", initBindings=initb - ): + for boolprop, col in store.query(qstr, processor="sparql", initBindings=initb): if not isinstance(thing, URIRef): - return manchesterSyntax(col, store, boolean=boolProp) + return manchesterSyntax(col, store, boolean=boolprop) try: - prefix, uri, localName = store.compute_qname(thing) # noqa: N806 - qname = ":".join([prefix, localName]) + prefix, uri, localname = store.compute_qname(thing) + qname = ":".join([prefix, localname]) except Exception: if isinstance(thing, BNode): return thing.n3() @@ -396,10 +390,8 @@ def __init__(self, identifier=None, graph=None): self.qname = None if not isinstance(self.identifier, BNode): try: - prefix, uri, localName = self.graph.compute_qname( # noqa: N806 - self.identifier - ) - self.qname = ":".join([prefix, localName]) + prefix, uri, localname = self.graph.compute_qname(self.identifier) + self.qname = ":".join([prefix, localname]) except: # noqa: E722 # pragma: no cover pass # pragma: no cover @@ -454,25 +446,25 @@ def _get_identifier(self): def _set_identifier(self, i): assert i if i != self.__identifier: - oldStmtsOut = [ # noqa: N806 + oldstatements_out = [ (p, o) for s, p, o in self.graph.triples((self.__identifier, None, None)) ] - oldStmtsIn = [ # noqa: N806 + oldstatements_in = [ (s, p) for s, p, o in self.graph.triples((None, None, self.__identifier)) ] - for p1, o1 in oldStmtsOut: + for p1, o1 in oldstatements_out: self.graph.remove((self.__identifier, p1, o1)) - for s1, p1 in oldStmtsIn: + for s1, p1 in oldstatements_in: self.graph.remove((s1, p1, self.__identifier)) self.__identifier = i - self.graph.addN([(i, p1, o1, self.graph) for p1, o1 in oldStmtsOut]) - self.graph.addN([(s1, p1, i, self.graph) for s1, p1 in oldStmtsIn]) + self.graph.addN([(i, p1, o1, self.graph) for p1, o1 in oldstatements_out]) + self.graph.addN([(s1, p1, i, self.graph) for s1, p1 in oldstatements_in]) if not isinstance(i, BNode): try: - prefix, uri, localName = self.graph.compute_qname(i) # noqa: N806 - self.qname = ":".join([prefix, localName]) + prefix, uri, localname = self.graph.compute_qname(i) + self.qname = ":".join([prefix, localname]) except: # noqa: E722 # pragma: no cover pass # pragma: no cover @@ -517,7 +509,7 @@ def __init__( super(AnnotatableTerms, self).__init__(identifier, graph) if nameAnnotation: self.setupACEAnnotations() - self.PN_sgProp.extent = [ + self.PN_sgprop.extent = [ (self.identifier, self.handleAnnotation(nameAnnotation)) ] if nameIsLabel: @@ -530,32 +522,32 @@ def setupACEAnnotations(self): # noqa: N802 self.graph.bind("ace", ACE_NS, override=False) # PN_sg singular form of a proper name () - self.PN_sgProp = Property( + self.PN_sgprop = Property( ACE_NS.PN_sg, baseType=OWL.AnnotationProperty, graph=self.graph ) # CN_sg singular form of a common noun - self.CN_sgProp = Property( + self.CN_sgprop = Property( ACE_NS.CN_sg, baseType=OWL.AnnotationProperty, graph=self.graph ) # CN_pl plural form of a common noun - self.CN_plProp = Property( + self.CN_plprop = Property( ACE_NS.CN_pl, baseType=OWL.AnnotationProperty, graph=self.graph ) # singular form of a transitive verb - self.TV_sgProp = Property( + self.tv_sgprop = Property( ACE_NS.TV_sg, baseType=OWL.AnnotationProperty, graph=self.graph ) # plural form of a transitive verb - self.TV_plProp = Property( + self.tv_plprop = Property( ACE_NS.TV_pl, baseType=OWL.AnnotationProperty, graph=self.graph ) # past participle form a transitive verb - self.TV_vbgProp = Property( + self.tv_vbgprop = Property( ACE_NS.TV_vbg, baseType=OWL.AnnotationProperty, graph=self.graph ) @@ -580,23 +572,23 @@ def _del_comment(self): comment = property(_get_comment, _set_comment, _del_comment) - def _get_seeAlso(self): # noqa: N802 - for sA in self.graph.objects( # noqa: N806 + def _get_seealso(self): + for seealso in self.graph.objects( subject=self.identifier, predicate=RDFS.seeAlso ): - yield sA + yield seealso - def _set_seeAlso(self, seeAlsos): # noqa: N802, N803 - if not seeAlsos: + def _set_seealso(self, seealsos): + if not seealsos: return - for s in seeAlsos: + for s in seealsos: self.graph.add((self.identifier, RDFS.seeAlso, s)) @TermDeletionHelper(RDFS.seeAlso) - def _del_seeAlso(self): # noqa: N802 + def _del_seealso(self): pass # pragma: no cover - seeAlso = property(_get_seeAlso, _set_seeAlso, _del_seeAlso) # noqa: N815 + seeAlso = property(_get_seealso, _set_seealso, _del_seealso) # noqa: N815 def _get_label(self): for label in self.graph.objects(subject=self.identifier, predicate=RDFS.label): @@ -661,15 +653,15 @@ def _del_imports(self): def AllClasses(graph): # noqa: N802 - prevClasses = set() # noqa: N806 + prevclasses = set() for c in graph.subjects(predicate=RDF.type, object=OWL.Class): - if c not in prevClasses: - prevClasses.add(c) + if c not in prevclasses: + prevclasses.add(c) yield Class(c) def AllProperties(graph): # noqa: N802 - prevProps = set() # noqa: N806 + prevprops = set() for s, p, o in graph.triples_choices( ( None, @@ -694,8 +686,8 @@ def AllProperties(graph): # noqa: N802 bType = OWL.ObjectProperty # noqa: N806 else: bType = OWL.DatatypeProperty # noqa: N806 - if s not in prevProps: - prevProps.add(s) + if s not in prevprops: + prevprops.add(s) yield Property(s, graph=graph, baseType=bType) @@ -741,15 +733,15 @@ def ComponentTerms(cls): # noqa: N802 if OWL.Restriction in cls.type: try: cls = CastClass(cls, Individual.factoryGraph) - for s, p, innerClsId in cls.factoryGraph.triples_choices( # noqa: N806 + for s, p, inner_class_id in cls.factoryGraph.triples_choices( (cls.identifier, [OWL.allValuesFrom, OWL.someValuesFrom], None) ): - innerCls = Class(innerClsId, skipOWLClassMembership=True) # noqa: N806 - if isinstance(innerClsId, BNode): - for _c in ComponentTerms(innerCls): + inner_class = Class(inner_class_id, skipOWLClassMembership=True) + if isinstance(inner_class_id, BNode): + for _c in ComponentTerms(inner_class): yield _c else: - yield innerCls + yield inner_class except: # noqa: E722 # pragma: no cover pass # pragma: no cover else: @@ -763,12 +755,12 @@ def ComponentTerms(cls): # noqa: N802 else: yield _cls else: - for innerCls in cls.subClassOf: # noqa: N806 - if isinstance(innerCls.identifier, BNode): - for _c in ComponentTerms(innerCls): + for inner_class in cls.subClassOf: + if isinstance(inner_class.identifier, BNode): + for _c in ComponentTerms(inner_class): yield _c else: - yield innerCls + yield inner_class for s, p, o in cls.factoryGraph.triples_choices( (classOrIdentifier(cls), CLASS_RELATIONS, None) ): @@ -776,10 +768,10 @@ def ComponentTerms(cls): # noqa: N802 for _c in ComponentTerms(CastClass(o, Individual.factoryGraph)): yield _c else: - yield innerCls + yield inner_class -def DeepClassClear(classToPrune): # noqa: N802, N803 +def DeepClassClear(class_to_prune): # noqa: N802 """ Recursively clear the given class, continuing where any related class is an anonymous class @@ -829,23 +821,23 @@ def deepClearIfBNode(_class): # noqa: N802 if isinstance(classOrIdentifier(_class), BNode): DeepClassClear(_class) - classToPrune = CastClass(classToPrune, Individual.factoryGraph) # noqa: N806 - for c in classToPrune.subClassOf: + class_to_prune = CastClass(class_to_prune, Individual.factoryGraph) + for c in class_to_prune.subClassOf: deepClearIfBNode(c) - classToPrune.graph.remove((classToPrune.identifier, RDFS.subClassOf, None)) - for c in classToPrune.equivalentClass: + class_to_prune.graph.remove((class_to_prune.identifier, RDFS.subClassOf, None)) + for c in class_to_prune.equivalentClass: deepClearIfBNode(c) - classToPrune.graph.remove((classToPrune.identifier, OWL.equivalentClass, None)) - inverseClass = classToPrune.complementOf # noqa: N806 - if inverseClass: - classToPrune.graph.remove((classToPrune.identifier, OWL.complementOf, None)) - deepClearIfBNode(inverseClass) - if isinstance(classToPrune, BooleanClass): - for c in classToPrune: + class_to_prune.graph.remove((class_to_prune.identifier, OWL.equivalentClass, None)) + inverse_class = class_to_prune.complementOf + if inverse_class: + class_to_prune.graph.remove((class_to_prune.identifier, OWL.complementOf, None)) + deepClearIfBNode(inverse_class) + if isinstance(class_to_prune, BooleanClass): + for c in class_to_prune: deepClearIfBNode(c) - classToPrune.clear() - classToPrune.graph.remove( - (classToPrune.identifier, classToPrune._operator, None) + class_to_prune.clear() + class_to_prune.graph.remove( + (class_to_prune.identifier, class_to_prune._operator, None) ) @@ -861,20 +853,20 @@ def CastClass(c, graph=None): # noqa: N802 graph = graph is None and c.factoryGraph or graph for kind in graph.objects(subject=classOrIdentifier(c), predicate=RDF.type): if kind == OWL.Restriction: - kwArgs = {"identifier": classOrIdentifier(c), "graph": graph} # noqa: N806 + kwargs = {"identifier": classOrIdentifier(c), "graph": graph} for s, p, o in graph.triples((classOrIdentifier(c), None, None)): if p != RDF.type: if p == OWL.onProperty: - kwArgs["onProperty"] = o + kwargs["onProperty"] = o else: if p not in Restriction.restrictionKinds: continue - kwArgs[str(p.split(str(OWL))[-1])] = o + kwargs[str(p.split(str(OWL))[-1])] = o if not set( [str(i.split(str(OWL))[-1]) for i in Restriction.restrictionKinds] - ).intersection(kwArgs): + ).intersection(kwargs): raise MalformedClass("Malformed owl:Restriction") - return Restriction(**kwArgs) + return Restriction(**kwargs) else: for s, p, o in graph.triples_choices( ( @@ -936,20 +928,20 @@ def serialize(self, graph): graph.add(fact) self._serialize(graph) - def setupNounAnnotations(self, nounAnnotations): # noqa: N802, N803 - if isinstance(nounAnnotations, tuple): - CN_sgProp, CN_plProp = nounAnnotations # noqa: N806 + def setupNounAnnotations(self, noun_annotations): # noqa: N802 + if isinstance(noun_annotations, tuple): + cn_sgprop, cn_plprop = noun_annotations else: - CN_sgProp = nounAnnotations # noqa: N806 - CN_plProp = nounAnnotations # noqa: N806 + cn_sgprop = noun_annotations + cn_plprop = noun_annotations - if CN_sgProp: - self.CN_sgProp.extent = [ - (self.identifier, self.handleAnnotation(CN_sgProp)) + if cn_sgprop: + self.CN_sgprop.extent = [ + (self.identifier, self.handleAnnotation(cn_sgprop)) ] - if CN_plProp: - self.CN_plProp.extent = [ - (self.identifier, self.handleAnnotation(CN_plProp)) + if cn_plprop: + self.CN_plprop.extent = [ + (self.identifier, self.handleAnnotation(cn_plprop)) ] def __init__( @@ -1003,18 +995,18 @@ def _del_type(self): extent = property(_get_extent, _set_extent, _del_type) def _get_annotation(self, term=RDFS.label): - for annotation in self.graph.objects(subject=self, predicate=term): + for annotation in self.graph.objects(subject=self.identifier, predicate=term): yield annotation annotation = property(_get_annotation, lambda x: x) # type: ignore[arg-type,misc] - def _get_extentQuery(self): # noqa: N802 + def _get_extentquery(self): return (Variable("CLASS"), RDF.type, self.identifier) - def _set_extentQuery(self, other): # noqa: N802 + def _set_extentquery(self, other): pass # pragma: no cover - extentQuery = property(_get_extentQuery, _set_extentQuery) # noqa: N815 + extentQuery = property(_get_extentquery, _set_extentquery) # noqa: N815 def __hash__(self): """ @@ -1083,33 +1075,33 @@ def __and__(self, other): operator=OWL.intersectionOf, members=[self, other], graph=self.graph ) - def _get_subClassOf(self): # noqa: N802 + def _get_subclassof(self): for anc in self.graph.objects( subject=self.identifier, predicate=RDFS.subClassOf ): yield Class(anc, graph=self.graph, skipOWLClassMembership=True) - def _set_subClassOf(self, other): # noqa: N802 + def _set_subclassof(self, other): if not other: return for sc in other: self.graph.add((self.identifier, RDFS.subClassOf, classOrIdentifier(sc))) @TermDeletionHelper(RDFS.subClassOf) - def _del_subClassOf(self): # noqa: N802 + def _del_subclassof(self): pass # pragma: no cover subClassOf = property( # noqa: N815 - _get_subClassOf, _set_subClassOf, _del_subClassOf + _get_subclassof, _set_subclassof, _del_subclassof ) - def _get_equivalentClass(self): # noqa: N802 + def _get_equivalentclass(self): for ec in self.graph.objects( subject=self.identifier, predicate=OWL.equivalentClass ): yield Class(ec, graph=self.graph) - def _set_equivalentClass(self, other): # noqa: N802 + def _set_equivalentclass(self, other): if not other: return for sc in other: @@ -1118,34 +1110,34 @@ def _set_equivalentClass(self, other): # noqa: N802 ) @TermDeletionHelper(OWL.equivalentClass) - def _del_equivalentClass(self): # noqa: N802 + def _del_equivalentclass(self): pass # pragma: no cover equivalentClass = property( # noqa: N815 - _get_equivalentClass, _set_equivalentClass, _del_equivalentClass + _get_equivalentclass, _set_equivalentclass, _del_equivalentclass ) - def _get_disjointWith(self): # noqa: N802 + def _get_disjointwith(self): for dc in self.graph.objects( subject=self.identifier, predicate=OWL.disjointWith ): yield Class(dc, graph=self.graph) - def _set_disjointWith(self, other): # noqa: N802 + def _set_disjointwith(self, other): if not other: return for c in other: self.graph.add((self.identifier, OWL.disjointWith, classOrIdentifier(c))) @TermDeletionHelper(OWL.disjointWith) - def _del_disjointWith(self): # noqa: N802 + def _del_disjointwith(self): pass # pragma: no cover disjointWith = property( # noqa: N815 - _get_disjointWith, _set_disjointWith, _del_disjointWith + _get_disjointwith, _set_disjointwith, _del_disjointwith ) - def _get_complementOf(self): # noqa: N802 + def _get_complementof(self): comp = list( self.graph.objects(subject=self.identifier, predicate=OWL.complementOf) ) @@ -1156,17 +1148,17 @@ def _get_complementOf(self): # noqa: N802 else: raise Exception(len(comp)) - def _set_complementOf(self, other): # noqa: N802 + def _set_complementof(self, other): if not other: return self.graph.add((self.identifier, OWL.complementOf, classOrIdentifier(other))) @TermDeletionHelper(OWL.complementOf) - def _del_complementOf(self): # noqa: N802 + def _del_complementof(self): pass # pragma: no cover complementOf = property( # noqa: N815 - _get_complementOf, _set_complementOf, _del_complementOf + _get_complementof, _set_complementof, _del_complementof ) def _get_parents(self): @@ -1203,22 +1195,18 @@ def _get_parents(self): link = first(self.factoryGraph.subjects(RDF.first, self.identifier)) if link: - listSiblings = list( # noqa: N806 - self.factoryGraph.transitive_subjects(RDF.rest, link) - ) - if listSiblings: - collectionHead = listSiblings[-1] # noqa: N806 + siblingslist = list(self.factoryGraph.transitive_subjects(RDF.rest, link)) + if siblingslist: + collectionhead = siblingslist[-1] else: - collectionHead = link # noqa: N806 - for disjCls in self.factoryGraph.subjects( # noqa: N806 - OWL.unionOf, collectionHead + collectionhead = link + for disjointclass in self.factoryGraph.subjects( + OWL.unionOf, collectionhead ): - if isinstance(disjCls, URIRef): - yield Class(disjCls, skipOWLClassMembership=True) - for rdfList in self.factoryGraph.objects( # noqa: N806 - self.identifier, OWL.intersectionOf - ): - for member in OWLRDFListProxy([rdfList], graph=self.factoryGraph): + if isinstance(disjointclass, URIRef): + yield Class(disjointclass, skipOWLClassMembership=True) + for rdf_list in self.factoryGraph.objects(self.identifier, OWL.intersectionOf): + for member in OWLRDFListProxy([rdf_list], graph=self.factoryGraph): if isinstance(member, URIRef): yield Class(member, skipOWLClassMembership=True) @@ -1229,10 +1217,10 @@ def isPrimitive(self): # noqa: N802 return False # sc = list(self.subClassOf) ec = list(self.equivalentClass) - for boolClass, p, rdfList in self.graph.triples_choices( # noqa: N806 + for boolclass, p, rdf_list in self.graph.triples_choices( (self.identifier, [OWL.intersectionOf, OWL.unionOf], None) ): - ec.append(manchesterSyntax(rdfList, self.graph, boolean=p)) + ec.append(manchesterSyntax(rdf_list, self.graph, boolean=p)) for e in ec: return False if self.complementOf: @@ -1255,50 +1243,50 @@ def __repr__(self, full=False, normalization=True): exprs = [] sc = list(self.subClassOf) ec = list(self.equivalentClass) - for boolClass, p, rdfList in self.graph.triples_choices( # noqa: N806 + for boolclass, p, rdf_list in self.graph.triples_choices( (self.identifier, [OWL.intersectionOf, OWL.unionOf], None) ): - ec.append(manchesterSyntax(rdfList, self.graph, boolean=p)) + ec.append(manchesterSyntax(rdf_list, self.graph, boolean=p)) dc = list(self.disjointWith) c = self.complementOf if c: dc.append(c) - klassKind = "" # noqa: N806 + klasskind = "" label = list(self.graph.objects(self.identifier, RDFS.label)) label = label and "(" + label[0] + ")" or "" if sc: if full: - scJoin = "\n " # noqa: N806 + scjoin = "\n " else: - scJoin = ", " # noqa: N806 - necStatements = [ # noqa: N806 + scjoin = ", " + nec_statements = [ isinstance(s, Class) and isinstance(self.identifier, BNode) and repr(CastClass(s, self.graph)) - or + or # noqa: W504 # repr(BooleanClass(classOrIdentifier(s), # operator=None, # graph=self.graph)) or manchesterSyntax(classOrIdentifier(s), self.graph) for s in sc ] - if necStatements: - klassKind = "Primitive Type %s" % label # noqa: N806 + if nec_statements: + klasskind = "Primitive Type %s" % label exprs.append( - "SubClassOf: %s" % scJoin.join([str(n) for n in necStatements]) + "SubClassOf: %s" % scjoin.join([str(n) for n in nec_statements]) ) if full: exprs[-1] = "\n " + exprs[-1] if ec: - nec_SuffStatements = [ # noqa: N806 + nec_suff_statements = [ isinstance(s, str) and s or manchesterSyntax(classOrIdentifier(s), self.graph) for s in ec ] - if nec_SuffStatements: - klassKind = "A Defined Class %s" % label # noqa: N806 - exprs.append("EquivalentTo: %s" % ", ".join(nec_SuffStatements)) + if nec_suff_statements: + klasskind = "A Defined Class %s" % label + exprs.append("EquivalentTo: %s" % ", ".join(nec_suff_statements)) if full: exprs[-1] = "\n " + exprs[-1] if dc: @@ -1312,15 +1300,15 @@ def __repr__(self, full=False, normalization=True): exprs[-1] = "\n " + exprs[-1] descr = list(self.graph.objects(self.identifier, RDFS.comment)) if full and normalization: - klassDescr = ( # noqa: N806 - klassKind - and "\n ## %s ##" % klassKind + klassdescr = ( + klasskind + and "\n ## %s ##" % klasskind + (descr and "\n %s" % descr[0] or "") + " . ".join(exprs) or " . ".join(exprs) ) else: - klassDescr = ( # noqa: N806 + klassdescr = ( full and (descr and "\n %s" % descr[0] or "") or "" + " . ".join(exprs) @@ -1329,16 +1317,16 @@ def __repr__(self, full=False, normalization=True): isinstance(self.identifier, BNode) and "Some Class " or "Class: %s " % self.qname - ) + klassDescr + ) + klassdescr class OWLRDFListProxy(object): - def __init__(self, rdfList, members=None, graph=None): # noqa: N803 + def __init__(self, rdf_list, members=None, graph=None): if graph: self.graph = graph members = [] if members is None else members - if rdfList: - self._rdfList = Collection(self.graph, rdfList[0]) + if rdf_list: + self._rdfList = Collection(self.graph, rdf_list[0]) for member in members: if member not in self._rdfList: self._rdfList.append(classOrIdentifier(member)) @@ -1461,12 +1449,12 @@ def __repr__(self): return manchesterSyntax(self._rdfList.uri, self.graph, boolean=self._operator) def serialize(self, graph): - clonedList = Collection(graph, BNode()) # noqa: N806 + clonedlist = Collection(graph, BNode()) for cl in self._rdfList: - clonedList.append(cl) + clonedlist.append(cl) CastClass(cl, self.graph).serialize(graph) - graph.add((self.identifier, self._operator, clonedList.uri)) + graph.add((self.identifier, self._operator, clonedlist.uri)) for s, p, o in self.graph.triples((self.identifier, None, None)): if p != self._operator: graph.add((s, p, o)) @@ -1549,32 +1537,30 @@ def __init__( Class.__init__(self, identifier, graph=graph) assert operator in [OWL.intersectionOf, OWL.unionOf], str(operator) self._operator = operator - rdfList = list( # noqa: N806 - self.graph.objects(predicate=operator, subject=self.identifier) - ) + rdf_list = list(self.graph.objects(predicate=operator, subject=self.identifier)) assert ( - not members or not rdfList + not members or not rdf_list ), "This is a previous boolean class description!" + repr( - Collection(self.graph, rdfList[0]).n3() + Collection(self.graph, rdf_list[0]).n3() ) - OWLRDFListProxy.__init__(self, rdfList, members) + OWLRDFListProxy.__init__(self, rdf_list, members) def copy(self): """ Create a copy of this class """ - copyOfClass = BooleanClass( # noqa: N806 + copy_of_class = BooleanClass( operator=self._operator, members=list(self), graph=self.graph ) - return copyOfClass + return copy_of_class def serialize(self, graph): - clonedList = Collection(graph, BNode()) # noqa: N806 + clonedlist = Collection(graph, BNode()) for cl in self._rdfList: - clonedList.append(cl) + clonedlist.append(cl) CastClass(cl, self.graph).serialize(graph) - graph.add((self.identifier, self._operator, clonedList.uri)) + graph.add((self.identifier, self._operator, clonedlist.uri)) for s, p, o in self.graph.triples((self.identifier, None, None)): if p != self._operator: @@ -1680,7 +1666,7 @@ def __init__( (self.identifier, OWL.onProperty, propertyOrIdentifier(onProperty)) ) self.onProperty = onProperty - restrTypes = [ # noqa: N806 + restr_types = [ (allValuesFrom, OWL.allValuesFrom), (someValuesFrom, OWL.someValuesFrom), (value, OWL.hasValue), @@ -1688,22 +1674,24 @@ def __init__( (maxCardinality, OWL.maxCardinality), (minCardinality, OWL.minCardinality), ] - validRestrProps = [ # noqa: N806 - (i, oTerm) for (i, oTerm) in restrTypes if i is not None # noqa: N806 - ] - assert len(validRestrProps) - restrictionRange, restrictionType = validRestrProps.pop() # noqa: N806 - self.restrictionType = restrictionType - if isinstance(restrictionRange, Identifier): - self.restrictionRange = restrictionRange - elif isinstance(restrictionRange, Class): - self.restrictionRange = classOrIdentifier(restrictionRange) + valid_restr_props = [(i, oterm) for (i, oterm) in restr_types if i is not None] + assert len(valid_restr_props) + restriction_range, restriction_type = valid_restr_props.pop() + self.restrictionType = restriction_type + if isinstance(restriction_range, Identifier): + self.restrictionRange = restriction_range + elif isinstance(restriction_range, Class): + self.restrictionRange = classOrIdentifier(restriction_range) else: self.restrictionRange = first( - self.graph.objects(self.identifier, restrictionType) + self.graph.objects(self.identifier, restriction_type) ) - if (self.identifier, restrictionType, self.restrictionRange) not in self.graph: - self.graph.add((self.identifier, restrictionType, self.restrictionRange)) + if ( + self.identifier, + restriction_type, + self.restrictionRange, + ) not in self.graph: + self.graph.add((self.identifier, restriction_type, self.restrictionRange)) assert self.restrictionRange is not None, Class(self.identifier) if (self.identifier, RDF.type, OWL.Restriction) not in self.graph: self.graph.add((self.identifier, RDF.type, OWL.Restriction)) @@ -1754,17 +1742,17 @@ def __eq__(self, other): if isinstance(other, Restriction): return ( other.onProperty == self.onProperty - and other.restrictionRange == self.restrictionRange + and other.restriction_range == self.restrictionRange ) else: return False - def _get_onProperty(self): # noqa: N802 + def _get_onproperty(self): return list( self.graph.objects(subject=self.identifier, predicate=OWL.onProperty) )[0] - def _set_onProperty(self, prop): # noqa: N802 + def _set_onproperty(self, prop): triple = (self.identifier, OWL.onProperty, propertyOrIdentifier(prop)) if not prop: return @@ -1774,21 +1762,21 @@ def _set_onProperty(self, prop): # noqa: N802 self.graph.set(triple) @TermDeletionHelper(OWL.onProperty) - def _del_onProperty(self): # noqa: N802 + def _del_onproperty(self): pass # pragma: no cover onProperty = property( # noqa: N815 - _get_onProperty, _set_onProperty, _del_onProperty + _get_onproperty, _set_onproperty, _del_onproperty ) - def _get_allValuesFrom(self): # noqa: N802 + def _get_allvaluesfrom(self): for i in self.graph.objects( subject=self.identifier, predicate=OWL.allValuesFrom ): return Class(i, graph=self.graph) return None - def _set_allValuesFrom(self, other): # noqa: N802 + def _set_allvaluesfrom(self, other): triple = (self.identifier, OWL.allValuesFrom, classOrIdentifier(other)) if not other: return @@ -1798,21 +1786,21 @@ def _set_allValuesFrom(self, other): # noqa: N802 self.graph.set(triple) @TermDeletionHelper(OWL.allValuesFrom) - def _del_allValuesFrom(self): # noqa: N802 + def _del_allvaluesfrom(self): pass # pragma: no cover allValuesFrom = property( # noqa: N815 - _get_allValuesFrom, _set_allValuesFrom, _del_allValuesFrom + _get_allvaluesfrom, _set_allvaluesfrom, _del_allvaluesfrom ) - def _get_someValuesFrom(self): # noqa: N802 + def _get_somevaluesfrom(self): for i in self.graph.objects( subject=self.identifier, predicate=OWL.someValuesFrom ): return Class(i, graph=self.graph) return None - def _set_someValuesFrom(self, other): # noqa: N802 + def _set_somevaluesfrom(self, other): triple = (self.identifier, OWL.someValuesFrom, classOrIdentifier(other)) if not other: return @@ -1822,19 +1810,19 @@ def _set_someValuesFrom(self, other): # noqa: N802 self.graph.set(triple) @TermDeletionHelper(OWL.someValuesFrom) - def _del_someValuesFrom(self): # noqa: N802 + def _del_somevaluesfrom(self): pass # pragma: no cover someValuesFrom = property( # noqa: N815 - _get_someValuesFrom, _set_someValuesFrom, _del_someValuesFrom + _get_somevaluesfrom, _set_somevaluesfrom, _del_somevaluesfrom ) - def _get_hasValue(self): # noqa: N802 + def _get_hasvalue(self): for i in self.graph.objects(subject=self.identifier, predicate=OWL.hasValue): return Class(i, graph=self.graph) return None - def _set_hasValue(self, other): # noqa: N802 + def _set_hasvalue(self, other): triple = (self.identifier, OWL.hasValue, classOrIdentifier(other)) if not other: return @@ -1844,10 +1832,10 @@ def _set_hasValue(self, other): # noqa: N802 self.graph.set(triple) @TermDeletionHelper(OWL.hasValue) - def _del_hasValue(self): # noqa: N802 + def _del_hasvalue(self): pass # pragma: no cover - hasValue = property(_get_hasValue, _set_hasValue, _del_hasValue) # noqa: N815 + hasValue = property(_get_hasvalue, _set_hasvalue, _del_hasvalue) # noqa: N815 def _get_cardinality(self): for i in self.graph.objects(subject=self.identifier, predicate=OWL.cardinality): @@ -1869,14 +1857,14 @@ def _del_cardinality(self): cardinality = property(_get_cardinality, _set_cardinality, _del_cardinality) - def _get_maxCardinality(self): # noqa: N802 + def _get_maxcardinality(self): for i in self.graph.objects( subject=self.identifier, predicate=OWL.maxCardinality ): return Class(i, graph=self.graph) return None - def _set_maxCardinality(self, other): # noqa: N802 + def _set_maxcardinality(self, other): triple = (self.identifier, OWL.maxCardinality, classOrIdentifier(other)) if not other: return @@ -1886,21 +1874,21 @@ def _set_maxCardinality(self, other): # noqa: N802 self.graph.set(triple) @TermDeletionHelper(OWL.maxCardinality) - def _del_maxCardinality(self): # noqa: N802 + def _del_maxcardinality(self): pass # pragma: no cover maxCardinality = property( # noqa: N815 - _get_maxCardinality, _set_maxCardinality, _del_maxCardinality + _get_maxcardinality, _set_maxcardinality, _del_maxcardinality ) - def _get_minCardinality(self): # noqa: N802 + def _get_mincardinality(self): for i in self.graph.objects( subject=self.identifier, predicate=OWL.minCardinality ): return Class(i, graph=self.graph) return None - def _set_minCardinality(self, other): # noqa: N802 + def _set_mincardinality(self, other): triple = (self.identifier, OWL.minCardinality, classOrIdentifier(other)) if not other: return @@ -1910,11 +1898,11 @@ def _set_minCardinality(self, other): # noqa: N802 self.graph.set(triple) @TermDeletionHelper(OWL.minCardinality) - def _del_minCardinality(self): # noqa: N802 + def _del_mincardinality(self): pass # pragma: no cover minCardinality = property( # noqa: N815 - _get_minCardinality, _set_minCardinality, _del_minCardinality + _get_mincardinality, _set_mincardinality, _del_mincardinality ) def restrictionKind(self): # noqa: N802 @@ -1975,23 +1963,23 @@ class Property(AnnotatableTerms): """ - def setupVerbAnnotations(self, verbAnnotations): # noqa: N802, N803 - if isinstance(verbAnnotations, tuple): - TV_sgProp, TV_plProp, TV_vbg = verbAnnotations # noqa: N806 + def setupVerbAnnotations(self, verb_annotations): # noqa: N802 + if isinstance(verb_annotations, tuple): + tv_sgprop, tv_plprop, tv_vbg = verb_annotations else: - TV_sgProp = verbAnnotations # noqa: N806 - TV_plProp = verbAnnotations # noqa: N806 - TV_vbg = verbAnnotations # noqa: N806 - if TV_sgProp: - self.TV_sgProp.extent = [ - (self.identifier, self.handleAnnotation(TV_sgProp)) + tv_sgprop = verb_annotations + tv_plprop = verb_annotations + tv_vbg = verb_annotations + if tv_sgprop: + self.tv_sgprop.extent = [ + (self.identifier, self.handleAnnotation(tv_sgprop)) ] - if TV_plProp: - self.TV_plProp.extent = [ - (self.identifier, self.handleAnnotation(TV_plProp)) + if tv_plprop: + self.tv_plprop.extent = [ + (self.identifier, self.handleAnnotation(tv_plprop)) ] - if TV_vbg: - self.TV_vbgProp.extent = [(self.identifier, self.handleAnnotation(TV_vbg))] + if tv_vbg: + self.tv_vbgprop.extent = [(self.identifier, self.handleAnnotation(tv_vbg))] def __init__( self, @@ -2057,19 +2045,19 @@ def __repr__(self): % (self.qname, first(self.comment) and first(self.comment) or "") ) if first(self.inverseOf): - twoLinkInverse = first(first(self.inverseOf).inverseOf) # noqa: N806 - if twoLinkInverse and twoLinkInverse.identifier == self.identifier: - inverseRepr = first(self.inverseOf).qname # noqa: N806 + two_link_inverse = first(first(self.inverseOf).inverseOf) + if two_link_inverse and two_link_inverse.identifier == self.identifier: + inverserepr = first(self.inverseOf).qname else: - inverseRepr = repr(first(self.inverseOf)) # noqa: N806 + inverserepr = repr(first(self.inverseOf)) rt.append( " inverseOf( %s )%s" % ( - inverseRepr, + inverserepr, OWL.SymmetricProperty in self.type and " Symmetric" or "", ) ) - for s, p, roleType in self.graph.triples_choices( # noqa: N806 + for s, p, roletype in self.graph.triples_choices( ( self.identifier, RDF.type, @@ -2080,26 +2068,26 @@ def __repr__(self): ], ) ): - rt.append(str(roleType.split(OWL)[-1])) + rt.append(str(roletype.split(OWL)[-1])) else: rt.append( "DatatypeProperty( %s %s" % (self.qname, first(self.comment) and first(self.comment) or "") ) - for s, p, roleType in self.graph.triples( # noqa: N806 + for s, p, roletype in self.graph.triples( (self.identifier, RDF.type, OWL.FunctionalProperty) ): rt.append(" Functional") def canonicalName(term, g): # noqa: N802 - normalizedName = classOrIdentifier(term) # noqa: N806 - if isinstance(normalizedName, BNode): + normalized_name = classOrIdentifier(term) + if isinstance(normalized_name, BNode): return term - elif normalizedName.startswith(XSD): + elif normalized_name.startswith(XSD): return str(term) elif first( g.triples_choices( - (normalizedName, [OWL.unionOf, OWL.intersectionOf], None) + (normalized_name, [OWL.unionOf, OWL.intersectionOf], None) ) ): return repr(term) @@ -2109,8 +2097,8 @@ def canonicalName(term, g): # noqa: N802 rt.append( " ".join( [ - " super( %s )" % canonicalName(superP, self.graph) - for superP in self.subPropertyOf # noqa: N806 + " super( %s )" % canonicalName(super_property, self.graph) + for super_property in self.subPropertyOf ] ) ) @@ -2134,40 +2122,42 @@ def canonicalName(term, g): # noqa: N802 rt += "\n)" return rt - def _get_subPropertyOf(self): # noqa: N802 + def _get_subpropertyof(self): for anc in self.graph.objects( subject=self.identifier, predicate=RDFS.subPropertyOf ): yield Property(anc, graph=self.graph, baseType=None) - def _set_subPropertyOf(self, other): # noqa: N802 + def _set_subpropertyof(self, other): if not other: return - for sP in other: # noqa: N806 - self.graph.add((self.identifier, RDFS.subPropertyOf, classOrIdentifier(sP))) + for subproperty in other: + self.graph.add( + (self.identifier, RDFS.subPropertyOf, classOrIdentifier(subproperty)) + ) @TermDeletionHelper(RDFS.subPropertyOf) - def _del_subPropertyOf(self): # noqa: N802 + def _del_subpropertyof(self): pass # pragma: no cover subPropertyOf = property( # noqa: N815 - _get_subPropertyOf, _set_subPropertyOf, _del_subPropertyOf + _get_subpropertyof, _set_subpropertyof, _del_subpropertyof ) - def _get_inverseOf(self): # noqa: N802 + def _get_inverseof(self): for anc in self.graph.objects(subject=self.identifier, predicate=OWL.inverseOf): yield Property(anc, graph=self.graph, baseType=None) - def _set_inverseOf(self, other): # noqa: N802 + def _set_inverseof(self, other): if not other: return self.graph.add((self.identifier, OWL.inverseOf, classOrIdentifier(other))) @TermDeletionHelper(OWL.inverseOf) - def _del_inverseOf(self): # noqa: N802 + def _del_inverseof(self): pass # pragma: no cover - inverseOf = property(_get_inverseOf, _set_inverseOf, _del_inverseOf) # noqa: N815 + inverseOf = property(_get_inverseof, _set_inverseof, _del_inverseof) # noqa: N815 def _get_domain(self): for dom in self.graph.objects(subject=self.identifier, predicate=RDFS.domain): From a32f69adf1b20c7432aba828a7e069cc3539ece7 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 24 Jun 2022 13:11:22 +0100 Subject: [PATCH 03/15] remedy untranscribed change --- rdflib/extras/infixowl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdflib/extras/infixowl.py b/rdflib/extras/infixowl.py index ae4335a97..66a703080 100644 --- a/rdflib/extras/infixowl.py +++ b/rdflib/extras/infixowl.py @@ -254,7 +254,7 @@ def manchesterSyntax( # noqa: N802 assert thing is not None if boolean: if transientList: - liveChildren = iter(thing) # noqa: N806 + livechildren = iter(thing) children = [manchesterSyntax(child, store) for child in thing] else: livechildren = iter(Collection(store, thing)) From 7a10034bd442e6a9f9489473d385e62d1b0265cf Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 24 Jun 2022 15:04:45 +0100 Subject: [PATCH 04/15] change test to expect actual results rather than empty lists. --- test/test_extras/test_infixowl/test_class.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/test/test_extras/test_infixowl/test_class.py b/test/test_extras/test_infixowl/test_class.py index 4bb02ff61..b31c57617 100644 --- a/test/test_extras/test_infixowl/test_class.py +++ b/test/test_extras/test_infixowl/test_class.py @@ -241,14 +241,10 @@ def test_class_serialize(graph): tgt = (EXNS.test, pred, Literal("Men")) assert tgt in owlc.graph - assert list(owlc._get_annotation(pred)) == [] - - # Not yet: - with pytest.raises(AssertionError): - assert list(owlc._get_annotation(pred)) == [ - Literal("Men"), - Literal("['Man', 'Men']"), - ] + assert list(owlc._get_annotation(pred)) == [ + Literal("Men"), + Literal("['Man', 'Men']"), + ] assert owlc.extentQuery == ( Variable("CLASS"), @@ -290,11 +286,7 @@ def test_class_nameislabel(graph): nameIsLabel=True, ) - assert list(owlc.annotation) == [] - - # Not yet - with pytest.raises(AssertionError): - assert list(owlc.annotation) == [Literal("Man")] + assert list(owlc.annotation) == [Literal("Man")] assert graph.serialize(format="ttl") == ( "@prefix ace: .\n" From 3685962b09787b1666181dd9b67b0e611a1a64c8 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 24 Jun 2022 15:09:14 +0100 Subject: [PATCH 05/15] remedy transcription omission --- rdflib/extras/infixowl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rdflib/extras/infixowl.py b/rdflib/extras/infixowl.py index 66a703080..9ddca4008 100644 --- a/rdflib/extras/infixowl.py +++ b/rdflib/extras/infixowl.py @@ -215,8 +215,8 @@ def __call__(self, value1, value2): def generateQName(graph, uri): # noqa: N802 - prefix, uri, localName = graph.compute_qname(classOrIdentifier(uri)) # noqa: N806 - return ":".join([prefix, localName]) + prefix, uri, localname = graph.compute_qname(classOrIdentifier(uri)) + return ":".join([prefix, localname]) def classOrTerm(thing): # noqa: N802 From 559d7f58376817d38899bc4ce51db16169cc2e5c Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 24 Jun 2022 15:13:57 +0100 Subject: [PATCH 06/15] Address remaining E722 "bare except" instances objectionable to flake8 --- rdflib/extras/infixowl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rdflib/extras/infixowl.py b/rdflib/extras/infixowl.py index 9ddca4008..166186629 100644 --- a/rdflib/extras/infixowl.py +++ b/rdflib/extras/infixowl.py @@ -392,7 +392,7 @@ def __init__(self, identifier=None, graph=None): try: prefix, uri, localname = self.graph.compute_qname(self.identifier) self.qname = ":".join([prefix, localname]) - except: # noqa: E722 # pragma: no cover + except Exception: # pragma: no cover pass # pragma: no cover def clearInDegree(self): # noqa: N802 @@ -465,7 +465,7 @@ def _set_identifier(self, i): try: prefix, uri, localname = self.graph.compute_qname(i) self.qname = ":".join([prefix, localname]) - except: # noqa: E722 # pragma: no cover + except Exception: # pragma: no cover pass # pragma: no cover identifier = property(_get_identifier, _set_identifier) @@ -742,7 +742,7 @@ def ComponentTerms(cls): # noqa: N802 yield _c else: yield inner_class - except: # noqa: E722 # pragma: no cover + except Exception: # pragma: no cover pass # pragma: no cover else: cls = CastClass(cls, Individual.factoryGraph) From 1863e72d9c78d7b8cc51548b08e38a242b9781ef Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 15 Jul 2022 18:27:43 +0100 Subject: [PATCH 07/15] Remove unused code and shebang, shuffle imports, fix doctests, add "Error" suffix to MaformedClass and stringify OWL namespace where necessary for `split`. --- rdflib/extras/infixowl.py | 41 ++++++++++++++------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/rdflib/extras/infixowl.py b/rdflib/extras/infixowl.py index 166186629..71a96476e 100644 --- a/rdflib/extras/infixowl.py +++ b/rdflib/extras/infixowl.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- __doc__ = """RDFLib Python binding for OWL Abstract Syntax @@ -111,10 +110,10 @@ import itertools import logging -from rdflib import RDF, RDFS, BNode, Literal, Namespace, URIRef, Variable +from rdflib import OWL, RDF, RDFS, XSD, BNode, Literal, Namespace, URIRef, Variable from rdflib.collection import Collection from rdflib.graph import Graph -from rdflib.namespace import OWL, XSD, NamespaceManager +from rdflib.namespace import NamespaceManager from rdflib.term import Identifier from rdflib.util import first @@ -173,21 +172,15 @@ # definition of an Infix operator class # this recipe also works in jython # calling sequence for the infix is either: -# x |op| y +# x << op >> y # or: -# x <> y +# x @ op @ y class Infix: def __init__(self, function): self.function = function - def __ror__(self, other): - return Infix(lambda x, self=self, other=other: self.function(other, x)) - - def __or__(self, other): - return self.function(other) - def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) @@ -351,14 +344,6 @@ def GetIdentifiedClasses(graph): # noqa: N802 yield Class(c) -def termDeletionDecorator(prop): # noqa: N802 - def someFunc(func): # noqa: N802 - func.property = prop - return func - - return someFunc - - class TermDeletionHelper: def __init__(self, prop): self.prop = prop @@ -841,7 +826,7 @@ def deepClearIfBNode(_class): # noqa: N802 ) -class MalformedClass(Exception): +class MalformedClassError(Exception): def __init__(self, msg): self.msg = msg @@ -865,7 +850,7 @@ def CastClass(c, graph=None): # noqa: N802 if not set( [str(i.split(str(OWL))[-1]) for i in Restriction.restrictionKinds] ).intersection(kwargs): - raise MalformedClass("Malformed owl:Restriction") + raise MalformedClassError("Malformed owl:Restriction") return Restriction(**kwargs) else: for s, p, o in graph.triples_choices( @@ -1585,13 +1570,15 @@ def changeOperator(self, newOperator): # noqa: N802, N803 >>> fire = Class(EX.Fire) >>> water = Class(EX.Water) >>> testClass = BooleanClass(members=[fire,water]) - >>> testClass #doctest: +SKIP + >>> testClass ( ex:Fire AND ex:Water ) >>> testClass.changeOperator(OWL.unionOf) - >>> testClass #doctest: +SKIP + >>> testClass ( ex:Fire OR ex:Water ) - >>> try: testClass.changeOperator(OWL.unionOf) - ... except Exception as e: print(e) + >>> try: + ... testClass.changeOperator(OWL.unionOf) + ... except Exception as e: + ... print(e) #doctest: +SKIP The new operator is already being used! """ @@ -1617,6 +1604,8 @@ def __or__(self, other): def AllDifferent(members): # noqa: N802 """ + TODO: implement this function + DisjointClasses(' description description { description } ')' """ @@ -2068,7 +2057,7 @@ def __repr__(self): ], ) ): - rt.append(str(roletype.split(OWL)[-1])) + rt.append(str(roletype.split(str(OWL))[-1])) else: rt.append( "DatatypeProperty( %s %s" From e198147f994a3603ba8f3974206949c0d776b284 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 15 Jul 2022 18:35:28 +0100 Subject: [PATCH 08/15] sort __all__, streamline `AllClasses`, raise informative ValueError for `valid_restr_props`, adjust various methods to handle None, add informative docucomments w.r.t. Attempto integration. --- rdflib/extras/infixowl.py | 170 +++++++++++++++++++++++++++++--------- 1 file changed, 130 insertions(+), 40 deletions(-) diff --git a/rdflib/extras/infixowl.py b/rdflib/extras/infixowl.py index 71a96476e..35a571077 100644 --- a/rdflib/extras/infixowl.py +++ b/rdflib/extras/infixowl.py @@ -130,43 +130,42 @@ """ __all__ = [ - "nsBinds", "ACE_NS", - "CLASS_RELATIONS", - "some", - "only", - "max", - "min", - "exactly", - "value", - "PropertyAbstractSyntax", "AllClasses", "AllDifferent", "AllProperties", "AnnotatableTerms", "BooleanClass", + "CLASS_RELATIONS", "Callable", "CastClass", "Class", "ClassNamespaceFactory", - "classOrIdentifier", - "classOrTerm", "CommonNSBindings", "ComponentTerms", "DeepClassClear", "EnumeratedClass", - "generateQName", "GetIdentifiedClasses", "Individual", "Infix", - "MalformedClass", - "manchesterSyntax", - "Ontology", + "MalformedClassError", "OWLRDFListProxy", + "Ontology", "Property", - "propertyOrIdentifier", + "PropertyAbstractSyntax", "Restriction", - "termDeletionDecorator", + "classOrIdentifier", + "classOrTerm", + "exactly", + "generateQName", + "manchesterSyntax", + "max", + "min", + "nsBinds", + "only", + "propertyOrIdentifier", + "some", + "value", ] # definition of an Infix operator class @@ -243,6 +242,8 @@ def manchesterSyntax( # noqa: N802 ): """ Core serialization + thing is a Class and is processed as a subject + store is an RDFLib Graph to be queried about thing """ assert thing is not None if boolean: @@ -310,6 +311,7 @@ def castToQName(x): # noqa: N802 } for s, p, o in store.triples_choices((thing, list(cardlookup.keys()), None)): return "( %s %s %s )" % (propstring, cardlookup[p], o) + # is thing a complement of anything compl = list(store.objects(subject=thing, predicate=OWL.complementOf)) if compl: return "( NOT %s )" % (manchesterSyntax(compl[0], store)) @@ -482,6 +484,74 @@ def _delete_sameAs(self): # noqa: N802 class AnnotatableTerms(Individual): """ Terms in an OWL ontology with rdfs:label and rdfs:comment + + + Interface with ATTEMPTO (http://attempto.ifi.uzh.ch/site) + + Verbalisation of OWL entity IRIS + ================================ + + How are OWL entity IRIs verbalized? + ----------------------------------- + + The OWL verbalizer maps OWL entity IRIs to ACE content words such + that + + OWL individuals map to ACE proper names (PN) + OWL classes map to ACE common nouns (CN) + OWL properties map to ACE transitive verbs (TV) + + There are 6 morphological categories that determine the surface form + of an IRI: + + singular form of a proper name (e.g. John) + singular form of a common noun (e.g. man) + plural form of a common noun (e.g. men) + singular form of a transitive verb (e.g. mans) + plural form of a transitive verb (e.g. man) + past participle form a transitive verb (e.g. manned) + + The user has full control over the eventual surface forms of the IRIs + but has to choose them in terms of the above categories. + Furthermore, + + - the surface forms must be legal ACE content words (e.g. they + should not contain punctuation symbols); + - the mapping of IRIs to surface forms must be bidirectional + within the same word class, in order to be able to (if needed) + parse the verbalization back into OWL in a semantics preserving + way. + + Using the lexicon + ----------------- + + It is possible to specify the mapping of IRIs to surface forms using + the following annotation properties: + + http://attempto.ifi.uzh.ch/ace_lexicon#PN_sg + http://attempto.ifi.uzh.ch/ace_lexicon#CN_sg + http://attempto.ifi.uzh.ch/ace_lexicon#CN_pl + http://attempto.ifi.uzh.ch/ace_lexicon#TV_sg + http://attempto.ifi.uzh.ch/ace_lexicon#TV_pl + http://attempto.ifi.uzh.ch/ace_lexicon#TV_vbg + + For example, the following axioms state that if the IRI "#man" is used + as a plural common noun, then the wordform men must be used by the + verbalizer. If, however, it is used as a singular transitive verb, + then mans must be used. + + + + #man + men + + + + + #man + mans + + """ def __init__( @@ -638,11 +708,8 @@ def _del_imports(self): def AllClasses(graph): # noqa: N802 - prevclasses = set() - for c in graph.subjects(predicate=RDF.type, object=OWL.Class): - if c not in prevclasses: - prevclasses.add(c) - yield Class(c) + for c in set(graph.subjects(predicate=RDF.type, object=OWL.Class)): + yield Class(c) def AllProperties(graph): # noqa: N802 @@ -1664,7 +1731,12 @@ def __init__( (minCardinality, OWL.minCardinality), ] valid_restr_props = [(i, oterm) for (i, oterm) in restr_types if i is not None] - assert len(valid_restr_props) + if not len(valid_restr_props): + raise ValueError( + "Missing value. One of: allValuesFrom, someValuesFrom," + "value, cardinality, maxCardinality or minCardinality" + "must have a value." + ) restriction_range, restriction_type = valid_restr_props.pop() self.restrictionType = restriction_type if isinstance(restriction_range, Identifier): @@ -1742,10 +1814,10 @@ def _get_onproperty(self): )[0] def _set_onproperty(self, prop): - triple = (self.identifier, OWL.onProperty, propertyOrIdentifier(prop)) if not prop: return - elif triple in self.graph: + triple = (self.identifier, OWL.onProperty, propertyOrIdentifier(prop)) + if triple in self.graph: return else: self.graph.set(triple) @@ -1766,10 +1838,10 @@ def _get_allvaluesfrom(self): return None def _set_allvaluesfrom(self, other): - triple = (self.identifier, OWL.allValuesFrom, classOrIdentifier(other)) if not other: return - elif triple in self.graph: + triple = (self.identifier, OWL.allValuesFrom, classOrIdentifier(other)) + if triple in self.graph: return else: self.graph.set(triple) @@ -1790,10 +1862,10 @@ def _get_somevaluesfrom(self): return None def _set_somevaluesfrom(self, other): - triple = (self.identifier, OWL.someValuesFrom, classOrIdentifier(other)) if not other: return - elif triple in self.graph: + triple = (self.identifier, OWL.someValuesFrom, classOrIdentifier(other)) + if triple in self.graph: return else: self.graph.set(triple) @@ -1812,10 +1884,10 @@ def _get_hasvalue(self): return None def _set_hasvalue(self, other): - triple = (self.identifier, OWL.hasValue, classOrIdentifier(other)) if not other: return - elif triple in self.graph: + triple = (self.identifier, OWL.hasValue, classOrIdentifier(other)) + if triple in self.graph: return else: self.graph.set(triple) @@ -1832,10 +1904,10 @@ def _get_cardinality(self): return None def _set_cardinality(self, other): - triple = (self.identifier, OWL.cardinality, classOrIdentifier(other)) if not other: return - elif triple in self.graph: + triple = (self.identifier, OWL.cardinality, classOrIdentifier(other)) + if triple in self.graph: return else: self.graph.set(triple) @@ -1854,10 +1926,10 @@ def _get_maxcardinality(self): return None def _set_maxcardinality(self, other): - triple = (self.identifier, OWL.maxCardinality, classOrIdentifier(other)) if not other: return - elif triple in self.graph: + triple = (self.identifier, OWL.maxCardinality, classOrIdentifier(other)) + if triple in self.graph: return else: self.graph.set(triple) @@ -1878,10 +1950,10 @@ def _get_mincardinality(self): return None def _set_mincardinality(self, other): - triple = (self.identifier, OWL.minCardinality, classOrIdentifier(other)) if not other: return - elif triple in self.graph: + triple = (self.identifier, OWL.minCardinality, classOrIdentifier(other)) + if triple in self.graph: return else: self.graph.set(triple) @@ -1895,11 +1967,11 @@ def _del_mincardinality(self): ) def restrictionKind(self): # noqa: N802 - for p in self.graph.triple_choices( + for (s, p, o) in self.graph.triples_choices( (self.identifier, self.restrictionKinds, None) ): - return p.split(OWL)[-1] - raise + return p.split(str(OWL))[-1] + return None def __repr__(self): """ @@ -1928,6 +2000,7 @@ def __repr__(self): ) value = Infix(lambda prop, _class: Restriction(prop, graph=prop.graph, value=_class)) +# Unused PropertyAbstractSyntax = """ %s( %s { %s } %s @@ -1953,6 +2026,23 @@ class Property(AnnotatableTerms): """ def setupVerbAnnotations(self, verb_annotations): # noqa: N802 + """ + + OWL properties map to ACE transitive verbs (TV) + + There are 6 morphological categories that determine the surface form + of an IRI: + + singular form of a transitive verb (e.g. mans) + plural form of a transitive verb (e.g. man) + past participle form a transitive verb (e.g. manned) + + http://attempto.ifi.uzh.ch/ace_lexicon#TV_sg + http://attempto.ifi.uzh.ch/ace_lexicon#TV_pl + http://attempto.ifi.uzh.ch/ace_lexicon#TV_vbg + + """ + if isinstance(verb_annotations, tuple): tv_sgprop, tv_plprop, tv_vbg = verb_annotations else: From 7cbeb784bf2ccb85977dc1fd2bc095854337c71c Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 15 Jul 2022 18:35:49 +0100 Subject: [PATCH 09/15] Update tests. --- test/test_extras/test_infixowl/test_class.py | 22 +- test/test_extras/test_infixowl/test_cover.py | 187 +++++------ .../test_infixowl/test_restriction.py | 102 +----- test/test_extras/test_infixowl/test_rubric.py | 306 +++++------------- 4 files changed, 214 insertions(+), 403 deletions(-) diff --git a/test/test_extras/test_infixowl/test_class.py b/test/test_extras/test_infixowl/test_class.py index b31c57617..37adf5714 100644 --- a/test/test_extras/test_infixowl/test_class.py +++ b/test/test_extras/test_infixowl/test_class.py @@ -1,4 +1,4 @@ -from test.data import context1 +from test.data import context0, context1 import pytest @@ -274,13 +274,16 @@ def test_class_serialize(graph): assert owlc.complementOf == sister -def test_class_nameislabel(graph): +def test_class_nameislabel(): + g = Graph(identifier=context0) + g.bind("ex", EXNS) + Individual.factoryGraph = g nameannotation = Literal("Man") owlc = Class( EXNS.test, - graph=graph, + graph=g, comment=Literal("This is a Man"), nameAnnotation=nameannotation, nameIsLabel=True, @@ -288,7 +291,7 @@ def test_class_nameislabel(graph): assert list(owlc.annotation) == [Literal("Man")] - assert graph.serialize(format="ttl") == ( + assert g.serialize(format="ttl") == ( "@prefix ace: .\n" "@prefix ex: .\n" "@prefix owl: .\n" @@ -314,20 +317,23 @@ def test_class_nameislabel(graph): ) -def test_class_nameisnotlabel(graph): +def test_class_nameisnotlabel(): + g = Graph(identifier=context0) + g.bind("ex", EXNS) + Individual.factoryGraph = g nameannotation = Literal("Man") owlc = Class( EXNS.test, - graph=graph, + graph=g, comment=Literal("This is a Man"), nameAnnotation=nameannotation, ) assert list(owlc.annotation) == [] - assert graph.serialize(format="ttl") == ( + assert g.serialize(format="ttl") == ( "@prefix ace: .\n" "@prefix ex: .\n" "@prefix owl: .\n" @@ -351,4 +357,4 @@ def test_class_nameisnotlabel(graph): "\n" ) - assert (EXNS.test, RDFS.label, nameannotation) not in graph + assert (EXNS.test, RDFS.label, nameannotation) not in g diff --git a/test/test_extras/test_infixowl/test_cover.py b/test/test_extras/test_infixowl/test_cover.py index 3cbc8a7ac..b790adf47 100644 --- a/test/test_extras/test_infixowl/test_cover.py +++ b/test/test_extras/test_infixowl/test_cover.py @@ -1,8 +1,8 @@ -from test.data import TEST_DATA_DIR, bob, michel, tarek +from test.data import TEST_DATA_DIR, context0 import pytest -from rdflib import OWL, RDF, RDFS, XSD, Graph, Literal, Namespace, URIRef +from rdflib import OWL, RDF, RDFS, XSD, Graph, Literal, Namespace, URIRef, logger from rdflib.extras.infixowl import ( AllClasses, AllProperties, @@ -16,7 +16,7 @@ GetIdentifiedClasses, Individual, Infix, - MalformedClass, + MalformedClassError, Property, Restriction, classOrTerm, @@ -35,25 +35,12 @@ ) -@pytest.fixture(scope="function") -def graph(): - g = Graph() - g.bind("ex", EXNS) - Individual.factoryGraph = g - - yield g - - del g - - def test_infix_operators_dunders(): def fn(other, arg=""): return None i = Infix(fn) - assert i.__ror__("foo") is not None - assert i.__or__("foo") is None assert i.__rlshift__("foo") is not None assert i.__rshift__("foo") is None assert i.__rmatmul__("foo") is not None @@ -61,97 +48,86 @@ def fn(other, arg=""): assert i.__call__("foo", "baz") is None -@pytest.mark.xfail(reason="__or__/__ror__ operators broken for years") -def test_or_ror_operators(graph): +def test_infix_operators(): + g = Graph() + g.bind("ex", EXNS) + # Broken since forever with pytest.raises(Exception, match="Only URIRefs or Paths can be in paths!"): - EXNS.hasParent | some | Class(EXNS.Physician, graph=graph) - - EXNS.hasParent | some | Class(EXNS.Physician, graph=graph) - - -@pytest.mark.xfail( - reason="__lshift__/__rlshift__ operators expected to break when RDF Star work is merged in autumn 2022" -) -def test_lshift_rlshift_infix_operators(graph): - - res = EXNS.hasParent << some >> Class(EXNS.Physician, graph=graph) + EXNS.hasParent | some | Class(EXNS.Physician, graph=g) + # Will break when RDF Star syntax is added + res = EXNS.hasParent << some >> Class(EXNS.Physician, graph=g) assert str(res) == "( ex:hasParent SOME ex:Physician )" - -def test_matmul_infix_operators(graph): - - res = EXNS.hasParent @ some @ Class(EXNS.Physician, graph=graph) - + res = EXNS.hasParent @ some @ Class(EXNS.Physician, graph=g) assert str(res) == "( ex:hasParent SOME ex:Physician )" -def test_common_ns_bindings(): - graph = Graph(bind_namespaces=None) - exns1 = Namespace("http://example.com") - - CommonNSBindings(graph, additionalNS={"ex1": exns1}) - - bound_namespaces = list(graph.namespace_manager.namespaces()) - - assert ("ex1", URIRef(str(exns1))) in bound_namespaces - assert ("owl", URIRef(str(OWL))) in bound_namespaces +def test_generateqname(): + g = Graph() + g.bind("ex", EXNS) + assert ( + generateQName(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" + ) def test_classorterm(): term = URIRef("http://example.org/vocab/D") - assert classOrTerm(Class(EXNS.D)) == term assert classOrTerm(term) == term -def test_generateqname(graph): - - assert ( - generateQName(graph, URIRef("http://example.org/vocab/ontology")) - == "ex:ontology" - ) +def test_getidentifiedclasses(): + g = Graph() + g.bind("ex", PZNS) + g.parse(TEST_DATA_DIR / "owl" / "pizza.owl", format="xml") + assert len(list(GetIdentifiedClasses(g))) == 97 -def test_getidentifiedclasses(graph): +class Foo: + pass - graph.bind("ex", PZNS) - graph.parse(TEST_DATA_DIR / "owl" / "pizza.owl", format="xml") - assert len(list(GetIdentifiedClasses(graph))) == 97 +def test_common_ns_bindings(): + g = Graph(bind_namespaces=None) + CommonNSBindings(g, additionalNS={"ex": EXNS}) -def test_allclasses(graph): +def test_allclasses(): + g = Graph() + g.bind("ex", PZNS) - graph.bind("ex", PZNS) - graph.parse(TEST_DATA_DIR / "owl" / "pizza.owl", format="xml") + g.parse(TEST_DATA_DIR / "owl" / "pizza.owl", format="xml") - for c in AllClasses(graph): + for c in AllClasses(g): assert isinstance(c, Class) -def test_check_allclasses(graph): +def test_check_allclasses(): + from test.data import bob, michel, tarek - graph.bind("ex", PZNS) + g = Graph() + g.bind("ex", PZNS) - graph.add((tarek, RDF.type, OWL.Class)) - graph.add((michel, RDF.type, OWL.Class)) - graph.add((bob, RDF.type, OWL.Class)) + g.add((tarek, RDF.type, OWL.Class)) + g.add((michel, RDF.type, OWL.Class)) + g.add((bob, RDF.type, OWL.Class)) - assert set(graph.subjects(predicate=RDF.type, object=OWL.Class)) == { + assert set(g.subjects(predicate=RDF.type, object=OWL.Class)) == { URIRef("urn:example:bob"), URIRef("urn:example:michel"), URIRef("urn:example:tarek"), } -def test_check_allproperties(graph): +def test_check_allproperties(): + g = Graph() + g.bind("ex", PZNS) - graph.bind("ex", PZNS) - graph.parse(TEST_DATA_DIR / "owl" / "pizza.owl", format="xml") + g.parse(TEST_DATA_DIR / "owl" / "pizza.owl", format="xml") - for p in AllProperties(graph): + for p in AllProperties(g): assert isinstance(p, Property) @@ -167,12 +143,15 @@ def test_classnamespacefactory(): assert x is not None -def test_componentterms(graph): +def test_componentterms(): + g = Graph() + g.bind("ex", PZNS) + + Individual.factoryGraph = g - graph.bind("ex", PZNS) - graph.parse(TEST_DATA_DIR / "owl" / "pizza.owl", format="xml") + g.parse(TEST_DATA_DIR / "owl" / "pizza.owl", format="xml") - owlcls = list(AllClasses(graph))[-1] + owlcls = list(AllClasses(g))[-1] assert isinstance(owlcls, Class) @@ -180,13 +159,16 @@ def test_componentterms(graph): assert isinstance(c, Class) -def test_componentterms_extended(graph): +def test_componentterms_extended(): + g = Graph() + g.bind("ex", PZNS) + Individual.factoryGraph = g isPartOf = Property(EXNS.isPartOf) # noqa: N806 - graph.add((isPartOf.identifier, RDF.type, OWL.TransitiveProperty)) + g.add((isPartOf.identifier, RDF.type, OWL.TransitiveProperty)) hasLocation = Property(EXNS.hasLocation, subPropertyOf=[isPartOf]) # noqa: N806 - graph.add((hasLocation.identifier, RDFS.subPropertyOf, isPartOf.identifier)) + g.add((hasLocation.identifier, RDFS.subPropertyOf, isPartOf.identifier)) leg = EXCL.Leg knee = EXCL.Knee @@ -212,17 +194,22 @@ def test_componentterms_extended(graph): for c in ComponentTerms(legStructure): assert isinstance(c, Class) + logger.debug(f"G\n{g.serialize(format='ttl')}") + def test_raise_malformedclasserror(): - e = MalformedClass("Malformed owl:Restriction") + e = MalformedClassError("Malformed owl:Restriction") assert str(repr(e)) == "Malformed owl:Restriction" - with pytest.raises(MalformedClass, match="Malformed owl:Restriction"): + with pytest.raises(MalformedClassError, match="Malformed owl:Restriction"): raise e -def test_owlrdfproxylist(graph): +def test_owlrdfproxylist(): + g = Graph() + g.bind("ex", EXNS) + Individual.factoryGraph = g ogbujiBros = EnumeratedClass( # noqa: N806 EXNS.ogbujiBros, members=[EXNS.chime, EXNS.uche, EXNS.ejike] @@ -258,11 +245,11 @@ def test_owlrdfproxylist(graph): assert len(ogbujiBros) == 5 - male = Class(EXNS.Male, graph=graph) - female = Class(EXNS.Female, graph=graph) - human = Class(EXNS.Human, graph=graph) + male = Class(EXNS.Male, graph=g) + female = Class(EXNS.Female, graph=g) + human = Class(EXNS.Human, graph=g) - youngPerson = Class(EXNS.YoungPerson, graph=graph) # noqa: N806 + youngPerson = Class(EXNS.YoungPerson, graph=g) # noqa: N806 youngWoman = female & human & youngPerson # noqa: N806 assert isinstance(youngWoman, BooleanClass) @@ -276,7 +263,10 @@ def test_owlrdfproxylist(graph): assert res is False -def test_deepclassclear(graph): +def test_deepclassclear(): + g = Graph() + g.bind("ex", EXNS) + Individual.factoryGraph = g classB = Class(EXNS.B) # noqa: N806 classC = Class(EXNS.C) # noqa: N806 @@ -290,6 +280,7 @@ def test_deepclassclear(graph): assert str(classF) == "Class: ex:F " classF += anonClass # noqa: N806 + assert str(list(anonClass.subClassOf)) == "[Class: ex:F ]" classA = classE | classF | anonClass # noqa: N806 @@ -316,10 +307,14 @@ def test_deepclassclear(graph): assert str(otherClass) == "( )" otherClass.delete() - assert list(graph.triples((otherClass.identifier, None, None))) == [] + assert list(g.triples((otherClass.identifier, None, None))) == [] -def test_booleanclassextenthelper(graph): +def test_booleanclassextenthelper(): + g = Graph() + g.bind("ex", EXNS) + + Individual.factoryGraph = g fire = Class(EXNS.Fire) water = Class(EXNS.Water) @@ -331,10 +326,14 @@ def test_booleanclassextenthelper(graph): assert str(tc2) == "( ex:Fire OR ex:Water )" -def test_changeoperator(graph): +def test_changeoperator(): # Converts a unionOf / intersectionOf class expression into one # that instead uses the given operator + g = Graph(identifier=context0) + g.bind("ex", EXNS) + Individual.factoryGraph = g + fire = Class(EXNS.Fire) water = Class(EXNS.Water) @@ -351,20 +350,26 @@ def test_changeoperator(graph): assert str(e) == "The new operator is already being used!" -def test_cardinality_zero(graph): +def test_cardinality_zero(): + + g = Graph() + g.bind("ex", EXNS) prop = Property(EXNS.someProp, baseType=OWL.DatatypeProperty) r = Restriction( - prop, graph=graph, cardinality=Literal(0, datatype=XSD.nonNegativeInteger) + prop, graph=g, cardinality=Literal(0, datatype=XSD.nonNegativeInteger) ) assert str(r) == "( ex:someProp EQUALS 0 )" -def test_textual_infix_operators(graph): +def test_textual_infix_operators(): + g = Graph() + g.bind("ex", EXNS) + Individual.factoryGraph = g isPartOf = Property(EXNS.isPartOf) # noqa: N806 - graph.add((isPartOf.identifier, RDF.type, OWL.TransitiveProperty)) + g.add((isPartOf.identifier, RDF.type, OWL.TransitiveProperty)) knee = EXCL.Knee diff --git a/test/test_extras/test_infixowl/test_restriction.py b/test/test_extras/test_infixowl/test_restriction.py index 24cb958fb..050df4171 100644 --- a/test/test_extras/test_infixowl/test_restriction.py +++ b/test/test_extras/test_infixowl/test_restriction.py @@ -1,7 +1,7 @@ import pytest -from rdflib import OWL, XSD, BNode, Graph, Literal, Namespace, URIRef -from rdflib.extras.infixowl import Class, Individual, Property, Restriction, some +from rdflib import OWL, XSD, BNode, Graph, Literal, Namespace, URIRef, logger +from rdflib.extras.infixowl import Class, Individual, Property, Restriction, max, some EXNS = Namespace("http://example.org/vocab/") PZNS = Namespace( @@ -61,7 +61,6 @@ def test_restriction_range(graph): assert r1.__eq__(Class(EXNS.NoClass)) is False -@pytest.mark.xfail(reason="assert len(validRestrProps) fails to handle None") def test_restriction_onproperty(graph): r = Restriction( @@ -123,18 +122,6 @@ def test_restriction_inputs_with_identifier(graph): ) -@pytest.mark.xfail(reason="_set_allValues fails to handle None") -def test_restriction_allvalues_nonefail(graph): - - r = Restriction( - onProperty=EXNS.hasChild, - graph=graph, - allValuesFrom=EXNS.Human, - ) - - r.allValuesFrom = None - - def test_restriction_allvalues(graph): r = Restriction( @@ -146,6 +133,8 @@ def test_restriction_allvalues(graph): av = r.allValuesFrom assert av == Class(EXNS.Human) + r.allValuesFrom = None + r.allValuesFrom = Class(EXNS.Human) r.allValuesFrom = Class(EXNS.Parent) @@ -155,18 +144,6 @@ def test_restriction_allvalues(graph): assert r.allValuesFrom is None -@pytest.mark.xfail(reason="_set_someValues fails to handle None") -def test_restriction_somevalues_nonefail(graph): - - r = Restriction( - onProperty=EXNS.hasChild, - graph=graph, - someValuesFrom=EXNS.Parent, - ) - - r.someValuesFrom = None - - def test_restriction_somevalues(graph): r = Restriction( @@ -184,6 +161,8 @@ def test_restriction_somevalues(graph): # Does not need to be Class r.someValuesFrom = EXNS.Parent + r.someValuesFrom = None + r.someValuesFrom = Class(EXNS.Human) del r.someValuesFrom @@ -191,18 +170,6 @@ def test_restriction_somevalues(graph): assert r.someValuesFrom is None -@pytest.mark.xfail(reason="_set_hasValue fails to handle None") -def test_restriction_hasvalue_nonefail(graph): - - r = Restriction( - onProperty=EXNS.hasChild, - graph=graph, - value=EXNS.Parent, - ) - - r.hasValue = None - - def test_restriction_hasvalue(graph): r = Restriction( @@ -216,6 +183,8 @@ def test_restriction_hasvalue(graph): # Needs to be Class to match initialisation r.hasValue = Class(EXNS.Parent) + r.hasValue = None + r.hasValue = EXNS.Parent r.hasValue = EXNS.Human @@ -225,18 +194,6 @@ def test_restriction_hasvalue(graph): assert r.hasValue is None -@pytest.mark.xfail(reason="_set_Cardinality fails to handle None") -def test_restriction_cardinality_nonefail(graph): - - r = Restriction( - onProperty=EXNS.hasChild, - graph=graph, - cardinality=OWL.cardinality, - ) - - r.cardinality = None - - def test_restriction_cardinality(graph): r = Restriction( @@ -249,6 +206,8 @@ def test_restriction_cardinality(graph): r.cardinality = OWL.cardinality + r.cardinality = None + r.cardinality = EXNS.foo del r.cardinality @@ -282,6 +241,7 @@ def test_restriction_cardinality_value(graph): assert str(r.cardinality) == "Some Class " +@pytest.mark.xfail(reason="_set_cardinality fails to handle Literal") def test_restriction_cardinality_set_value(graph): r = Restriction( @@ -306,16 +266,6 @@ def test_restriction_cardinality_set_value(graph): assert str(r.cardinality) == "Class: owl:cardinality " - -@pytest.mark.xfail(reason="_set_cardinality fails to handle Literal") -def test_restriction_cardinality_set_value_literal_fail(graph): - - r = Restriction( - onProperty=EXNS.hasChild, - graph=graph, - cardinality=OWL.cardinality, - ) - r.cardinality = Literal("0", datatype=XSD.nonNegativeInteger) assert ( @@ -323,18 +273,6 @@ def test_restriction_cardinality_set_value_literal_fail(graph): ) -@pytest.mark.xfail(reason="_set_minCardinality fails to handle None") -def test_restriction_maxcardinality_nonefail(graph): - - r = Restriction( - onProperty=EXNS.hasChild, - graph=graph, - maxCardinality=OWL.maxCardinality, - ) - - r.maxCardinality = None - - def test_restriction_maxcardinality(graph): r = Restriction( @@ -347,6 +285,8 @@ def test_restriction_maxcardinality(graph): r.maxCardinality = OWL.maxCardinality + r.maxCardinality = None + r.maxCardinality = EXNS.foo del r.maxCardinality @@ -354,18 +294,6 @@ def test_restriction_maxcardinality(graph): assert r.maxCardinality is None -@pytest.mark.xfail(reason="_set_minCardinality fails to handle None") -def test_restriction_mincardinality_nonefail(graph): - - r = Restriction( - onProperty=EXNS.hasChild, - graph=graph, - minCardinality=OWL.minCardinality, - ) - - r.minCardinality = None - - def test_restriction_mincardinality(graph): r = Restriction( @@ -378,6 +306,8 @@ def test_restriction_mincardinality(graph): r.minCardinality = OWL.minCardinality + r.minCardinality = None + r.minCardinality = EXNS.foo del r.minCardinality @@ -385,7 +315,6 @@ def test_restriction_mincardinality(graph): assert r.minCardinality is None -@pytest.mark.xfail(reason="graph.triple_choices() call misspelt") def test_restriction_kind(graph): r = Restriction( @@ -396,7 +325,6 @@ def test_restriction_kind(graph): assert r.restrictionKind() == "minCardinality" -@pytest.mark.xfail(reason="graph.triple_choices() call misspelt") def test_deleted_restriction_kind(graph): r = Restriction( diff --git a/test/test_extras/test_infixowl/test_rubric.py b/test/test_extras/test_infixowl/test_rubric.py index 190229e29..0ff1207b3 100644 --- a/test/test_extras/test_infixowl/test_rubric.py +++ b/test/test_extras/test_infixowl/test_rubric.py @@ -1,11 +1,13 @@ -from rdflib import Namespace +from rdflib import BNode, ConjunctiveGraph, Dataset, Graph, Literal, Namespace, URIRef +from rdflib.extras.infixowl import Class, Property, classOrTerm +from rdflib.extras.infixowl import generateQName as generate_qname # noqa: N813 +from rdflib.extras.infixowl import propertyOrIdentifier EXNS = Namespace("http://example.org/vocab/") PZNS = Namespace( "http://www.co-ode.org/ontologies/pizza/2005/10/18/classified/pizza.owl#" ) - mansyn = """ Prefix: : Prefix: g: @@ -102,219 +104,89 @@ NonVegetarianPizza """ -""" -class Infix: - def __init__(self, function): - def __rlshift__(self, other): - def __rshift__(self, other): - def __rmatmul__(self, other): - def __matmul__(self, other): - def __call__(self, value1, value2): - -def generateQName(graph, uri): # noqa: N802 - -def classOrTerm(thing): # noqa: N802 - -def classOrIdentifier(thing): # noqa: N802 - -def propertyOrIdentifier(thing): # noqa: N802 - -def manchesterSyntax( # noqa: N802 - -def GetIdentifiedClasses(graph): # noqa: N802 - -class TermDeletionHelper: - def someFunc(func): # noqa: N802 - -def termDeletionDecorator(prop): # noqa: N802 - def __init__(self, prop): - def __call__(self, f): - -class Individual(object): - def serialize(self, graph): - def __init__(self, identifier=None, graph=None): - def clearInDegree(self): # noqa: N802 - def clearOutDegree(self): # noqa: N802 - def delete(self): - def replace(self, other): - def _get_type(self): - def _set_type(self, kind): - def _delete_type(self): - def _get_identifier(self): - def _set_identifier(self, i): - def _get_sameAs(self): # noqa: N802 - def _set_sameAs(self, term): # noqa: N802 - def _delete_sameAs(self): # noqa: N802 - -class AnnotatableTerms(Individual): - def __init__( - def handleAnnotation(self, val): # noqa: N802 - def setupACEAnnotations(self): # noqa: N802 - def _get_comment(self): - def _set_comment(self, comment): - def _del_comment(self): - def _get_seeAlso(self): # noqa: N802 - def _set_seeAlso(self, seeAlsos): # noqa: N802, N803 - def _del_seeAlso(self): # noqa: N802 - def _get_label(self): - def _set_label(self, label): - def _delete_label(self): - -class Ontology(AnnotatableTerms): - def __init__(self, identifier=None, imports=None, comment=None, graph=None): - def setVersion(self, version): # noqa: N802 - def _get_imports(self): - def _set_imports(self, other): - def _del_imports(self): - -def AllClasses(graph): # noqa: N802 - -def AllProperties(graph): # noqa: N802 - -class ClassNamespaceFactory(Namespace): - def term(self, name): - def __getitem__(self, key, default=None): - def __getattr__(self, name): - -def ComponentTerms(cls): # noqa: N802 - -def DeepClassClear(classToPrune): # noqa: N802, N803 - def deepClearIfBNode(_class): # noqa: N802 - -class MalformedClassError(Exception): - def __init__(self, msg): - def __repr__(self): - -def CastClass(c, graph=None): # noqa: N802 - -class Class(AnnotatableTerms): - def _serialize(self, graph): - def serialize(self, graph): - def setupNounAnnotations(self, nounAnnotations): # noqa: N802, N803 - def __init__( - def _get_extent(self, graph=None): - def _set_extent(self, other): - def _del_type(self): - def _get_annotation(self, term=RDFS.label): - def _get_extentQuery(self): # noqa: N802 - def _set_extentQuery(self, other): # noqa: N802 - def __hash__(self): - def __eq__(self, other): - def __iadd__(self, other): - def __isub__(self, other): - def __invert__(self): - def __or__(self, other): - def __and__(self, other): - def _get_subClassOf(self): # noqa: N802 - def _set_subClassOf(self, other): # noqa: N802 - def _del_subClassOf(self): # noqa: N802 - def _get_equivalentClass(self): # noqa: N802 - def _set_equivalentClass(self, other): # noqa: N802 - def _del_equivalentClass(self): # noqa: N802 - def _get_disjointWith(self): # noqa: N802 - def _set_disjointWith(self, other): # noqa: N802 - def _del_disjointWith(self): # noqa: N802 - def _get_complementOf(self): # noqa: N802 - def _set_complementOf(self, other): # noqa: N802 - def _del_complementOf(self): # noqa: N802 - def _get_parents(self): - def isPrimitive(self): # noqa: N802 - def subSumpteeIds(self): # noqa: N802 - def __repr__(self, full=False, normalization=True): - - -class OWLRDFListProxy(object): - def __init__(self, rdfList, members=None, graph=None): # noqa: N803 - def __eq__(self, other): - def __len__(self): - def index(self, item): - def __getitem__(self, key): - def __setitem__(self, key, value): - def __delitem__(self, key): - def clear(self): - def __iter__(self): - def __contains__(self, item): - def append(self, item): - def __iadd__(self, other): - -class EnumeratedClass(OWLRDFListProxy, Class): - def isPrimitive(self): # noqa: N802 - def __init__(self, identifier=None, members=None, graph=None): - def __repr__(self): - def serialize(self, graph): - - -class BooleanClassExtentHelper: - def __init__(self, operator): - def __call__(self, f): - -class Callable: - def __init__(self, anycallable): - -class BooleanClass(OWLRDFListProxy, Class): - def getIntersections(): # type: ignore[misc] # noqa: N802 - def getUnions(): # type: ignore[misc] # noqa: N802 - def __init__( - def copy(self): - def serialize(self, graph): - def isPrimitive(self): # noqa: N802 - def changeOperator(self, newOperator): # noqa: N802, N803 - def __repr__(self): - def __or__(self, other): - -def AllDifferent(members): # noqa: N802 - -class Restriction(Class): - def __init__( - def serialize(self, graph): - def isPrimitive(self): # noqa: N802 - def __hash__(self): - def __eq__(self, other): - def _get_onProperty(self): # noqa: N802 - def _set_onProperty(self, prop): # noqa: N802 - def _del_onProperty(self): # noqa: N802 - def _get_allValuesFrom(self): # noqa: N802 - def _set_allValuesFrom(self, other): # noqa: N802 - def _del_allValuesFrom(self): # noqa: N802 - def _get_someValuesFrom(self): # noqa: N802 - def _set_someValuesFrom(self, other): # noqa: N802 - def _del_someValuesFrom(self): # noqa: N802 - def _get_hasValue(self): # noqa: N802 - def _set_hasValue(self, other): # noqa: N802 - def _del_hasValue(self): # noqa: N802 - def _get_cardinality(self): - def _set_cardinality(self, other): - def _del_cardinality(self): - def _get_maxCardinality(self): # noqa: N802 - def _set_maxCardinality(self, other): # noqa: N802 - def _del_maxCardinality(self): # noqa: N802 - def _get_minCardinality(self): # noqa: N802 - def _set_minCardinality(self, other): # noqa: N802 - def _del_minCardinality(self): # noqa: N802 - def restrictionKind(self): # noqa: N802 - def __repr__(self): - -class Property(AnnotatableTerms): - def setupVerbAnnotations(self, verbAnnotations): # noqa: N802, N803 - def __init__( - def serialize(self, graph): - def _get_extent(self, graph=None): - def _set_extent(self, other): - def __repr__(self): - def _get_subPropertyOf(self): # noqa: N802 - def _set_subPropertyOf(self, other): # noqa: N802 - def _del_subPropertyOf(self): # noqa: N802 - def _get_inverseOf(self): # noqa: N802 - def _set_inverseOf(self, other): # noqa: N802 - def _del_inverseOf(self): # noqa: N802 - def _get_domain(self): - def _set_domain(self, other): - def _del_domain(self): - def _get_range(self): - def _set_range(self, ranges): - def _del_range(self): - def replace(self, other): - -def CommonNSBindings(graph, additionalNS={}): # noqa: N802, N803 -""" +def test_generateqname_using_conjunctivegraph() -> None: + g = ConjunctiveGraph() + g.bind("ex", EXNS) + + assert ( + generate_qname(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" + ) + + +def test_generateqname_using_dataset() -> None: + g = Dataset() # type: ignore[no-untyped-call] + g.bind("ex", EXNS) + + assert ( + generate_qname(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" + ) + + +def test_generateqname_using_graph() -> None: + g = Graph() + g.bind("ex", EXNS) + + assert ( + generate_qname(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" + ) + + +def test_generateqname_using_graph_and_uriref() -> None: + g = Graph() + g.bind("ex", EXNS) + + res = generate_qname(g, URIRef("http://example.org/vocab/ontology")) + + assert res == "ex:ontology" + + +def test_generateqname_using_graph_and_bnode() -> None: + g = Graph() + g.bind("ex", EXNS) + + res = generate_qname(g, BNode("http://example.org/vocab/ontology")) + + assert res == "ex:ontology" + + res = generate_qname(g, BNode("urn:example:foo")) + + assert res == "ns1:foo" + + +def test_generateqname_using_graph_and_property() -> None: + g = Graph() + g.bind("ex", EXNS) + + iswoman_property = Property(identifier=EXNS.iswoman, graph=g) + + res = generate_qname(g, iswoman_property) + + assert res == "ex:iswoman" + + +def test_class_or_term() -> None: + uriref_term = URIRef("http://example.org/vocab/D") + bnode_term = BNode("http://example.org/vocab/D") + literal_term = Literal("http://example.org/vocab/D") + + assert classOrTerm(Class(EXNS.D)) == uriref_term + assert classOrTerm(uriref_term) == uriref_term + assert classOrTerm(bnode_term) == bnode_term + assert classOrTerm(literal_term) == literal_term + + +def test_property_or_identifier() -> None: + + g = Graph() + g.bind("ex", EXNS) + + is_a_woman = Property(identifier=EXNS.iswoman, graph=g) + + assert propertyOrIdentifier(is_a_woman) == URIRef( + "http://example.org/vocab/iswoman" + ) + + uriref_term = URIRef("http://example.org/vocab/D") + + assert propertyOrIdentifier(uriref_term) == URIRef("http://example.org/vocab/D") From 893282dd4c1f0f4295643e052ae827cfa1435b05 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 15 Jul 2022 18:41:01 +0100 Subject: [PATCH 10/15] fix Unused "type: ignore" comment --- test/test_extras/test_infixowl/test_rubric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_extras/test_infixowl/test_rubric.py b/test/test_extras/test_infixowl/test_rubric.py index 0ff1207b3..bd12f80ac 100644 --- a/test/test_extras/test_infixowl/test_rubric.py +++ b/test/test_extras/test_infixowl/test_rubric.py @@ -115,7 +115,7 @@ def test_generateqname_using_conjunctivegraph() -> None: def test_generateqname_using_dataset() -> None: - g = Dataset() # type: ignore[no-untyped-call] + g = Dataset() g.bind("ex", EXNS) assert ( From 90d8ad1a85248649699c7fdf82985b7ac42662fd Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 15 Jul 2022 18:52:23 +0100 Subject: [PATCH 11/15] remove unused imports from test --- test/test_extras/test_infixowl/test_restriction.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_extras/test_infixowl/test_restriction.py b/test/test_extras/test_infixowl/test_restriction.py index 050df4171..ca621a1b6 100644 --- a/test/test_extras/test_infixowl/test_restriction.py +++ b/test/test_extras/test_infixowl/test_restriction.py @@ -1,7 +1,7 @@ import pytest -from rdflib import OWL, XSD, BNode, Graph, Literal, Namespace, URIRef, logger -from rdflib.extras.infixowl import Class, Individual, Property, Restriction, max, some +from rdflib import OWL, XSD, BNode, Graph, Literal, Namespace, URIRef +from rdflib.extras.infixowl import Class, Individual, Property, Restriction, some EXNS = Namespace("http://example.org/vocab/") PZNS = Namespace( From 87fad416e58f1bb5b4890da6f299d076f128c3bd Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Fri, 15 Jul 2022 21:36:56 +0100 Subject: [PATCH 12/15] Fix sphinx issue with docucomment --- rdflib/extras/infixowl.py | 67 ++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/rdflib/extras/infixowl.py b/rdflib/extras/infixowl.py index 35a571077..4295e1699 100644 --- a/rdflib/extras/infixowl.py +++ b/rdflib/extras/infixowl.py @@ -486,48 +486,47 @@ class AnnotatableTerms(Individual): Terms in an OWL ontology with rdfs:label and rdfs:comment - Interface with ATTEMPTO (http://attempto.ifi.uzh.ch/site) + ## Interface with ATTEMPTO (http://attempto.ifi.uzh.ch/site) - Verbalisation of OWL entity IRIS - ================================ + ### Verbalisation of OWL entity IRIS - How are OWL entity IRIs verbalized? - ----------------------------------- + #### How are OWL entity IRIs verbalized? The OWL verbalizer maps OWL entity IRIs to ACE content words such that - OWL individuals map to ACE proper names (PN) - OWL classes map to ACE common nouns (CN) - OWL properties map to ACE transitive verbs (TV) + - OWL individuals map to ACE proper names (PN) + - OWL classes map to ACE common nouns (CN) + - OWL properties map to ACE transitive verbs (TV) There are 6 morphological categories that determine the surface form of an IRI: - singular form of a proper name (e.g. John) - singular form of a common noun (e.g. man) - plural form of a common noun (e.g. men) - singular form of a transitive verb (e.g. mans) - plural form of a transitive verb (e.g. man) - past participle form a transitive verb (e.g. manned) + - singular form of a proper name (e.g. John) + - singular form of a common noun (e.g. man) + - plural form of a common noun (e.g. men) + - singular form of a transitive verb (e.g. mans) + - plural form of a transitive verb (e.g. man) + - past participle form a transitive verb (e.g. manned) The user has full control over the eventual surface forms of the IRIs but has to choose them in terms of the above categories. Furthermore, - - the surface forms must be legal ACE content words (e.g. they - should not contain punctuation symbols); - - the mapping of IRIs to surface forms must be bidirectional - within the same word class, in order to be able to (if needed) - parse the verbalization back into OWL in a semantics preserving - way. + - the surface forms must be legal ACE content words (e.g. they + should not contain punctuation symbols); + - the mapping of IRIs to surface forms must be bidirectional + within the same word class, in order to be able to (if needed) + parse the verbalization back into OWL in a semantics preserving + way. - Using the lexicon - ----------------- + ### Using the lexicon It is possible to specify the mapping of IRIs to surface forms using the following annotation properties: + .. code-block:: none + http://attempto.ifi.uzh.ch/ace_lexicon#PN_sg http://attempto.ifi.uzh.ch/ace_lexicon#CN_sg http://attempto.ifi.uzh.ch/ace_lexicon#CN_pl @@ -540,17 +539,19 @@ class AnnotatableTerms(Individual): verbalizer. If, however, it is used as a singular transitive verb, then mans must be used. - - - #man - men - - - - - #man - mans - + .. code-block:: none + + + + #man + men + + + + + #man + mans + """ From 0d818bc5e9b6306d7a4c5a295a8ff3e484836601 Mon Sep 17 00:00:00 2001 From: Iwan Aucamp Date: Sat, 16 Jul 2022 23:08:57 +0200 Subject: [PATCH 13/15] Update changelog and restore MalformedClass (exception) --- CHANGELOG.md | 28 ++ rdflib/extras/infixowl.py | 12 +- test/test_extras/test_infixowl/test_rubric.py | 306 +++++++++++++----- test_reports/rdflib_w3c_sparql10-HEAD.ttl | 2 +- 4 files changed, 257 insertions(+), 91 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 356a961f6..d20e086d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,34 @@ and will be removed for release. +- InfixOWL fixes and cleanup. + [PR #2024](https://github.com/RDFLib/rdflib/pull/2024). + - `rdflib.extras.infixowl.Restriction.__init__` will now raise a `ValueError` + if there is no restriction value instead of an `AssertionError`. + - Fixed numerous issues with + `rdflib.extras.infixowl.Restriction.restrictionKind` which was essentially + not working at all. + - Fixed how `rdflib.extras.infixowl.Property.__repr__` uses + `rdflib.namespace.OWL`. + - Removed `rdflib.extras.infixowl.Infix.__ror__` and + `rdflib.extras.infixowl.Infix.__or__` as they were broken. + - Removed unused `rdflib.extras.infixowl.termDeletionDecorator`. + - Added `rdflib.extras.infixowl.MalformedClassError` which will replace + `rdflib.extras.infixowl.MalformedClass` (which is an exception) in the next + major version. + + + + + + + + + + + + + - Description of changes. Closed [issue #....](https://github.com/RDFLib/rdflib/issues/). [PR #....](https://ichard26.github.io/next-pr-number/?owner=RDFLib&name=rdflib). diff --git a/rdflib/extras/infixowl.py b/rdflib/extras/infixowl.py index 4295e1699..a17eee3f6 100644 --- a/rdflib/extras/infixowl.py +++ b/rdflib/extras/infixowl.py @@ -148,6 +148,7 @@ "GetIdentifiedClasses", "Individual", "Infix", + "MalformedClass", "MalformedClassError", "OWLRDFListProxy", "Ontology", @@ -894,7 +895,16 @@ def deepClearIfBNode(_class): # noqa: N802 ) -class MalformedClassError(Exception): +class MalformedClass(ValueError): + """ + .. deprecated:: TODO-NEXT-VERSION + This class will be removed in version ``7.0.0``. + """ + + pass + + +class MalformedClassError(MalformedClass): def __init__(self, msg): self.msg = msg diff --git a/test/test_extras/test_infixowl/test_rubric.py b/test/test_extras/test_infixowl/test_rubric.py index bd12f80ac..190229e29 100644 --- a/test/test_extras/test_infixowl/test_rubric.py +++ b/test/test_extras/test_infixowl/test_rubric.py @@ -1,13 +1,11 @@ -from rdflib import BNode, ConjunctiveGraph, Dataset, Graph, Literal, Namespace, URIRef -from rdflib.extras.infixowl import Class, Property, classOrTerm -from rdflib.extras.infixowl import generateQName as generate_qname # noqa: N813 -from rdflib.extras.infixowl import propertyOrIdentifier +from rdflib import Namespace EXNS = Namespace("http://example.org/vocab/") PZNS = Namespace( "http://www.co-ode.org/ontologies/pizza/2005/10/18/classified/pizza.owl#" ) + mansyn = """ Prefix: : Prefix: g: @@ -104,89 +102,219 @@ NonVegetarianPizza """ +""" +class Infix: + def __init__(self, function): + def __rlshift__(self, other): + def __rshift__(self, other): + def __rmatmul__(self, other): + def __matmul__(self, other): + def __call__(self, value1, value2): + +def generateQName(graph, uri): # noqa: N802 + +def classOrTerm(thing): # noqa: N802 + +def classOrIdentifier(thing): # noqa: N802 + +def propertyOrIdentifier(thing): # noqa: N802 + +def manchesterSyntax( # noqa: N802 + +def GetIdentifiedClasses(graph): # noqa: N802 + +class TermDeletionHelper: + def someFunc(func): # noqa: N802 + +def termDeletionDecorator(prop): # noqa: N802 + def __init__(self, prop): + def __call__(self, f): + +class Individual(object): + def serialize(self, graph): + def __init__(self, identifier=None, graph=None): + def clearInDegree(self): # noqa: N802 + def clearOutDegree(self): # noqa: N802 + def delete(self): + def replace(self, other): + def _get_type(self): + def _set_type(self, kind): + def _delete_type(self): + def _get_identifier(self): + def _set_identifier(self, i): + def _get_sameAs(self): # noqa: N802 + def _set_sameAs(self, term): # noqa: N802 + def _delete_sameAs(self): # noqa: N802 + +class AnnotatableTerms(Individual): + def __init__( + def handleAnnotation(self, val): # noqa: N802 + def setupACEAnnotations(self): # noqa: N802 + def _get_comment(self): + def _set_comment(self, comment): + def _del_comment(self): + def _get_seeAlso(self): # noqa: N802 + def _set_seeAlso(self, seeAlsos): # noqa: N802, N803 + def _del_seeAlso(self): # noqa: N802 + def _get_label(self): + def _set_label(self, label): + def _delete_label(self): + +class Ontology(AnnotatableTerms): + def __init__(self, identifier=None, imports=None, comment=None, graph=None): + def setVersion(self, version): # noqa: N802 + def _get_imports(self): + def _set_imports(self, other): + def _del_imports(self): + +def AllClasses(graph): # noqa: N802 + +def AllProperties(graph): # noqa: N802 + +class ClassNamespaceFactory(Namespace): + def term(self, name): + def __getitem__(self, key, default=None): + def __getattr__(self, name): + +def ComponentTerms(cls): # noqa: N802 + +def DeepClassClear(classToPrune): # noqa: N802, N803 + def deepClearIfBNode(_class): # noqa: N802 + +class MalformedClassError(Exception): + def __init__(self, msg): + def __repr__(self): + +def CastClass(c, graph=None): # noqa: N802 + +class Class(AnnotatableTerms): + def _serialize(self, graph): + def serialize(self, graph): + def setupNounAnnotations(self, nounAnnotations): # noqa: N802, N803 + def __init__( + def _get_extent(self, graph=None): + def _set_extent(self, other): + def _del_type(self): + def _get_annotation(self, term=RDFS.label): + def _get_extentQuery(self): # noqa: N802 + def _set_extentQuery(self, other): # noqa: N802 + def __hash__(self): + def __eq__(self, other): + def __iadd__(self, other): + def __isub__(self, other): + def __invert__(self): + def __or__(self, other): + def __and__(self, other): + def _get_subClassOf(self): # noqa: N802 + def _set_subClassOf(self, other): # noqa: N802 + def _del_subClassOf(self): # noqa: N802 + def _get_equivalentClass(self): # noqa: N802 + def _set_equivalentClass(self, other): # noqa: N802 + def _del_equivalentClass(self): # noqa: N802 + def _get_disjointWith(self): # noqa: N802 + def _set_disjointWith(self, other): # noqa: N802 + def _del_disjointWith(self): # noqa: N802 + def _get_complementOf(self): # noqa: N802 + def _set_complementOf(self, other): # noqa: N802 + def _del_complementOf(self): # noqa: N802 + def _get_parents(self): + def isPrimitive(self): # noqa: N802 + def subSumpteeIds(self): # noqa: N802 + def __repr__(self, full=False, normalization=True): + + +class OWLRDFListProxy(object): + def __init__(self, rdfList, members=None, graph=None): # noqa: N803 + def __eq__(self, other): + def __len__(self): + def index(self, item): + def __getitem__(self, key): + def __setitem__(self, key, value): + def __delitem__(self, key): + def clear(self): + def __iter__(self): + def __contains__(self, item): + def append(self, item): + def __iadd__(self, other): + +class EnumeratedClass(OWLRDFListProxy, Class): + def isPrimitive(self): # noqa: N802 + def __init__(self, identifier=None, members=None, graph=None): + def __repr__(self): + def serialize(self, graph): + + +class BooleanClassExtentHelper: + def __init__(self, operator): + def __call__(self, f): + +class Callable: + def __init__(self, anycallable): + +class BooleanClass(OWLRDFListProxy, Class): + def getIntersections(): # type: ignore[misc] # noqa: N802 + def getUnions(): # type: ignore[misc] # noqa: N802 + def __init__( + def copy(self): + def serialize(self, graph): + def isPrimitive(self): # noqa: N802 + def changeOperator(self, newOperator): # noqa: N802, N803 + def __repr__(self): + def __or__(self, other): + +def AllDifferent(members): # noqa: N802 + +class Restriction(Class): + def __init__( + def serialize(self, graph): + def isPrimitive(self): # noqa: N802 + def __hash__(self): + def __eq__(self, other): + def _get_onProperty(self): # noqa: N802 + def _set_onProperty(self, prop): # noqa: N802 + def _del_onProperty(self): # noqa: N802 + def _get_allValuesFrom(self): # noqa: N802 + def _set_allValuesFrom(self, other): # noqa: N802 + def _del_allValuesFrom(self): # noqa: N802 + def _get_someValuesFrom(self): # noqa: N802 + def _set_someValuesFrom(self, other): # noqa: N802 + def _del_someValuesFrom(self): # noqa: N802 + def _get_hasValue(self): # noqa: N802 + def _set_hasValue(self, other): # noqa: N802 + def _del_hasValue(self): # noqa: N802 + def _get_cardinality(self): + def _set_cardinality(self, other): + def _del_cardinality(self): + def _get_maxCardinality(self): # noqa: N802 + def _set_maxCardinality(self, other): # noqa: N802 + def _del_maxCardinality(self): # noqa: N802 + def _get_minCardinality(self): # noqa: N802 + def _set_minCardinality(self, other): # noqa: N802 + def _del_minCardinality(self): # noqa: N802 + def restrictionKind(self): # noqa: N802 + def __repr__(self): + +class Property(AnnotatableTerms): + def setupVerbAnnotations(self, verbAnnotations): # noqa: N802, N803 + def __init__( + def serialize(self, graph): + def _get_extent(self, graph=None): + def _set_extent(self, other): + def __repr__(self): + def _get_subPropertyOf(self): # noqa: N802 + def _set_subPropertyOf(self, other): # noqa: N802 + def _del_subPropertyOf(self): # noqa: N802 + def _get_inverseOf(self): # noqa: N802 + def _set_inverseOf(self, other): # noqa: N802 + def _del_inverseOf(self): # noqa: N802 + def _get_domain(self): + def _set_domain(self, other): + def _del_domain(self): + def _get_range(self): + def _set_range(self, ranges): + def _del_range(self): + def replace(self, other): + +def CommonNSBindings(graph, additionalNS={}): # noqa: N802, N803 -def test_generateqname_using_conjunctivegraph() -> None: - g = ConjunctiveGraph() - g.bind("ex", EXNS) - - assert ( - generate_qname(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" - ) - - -def test_generateqname_using_dataset() -> None: - g = Dataset() - g.bind("ex", EXNS) - - assert ( - generate_qname(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" - ) - - -def test_generateqname_using_graph() -> None: - g = Graph() - g.bind("ex", EXNS) - - assert ( - generate_qname(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" - ) - - -def test_generateqname_using_graph_and_uriref() -> None: - g = Graph() - g.bind("ex", EXNS) - - res = generate_qname(g, URIRef("http://example.org/vocab/ontology")) - - assert res == "ex:ontology" - - -def test_generateqname_using_graph_and_bnode() -> None: - g = Graph() - g.bind("ex", EXNS) - - res = generate_qname(g, BNode("http://example.org/vocab/ontology")) - - assert res == "ex:ontology" - - res = generate_qname(g, BNode("urn:example:foo")) - - assert res == "ns1:foo" - - -def test_generateqname_using_graph_and_property() -> None: - g = Graph() - g.bind("ex", EXNS) - - iswoman_property = Property(identifier=EXNS.iswoman, graph=g) - - res = generate_qname(g, iswoman_property) - - assert res == "ex:iswoman" - - -def test_class_or_term() -> None: - uriref_term = URIRef("http://example.org/vocab/D") - bnode_term = BNode("http://example.org/vocab/D") - literal_term = Literal("http://example.org/vocab/D") - - assert classOrTerm(Class(EXNS.D)) == uriref_term - assert classOrTerm(uriref_term) == uriref_term - assert classOrTerm(bnode_term) == bnode_term - assert classOrTerm(literal_term) == literal_term - - -def test_property_or_identifier() -> None: - - g = Graph() - g.bind("ex", EXNS) - - is_a_woman = Property(identifier=EXNS.iswoman, graph=g) - - assert propertyOrIdentifier(is_a_woman) == URIRef( - "http://example.org/vocab/iswoman" - ) - - uriref_term = URIRef("http://example.org/vocab/D") - - assert propertyOrIdentifier(uriref_term) == URIRef("http://example.org/vocab/D") +""" diff --git a/test_reports/rdflib_w3c_sparql10-HEAD.ttl b/test_reports/rdflib_w3c_sparql10-HEAD.ttl index 0852d69ec..5a05e8d32 100644 --- a/test_reports/rdflib_w3c_sparql10-HEAD.ttl +++ b/test_reports/rdflib_w3c_sparql10-HEAD.ttl @@ -1483,7 +1483,7 @@ earl:assertedBy ; earl:mode earl:automatic ; earl:result [ a earl:TestResult ; - earl:outcome earl:failed ] ; + earl:outcome earl:passed ] ; earl:subject ; earl:test . From 3cc372d51c9a47c919ecde59b9d42b93c1328993 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Sun, 17 Jul 2022 10:06:43 +0100 Subject: [PATCH 14/15] remove devel detritus from test_rubric and restore misc tests of rubric. --- test/test_extras/test_infixowl/test_rubric.py | 300 +++++------------- 1 file changed, 85 insertions(+), 215 deletions(-) diff --git a/test/test_extras/test_infixowl/test_rubric.py b/test/test_extras/test_infixowl/test_rubric.py index 190229e29..f7fc96c43 100644 --- a/test/test_extras/test_infixowl/test_rubric.py +++ b/test/test_extras/test_infixowl/test_rubric.py @@ -102,219 +102,89 @@ NonVegetarianPizza """ -""" -class Infix: - def __init__(self, function): - def __rlshift__(self, other): - def __rshift__(self, other): - def __rmatmul__(self, other): - def __matmul__(self, other): - def __call__(self, value1, value2): - -def generateQName(graph, uri): # noqa: N802 - -def classOrTerm(thing): # noqa: N802 - -def classOrIdentifier(thing): # noqa: N802 - -def propertyOrIdentifier(thing): # noqa: N802 - -def manchesterSyntax( # noqa: N802 - -def GetIdentifiedClasses(graph): # noqa: N802 - -class TermDeletionHelper: - def someFunc(func): # noqa: N802 - -def termDeletionDecorator(prop): # noqa: N802 - def __init__(self, prop): - def __call__(self, f): - -class Individual(object): - def serialize(self, graph): - def __init__(self, identifier=None, graph=None): - def clearInDegree(self): # noqa: N802 - def clearOutDegree(self): # noqa: N802 - def delete(self): - def replace(self, other): - def _get_type(self): - def _set_type(self, kind): - def _delete_type(self): - def _get_identifier(self): - def _set_identifier(self, i): - def _get_sameAs(self): # noqa: N802 - def _set_sameAs(self, term): # noqa: N802 - def _delete_sameAs(self): # noqa: N802 - -class AnnotatableTerms(Individual): - def __init__( - def handleAnnotation(self, val): # noqa: N802 - def setupACEAnnotations(self): # noqa: N802 - def _get_comment(self): - def _set_comment(self, comment): - def _del_comment(self): - def _get_seeAlso(self): # noqa: N802 - def _set_seeAlso(self, seeAlsos): # noqa: N802, N803 - def _del_seeAlso(self): # noqa: N802 - def _get_label(self): - def _set_label(self, label): - def _delete_label(self): - -class Ontology(AnnotatableTerms): - def __init__(self, identifier=None, imports=None, comment=None, graph=None): - def setVersion(self, version): # noqa: N802 - def _get_imports(self): - def _set_imports(self, other): - def _del_imports(self): - -def AllClasses(graph): # noqa: N802 - -def AllProperties(graph): # noqa: N802 - -class ClassNamespaceFactory(Namespace): - def term(self, name): - def __getitem__(self, key, default=None): - def __getattr__(self, name): - -def ComponentTerms(cls): # noqa: N802 - -def DeepClassClear(classToPrune): # noqa: N802, N803 - def deepClearIfBNode(_class): # noqa: N802 - -class MalformedClassError(Exception): - def __init__(self, msg): - def __repr__(self): - -def CastClass(c, graph=None): # noqa: N802 - -class Class(AnnotatableTerms): - def _serialize(self, graph): - def serialize(self, graph): - def setupNounAnnotations(self, nounAnnotations): # noqa: N802, N803 - def __init__( - def _get_extent(self, graph=None): - def _set_extent(self, other): - def _del_type(self): - def _get_annotation(self, term=RDFS.label): - def _get_extentQuery(self): # noqa: N802 - def _set_extentQuery(self, other): # noqa: N802 - def __hash__(self): - def __eq__(self, other): - def __iadd__(self, other): - def __isub__(self, other): - def __invert__(self): - def __or__(self, other): - def __and__(self, other): - def _get_subClassOf(self): # noqa: N802 - def _set_subClassOf(self, other): # noqa: N802 - def _del_subClassOf(self): # noqa: N802 - def _get_equivalentClass(self): # noqa: N802 - def _set_equivalentClass(self, other): # noqa: N802 - def _del_equivalentClass(self): # noqa: N802 - def _get_disjointWith(self): # noqa: N802 - def _set_disjointWith(self, other): # noqa: N802 - def _del_disjointWith(self): # noqa: N802 - def _get_complementOf(self): # noqa: N802 - def _set_complementOf(self, other): # noqa: N802 - def _del_complementOf(self): # noqa: N802 - def _get_parents(self): - def isPrimitive(self): # noqa: N802 - def subSumpteeIds(self): # noqa: N802 - def __repr__(self, full=False, normalization=True): - - -class OWLRDFListProxy(object): - def __init__(self, rdfList, members=None, graph=None): # noqa: N803 - def __eq__(self, other): - def __len__(self): - def index(self, item): - def __getitem__(self, key): - def __setitem__(self, key, value): - def __delitem__(self, key): - def clear(self): - def __iter__(self): - def __contains__(self, item): - def append(self, item): - def __iadd__(self, other): - -class EnumeratedClass(OWLRDFListProxy, Class): - def isPrimitive(self): # noqa: N802 - def __init__(self, identifier=None, members=None, graph=None): - def __repr__(self): - def serialize(self, graph): - - -class BooleanClassExtentHelper: - def __init__(self, operator): - def __call__(self, f): - -class Callable: - def __init__(self, anycallable): - -class BooleanClass(OWLRDFListProxy, Class): - def getIntersections(): # type: ignore[misc] # noqa: N802 - def getUnions(): # type: ignore[misc] # noqa: N802 - def __init__( - def copy(self): - def serialize(self, graph): - def isPrimitive(self): # noqa: N802 - def changeOperator(self, newOperator): # noqa: N802, N803 - def __repr__(self): - def __or__(self, other): - -def AllDifferent(members): # noqa: N802 - -class Restriction(Class): - def __init__( - def serialize(self, graph): - def isPrimitive(self): # noqa: N802 - def __hash__(self): - def __eq__(self, other): - def _get_onProperty(self): # noqa: N802 - def _set_onProperty(self, prop): # noqa: N802 - def _del_onProperty(self): # noqa: N802 - def _get_allValuesFrom(self): # noqa: N802 - def _set_allValuesFrom(self, other): # noqa: N802 - def _del_allValuesFrom(self): # noqa: N802 - def _get_someValuesFrom(self): # noqa: N802 - def _set_someValuesFrom(self, other): # noqa: N802 - def _del_someValuesFrom(self): # noqa: N802 - def _get_hasValue(self): # noqa: N802 - def _set_hasValue(self, other): # noqa: N802 - def _del_hasValue(self): # noqa: N802 - def _get_cardinality(self): - def _set_cardinality(self, other): - def _del_cardinality(self): - def _get_maxCardinality(self): # noqa: N802 - def _set_maxCardinality(self, other): # noqa: N802 - def _del_maxCardinality(self): # noqa: N802 - def _get_minCardinality(self): # noqa: N802 - def _set_minCardinality(self, other): # noqa: N802 - def _del_minCardinality(self): # noqa: N802 - def restrictionKind(self): # noqa: N802 - def __repr__(self): - -class Property(AnnotatableTerms): - def setupVerbAnnotations(self, verbAnnotations): # noqa: N802, N803 - def __init__( - def serialize(self, graph): - def _get_extent(self, graph=None): - def _set_extent(self, other): - def __repr__(self): - def _get_subPropertyOf(self): # noqa: N802 - def _set_subPropertyOf(self, other): # noqa: N802 - def _del_subPropertyOf(self): # noqa: N802 - def _get_inverseOf(self): # noqa: N802 - def _set_inverseOf(self, other): # noqa: N802 - def _del_inverseOf(self): # noqa: N802 - def _get_domain(self): - def _set_domain(self, other): - def _del_domain(self): - def _get_range(self): - def _set_range(self, ranges): - def _del_range(self): - def replace(self, other): - -def CommonNSBindings(graph, additionalNS={}): # noqa: N802, N803 -""" +def test_generateqname_using_conjunctivegraph() -> None: + g = ConjunctiveGraph() + g.bind("ex", EXNS) + + assert ( + generate_qname(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" + ) + + +def test_generateqname_using_dataset() -> None: + g = Dataset() + g.bind("ex", EXNS) + + assert ( + generate_qname(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" + ) + + +def test_generateqname_using_graph() -> None: + g = Graph() + g.bind("ex", EXNS) + + assert ( + generate_qname(g, URIRef("http://example.org/vocab/ontology")) == "ex:ontology" + ) + + +def test_generateqname_using_graph_and_uriref() -> None: + g = Graph() + g.bind("ex", EXNS) + + res = generate_qname(g, URIRef("http://example.org/vocab/ontology")) + + assert res == "ex:ontology" + + +def test_generateqname_using_graph_and_bnode() -> None: + g = Graph() + g.bind("ex", EXNS) + + res = generate_qname(g, BNode("http://example.org/vocab/ontology")) + + assert res == "ex:ontology" + + res = generate_qname(g, BNode("urn:example:foo")) + + assert res == "ns1:foo" + + +def test_generateqname_using_graph_and_property() -> None: + g = Graph() + g.bind("ex", EXNS) + + iswoman_property = Property(identifier=EXNS.iswoman, graph=g) + + res = generate_qname(g, iswoman_property) + + assert res == "ex:iswoman" + + +def test_class_or_term() -> None: + uriref_term = URIRef("http://example.org/vocab/D") + bnode_term = BNode("http://example.org/vocab/D") + literal_term = Literal("http://example.org/vocab/D") + + assert classOrTerm(Class(EXNS.D)) == uriref_term + assert classOrTerm(uriref_term) == uriref_term + assert classOrTerm(bnode_term) == bnode_term + assert classOrTerm(literal_term) == literal_term + + +def test_property_or_identifier() -> None: + + g = Graph() + g.bind("ex", EXNS) + + is_a_woman = Property(identifier=EXNS.iswoman, graph=g) + + assert propertyOrIdentifier(is_a_woman) == URIRef( + "http://example.org/vocab/iswoman" + ) + + uriref_term = URIRef("http://example.org/vocab/D") + + assert propertyOrIdentifier(uriref_term) == URIRef("http://example.org/vocab/D") From 908aa926b1954a9180c491ff0609c8cb8c341a47 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Sun, 17 Jul 2022 11:22:52 +0100 Subject: [PATCH 15/15] replace omitted imports --- test/test_extras/test_infixowl/test_rubric.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_extras/test_infixowl/test_rubric.py b/test/test_extras/test_infixowl/test_rubric.py index f7fc96c43..bd12f80ac 100644 --- a/test/test_extras/test_infixowl/test_rubric.py +++ b/test/test_extras/test_infixowl/test_rubric.py @@ -1,11 +1,13 @@ -from rdflib import Namespace +from rdflib import BNode, ConjunctiveGraph, Dataset, Graph, Literal, Namespace, URIRef +from rdflib.extras.infixowl import Class, Property, classOrTerm +from rdflib.extras.infixowl import generateQName as generate_qname # noqa: N813 +from rdflib.extras.infixowl import propertyOrIdentifier EXNS = Namespace("http://example.org/vocab/") PZNS = Namespace( "http://www.co-ode.org/ontologies/pizza/2005/10/18/classified/pizza.owl#" ) - mansyn = """ Prefix: : Prefix: g: