Вот мой код:
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());
}
}
}
При выполнении функции playWithJenaReasoner() выдается ошибка:
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) ]";
Так что с этим не так
String customRule = "@prefix vocab: <http://myweb.com/vocab#>. " +
"[rule1: (?a vocab:isFriendOf ?b) (?b vocab:isFriendOf ?c) -> (?a vocab:isFriendOf ?c) ]";
В этой Jena Documentation они упомянули @prefix с правилом . Где я делаю неправильно?