RDFLib / OWL-RL

A simple implementation of the OWL2 RL Profile on top of RDFLib: it expands the graph with all possible triples that OWL RL defines. It can be used together with RDFLib to expand an RDFLib Graph object, or as a stand alone service with its own serialization.
http://www.ivan-herman.net/Misc/2008/owlrl/
Other
140 stars 30 forks source link

Extract code, which creates and adds new BNode, into a separate function #10

Closed wrobell closed 5 years ago

wrobell commented 5 years ago

This should make the code of LiteralProxies class constructor easier to understand.

ashleysommer commented 5 years ago

Looks good. Any idea if this introduces any decrease in performance, due to the extra function calls?

wrobell commented 5 years ago

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))
ashleysommer commented 5 years ago

2.2% is fine, and I agree the benefits are worth it.