Hi all,
There is a shortcoming in Jena. Mainly the fact that it cannot handle complex
rules.. i.e. throwing the following exception
Exception in thread "main"
com.hp.hpl.jena.reasoner.rulesys.impl.LPRuleSyntaxException: Syntax error in
backward rule: rule1
Rule too complex for current implementation
Rule clauses are limited to 15 permanent variables
So I have decided to split the complex rule into smaller rules. Then apply a
small rule to a dataset, which results into a bigger dataset, then apply the
next small rule to the bigger dataset and so on and so forth.. Code looks like
the following:
private static InfModel applyRule(String dataset, String
filepath) {
InputStream stream = new ByteArrayInputStream(dataset.getBytes("UTF-8"));
Model instances = ModelFactory.createDefaultModel();
instances.read(stream, null);
Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL(filepath));
reasoner.setDerivationLogging(true);
return ModelFactory.createInfModel(reasoner, instances);
}
private static String inferConnName(String dataset) {
InfModel inf = applyRule(dataset, "file:rules/conn_name.txt");
ByteArrayOutputStream out = new ByteArrayOutputStream();
inf.write(out, "RDF/XML");
return out.toString();
}
private static String inferStatementName(String dataset) {
InfModel inf = applyRule(dataset, "file:rules/statement_name.txt");
ByteArrayOutputStream out = new ByteArrayOutputStream();
inf.write(out, "RDF/XML");
return out.toString();
}
private static void getVuln(String dataset) {
String conn_name_dataset = inferConnName(dataset);
String statement_name_dataset = inferStatementName(conn_name_dataset);
InfModel inf = applyRule(statement_name_dataset, "file:rules/param.txt");
//print out the statements in the model
StmtIterator iter = inf.listStatements();
while (iter.hasNext()) {
Statement stmt = iter.nextStatement(); // get next statement
............................
}
I was wondering if there is a better way to do this?
Thank you,
Oana.