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

Starting to implement some basic tests to allow removal of LiteralProxies class in near future #16

Merged
merged 5 commits into from
Oct 27, 2018
Merged
Changes from all 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
91 changes: 91 additions & 0 deletions tests/test_datatypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
Test for OWL 2 RL/RDF rules from

Table 8. The Semantics of Datatypes

https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs_using_Rules

NOTE: The following axioms are skipped on purpose

- dt-eq
- dt-diff
"""

from rdflib import Graph, Literal, Namespace, RDF, XSD, RDFS

import RDFClosure

DAML = Namespace('http://www.daml.org/2002/03/agents/agent-ont#')
T = Namespace('http://test.org/')

def test_dt_type1():
"""
Test dt-type1 rule for OWL 2 RL.
"""
g = Graph()
RDFClosure.DeductiveClosure(RDFClosure.OWLRL_Semantics).expand(g)

assert (RDF.PlainLiteral, RDF.type, RDFS.Datatype) in g
assert (RDF.XMLLiteral, RDF.type, RDFS.Datatype) in g
assert (RDFS.Literal, RDF.type, RDFS.Datatype) in g
assert (XSD.decimal, RDF.type, RDFS.Datatype) in g
assert (XSD.integer, RDF.type, RDFS.Datatype) in g
assert (XSD.nonNegativeInteger, RDF.type, RDFS.Datatype) in g
assert (XSD.nonPositiveInteger, RDF.type, RDFS.Datatype) in g
assert (XSD.positiveInteger, RDF.type, RDFS.Datatype) in g
assert (XSD.negativeInteger, RDF.type, RDFS.Datatype) in g
assert (XSD.long, RDF.type, RDFS.Datatype) in g
assert (XSD.int, RDF.type, RDFS.Datatype) in g
assert (XSD.short, RDF.type, RDFS.Datatype) in g
assert (XSD.byte, RDF.type, RDFS.Datatype) in g
assert (XSD.unsignedLong, RDF.type, RDFS.Datatype) in g
assert (XSD.unsignedInt, RDF.type, RDFS.Datatype) in g
assert (XSD.unsignedShort, RDF.type, RDFS.Datatype) in g
assert (XSD.unsignedByte, RDF.type, RDFS.Datatype) in g
assert (XSD.float, RDF.type, RDFS.Datatype) in g
assert (XSD.double, RDF.type, RDFS.Datatype) in g
assert (XSD.string, RDF.type, RDFS.Datatype) in g
assert (XSD.normalizedString, RDF.type, RDFS.Datatype) in g
assert (XSD.token, RDF.type, RDFS.Datatype) in g
assert (XSD.language, RDF.type, RDFS.Datatype) in g
assert (XSD.Name, RDF.type, RDFS.Datatype) in g
assert (XSD.NCName, RDF.type, RDFS.Datatype) in g
assert (XSD.NMTOKEN, RDF.type, RDFS.Datatype) in g
assert (XSD.boolean, RDF.type, RDFS.Datatype) in g
assert (XSD.hexBinary, RDF.type, RDFS.Datatype) in g
assert (XSD.base64Binary, RDF.type, RDFS.Datatype) in g
assert (XSD.anyURI, RDF.type, RDFS.Datatype) in g
assert (XSD.dateTime, RDF.type, RDFS.Datatype) in g
assert (XSD.dateTimeStamp, RDF.type, RDFS.Datatype) in g

def test_dt_type2():
"""
Test dt-type2 rule for OWL 2 RL.
"""
p_one = Literal(1, datatype=XSD.positiveInteger)

g = Graph()
g.add((T.A, T.prop, p_one))
RDFClosure.DeductiveClosure(RDFClosure.OWLRL_Semantics).expand(g)

assert (T.A, T.prop, p_one) in g
assert (p_one, RDF.type, XSD.positiveInteger) in g

def test_dt_not_type():
"""
Test dt-not-type rule for OWL 2 RL.
"""
m_one = Literal(-1, datatype=XSD.nonNegativeInteger)

g = Graph()
g.add((T.A, T.prop, m_one))
RDFClosure.DeductiveClosure(RDFClosure.OWLRL_Semantics).expand(g)

assert (m_one, RDF.type, XSD.nonNegativeInteger) not in g

result = next(g.objects(predicate=DAML.error))
expected = Literal(
'Lexical value of the literal \'-1\' does not match its datatype'
' (http://www.w3.org/2001/XMLSchema#nonNegativeInteger)'
)
assert expected == result