Hi Andrea
I'm still not getting this to work, maybe I'm missing something obvious...
My test code:
public void rulesAndRecipesTest() throws NoSuchRecipeException {
String ns = "http://www.example.org/dummy/ns#";
String rule1 = "Rule[ has(<" + ns + "x" + ">, ?s, ?o) -> has(<" + ns +
"y" + ">, ?s, ?o) ] ";
String rule2 = "Rule[ has(<" + ns + "a" + ">, ?s, ?o) -> has(<" + ns +
"b" + ">, ?s, ?o) ] ";
String rule3 = "Rule[ has(<" + ns + "c" + ">, ?s, ?o) -> has(<" + ns +
"d" + ">, ?s, ?o) ] ";
String recipeID = "http://www.example/org/dummy/recipe";
IRI recipeIRI = IRI.create(recipeID);
boolean ok = m_ruleStore.addRecipe(recipeIRI, "example recipe");
if (!ok) System.out.println("Failed to create recipe");
Recipe recipe = m_ruleStore.addRuleToRecipe(recipeID, rule1);
recipe = m_ruleStore.addRuleToRecipe(recipeID, rule2);
recipe = m_ruleStore.addRuleToRecipe(recipeID, rule3);
System.out.println("rules in recipe: " +
recipe.getkReSRuleList().size());
recipe = m_ruleStore.getRecipe(recipeIRI);
for (Rule rule : recipe.getkReSRuleList()) {
System.out.println("rule: " + rule.getRuleName() + ": " +
rule.getRule());
}
}
And the output on running this is:
-----
rules in recipe: 2
rule: http://kres.iks-project.eu/ontology/meta/variables#Rule: null
-----
Thanks
Steve
> -----Original Message-----
> From: Stephen Bayliss [mailto:[email protected]]
> Sent: 09 February 2012 10:31
> To: [email protected]
> Subject: RE: NPE on refactoring using Java API
>
>
> Hello Andrea
>
> Many thanks for this - I'm re-writing this bit of code to use
> the API as you have suggested, I'll let you know how it goes.
>
> Out of interest - what is the intended usage of eg AddRule?
> Or is that not part of the API and therefore should be ignored...
>
> Thanks
> Steve
>
> > -----Original Message-----
> > From: Andrea Giovanni Nuzzolese [mailto:[email protected]]
> > Sent: 09 February 2012 10:01
> > To: Stephen Bayliss; [email protected]
> > Subject: Re: NPE on refactoring using Java API
> >
> >
> > I Stephen,
> >
> > do not directly use methods of the classes AddRule and
> > AddRecipe. Instead, use methods of the RuleStore. You can
> > create a recipe with the method addRecipe(IRI, String), where
> > the first argument is the recipe ID and the second is a
> > description of the recipe.
> > Then you can add rules to the recipe created with the method
> > addRuleToRecipe(String, String), where the first argument is
> > the ID of the recipe to which you want to add the rule and
> > the second argument is the rule itself.
> >
> > I hope it helps.
> >
> > Best.
> > Andrea
> >
> > On Feb 8, 2012, at 5:43 PM, Stephen Bayliss wrote:
> >
> > > Hi
> > >
> > > I'm getting an NPE when refactoring using the Java API:
> > >
> > > java.lang.NullPointerException
> > > at
> > >
> >
> org.apache.stanbol.rules.refactor.impl.RefactorerImpl.ontologyRefactor
> > > ing(Re
> > > factorerImpl.java:284)
> > >
> > > This is something that used to work with an old svn
> > revision, current
> > > rev is 1236695.
> > >
> > > I'm creating a Recipe with some rules, following the code
> > in the REST
> > > API as an example.
> > >
> > > My Bundle is getting the rule store with
> > >
> > > @Reference
> > > protected RuleStore m_ruleStore;
> > >
> > > I'm adding rules to the store with:
> > >
> > > AddRule adder = new AddRule(m_ruleStore);
> > adder.addRule(ruleIRI, rule,
> > > description);
> > >
> > > (which is returning true)
> > >
> > > I'm adding the recipe by creating a Vector<IRI> ruleIris and
> > > populating with the rule IRIs, then
> > >
> > > AddRecipe recipeAdder = new AddRecipe(m_ruleStore);
> > > recipeAdder.addRecipe(recipeIri, ruleIris, "my rule");
> > >
> > > (returns true)
> > >
> > > and
> > > m_ruleStore.saveOntology().
> > >
> > > I can query for the recipe and list the rules fine using a
> > > GetRecipe#getAllRecipes();
> > >
> > > However, on refactoring with a Refactorer, got in my bundle using:
> > >
> > > @Reference
> > > Refactorer m_refactorer;
> > >
> > > Then
> > >
> > > m_refactorer.ontologyRefactoring(outputIri, inputIri, recipeIri)
> > >
> > > But this is throwing the NPE above.
> > >
> > > (I notice it is using
> > > RuleStore#getRecipe and then Recipe#getkReSRuleList
> > > And if I try to get the recipes using m_ruleStore.listRecipes();
> > > this returns Null, which is odd...)
> > >
> > > So how do I get this working? There seem to be "two APIs"
> > in a sense,
> > > the AddRule/GetRule etc stuff and the methods directly on the
> > > RuleStore.
> > >
> > > Thanks
> > > Steve
> >
> >
> >
>
>