Hi Stephen,

yes, the reference to the RuleStore you did in your bundle is ok. 
Sorry, I missed that in previous emails.

I am here for any further developments.

Andrea

On Feb 9, 2012, at 3:57 PM, Stephen Bayliss wrote:

> Thanks Andrea
> 
> I'm getting RuleStoreImpl in my bundle using SCM; ie by declaring
> 
> @Reference
> protected RuleStore m_ruleStore
> 
> Is that ok?
> 
> (this is later cast to RuleStoreImpl)
> 
> I'll try giving the rules different names; and try the toKReSSyntax method
> also and get back to you.
> 
> Thanks
> Steve
> 
>> -----Original Message-----
>> From: Andrea Giovanni Nuzzolese [mailto:[email protected]] 
>> Sent: 09 February 2012 14:18
>> To: Stephen Bayliss; [email protected]
>> Subject: Re: NPE on refactoring using Java API
>> 
>> 
>> Hi Stephen,
>> 
>> It may depends on the constructor you use for initializing 
>> the RuleStoreImpl. If you used the default constructor 
>> RuleStoreImpl(), it is intended to be used by the OSGI 
>> environment with Service Component Runtime support (it is 
>> suggested in the javadoc). You might use 
>> RuleStoreImpl(Dictionary<String, Object>) also with an empty 
>> but not null dictionary. About the rule syntax, you should 
>> specify different names for each rule. I mean something like 
>> the following
>> 
>>      ...
>>      String rule1 = "Rule1[ has(<" + ns + "x" + ">, ?s, ?o) 
>> -> has(<" + ns +,    "y" + ">, ?s, ?o)  ] ";
>>      String rule2 = "Rule2[ has(<" + ns + "a" + ">, ?s, ?o) 
>> -> has(<" + ns +,    "b" + ">, ?s, ?o)  ] ";
>>      String rule3 = "Rule3[ has(<" + ns + "c" + ">, ?s, ?o) 
>> -> has(<" + ns +,    "d" + ">, ?s, ?o)  ] ";
>>      ...
>> 
>> Finally, in the last System.out.println you used 
>> rule.getRule(). I noticed how that method does not return 
>> anything and should be removed (I have just opened an issue 
>> on Jira [1] about that). Use, instead toKReSSyntax() which 
>> returns a string containing the rule in the native syntax.
>> 
>> Andrea
>> 
>> 
>> [1] https://issues.apache.org/jira/browse/STANBOL-489
>> 
>> 
>> On Feb 9, 2012, at 1:08 PM, Stephen Bayliss wrote:
>> 
>>> 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.ontologyRefacto
>>>> r
>>>>>> 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
>>>>> 
>>>>> 
>>>>> 
>>>> 
>>>> 
>>> 
>> 
>> --
>> Andrea Giovanni Nuzzolese
>> Semantic Technology Laboratory (STLab)
>> Institute for Cognitive Science and Technology (ISTC)
>> National Research Council  (CNR)
>> Via Nomentana 56, Roma - Italy
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
> 


Reply via email to