Very Strange.

I made the change.

Now when I ask for all of the statements for an indivudal "Beachely" that
require the forward chain rule, I get the backward chain, but nothign from
the previous rule.  In other words. when I ask, what groups is beachley
part of, I get nothing.

Now when I do a listStatements(), then the rule fires, and I get beachley
is a member of the group, (backward chain rule), but I get none of the
things that implies, (the first forward chain rule).

So I get..

[IndividualGetsGroupInterests:   (?x ie:memberOf ?y), (?y
ie:hasGroupInterestOf ?z)  -> (?x ie:hasIndividualInterestOf ?z)]

and when I ask for statements, it works.

I only get

[InferredMembership:  (?u ie:memberOf ?g)
    <-  (?g ie:mandatoryInterestsForGroupInclusion ?i)
        (?i ie:helpsIndividualDefine ?u)

         allValue(?g ie:mandatoryInterestsForGroupInclusion
                          ie:helpsIndividualDefine ?u)]

when I ask for all staements, before it does not fire,  and even when I ask
for all the statemetns, I do not get


[IndividualGetsGroupInterests:   (?x ie:memberOf ?y), (?y
ie:hasGroupInterestOf ?z)  -> (?x ie:hasIndividualInterestOf ?z)]


To fire again.

I need the


[IndividualGetsGroupInterests:   (?x ie:memberOf ?y), (?y
ie:hasGroupInterestOf ?z)  -> (?x ie:hasIndividualInterestOf ?z)]

to fire frist,

then I need,

[InferredMembership:  (?u ie:memberOf ?g)
    <-  (?g ie:mandatoryInterestsForGroupInclusion ?i)
        (?i ie:helpsIndividualDefine ?u)

         allValue(?g ie:mandatoryInterestsForGroupInclusion
                          ie:helpsIndividualDefine ?u)]

Then I need.

[IndividualGetsGroupInterests:   (?x ie:memberOf ?y), (?y
ie:hasGroupInterestOf ?z)  -> (?x ie:hasIndividualInterestOf ?z)]

For the result to be right.  What can I do to get this?


On Thu, Nov 8, 2012 at 5:00 PM, Dave Reynolds <[email protected]>wrote:

> The basic issue here is that you have to decide what binding pattern your
> primitive supports.
>
> Jena rules is not full prolog, the builtins are only usable as filters or
> deterministic predicates, they don't support iteration over results.
>
> So you are calling your primitive with one or both of ?u and ?g unbound
> and your code does not bind them as a result.
>
> One option is to do the binding in your calling rule and just use your
> primitive as a filter:
>
>
> [InferredMembership:  (?u ie:memberOf ?g)
>     <-  (?g ie:**mandatoryInterestsForGroupIncl**usion ?i)
>         (?i ie:helpsIndividualDefine ?u)
>
>          allValue(?g ie:**mandatoryInterestsForGroupIncl**usion
>                           ie:helpsIndividualDefine ?u)]
>
> So the first two terms find possible groups and users to check and the
> allValue primitive does the check.
>
> (I've no idea what ie:helpsIndividualDefine means so the example may not
> be right.)
>
> Dave
>
>
> On 08/11/12 20:50, Scott Streit wrote:
>
>> Dave,
>>
>> I simplified my code, removing reification and just down to the bare
>> essentials.
>>
>> Rule:
>>
>>
>> [InferredMembership:  (?u ie:memberOf ?g)
>>            <- allValue(?g ie:**mandatoryInterestsForGroupIncl**usion
>>                           ie:helpsIndividualDefine ?u)]
>>
>> Code:
>>
>> AllValue.java
>>
>> public class AllValue extends BaseBuiltin {
>> final static Logger logger = Logger.getLogger(AllValue.**class
>> .getName());
>>
>>      /**
>>       * Return a name for this builtin, normally this will be the name of
>> the
>>       * functor that will be used to invoke it.
>>       */
>>      @Override
>>      public String getName() {
>>          return "allValue";
>>      }
>>
>>      /**
>>       * This method is invoked when the builtin is called in a rule body.
>>       * @param args the array of argument values for the builtin, this is
>> an
>> array
>>       * of Nodes, some of which may be Node_RuleVariables.
>>       * @param length the length of the argument list, may be less than
>> the
>> length of the args array
>>       * for some rule engines
>>       * @param context an execution context giving access to other
>> relevant
>> data
>>       * @return return true if the buildin predicate is deemed to have
>> succeeded in
>>       * the current environment
>>       */
>>      @Override
>>      public boolean bodyCall(Node[] args, int length, RuleContext
>> context) {
>>          if (length !=4) {
>>              throw new BuiltinException(this, context, "builtin " +
>> getName() + " requires 4 arguments but saw " + length);
>>          }
>>          Node subj = getArg(0, args, context);
>>          // Allow variables in subject position to correspond to wild
>> cards
>>          if (subj.isVariable()) {
>>              subj = null;
>>          }
>>          Node pred = getArg(1, args, context);
>>          if (pred.isVariable()) {
>>              pred = null;
>>          }
>>          Node pred2 = getArg(2, args, context);
>>          if (pred.isVariable()) {
>>              pred = null;
>>          }
>>
>>          Node obj = getArg(3, args, context);
>>          logger.info(" subject is " + subj + " pred is " + pred + " pred2
>>   is " + pred2 + " obj is " + obj);
>>
>>          ClosableIterator<Triple> ti =  context.find(subj, pred, (Node)
>> null);
>>          while (ti.hasNext()) {
>>          Triple triple = ti.next();
>>          logger.info(" got a triple of " + triple);
>>          logger.info(" looking for subject (triple.getObject()" +
>> triple.getObject() + " pred2 is " + pred2 + " obj is " + obj);
>>          if (!context.contains(triple.**getObject(), pred2, obj)) {
>>          logger.info(" returning false");
>>          return false;
>>          }
>>          }
>>
>>
>>          logger.info(" returning true");
>>
>>          return true;
>>          //return !context.contains(subj, pred, obj);
>>      }
>>
>>      /**
>>       * Flag as non-monotonic so the guard clause will get rerun after
>> deferal
>>       * as part of a non-trivial conflict set.
>>       */
>>      @Override
>>      public boolean isMonotonic() {
>>          return false;
>>      }
>>
>> }
>>
>> log file:
>>
>>      [java] INFO:  looking for subject (triple.getObject()
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**InterestAreaFishing<http://www.compscii.com/ontologies/0.1/AutoIE.owl#InterestAreaFishing>pred2
>> is http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> helpsIndividualDefineobj<http://www.compscii.com/ontologies/0.1/AutoIE.owl#helpsIndividualDefineobj>
>> is *
>>       [java] Nov 8, 2012 3:33:04 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  got a triple of
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**GroupHemmingway<http://www.compscii.com/ontologies/0.1/AutoIE.owl#GroupHemmingway>@
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> mandatoryInterestsForGroupIncl**usion<http://www.compscii.com/ontologies/0.1/AutoIE.owl#mandatoryInterestsForGroupInclusion>
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> InterestAreaBachelors<http://www.compscii.com/ontologies/0.1/AutoIE.owl#InterestAreaBachelors>
>>       [java] Nov 8, 2012 3:33:04 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  looking for subject (triple.getObject()
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> InterestAreaBachelorspred2<http://www.compscii.com/ontologies/0.1/AutoIE.owl#InterestAreaBachelorspred2>is
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> helpsIndividualDefine<http://www.compscii.com/ontologies/0.1/AutoIE.owl#helpsIndividualDefine>obj
>> is *
>>       [java] Nov 8, 2012 3:33:04 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  returning true
>>       [java] 15:33:04 ERROR RDFDefaultErrorHandler :: Internal error in LP
>> reasoner: variable in triple result
>>       [java] Nov 8, 2012 3:33:04 PM
>> com.compscii.ontology.created.**LoadUserPreferences doFile
>>       [java] INFO: completed processing, writing out RDF/XML-ABBREV
>>       [java] 15:33:04 WARN  BaseXMLWriter        :: Workaround for bugs
>> 803804 and 858163: using RDF/XML (not RDF/XML-ABBREV) writer  for unsafe
>> graph class com.hp.hpl.jena.reasoner.**rulesys.FBRuleInfGraph
>>       [java] Nov 8, 2012 3:33:04 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  subject is null pred is
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> mandatoryInterestsForGroupIncl**usionpred2<http://www.compscii.com/ontologies/0.1/AutoIE.owl#mandatoryInterestsForGroupInclusionpred2>
>>   is
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> helpsIndividualDefine<http://www.compscii.com/ontologies/0.1/AutoIE.owl#helpsIndividualDefine>obj
>> is *
>>       [java] Nov 8, 2012 3:33:04 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  got a triple of
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**GroupHemmingway<http://www.compscii.com/ontologies/0.1/AutoIE.owl#GroupHemmingway>@
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> mandatoryInterestsForGroupIncl**usion<http://www.compscii.com/ontologies/0.1/AutoIE.owl#mandatoryInterestsForGroupInclusion>
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**InterestAreaFishing<http://www.compscii.com/ontologies/0.1/AutoIE.owl#InterestAreaFishing>
>>       [java] Nov 8, 2012 3:33:04 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  looking for subject (triple.getObject()
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**InterestAreaFishing<http://www.compscii.com/ontologies/0.1/AutoIE.owl#InterestAreaFishing>pred2
>> is http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> helpsIndividualDefineobj<http://www.compscii.com/ontologies/0.1/AutoIE.owl#helpsIndividualDefineobj>
>> is *
>>       [java] Nov 8, 2012 3:33:04 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  got a triple of
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**GroupHemmingway<http://www.compscii.com/ontologies/0.1/AutoIE.owl#GroupHemmingway>@
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> mandatoryInterestsForGroupIncl**usion<http://www.compscii.com/ontologies/0.1/AutoIE.owl#mandatoryInterestsForGroupInclusion>
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> InterestAreaBachelors<http://www.compscii.com/ontologies/0.1/AutoIE.owl#InterestAreaBachelors>
>>       [java] Nov 8, 2012 3:33:04 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  looking for subject (triple.getObject()
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> InterestAreaBachelorspred2<http://www.compscii.com/ontologies/0.1/AutoIE.owl#InterestAreaBachelorspred2>is
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> helpsIndividualDefine<http://www.compscii.com/ontologies/0.1/AutoIE.owl#helpsIndividualDefine>obj
>> is *
>>       [java] Nov 8, 2012 3:33:04 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  returning true
>>       [java] Nov 8, 2012 3:33:04 PM
>> com.compscii.ontology.created.**LoadUserPreferences main
>>       [java] SEVERE: error processing file resultabsolute name
>> /home/scott/ontology/trunk/**ontology/../result
>>       [java] com.hp.hpl.jena.reasoner.**ReasonerException: Internal
>> error in
>> LP rea
>>
>> What in the world is the " and what does it mean?  I want to look for
>> people that all the interests are part of.  What am I missing here.
>>
>> I want to start with all groups with mandatory interests.  Make sure the
>> users have the mandatory interests before I allow them in a group via
>> backward chaining.  I am check for the interests, get them, then want to
>> get all users that have them and put them in with the
>>
>> ?g memberOf ?u   .... but all the ?u are *.  What am I missing here?
>>
>> I also tried
>>
>> [InferredMembership:  (?g ie:hasAsMember ?u)
>>            <- allValue(?g ie:**mandatoryInterestsForGroupIncl**usion
>>                           ie:helpsIndividualDefine ?u)]
>>
>> And still got
>>
>> .owl#GroupHemmingway @
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> mandatoryInterestsForGroupIncl**usion<http://www.compscii.com/ontologies/0.1/AutoIE.owl#mandatoryInterestsForGroupInclusion>
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> InterestAreaBachelors<http://www.compscii.com/ontologies/0.1/AutoIE.owl#InterestAreaBachelors>
>>       [java] Nov 8, 2012 3:48:23 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  looking for subject (triple.getObject()
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> InterestAreaBachelorspred2<http://www.compscii.com/ontologies/0.1/AutoIE.owl#InterestAreaBachelorspred2>is
>> http://www.compscii.com/**ontologies/0.1/AutoIE.owl#**
>> helpsIndividualDefine<http://www.compscii.com/ontologies/0.1/AutoIE.owl#helpsIndividualDefine>obj
>> is *
>>       [java] Nov 8, 2012 3:48:23 PM com.compscii.ontology.created.**
>> AllValue
>> bodyCall
>>       [java] INFO:  returning true
>>       [java] Nov 8, 2012 3:48:23 PM
>> com.compscii.ontology.created.**LoadUserPreferences main
>>       [java] SEVERE: error processing file resultabsolute name
>> /home/scott/ontology/trunk/**ontology/../result
>>       [java] com.hp.hpl.jena.reasoner.**ReasonerException: Internal
>> error in
>> LP reasoner: variable in triple result
>>
>>
>> I am out of ideas..  Help
>>
>>
>>
>>
>> On Wed, Nov 7, 2012 at 1:15 PM, Scott Streit <[email protected]>
>> wrote:
>>
>>  Ok so here is the rule
>>>
>>> [InferredMembership:  (?u ie:memberOf ?g)
>>>            <- allValue(?g ie:**mandatoryInterestsForGroupIncl**usion
>>>                           ie:helpsIndividualDefine ?u)]
>>>
>>>
>>> And here is the code for AllValues
>>>
>>>        logger.info(" subject is " + subj + " pred is " + pred + " pred2
>>> is " + pred2 + " obj is " + obj);
>>>
>>>          ClosableIterator<Triple> ti =  context.find(subj, pred, (Node)
>>> null);
>>>          while (ti.hasNext()) {
>>>              Triple triple = ti.next();
>>>              logger.info(" got a triple of " + triple);
>>>              logger.info(" triple subject is " + triple.getSubject());
>>>              logger.info(" triple pred is " + triple.getPredicate());
>>>              logger.info(" triple object is " + triple.getObject());
>>>              logger.info(" looking for subject (triple.getObject()" +
>>> triple.getObject() + " pred2 is " + pred2 + " obj is " + obj);
>>>              if (!context.contains(triple.**getObject(), pred2, obj)) {
>>>                  logger.info(" returning false");
>>>                  return false;
>>>              }
>>>          }
>>>
>>>
>>>          logger.info(" returning true");
>>>
>>>          return true;
>>>
>>>
>>> When I have a case of true I get an error:
>>>
>>>      [java] com.hp.hpl.jena.reasoner.**ReasonerException: Internal
>>> error in
>>> LP reasoner: variable in triple result
>>>       [java]     at
>>> com.hp.hpl.jena.reasoner.**rulesys.impl.LPInterpreter.**
>>> derefPossFunctor(**LPInterpreter.java:784)
>>>
>>>
>>> I assume I have to bind ?u somewhere.  How?  Where ?
>>>
>>>
>>> On Wed, Nov 7, 2012 at 9:06 AM, Dave Reynolds <[email protected]
>>> >**wrote:
>>>
>>>  On 07/11/12 13:44, Scott Streit wrote:
>>>>
>>>>     (?u ie:memberOf ?g)
>>>>>           <- (?g ie:****mandatoryInterestsForGroupIncl****usion ?i)
>>>>>
>>>>>              allValue(?i ie:#hasIndivudalInterestOf ?u)
>>>>>
>>>>> If I wrote an allValue builtIn, this would solve the problem correct.
>>>>>
>>>>>
>>>> You can't have an allValue predicate with that signature, what would it
>>>> mean?
>>>>
>>>>
>>>>   What I mean by this is all forward chaining would take place first,
>>>> and
>>>>
>>>>> now
>>>>> I could backward chain allValue.  All I need to do is write allValue.
>>>>>
>>>>> This is correct, right?
>>>>>
>>>>>
>>>> You could certainly do that bit of the work in code instead of in rules,
>>>> sure. Though if you end up with just a few simple rules and a lot of
>>>> special case builtins then the rule engine may not be offering you much
>>>> value. You might just use code for everything or a sequenced set of
>>>> SPARQL
>>>> CONSTRUCT queries (SPARQL sub-queries, coupled with the unbound
>>>> predicate,
>>>> can do some closed world tests for you).
>>>>
>>>> If you do choose to go for a builtin then you'll need one that looks
>>>> more
>>>> like:
>>>>
>>>>    (?u ie:memberOf ?g)
>>>>            <- allValue(?g ie:****mandatoryInterestsForGroupIncl**
>>>> **usion
>>>>
>>>>                           ie:hasIndivudalInterestOf ?u)
>>>>
>>>> Then the predicate allValue(root P Q u) would find all values ?x such
>>>> that (root P ?x) and then pass if (u Q ?x) is true for all of those ?x.
>>>>
>>>> You would need to decide whether either or both of u and g can be
>>>> unbound.
>>>>
>>>>
>>>>   Now I looked at noValue and
>>>>
>>>>>
>>>>>          return !context.contains(subj, pred, obj);
>>>>>
>>>>> and this is where I would make the change correct?
>>>>>
>>>>>
>>>> You'll need bigger changes than that, see above.
>>>>
>>>>
>>>>   Also, how do I tell Jena of a new built in?
>>>>
>>>>>
>>>>>
>>>>     BuiltinRegistry.theRegistry.****register(new MyBuiltin());
>>>>
>>>> Dave
>>>>
>>>>
>>>>
>>>
>>> --
>>> "If you are lucky enough to have lived in Paris as a young man, then
>>> wherever you go for the rest of your life, it stays with you, for Paris
>>> is
>>> a moveable feast." -  Ernest Hemingway
>>>
>>> www.scottstreit.com
>>>
>>>
>>
>>
>>
>


-- 
"If you are lucky enough to have lived in Paris as a young man, then
wherever you go for the rest of your life, it stays with you, for Paris is
a moveable feast." -  Ernest Hemingway

www.scottstreit.com

Reply via email to