blazegraph / database

Blazegraph High Performance Graph Database
GNU General Public License v2.0
871 stars 170 forks source link

Is it possible to add inference rules via a TTL style update? #195

Closed Craphtex closed 3 years ago

Craphtex commented 3 years ago

I'm running BlazeGraph Server version 2.1.5 via docker and testing things out via the web interface.

As I watched this presentation on YouTube by Stacy Hirschberg a for me attractive syntax for defining inference rules are displayed on a slide (see attached image below).

The syntax goes like this

# geographic rules for inference
PREFIX ex: <http://example.com/>
PREFIX gn: <http://www.geonames.org/ontology/>

RULE "livesIn" CONSTRUCT {
  ?person ex:livesIn ?place2
} {
  ?person ex:livesIn ?place1 .
  ?place1 gn:parentFeature ?place2
}

If I run this query in the UPDATE tab (selecting RDF data and Turtle) though I get

this error

``` ERROR: INSERT-WITH-BODY: baseURI=http://localhost:8090/blazegraph/namespace/cardano/sparql, Content-Type=application/x-turtle, context-uri=[] java.util.concurrent.ExecutionException: org.openrdf.rio.RDFParseException: Expected ':', found ' ' [line 4] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at com.bigdata.rdf.sail.webapp.BigdataServlet.submitApiTask(BigdataServlet.java:294) at com.bigdata.rdf.sail.webapp.InsertServlet.doPostWithBody(InsertServlet.java:206) at com.bigdata.rdf.sail.webapp.InsertServlet.doPost(InsertServlet.java:122) at com.bigdata.rdf.sail.webapp.RESTServlet.doPost(RESTServlet.java:308) at com.bigdata.rdf.sail.webapp.MultiTenancyServlet.doPost(MultiTenancyServlet.java:195) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220) at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:335) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.server.Server.handle(Server.java:503) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683) at java.lang.Thread.run(Thread.java:748) Caused by: org.openrdf.rio.RDFParseException: Expected ':', found ' ' [line 4] at org.openrdf.rio.helpers.RDFParserHelper.reportFatalError(RDFParserHelper.java:441) at org.openrdf.rio.helpers.RDFParserBase.reportFatalError(RDFParserBase.java:671) at org.openrdf.rio.turtle.TurtleParser.reportFatalError(TurtleParser.java:1306) at org.openrdf.rio.turtle.TurtleParser.verifyCharacterOrFail(TurtleParser.java:1185) at org.openrdf.rio.turtle.TurtleParser.parseQNameOrBoolean(TurtleParser.java:1035) at org.openrdf.rio.turtle.TurtleParser.parseValue(TurtleParser.java:618) at org.openrdf.rio.turtle.TurtleParser.parseSubject(TurtleParser.java:449) at org.openrdf.rio.turtle.TurtleParser.parseTriples(TurtleParser.java:383) at org.openrdf.rio.turtle.TurtleParser.parseStatement(TurtleParser.java:261) at org.openrdf.rio.turtle.TurtleParser.parse(TurtleParser.java:216) at org.openrdf.rio.turtle.TurtleParser.parse(TurtleParser.java:159) at com.bigdata.rdf.sail.webapp.InsertServlet$InsertWithBodyTask.call(InsertServlet.java:308) at com.bigdata.rdf.sail.webapp.InsertServlet$InsertWithBodyTask.call(InsertServlet.java:229) at com.bigdata.rdf.task.ApiTaskForIndexManager.call(ApiTaskForIndexManager.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ... 1 more ```

and after google for a bit it doesn't seem like RULE is a keyword.

Is there any counterpart syntax in BlazeGraph for using TTL syntax to insert inference rules?

Thanks a lot in advance!

image

thompsonbry commented 3 years ago

Blazegraph does not support the declaration of rules in this manner. You can extend the set of rules using in code. You can also achieve many of the effects of rules by issuing specific SPARQL UPDATE requests. There are a lot of rules where you are better off rewriting the query to use a property path which perhaps the extra hop of the rule at query time vs write time. For example, your rule below is likely one where you want to chase a hierarchy of “place”.

Rules are generally used to support eager materialization of entailments. The advantage of eager materialization is that the cost of the data access is a single lookup pattern once the entailment has been materialized. But the downsize is that you are carrying more data in the database and the maintenance of those entailments can be expensive.

Bryan

On Wed, Feb 24, 2021 at 22:42 Christian Lindgren notifications@github.com wrote:

I'm running BlazeGraph Server version 2.1.5 via docker and testing things out via the web interface.

As I watched this presentation on YouTube https://youtu.be/zeYfT1cNKQg?t=77 by Stacy Hirschberg a for me attractive syntax for defining inference rules are displayed on a slide (see attached image below).

The syntax goes like this

geographic rules for inferencePREFIX ex: http://example.com/PREFIX gn: http://www.geonames.org/ontology/

RULE "livesIn" CONSTRUCT { ?person ex:livesIn ?place2 } { ?person ex:livesIn ?place1 . ?place1 gn:parentFeature ?place2 }

If I run this query in the UPDATE tab (selecting RDF data and Turtle) though I get this error

      ERROR: INSERT-WITH-BODY: baseURI=http://localhost:8090/blazegraph/namespace/cardano/sparql, Content-Type=application/x-turtle, context-uri=[]

java.util.concurrent.ExecutionException: org.openrdf.rio.RDFParseException: Expected ':', found ' ' [line 4] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at com.bigdata.rdf.sail.webapp.BigdataServlet.submitApiTask(BigdataServlet.java:294) at com.bigdata.rdf.sail.webapp.InsertServlet.doPostWithBody(InsertServlet.java:206) at com.bigdata.rdf.sail.webapp.InsertServlet.doPost(InsertServlet.java:122) at com.bigdata.rdf.sail.webapp.RESTServlet.doPost(RESTServlet.java:308) at com.bigdata.rdf.sail.webapp.MultiTenancyServlet.doPost(MultiTenancyServlet.java:195) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220) at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:335) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.server.Server.handle(Server.java:503) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683) at java.lang.Thread.run(Thread.java:748) Caused by: org.openrdf.rio.RDFParseException: Expected ':', found ' ' [line 4] at org.openrdf.rio.helpers.RDFParserHelper.reportFatalError(RDFParserHelper.java:441) at org.openrdf.rio.helpers.RDFParserBase.reportFatalError(RDFParserBase.java:671) at org.openrdf.rio.turtle.TurtleParser.reportFatalError(TurtleParser.java:1306) at org.openrdf.rio.turtle.TurtleParser.verifyCharacterOrFail(TurtleParser.java:1185) at org.openrdf.rio.turtle.TurtleParser.parseQNameOrBoolean(TurtleParser.java:1035) at org.openrdf.rio.turtle.TurtleParser.parseValue(TurtleParser.java:618) at org.openrdf.rio.turtle.TurtleParser.parseSubject(TurtleParser.java:449) at org.openrdf.rio.turtle.TurtleParser.parseTriples(TurtleParser.java:383) at org.openrdf.rio.turtle.TurtleParser.parseStatement(TurtleParser.java:261) at org.openrdf.rio.turtle.TurtleParser.parse(TurtleParser.java:216) at org.openrdf.rio.turtle.TurtleParser.parse(TurtleParser.java:159) at com.bigdata.rdf.sail.webapp.InsertServlet$InsertWithBodyTask.call(InsertServlet.java:308) at com.bigdata.rdf.sail.webapp.InsertServlet$InsertWithBodyTask.call(InsertServlet.java:229) at com.bigdata.rdf.task.ApiTaskForIndexManager.call(ApiTaskForIndexManager.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ... 1 more

and after google for a bit it doesn't seem like RULE is a keyword.

Is there any counterpart syntax in BlazeGraph for using TTL syntax to insert inference rules?

Thanks a lot in advance!

[image: image] https://user-images.githubusercontent.com/3471832/109112662-5de7f780-777e-11eb-8621-789d1b314130.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/blazegraph/database/issues/195, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATW7YFNIE42Z5JAXXCKXWLTAXWN5ANCNFSM4YF5I6KA .

Craphtex commented 3 years ago

Thanks @thompsonbry, I got you, and extra thanks for the elaborate response. :+1:

I think I'll roll with the extra data in the database in my real use case, as storage (in general) is cheap, my dataset is to a large extent immutable, and I'll make larger reads than writes (but more writes than reads). I could even have a cron job checking and filling in missing edges every now and again.