Closed wrobell closed 5 years ago
Looks good. Any idea if this introduces any decrease in performance, due to the extra function calls?
There is 2.2% performance penalty for the example below.
However, once we shrink the size of the loop, I hope it will be easier to understand it and provide performance improvements over the original code.
import io
import sys
import time
import RDFClosure
from rdflib import Graph, Namespace, BNode, Literal, XSD
T = Namespace('http://test.net/')
DATA = """
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix : <http://test.net/>.
:C a owl:Class.
:dprop a owl:DataProperty;
rdfs:domain :C;
rdfs:range xsd:integer.
"""
test_name = sys.argv[1]
dprop = T.dprop
print('test,graph_size,time')
for _ in range(50):
g = Graph()
g.parse(io.StringIO(DATA), format='n3')
for i in range(10):
d = BNode()
for j in range(200):
b = BNode()
g.add((b, dprop, Literal(j * 10, datatype=XSD.integer)))
t = time.time()
RDFClosure.DeductiveClosure(RDFClosure.OWLRL_Semantics).expand(g)
duration = time.time() - t
print('{},{},{:.6f}'.format(test_name, len(g), duration))
2.2% is fine, and I agree the benefits are worth it.
This should make the code of
LiteralProxies
class constructor easier to understand.