Skip to content

Instantly share code, notes, and snippets.

@anatoly-scherbakov
Created November 13, 2021 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anatoly-scherbakov/ebde3d6b70ddde7f7b3baadb65d8464b to your computer and use it in GitHub Desktop.
Save anatoly-scherbakov/ebde3d6b70ddde7f7b3baadb65d8464b to your computer and use it in GitHub Desktop.
OWL RL creates invalid triples when working on PROV-O ontology
import logging
import sys
import owlrl
import rdflib
from owlrl import OWLRL_Extension
from rdflib import Graph, Literal
logger = logging.getLogger(__name__)
def find_literal_subject_triples(graph: Graph):
return list(
filter(
lambda triple: isinstance(triple[0], Literal),
graph,
),
)
def test_owlrl_literal_subject():
logger.info(sys.version)
logger.info('rdflib=={}'.format(
rdflib.__version__,
))
logger.info('owlrl=={}'.format(
owlrl.__version__,
))
graph = Graph()
graph.parse('http://www.w3.org/ns/prov#')
assert not find_literal_subject_triples(graph), (
'Import of PROV-O ontology creates triples where Literal is a subject.'
)
owlrl.DeductiveClosure(OWLRL_Extension).expand(graph)
literal_triples = find_literal_subject_triples(graph)
assert not literal_triples, (
'OWL RL creates triples with literal as subject. Example: {t}'.format(
t=literal_triples[0],
)
)
@anatoly-scherbakov
Copy link
Author

Output:

FAILED         [100%]
2021-11-13 21:43:32,407 [INFO] tests.test_experiments.test_owlrl_literal_subject: 3.8.1 (default, Feb 21 2020, 23:12:01) 
[GCC 9.2.1 20191008]
2021-11-13 21:43:32,407 [INFO] tests.test_experiments.test_owlrl_literal_subject: rdflib==6.0.1
2021-11-13 21:43:32,407 [INFO] tests.test_experiments.test_owlrl_literal_subject: owlrl==5.2.3

tests/test_experiments/test_owlrl_literal_subject.py:20 (test_owlrl_literal_subject)
test_owlrl_literal_subject.py:38: in test_owlrl_literal_subject
    assert not literal_triples, (
E   AssertionError: OWL RL creates triples with literal as subject. Example: (rdflib.term.Literal('has_anchor'), rdflib.term.URIRef('http://www.w3.org/2002/07/owl#sameAs'), rdflib.term.Literal('has_anchor'))
E   assert not [(rdflib.term.Literal('has_anchor'), rdflib.term.URIRef('http://www.w3.org/2002/07/owl#sameAs'), rdflib.term.Literal('...rov-n-20130430/#expression-attribution', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#anyURI'))), ...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment