は私のコードです:
それはエラースローplayingWithJenaReasoner()関数を実行するにはpublic class FunctionalityCheckTest1 {
InfModel infModel;
Model model = ModelFactory.createDefaultModel();
String NS = "http://myweb.com/vocab#";
@Test
public void playingWithJenaReasoner()
{
Resource alex = this.model.createResource(NS+"Alex");
Resource bob = this.model.createResource(NS+"Bob");
Resource alice = this.model.createResource(NS+"Alice");
Property isFriendOf = this.model.createProperty(NS,"isFriendOf");
alex.addProperty(isFriendOf,bob);
bob.addProperty(isFriendOf,alice);
StmtIterator stmtIterator1 = this.model.listStatements();
while (stmtIterator1.hasNext())
{
System.out.println(stmtIterator1.next());
}
String customRule = "@prefix vocab: <http://myweb.com/vocab#>. " +
"[rule1: (?a vocab:isFriendOf ?b) (?b vocab:isFriendOf ?c) -> (?a vocab:isFriendOf ?c) ]";
List<Rule> rules = new ArrayList<>();
rules.add(Rule.parseRule(customRule));
GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
reasoner.setDerivationLogging(false);
this.infModel = ModelFactory.createInfModel(reasoner, this.model);
StmtIterator stmtIterator2 = this.infModel.listStatements();
while (stmtIterator2.hasNext())
{
System.out.println(stmtIterator2.next());
}
}
}
:の開始時に予想される '(':
com.hp.hpl.jena.reasoner.rulesys.Rule $をParserException句、見つかった単語:ラインrules.addから
(Rule.parseRule(customRule));
私は上記のコードにこれらの変更を追加した場合、すべてが正常に動作している間
PrintUtil.registerPrefix("vocab",NS);
String customRule = "[rule1: (?a vocab:isFriendOf ?b) (?b vocab:isFriendOf ?c) -> (?a vocab:isFriendOf ?c) ]";
この
Jena Documentationでこの
String customRule = "@prefix vocab: <http://myweb.com/vocab#>. " +
"[rule1: (?a vocab:isFriendOf ?b) (?b vocab:isFriendOf ?c) -> (?a vocab:isFriendOf ?c) ]";
とそういただきました!間違っ
、彼らはルールに@prefix言及しています。どこが間違っていますか?