-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow controling ontology IRI when saving (#700)
# Description Allow separating the IRI of the ontology from `base_iri` when saving using rdflib. Owlready2 doesn't allow to separate the IRI of the ontology from the `base_iri` (the namespace of the entities in the ontology). In many ontologies, e.g. EMMO, are these not the same. Further work: Also assign the ontology IRI when loading an ontology. ## Type of change <!-- Put an `x` in the box that applies. --> - [ ] Bug fix. - [x] New feature. - [ ] Documentation update. - [ ] Test update. ## Checklist <!-- Put an `x` in the boxes that apply. You can also fill these out after creating the PR. --> This checklist can be used as a help for the reviewer. - [ ] Is the code easy to read and understand? - [ ] Are comments for humans to read, not computers to disregard? - [ ] Does a new feature has an accompanying new test (in the CI or unit testing schemes)? - [ ] Has the documentation been updated as necessary? - [ ] Does this close the issue? - [ ] Is the change limited to the issue? - [ ] Are errors handled for all outcomes? - [ ] Does the new feature provide new restrictions on dependencies, and if so is this documented? ## Comments <!-- Additional comments here, including clarifications on checklist if applicable. --> --------- Co-authored-by: Francesca L. Bleken <[email protected]>
- Loading branch information
1 parent
ada4ea5
commit 9df0345
Showing
3 changed files
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import re | ||
from pathlib import Path | ||
|
||
from ontopy import get_ontology | ||
|
||
|
||
# if True: | ||
def test_iri(): | ||
thisdir = Path(__file__).resolve().parent | ||
ontodir = thisdir.parent / "testonto" | ||
outdir = thisdir.parent / "output" | ||
|
||
onto = get_ontology(ontodir / "testonto.ttl").load() | ||
onto.base_iri = "http://example.com/onto" | ||
onto.iri = "http://example.com/onto/testonto" | ||
ontofile = outdir / "testonto.ttl" | ||
if ontofile.exists(): | ||
ontofile.unlink() | ||
onto.save(outdir / "testonto.ttl") | ||
|
||
# Load saved ontology and make sure that base_iri and iri are stored | ||
# correctly | ||
with open(outdir / "testonto.ttl", mode="r") as f: | ||
ttl = f.read() | ||
assert re.findall(r"@prefix : (\S+) \.", ttl) == [f"<{onto.base_iri}>"] | ||
assert re.findall(r"(\S+) a owl:Ontology", ttl) == [f"<{onto.iri}>"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.ttl |