On 12/12/12 04:07, Oana Ureche wrote:
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:

Some suggestions here ...

Firstly, if you can split your big rule into smaller rules then why not do so within one rule set? I don't follow the need to have separate rule sets.

Secondly, since your are running the inference to completion then forward rules would be both higher performance and can handle more complex rules then backward rules.

Thirdly if you are going to split your rules into different rule sets then just pass the models around. I don't understand why you are serializing the models to strings and then deserializing them. Seems unnecessary.

Dave


               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.


Reply via email to