On 03/09/16 23:11, Martynas Jusevičius wrote:
Hey,
I think https://issues.apache.org/jira/browse/JENA-1030 fix does not
work for List<Rule>.
I tried roundtripping
Rule.parseRules(GenericRuleReasoner.getRules().toString()) and what I
get is:
A java parse error?
org.apache.jena.reasoner.rulesys.Rule$ParserException: Malformed rule
At '[ rdfs9: ( ?x rdfs:subClassOf ?y ) ( ?a rdf:type ?x ) -> ( ?a
rdf:type ?y ) ] ] '
?? JENA-1030 was about bare URIs and I don't see a bare URI here.
The problem is "[]" added by Java's List<>.toString() returned by
getRules().toString().
That is nothing to do with Jena rule syntax.
Strip the out list-introduced [] and it will work.
Test case:
public static void main(String ...args) {
String s = "[one: (?a rdf:type ?y) <- (?a rdf:type ?y) ]" ;
rule(s) ;
String s2 = Arrays.asList(s).toString() ;
rule(s2) ;
System.out.println("DONE") ;
System.exit(0);
}
private static void rule(String string) {
System.out.println("Input: "+string) ;
try {
List<Rule> rules2 = Rule.parseRules(string) ;
System.out.println("Output: "+rules2) ;
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
System.out.println() ;
}
Not sure exactly what the cause is, but I have a RulePrinter that
roundtrips successfully:
https://github.com/AtomGraph/Processor/blob/master/src/main/java/com/atomgraph/processor/util/RulePrinter.java
A shorter one perhaps:
List<Rule> rules = ...
String s = rules.stream()
.map((r)->r.toString())
.collect(Collectors.joining("\n"));
Andy
Martynas
atomgraph.com