-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
321 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Prefix(:=<https://example.com/>) | ||
Prefix(dc:=<http://purl.org/dc/elements/1.1/>) | ||
Prefix(owl:=<http://www.w3.org/2002/07/owl#>) | ||
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>) | ||
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>) | ||
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>) | ||
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>) | ||
|
||
|
||
Ontology( | ||
Declaration(Class(:A)) | ||
Declaration(Class(:B)) | ||
############################ | ||
# Classes | ||
############################ | ||
|
||
# Class: :B (:B) | ||
|
||
SubClassOf(:B :A) | ||
|
||
|
||
) |
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,22 @@ | ||
Prefix(:=<https://example.com/>) | ||
Prefix(dc:=<http://purl.org/dc/elements/1.1/>) | ||
Prefix(owl:=<http://www.w3.org/2002/07/owl#>) | ||
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>) | ||
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>) | ||
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>) | ||
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>) | ||
|
||
|
||
Ontology( | ||
Declaration(Class(:A)) | ||
Declaration(Class(:B)) | ||
############################ | ||
# Classes | ||
############################ | ||
|
||
# Class: :B (:B) | ||
|
||
SubClassOf(:B :A) | ||
|
||
|
||
) |
File renamed without changes.
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,4 @@ | ||
Prefix: : <https://example.com/> | ||
Ontology: | ||
Class: A | ||
Class: B SubClassOf: A |
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,40 @@ | ||
<?xml version="1.0"?> | ||
<rdf:RDF xmlns="http://www.w3.org/2002/07/owl#" | ||
xml:base="http://www.w3.org/2002/07/owl" | ||
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#"> | ||
<Ontology/> | ||
|
||
|
||
|
||
<!-- | ||
/////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Classes | ||
// | ||
/////////////////////////////////////////////////////////////////////////////////////// | ||
--> | ||
|
||
|
||
|
||
|
||
<!-- https://example.com/A --> | ||
|
||
<Class rdf:about="https://example.com/A"/> | ||
|
||
|
||
|
||
<!-- https://example.com/B --> | ||
|
||
<Class rdf:about="https://example.com/B"> | ||
<rdfs:subClassOf rdf:resource="https://example.com/A"/> | ||
</Class> | ||
</rdf:RDF> | ||
|
||
|
||
|
||
<!-- Generated by the OWL API (version 4.5.6) https://github.com/owlcs/owlapi --> | ||
|
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,40 @@ | ||
<?xml version="1.0"?> | ||
<rdf:RDF xmlns="http://www.w3.org/2002/07/owl#" | ||
xml:base="http://www.w3.org/2002/07/owl" | ||
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#"> | ||
<Ontology/> | ||
|
||
|
||
|
||
<!-- | ||
/////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Classes | ||
// | ||
/////////////////////////////////////////////////////////////////////////////////////// | ||
--> | ||
|
||
|
||
|
||
|
||
<!-- https://example.com/A --> | ||
|
||
<Class rdf:about="https://example.com/A"/> | ||
|
||
|
||
|
||
<!-- https://example.com/B --> | ||
|
||
<Class rdf:about="https://example.com/B"> | ||
<rdfs:subClassOf rdf:resource="https://example.com/A"/> | ||
</Class> | ||
</rdf:RDF> | ||
|
||
|
||
|
||
<!-- Generated by the OWL API (version 4.5.6) https://github.com/owlcs/owlapi --> | ||
|
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,28 @@ | ||
<?xml version="1.0"?> | ||
<Ontology xmlns="http://www.w3.org/2002/07/owl#" | ||
xml:base="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#"> | ||
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/> | ||
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/> | ||
<Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/> | ||
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/> | ||
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/> | ||
<Declaration> | ||
<Class IRI="https://example.com/A"/> | ||
</Declaration> | ||
<Declaration> | ||
<Class IRI="https://example.com/B"/> | ||
</Declaration> | ||
<SubClassOf> | ||
<Class IRI="https://example.com/B"/> | ||
<Class IRI="https://example.com/A"/> | ||
</SubClassOf> | ||
</Ontology> | ||
|
||
|
||
|
||
<!-- Generated by the OWL API (version 4.5.6) https://github.com/owlcs/owlapi --> | ||
|
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,28 @@ | ||
<?xml version="1.0"?> | ||
<Ontology xmlns="http://www.w3.org/2002/07/owl#" | ||
xml:base="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#"> | ||
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/> | ||
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/> | ||
<Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/> | ||
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/> | ||
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/> | ||
<Declaration> | ||
<Class IRI="https://example.com/A"/> | ||
</Declaration> | ||
<Declaration> | ||
<Class IRI="https://example.com/B"/> | ||
</Declaration> | ||
<SubClassOf> | ||
<Class IRI="https://example.com/B"/> | ||
<Class IRI="https://example.com/A"/> | ||
</SubClassOf> | ||
</Ontology> | ||
|
||
|
||
|
||
<!-- Generated by the OWL API (version 4.5.6) https://github.com/owlcs/owlapi --> | ||
|
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,137 @@ | ||
import typing | ||
from tempfile import NamedTemporaryFile | ||
|
||
import os.path | ||
import unittest | ||
import pyhornedowl | ||
from pyhornedowl.model import * | ||
|
||
|
||
def r(*args: str) -> str: | ||
return os.path.abspath(os.path.join(os.path.dirname(__file__), "resources", *args)) | ||
|
||
|
||
def res(resource: str) -> str: | ||
with open(r(resource)) as f: | ||
return f.read() | ||
|
||
|
||
def simple_ontology() -> pyhornedowl.PyIndexedOntology: | ||
onto = pyhornedowl.PyIndexedOntology() | ||
onto.add_axiom(DeclareClass(Class(onto.iri("https://example.com/A")))) | ||
onto.add_axiom(DeclareClass(Class(onto.iri("https://example.com/B")))) | ||
onto.add_axiom(SubClassOf( | ||
Class(onto.iri("https://example.com/A")), | ||
Class(onto.iri("https://example.com/B")))) | ||
|
||
return onto | ||
|
||
|
||
SERIALIZATIONS: typing.List[typing.Literal['ofn', 'owx', 'owl']] = ['ofn', 'owx', 'owl'] | ||
|
||
|
||
class IO(unittest.TestCase): | ||
|
||
def assertOntologiesEqual(self, actual, expected): | ||
self.assertSetEqual(set(actual.get_axioms()), set(expected.get_axioms()), "Axioms do not match!") | ||
self.assertEqual(actual.get_iri(), expected.get_iri(), "Ontology IRIs do not match!") | ||
|
||
@unittest.skip("Functional syntax parser parses others formats without errors others panic") | ||
def test_load_simple_from_string_generic_guess(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
content = res(f"simple.{s}") | ||
|
||
actual = pyhornedowl.open_ontology(content) | ||
expected = simple_ontology() | ||
|
||
self.assertOntologiesEqual(actual, expected) | ||
|
||
def test_load_simple_from_string_generic_explicit(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
content = res(f"simple.{s}") | ||
|
||
actual = pyhornedowl.open_ontology(content, s) | ||
expected = simple_ontology() | ||
|
||
self.assertOntologiesEqual(actual, expected) | ||
|
||
def test_load_simple_from_string_explicit(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
content = res(f"simple.{s}") | ||
|
||
actual = pyhornedowl.open_ontology_from_string(content, s) | ||
expected = simple_ontology() | ||
|
||
self.assertOntologiesEqual(actual, expected) | ||
|
||
@unittest.skip("Functional syntax parser parses others formats without errors others panic") | ||
def test_load_simple_from_string_guess_parser(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
content = res(f"simple.{s}") | ||
|
||
actual = pyhornedowl.open_ontology_from_string(content) | ||
expected = simple_ontology() | ||
|
||
self.assertOntologiesEqual(actual, expected) | ||
|
||
def test_load_simple_from_file_generic_guess(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
actual = pyhornedowl.open_ontology(r(f'simple.{s}')) | ||
expected = simple_ontology() | ||
|
||
self.assertOntologiesEqual(actual, expected) | ||
|
||
def test_load_simple_from_file_generic_explicit(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
actual = pyhornedowl.open_ontology(r(f'simple.{s}'), s) | ||
expected = simple_ontology() | ||
|
||
self.assertOntologiesEqual(actual, expected) | ||
|
||
def test_load_simple_from_file_guess_ext(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
actual = pyhornedowl.open_ontology_from_file(r(f'simple.{s}')) | ||
expected = simple_ontology() | ||
|
||
self.assertOntologiesEqual(actual, expected) | ||
|
||
def test_load_simple_from_file_explicit(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
actual = pyhornedowl.open_ontology_from_file(r(f'simple.{s}.raw'), s) | ||
expected = simple_ontology() | ||
|
||
self.assertOntologiesEqual(actual, expected) | ||
|
||
def test_write_simple_guess_ext(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
with NamedTemporaryFile(suffix=f".{s}") as f: | ||
original = simple_ontology() | ||
original.save_to_file(f.name) | ||
|
||
actual = pyhornedowl.open_ontology_from_file(f.name, s) | ||
|
||
self.assertOntologiesEqual(original, actual) | ||
|
||
def test_write_simple_explicit(self): | ||
for s in SERIALIZATIONS: | ||
with self.subTest(serialization=s): | ||
with NamedTemporaryFile(suffix=f".{s}.raw") as f: | ||
original = simple_ontology() | ||
original.save_to_file(f.name, s) | ||
|
||
actual = pyhornedowl.open_ontology_from_file(f.name, s) | ||
|
||
self.assertOntologiesEqual(original, actual) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |