Can we load a data file wich contains a rule by using Java ?
I try it with Jena and SNARL but it seems impossible.
Sincerely.
Can we load a data file wich contains a rule by using Java ?
I try it with Jena and SNARL but it seems impossible.
Sincerely.
There should be no issues loading turtle files with rules in them via whatever method. What is the error you are seeing?
My ttl file is:
@prefix db: http://data/# .
@prefix fx: http://fx/# .
@prefix rdfs: http://www.w3.org/2000/01/rdf-schema# .db:Jean a fx:male ,
fx:parent;
rdfs:label "Jean" .IF {
?x a fx:male, fx:parent .
}
THEN {
?x a fx:father
}
Blockquote
db:Louis a fx:male .
db:Louis a fx:parent .
the error is:
Exception in thread "main" org.apache.jena.riot.RiotException: [line: 9, col: 1 ] Out of place: [KEYWORD:IF]
at org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:136)
at org.apache.jena.riot.lang.LangEngine.raiseException(LangEngine.java:165)
at org.apache.jena.riot.lang.LangEngine.exceptionDirect(LangEngine.java:158)
at org.apache.jena.riot.lang.LangEngine.exception(LangEngine.java:151)
at org.apache.jena.riot.lang.LangTurtleBase.triplesSameSubject(LangTurtleBase.java:238)
at org.apache.jena.riot.lang.LangTurtle.oneTopLevelElement(LangTurtle.java:46)
at org.apache.jena.riot.lang.LangTurtleBase.runParser(LangTurtleBase.java:89)
at org.apache.jena.riot.lang.LangBase.parse(LangBase.java:42)
at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTLang.read(RDFParserRegistry.java:175)
at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:905)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:256)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:242)
at org.apache.jena.riot.adapters.RDFReaderRIOT.read(RDFReaderRIOT.java:69)
at triplestores.StardogJena.insertWithRule(StardogJena.java:73)
at controllers.JenaControllerSD.insertModelWithRulesOnStardog(JenaControllerSD.java:336)
at main.Triples.main(Triples.java:183)
I apologize, I should have been more clear⌠Uploading a ttl file with inline rules like this will NOT work in Sesame/Jena/RDF4J because itâs non-standard Turtle. Via SNARL, however, I am able to load the rule in and query it just fine:
public static void main(String... args) {
try (Connection conn = Utils.getDefaultConnection("support")) {
conn.begin();
conn.add().io().file(new File("/Users/stephen/support/community/rules.ttl").toPath());
conn.commit();
try (TupleQueryResult res = conn.select("SELECT * WHERE { ?f a <http://fx/#father> }").reasoning(true).execute()) {
while (res.hasNext()) {
System.out.println(res.next().getBinding("f"));
}
}
}
}
f=http://data/#Jean
f=http://data/#Louis
Just a couple of gotchas to watch out for:
<>
"
characters, making the turtle invalidThank you very much it seems to work correctly
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.