-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Partially closes #811. Closes #797 I is not possible to easily access classes of typ rdfs:Class. This is needed if working simultaneously with an rdf-schema (as opposed to an owl ontology). Owlready2 does not search for enties that are not of type owl:XXX. A search for rdfs:Class is now added so that when asking for classes in an ontology also the rdfs:Class'es are returned as Python objects. This is not as readily fixed with rdfs:Property. As a first fix, such properties are now returned as a list of strings (instead of a list of python objcets). Note that the nodes are present in the onotology, but the rdfs:Poerty is not cast as a python object. Owlready2 is designed to support owl ontologies (not rdfs). If we really want to extend the suport for rdfs:Property the best solution is most likely to cast it to an owl:Annotation_property. If so this should be done in a next PR .
- Loading branch information
1 parent
de542a3
commit a64ffe3
Showing
6 changed files
with
223 additions
and
72 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 was deleted.
Oops, something went wrong.
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,78 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
from pathlib import Path | ||
|
||
|
||
def test_load_rdfs() -> None: | ||
"""Test to load non-emmo based ontologies rdf and rdfs""" | ||
from ontopy import get_ontology | ||
|
||
rdf_onto = get_ontology( | ||
"https://www.w3.org/1999/02/22-rdf-syntax-ns.ttl" | ||
).load(emmo_based=False) | ||
rdfs_onto = get_ontology("https://www.w3.org/2000/01/rdf-schema.ttl").load( | ||
emmo_based=False | ||
) | ||
rdfs_onto.Class # Needed to initialize rdfs_onto | ||
assert rdf_onto.HTML.is_a[0].iri == rdfs_onto.Datatype.iri | ||
|
||
|
||
def test_load_schema() -> None: | ||
"""Test to load non-emmo based ontologies rdf and rdfs""" | ||
from ontopy import get_ontology | ||
|
||
repo_dir = Path(__file__).resolve().parent | ||
onto = get_ontology(repo_dir / "testonto" / "minischema.ttl").load( | ||
emmo_based=False | ||
) | ||
assert list(onto.classes()) == [onto.AMRadioChannel] | ||
onto_owlclass = get_ontology( | ||
repo_dir / "testonto" / "minischema_owlclass.ttl" | ||
).load(emmo_based=False) | ||
assert list(onto_owlclass.classes()) == [onto_owlclass.AMRadioChannel] | ||
|
||
assert list(onto.properties()) == ["https://schema.org/abridged"] | ||
|
||
# Should be: | ||
# assert list(onto.properties()) == [onto.abridged] | ||
|
||
|
||
# @pytest.mark.skip("FOAF is currently unavailable.") | ||
# def test_import_foaf(emmo: "Ontology") -> None: | ||
if True: | ||
"""Test importing foaf | ||
foaf is the Friend-of-a-Friend ontology. | ||
This test serves more like an example. | ||
TODO: Move to `examples/` | ||
""" | ||
from ontopy import get_ontology | ||
|
||
emmo = get_ontology("emmo").load() | ||
# skos = get_ontology("https://www.w3.org/2009/08/skos-reference/skos.html#SKOS-RDF").load() | ||
foaf = get_ontology("http://xmlns.com/foaf/spec/index.rdf").load() | ||
|
||
# Needed since foaf refer to skos without importing it | ||
# foaf.imported_ontologies.append(skos) | ||
|
||
# Turn off label lookup. Needed because foaf uses labels that are not | ||
# valid Python identifiers | ||
# foaf._special_labels = () | ||
|
||
# Now we can load foaf | ||
# foaf.load() | ||
|
||
with emmo: | ||
|
||
class Person(emmo.Interpreter): | ||
equivalent_to = [foaf.Person] | ||
|
||
|
||
# def test_load_qudt: | ||
# if True: | ||
# units = get_ontology("http://qudt.org/2.1/vocab/unit").load() | ||
# rdflib comppains. Apparently it cannot serialize it once it is loaded. |
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,23 @@ | ||
@prefix dcat: <http://www.w3.org/ns/dcat#> . | ||
@prefix dcmitype: <http://purl.org/dc/dcmitype/> . | ||
@prefix dcterms: <http://purl.org/dc/terms/> . | ||
@prefix foaf: <http://xmlns.com/foaf/0.1/> . | ||
@prefix owl: <http://www.w3.org/2002/07/owl#> . | ||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
@prefix schema: <https://schema.org/> . | ||
@prefix skos: <http://www.w3.org/2004/02/skos/core#> . | ||
@prefix void: <http://rdfs.org/ns/void#> . | ||
|
||
schema:AMRadioChannel a rdfs:Class ; | ||
rdfs:label "AMRadioChannel" ; | ||
rdfs:comment "A radio channel that uses AM." ; | ||
rdfs:subClassOf schema:RadioChannel ; | ||
schema:source <https://github.com/schemaorg/schemaorg/issues/1004> . | ||
|
||
schema:abridged a rdf:Property ; | ||
rdfs:label "abridged" ; | ||
rdfs:comment "Indicates whether the book is an abridged edition." ; | ||
schema:domainIncludes schema:Book ; | ||
schema:isPartOf <https://bib.schema.org> ; | ||
schema:rangeIncludes schema:Boolean . |
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,16 @@ | ||
@prefix dcat: <http://www.w3.org/ns/dcat#> . | ||
@prefix dcmitype: <http://purl.org/dc/dcmitype/> . | ||
@prefix dcterms: <http://purl.org/dc/terms/> . | ||
@prefix foaf: <http://xmlns.com/foaf/0.1/> . | ||
@prefix owl: <http://www.w3.org/2002/07/owl#> . | ||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
@prefix schema: <https://schema.org/> . | ||
@prefix skos: <http://www.w3.org/2004/02/skos/core#> . | ||
@prefix void: <http://rdfs.org/ns/void#> . | ||
|
||
schema:AMRadioChannel a owl:Class ; | ||
rdfs:label "AMRadioChannel" ; | ||
rdfs:comment "A radio channel that uses AM." ; | ||
rdfs:subClassOf schema:RadioChannel ; | ||
schema:source <https://github.com/schemaorg/schemaorg/issues/1004> . |