Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handling of URIs in the default namespace #2365

Merged
merged 7 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion rdflib/namespace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ def qname(self, uri: str) -> str:
else:
return ":".join((prefix, name))

def curie(self, uri: str) -> str:
"""From a URI, generate a valid CURIE.

Result is guaranteed to contain a colon separating the prefix from the name,
even if the prefix is an empty string.
"""
prefix, namespace, name = self.compute_qname(uri)
return ":".join((prefix, name))

def qname_strict(self, uri: str) -> str:
prefix, namespace, name = self.compute_qname_strict(uri)
if prefix == "":
Expand Down Expand Up @@ -643,7 +652,7 @@ def expand_curie(self, curie: str) -> URIRef:
if not type(curie) is str:
raise TypeError(f"Argument must be a string, not {type(curie).__name__}.")
parts = curie.split(":", 1)
if len(parts) != 2 or len(parts[0]) < 1:
if len(parts) != 2:
raise ValueError(
"Malformed curie argument, format should be e.g. “foaf:name”."
)
Expand Down
7 changes: 7 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
from contextlib import ExitStack

Expand Down Expand Up @@ -44,6 +45,12 @@ def rdfs_graph() -> Graph:
return Graph().parse(TEST_DATA_DIR / "defined_namespaces/rdfs.ttl", format="turtle")


@pytest.fixture(scope="session")
def test_owl_graph() -> Graph:
onto_path: str = os.path.join(TEST_DATA_DIR, "owl", "test_ontology.owl")
return Graph().parse(source=onto_path)


_ServedBaseHTTPServerMocks = Tuple[ServedBaseHTTPServerMock, ServedBaseHTTPServerMock]


Expand Down
315 changes: 315 additions & 0 deletions test/data/owl/test_ontology.owl
aucampia marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.example.org/ontologies/mini-ont#"
xml:base="http://www.example.org/ontologies/mini-ont"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:oboInOwl="http://www.geneontology.org/formats/oboInOwl#"
xmlns:mini-ont="http://example.org/ontologies/mini-ont#">
<owl:Ontology rdf:about="http://www.example.org/ontologies/mini-ont">
<dc:creator>Orson B Osborn</dc:creator>
<dc:title>Test OBO ontology</dc:title>
<owl:versionInfo>0.1.0</owl:versionInfo>
</owl:Ontology>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Annotation properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://purl.obolibrary.org/obo/IAO_0000111 -->

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000111">
<obo:IAO_0000111 xml:lang="en">editor preferred term</obo:IAO_0000111>
<obo:IAO_0000114 rdf:resource="http://purl.obolibrary.org/obo/IAO_0000122"/>
<obo:IAO_0000115 xml:lang="en">The concise, meaningful, and human-friendly name for a class or property preferred by the ontology developers. (US-English)</obo:IAO_0000115>
<obo:IAO_0000117 xml:lang="en">PERSON:Daniel Schober</obo:IAO_0000117>
<obo:IAO_0000119 xml:lang="en">GROUP:OBI:&lt;http://purl.obolibrary.org/obo/obi&gt;</obo:IAO_0000119>
<rdfs:isDefinedBy rdf:resource="http://purl.obolibrary.org/obo/iao.owl"/>
<rdfs:label xml:lang="en">editor preferred term</rdfs:label>
</owl:AnnotationProperty>



<!-- http://purl.obolibrary.org/obo/IAO_0000112 -->

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000112">
<obo:IAO_0000111 xml:lang="en">example</obo:IAO_0000111>
<obo:IAO_0000111 xml:lang="en">example of usage</obo:IAO_0000111>
<obo:IAO_0000114 rdf:resource="http://purl.obolibrary.org/obo/IAO_0000122"/>
<obo:IAO_0000115 xml:lang="en">A phrase describing how a class name should be used. May also include other kinds of examples that facilitate immediate understanding of a class semantics, such as widely known prototypical subclasses or instances of the class. Although essential for high level terms, examples for low level terms (e.g., Affymetrix HU133 array) are not</obo:IAO_0000115>
<obo:IAO_0000115 xml:lang="en">A phrase describing how a term should be used and/or a citation to a work which uses it. May also include other kinds of examples that facilitate immediate understanding, such as widely know prototypes or instances of a class, or cases where a relation is said to hold.</obo:IAO_0000115>
<obo:IAO_0000117 xml:lang="en">PERSON:Daniel Schober</obo:IAO_0000117>
<obo:IAO_0000119 xml:lang="en">GROUP:OBI:&lt;http://purl.obolibrary.org/obo/obi&gt;</obo:IAO_0000119>
<oboInOwl:hasDbXref>IAO:0000112</oboInOwl:hasDbXref>
<oboInOwl:hasOBONamespace>uberon</oboInOwl:hasOBONamespace>
<oboInOwl:id>example_of_usage</oboInOwl:id>
<oboInOwl:is_metadata_tag rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</oboInOwl:is_metadata_tag>
<oboInOwl:shorthand>example_of_usage</oboInOwl:shorthand>
<rdfs:isDefinedBy rdf:resource="http://purl.obolibrary.org/obo/iao.owl"/>
<rdfs:label xml:lang="en">example of usage</rdfs:label>
</owl:AnnotationProperty>



<!-- http://purl.obolibrary.org/obo/IAO_0000114 -->

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000114">
<rdfs:label xml:lang="en">has curation status</rdfs:label>
</owl:AnnotationProperty>



<!-- http://purl.obolibrary.org/obo/IAO_0000115 -->

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000115">
<rdfs:label xml:lang="en">definition</rdfs:label>
</owl:AnnotationProperty>



<!-- http://purl.obolibrary.org/obo/IAO_0000117 -->

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000117">
<rdfs:label xml:lang="en">term editor</rdfs:label>
</owl:AnnotationProperty>



<!-- http://purl.obolibrary.org/obo/IAO_0000118 -->

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000118">
<rdfs:label xml:lang="en">alternative term</rdfs:label>
</owl:AnnotationProperty>



<!-- http://purl.obolibrary.org/obo/IAO_0000119 -->

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000119">
<rdfs:label xml:lang="en">definition source</rdfs:label>
</owl:AnnotationProperty>



<!-- http://purl.obolibrary.org/obo/RO_0002575 -->

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/RO_0002575">
<rdfs:label>is direct form of</rdfs:label>
</owl:AnnotationProperty>



<!-- http://purl.org/dc/elements/1.1/creator -->

<owl:AnnotationProperty rdf:about="http://purl.org/dc/elements/1.1/creator"/>



<!-- http://purl.org/dc/elements/1.1/title -->

<owl:AnnotationProperty rdf:about="http://purl.org/dc/elements/1.1/title"/>



<!-- http://www.geneontology.org/formats/oboInOwl#created_by -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#created_by"/>



<!-- http://www.geneontology.org/formats/oboInOwl#creation_date -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#creation_date"/>



<!-- http://www.geneontology.org/formats/oboInOwl#hasDbXref -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasDbXref"/>



<!-- http://www.geneontology.org/formats/oboInOwl#hasOBONamespace -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasOBONamespace"/>



<!-- http://www.geneontology.org/formats/oboInOwl#id -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#id"/>



<!-- http://www.geneontology.org/formats/oboInOwl#inSubset -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#inSubset"/>



<!-- http://www.geneontology.org/formats/oboInOwl#is_metadata_tag -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#is_metadata_tag"/>



<!-- http://www.geneontology.org/formats/oboInOwl#shorthand -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#shorthand"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://purl.obolibrary.org/obo/BFO_0000063 -->

<owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/BFO_0000063">
<rdfs:subPropertyOf rdf:resource="http://purl.obolibrary.org/obo/RO_0002222"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty"/>
<obo:IAO_0000111 xml:lang="en">precedes</obo:IAO_0000111>
<obo:IAO_0000115 xml:lang="en">x precedes y if and only if the time point at which x ends is before or equivalent to the time point at which y starts. Formally: x precedes y iff ω(x) &lt;= α(y), where α is a function that maps a process to a start point, and ω is a function that maps a process to an end point.</obo:IAO_0000115>
<oboInOwl:hasDbXref>BFO:0000063</oboInOwl:hasDbXref>
<oboInOwl:hasOBONamespace>uberon</oboInOwl:hasOBONamespace>
<oboInOwl:id>precedes</oboInOwl:id>
<oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/ro/subsets#ro-eco"/>
<oboInOwl:shorthand>precedes</oboInOwl:shorthand>
<rdfs:label xml:lang="en">precedes</rdfs:label>
</owl:ObjectProperty>



<!-- http://purl.obolibrary.org/obo/RO_0002090 -->

<owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/RO_0002090">
<rdfs:subPropertyOf rdf:resource="http://purl.obolibrary.org/obo/BFO_0000063"/>
<obo:IAO_0000117>David Osumi-Sutherland</obo:IAO_0000117>
<obo:IAO_0000118>ends_at_start_of</obo:IAO_0000118>
<obo:IAO_0000118>meets</obo:IAO_0000118>
<obo:RO_0002575 rdf:resource="http://purl.obolibrary.org/obo/BFO_0000063"/>
<oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/ro/subsets#ro-eco"/>
<rdfs:comment xml:lang="en">X immediately_precedes_Y iff: end(X) simultaneous_with start(Y)</rdfs:comment>
<rdfs:label xml:lang="en">immediately precedes</rdfs:label>
</owl:ObjectProperty>



<!-- http://purl.obolibrary.org/obo/RO_0002222 -->

<owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/RO_0002222">
<rdfs:domain rdf:resource="http://purl.obolibrary.org/obo/BFO_0000003"/>
<rdfs:range rdf:resource="http://purl.obolibrary.org/obo/BFO_0000003"/>
<obo:IAO_0000117>Chris Mungall</obo:IAO_0000117>
<rdfs:comment>A relation that holds between two occurrents. This is a grouping relation that collects together all the Allen relations.</rdfs:comment>
<rdfs:label>temporally related to</rdfs:label>
</owl:ObjectProperty>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://purl.obolibrary.org/obo/BFO_0000001 -->

<owl:Class rdf:about="http://purl.obolibrary.org/obo/BFO_0000001">
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
<rdfs:label xml:lang="en">entity</rdfs:label>
</owl:Class>



<!-- http://purl.obolibrary.org/obo/BFO_0000002 -->

<owl:Class rdf:about="http://purl.obolibrary.org/obo/BFO_0000002">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/BFO_0000001"/>
<rdfs:label xml:lang="en">occurrent</rdfs:label>
</owl:Class>



<!-- http://purl.obolibrary.org/obo/BFO_0000003 -->

<owl:Class rdf:about="http://purl.obolibrary.org/obo/BFO_0000003">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/BFO_0000001"/>
<rdfs:label xml:lang="en">continuant</rdfs:label>
</owl:Class>



<!-- http://www.example.org/ontologies/mini-ont#chair -->

<owl:Class rdf:about="http://www.example.org/ontologies/mini-ont#chair">
<rdfs:subClassOf rdf:resource="http://www.example.org/ontologies/mini-ont#furniture_item"/>
<oboInOwl:created_by>Jeff Lerman</oboInOwl:created_by>
<oboInOwl:creation_date rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2023-03-29T00:33:04Z</oboInOwl:creation_date>
<rdfs:comment>This is a comment which will be a fallback definition.</rdfs:comment>
<rdfs:label>chair</rdfs:label>
</owl:Class>



<!-- http://www.example.org/ontologies/mini-ont#furniture_item -->

<owl:Class rdf:about="http://www.example.org/ontologies/mini-ont#furniture_item">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/BFO_0000003"/>
<oboInOwl:created_by>Jeff Lerman</oboInOwl:created_by>
<oboInOwl:creation_date rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2023-03-29T00:32:55Z</oboInOwl:creation_date>
<rdfs:label>furniture item</rdfs:label>
</owl:Class>



<!-- http://www.example.org/ontologies/mini-ont#office_chair -->

<owl:Class rdf:about="http://www.example.org/ontologies/mini-ont#office_chair">
<rdfs:subClassOf rdf:resource="http://www.example.org/ontologies/mini-ont#chair"/>
<oboInOwl:created_by>Jeff Lerman</oboInOwl:created_by>
<oboInOwl:creation_date rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2023-03-29T00:33:24Z</oboInOwl:creation_date>
<rdfs:label>office chair</rdfs:label>
</owl:Class>



<!-- http://www.example.org/ontologies/mini-ont#table -->

<owl:Class rdf:about="http://www.example.org/ontologies/mini-ont#table">
<rdfs:subClassOf rdf:resource="http://www.example.org/ontologies/mini-ont#furniture_item"/>
<oboInOwl:created_by>Jeff Lerman</oboInOwl:created_by>
<oboInOwl:creation_date rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2023-03-29T00:32:46Z</oboInOwl:creation_date>
<rdfs:label>table</rdfs:label>
</owl:Class>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.5.25.2023-02-15T19:15:49Z) https://github.com/owlcs/owlapi -->

Loading
Loading