Hi Dona,

It is fascinating as well as frustrating as solving problem bring forth new ones.

Honestly, I dont know how the error vanished off my screen. I was trying something else and incidently the bug buggered off.

However, I dont see any difference in your code and mine. I reckon the problem is with protege instances. Sorry that I didnt help much about it.

I got interesting questions from the problems I faced.

Q1. what is the logical difference between

(defglobal ?*re* = (nth$ 1 (find-all-instances ((?h Hello)) (member$ 111 (slot-get ?h Resource\ ID)))))

and

(defglobal ?*re* = (nth$ 1 (find-all-instances ((?h Hello)) (eq (slot-get ?h Resource\ ID) 111))))

Because, the second statement points to the first instance, even if there is no field matching 111. Just try slot-get after the defglobal in Jess prompt to confirm.

Q2. What is the difference between defglobal and bind?

I understand defglobal is global and reset doesnt affect it. But I see funny things. In the project I gave in my last mail, jus change

(defglobal ?*res* = (nth$ 1 (find-instance ((?h Hello)) (slot-get ?h Resource\ ID ?n&:(member$ 111 ?n)))))

to

(bind ?res (nth$ 1 (find-instance ((?h Hello)) (slot-get ?h Resource\ ID ?n&:(member$ 111 ?n)))))

I get funny results. (change the variable in defrule also)

Q3. Can rules can be nested?

Finally, Dona, my problem of matching multifield to multifield instance slot is still unsolved.

find-all-instances provides a list of matching fields. However, inside the rule, the matching occurs only to the head instance of the list.

Why is the below code not firing any rules

(defrule simple-multi-multi-match

        ?rem <- (object(is-a Hello) (Resource\ ID $?before 111 $?after))
        ?behavior <- (object(is-a Node\ Spoof) (Resource\ sequence $?before ?rem $?after))
     =>
    (printout t "Behavior ID\: " (slot-get ?behavior Behavior\ ID)  crlf))

I understand ?rem is an object, then how do I get the multi-slot value from it, to use in second statement.(without defglobals)

In the project i gave in last mail:

The expected rule firing and output:

Jess> (batch h:\\CLIPS\\simple.clp)
Behavior ID: 5
Behavior ID: 2
Behavior ID: 1
3

Observed:

Jess> (batch h:\\CLIPS\\simple.clp)
[Activation: MAIN::simple-multi-multi-match  f-472 ; time=794 ; salience=0]
[Activation: MAIN::simple-multi-multi-match  f-468 ; time=786 ; salience=0]
For a total of 2 activations in module MAIN.
Behavior ID: 5
Behavior ID: 1
2


Thx indeed, for your time.

JFC

On 6/30/06, Dona Mommsen <[EMAIL PROTECTED] > wrote:
Hi John,


On Jun 29, 2006, at 3:54 AM, John wrote:

> Hi, Im back with problems, but quite interesting ones.
>
> I solved the problem Dona have listed in her last mail. However, I
> found more problems while doing so.

I apologize that I didn't have the time to look into it. But now I'm
curious: How did you get rid of the error message?
>> Jess reported an error in routine ValueVector.set
>>      while executing rule LHS (TECT).
>>   Message: Bad index 5 in call to set() on this vector: (MAIN::object
>> (is-a Hello) (is-a-name "Hello") (OBJECT
>> <Java-Object:edu.stanford.smi.protege.model.DefaultSimpleInstance >)
>> (Neighbor Address "rst" "uvw" "xyz") (Resource ID 4)).
>>   Program text: ( defrule testnest3 ?r2 <- ( MAIN::object ( is-a Node
>> Spoof ) ( Resource sequence $?r & : ( member$ ?*a* $?r ) ) ) = > (
>> printout t "Node" ( slot-get ?r2 Behavior ID ) crlf ) )  at line 7.


>
> I tried to match multislot to multislot instances. The problem is that
> only first occurence of the instance is searched. I have attached the
> protege/Jess project files. This project is just a modified
> implementation of Dona's model. The Jess batch files contains the
> pattern matching rules ( simple.clp).
>
> From the scripts:
>
> (mapclass :THING)

Well, I don't know if it is relevant, but I usually don't do  (mapclass
:THING), because it maps the entire Protege system classes (unnecessary
overload in your fact base if you are not doing anyting with them). In
addition, this mapping includes also the JessTab classes, see under
:SYSTEM-CLASS there are subclasses :JESS-ENGINGE, :JESS-DEFINITION,
:RULE, :FUNCTION. It would confuse me if I had them in the fact base.
On my system it apparently  also troubles Protege. When I tried
(mapclass :THING) everyting got asserted in the fact base, but calling
(clear) instantly crashes Protege. Have you tried to (clear) your fact
base? I wonder if this Is a version-specific issue on my machine, or a
general thing not to map :THING. Although I assume that you are using
protege frames, note that the JessTab website explicitly warns of doing
that with owl projects:

> Avoid doing (mapclass owl:Thing) under OWL, because JessTab will map
> all the hidden RDF/OWL classes as well, which may result in a large
> amount of unwanted Jess facts and stability problems. For the same
> reason, avoid mapping metaclasses and metaproperties under OWL. Use an
> intermediate subclass of owl:Thing and map this class instead.


>
>
> ;matching the integer 111 in the multislot "Resource ID"
>
>  (defglobal ?*res* = (nth$ 1 (find-instance ((?h Hello)) (slot-get ?h
> Resource\ ID ?n&:(member$ 111 ?n)))))

Putting just one instance in a global variable was just my lazy way to
get a test case, since I don't need to  bind it again when I clear
Jess.
You can also use

(find-all-instances ((?h Hello)) (member$ 111 (slot-get ?h Resource\
ID))))

and it will return a list of Protege instances.

One remark about the difference between  find-all-instance(s) and
defquery that I had to lear the hard way:
find-all-instance and find-all-instances are JessTab functions which
return Protégé instances
<Java-Object:edu.stanford.smi.protege.model.DefaultSimpleInstance>
    —> To access slots of the result use JessTab function (slot-get
object slot)
Alternatively, you can define a query with defquery, see JiA p. 129.
Note that this will return an iterator containing  mapped Protégé facts
<Java-Object:JessTab.DefaultMappedFact>
JiA p. 129 describes how to transform the interator into a list of
facts, but note that they are still different java objects.
—> To access slots of the result use Jess function (fact-slot-value
object slot)
—> JessTab function slot-get will not work here!

HTH

Dona


>
>
> ;Using the above found instance, the multi-slot instance field is
> searched
>  (defrule simple-multi-multi-match
>
> ?behavior <- (object(is-a Node\ Spoof) (Resource\ sequence $?before
> ?*res* $?after))
>   =>
> (printout t "Behavior ID\: " (slot-get ?behavior Behavior\ ID)
> crlf))
>
> (run)
>
>
> ; The problem is that the ?*res* points to only the first occurence of
> the list of matching occurences.
> ; Therefore, Only the first instance is searched inside the mulitfield
> instance slot.
>  ; Is there anyway, i can pattern match within the rule definition
>
> Thx in advance.
>
> JFC
>
>
> On 6/28/06, John < [EMAIL PROTECTED]> wrote:Hi all,
>>
>> Dona, I figured a way to match multislots with multislot instance.
>> However Im not able to solve the error you pointed out.
>>
>> Any help will be great.
>>
>> thx in advance.
>>
>> JFC
>>
>>
>>  On 6/27/06, John < [EMAIL PROTECTED]> wrote:Hi Dona,
>>> thx for helping me out. But what if the slot "Resource ID" is itself
>>> a multislot? how do I match multislot to a multislot of instances?
>>>
>>> Thx for your time.
>>>
>>> John Felix C J
>>>
>>>  On 6/23/06, Dona Mommsen <[EMAIL PROTECTED] > wrote:
>>>  Hi John,
>>>
>>> I was trying to reproduce John's small example and I was convinced
>>> that
>>> matching multislots with Protege is possible.
>>>
>>> I used the model described by John (see below).
>>> I created 4 Instances of Hello with Resource\ ID 1 through 4
>>> I created 3 Instances of Node\ Spoof:
>>> Behavior\ ID A Resource sequence (1 3 4)
>>> Behavior\ ID B Resource sequence (2 3)
>>> Behavior\ ID C Resource sequence (1 2 3 4)
>>>
>>> These are all mapped Protege instances, so the multislot resource
>>> sequence is actually a list of Protege intstances.
>>> For example, the fact for the instance with Behavior\ ID A looks like
>>> this:
>>>
>>> (MAIN::object (is-a Node Spoof) (is-a-name "Node Spoof") (OBJECT
>>>  <Java-Object: edu.stanford.smi.protege.model.DefaultSimpleInstance>)
>>> (Resource sequence
>>> <Java-Object:edu.stanford.smi.protege.model.DefaultSimpleInstance>
>>> <Java-Object:edu.stanford.smi.protege.model.DefaultSimpleInstance >
>>> <Java-Object:edu.stanford.smi.protege.model.DefaultSimpleInstance>)
>>> (Behavior ID "A"))
>>>
>>> I simplified the rule just to match multislots with instances, and I
>>> tried 2 alternatives, one with return value constraint and one with
>>> the
>>> multifield.
>>> For each test, I bind a Protege instance to a global variable that I
>>> use in the rules.
>>>
>>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>> ;;Example with return value constraint cf. JiA p. 106
>>> ;; Hello with Resource ID 1 is in Node Spoof A and C
>>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>> (defglobal ?*a* = (nth$ 1 (find-instance ((?h Hello)) (eq
>>> (slot-get
>>> ?h Resource\ ID) 1))))
>>>
>>> (defrule testnest3
>>> ?r2 <- (MAIN::object (is-a Node\ Spoof) (Resource\ sequence
>>> $?r&:(member$ ?*a* $?r)))
>>> =>
>>> (printout t "Node" (slot-get ?r2 Behavior\ ID)crlf))
>>>
>>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>> ;;Example with multifields JiA p. 103
>>> ;; Hello with Resource ID 2 is in Node Spoof B and C
>>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>>
>>> (defglobal ?*b* = (nth$ 1 (find-instance ((?h Hello)) (eq
>>> (slot-get
>>> ?h Resource\ ID) 2))))
>>>
>>> (defrule testnest4
>>> ?r2 <- (MAIN::object (is-a Node\ Spoof) (Resource\ sequence
>>> $?before
>>> ?*b* $?after))
>>> =>
>>> (printout t "Node" (slot-get ?r2 Behavior\ ID)crlf))
>>>
>>> The rules match properly and fire, but I do get error messages in
>>> both
>>> cases:
>>>
>>>
>>> > Jess> (defrule testnest3?r2 <- (MAIN::object (is-a Node\ Spoof)
>>> > (Resource\ sequence $?r&:(member$ ?*a* $?r))) => (printout
>>> t
>>> > "Node" (slot-get ?r2 Behavior\ ID)crlf))
>>> > ==> Activation: MAIN::testnest3 :f-4
>>> > ==> Activation: MAIN::testnest3 :f-6
>>> > Jess reported an error in routine ValueVector.set
>>> > while executing rule LHS (TECT).
>>> > Message: Bad index 5 in call to set() on this vector:
>>> (MAIN::object
>>> > (is-a Hello) (is-a-name "Hello") (OBJECT
>>> > <Java-Object:edu.stanford.smi.protege.model.DefaultSimpleInstance>)
>>> > (Neighbor Address "rst" "uvw" "xyz") (Resource ID 4)).
>>> > Program text: ( defrule testnest3 ?r2 <- ( MAIN::object ( is-a
>>> Node
>>> > Spoof ) ( Resource sequence $?r & : ( member$ ?*a* $?r ) ) ) = > (
>>> > printout t "Node" ( slot-get ?r2 Behavior ID ) crlf ) )at line 7.
>>> > Jess> (run)
>>> > FIRE 1 MAIN::testnest3 f-6
>>> > NodeC
>>> > FIRE 2 MAIN::testnest3 f-4
>>> > NodeA
>>> > 2
>>>
>>> > Jess> (defrule testnest4?r2 <- (MAIN::object (is-a Node\ Spoof)
>>> > (Resource\ sequence $?before ?*b* $?after)) => (printout t
>>> > "Node" (slot-get ?r2 Behavior\ ID)crlf))
>>> > ==> Activation: MAIN::testnest4 :f-5
>>> > ==> Activation: MAIN::testnest4 :f-6
>>> > Jess reported an error in routine ValueVector.set
>>>  > while executing rule LHS (TECT).
>>> > Message: Bad index 5 in call to set() on this vector:
>>> (MAIN::object
>>> > (is-a Hello) (is-a-name "Hello") (OBJECT
>>> > <Java-Object:edu.stanford.smi.protege.model.DefaultSimpleInstance
>>> >)
>>> > (Neighbor Address "rst" "uvw" "xyz") (Resource ID 4)).
>>> > Program text: ( defrule testnest4 ?r2 <- ( MAIN::object ( is-a
>>> Node
>>> > Spoof ) ( Resource sequence $?before ?*b* $?after ) ) = > (
>>> printout t
>>> > "Node" ( slot-get ?r2 Behavior ID ) crlf ) )at line 9.
>>> > Jess> (run)
>>> > FIRE 1 MAIN::testnest4 f-6
>>> > NodeC
>>> > FIRE 2 MAIN::testnest4 f-5
>>> > NodeB
>>> > 2
>>>
>>> While Jess is still able to fire the rules correctly, it is about the
>>> last thing it does before Protege hangs.
>>> Any idea what is going on here?
>>> I'm using Protege 3.1.1 Build 216, JessTab 1.4, Jess 7.0b4 on Mac OS
>>> X
>>> 10.3.9
>>>
>>> Thanks in advance for any hints
>>>
>>> Dona
>>>
>>>  P.S.: I'll gladly send the Protege project to anyone interested.
>>>
>>>
>>>
>>> On Jun 21, 2006, at 9:01 PM, John wrote:
>>>
>>> > first, thx for Dona & Jason for their valuable comments. Yes, Dona,
>>> > your guess is right. I am using protege in combo with Jess. I see
>>> > protege is more powerful if you combine the Jess features. As Dona
>>> > have accurately guessed, I used JessTab to map instances and
>>> classes
>>> > created in protege to Jess.
>>> >
>>> > Jason, Assert(ion) in Jess(with protoge) is done by a GUI interface
>>> > (Form based). The problem is that the object variable (for the
>>> > multislots) is a single instance address and doesnt contain the
>>> actual
>>> > contents.
>>> >
>>> > As of the contents of the Hello and Node Spoof class;
>>> >
>>> > Hello class contain two slots: Resource ID and Neighbor
>>> > Address(multislot type string)
>>> >
>>> > Node Spoof: Behavior ID (string) and Resouce sequence (multislot
>>> type
>>> > Hello)
>>> >
>>>  > When I pattern - match the resource sequence, the matching returns
>>> > false always since LHS obtains just the instance address of
>>> resource
>>> > sequence and not the contents of the multislot.
>>> >
>>> > One more silly question; is CLIPS more advanced than JESS? I see
>>> lot
>>> > of common syntax and features between them. Then why not use CLIPS?
>>> > Also from some sources, I heard CLIPS is more powerful and
>>> portable to
>>> > various other language.
>>> >
>>> > Thx in advance.
>>>  >
>>> > On 6/22/06, Dona Mommsen <[EMAIL PROTECTED] > wrote:
>>> >>
>>> >> I apologize for barging in. I'm just guessing that John might be
>>> using
>>> >> Jess in combination with Protégé
>>> >>
>>> >> >>(object (is-a Node\ Spoof) (resource\ sequence $? ?o $?)
>>> >> (Behavior\
>>> >> >> ID ?bid))
>>> >>
>>> >> looks very much like a mapped instance with JessTab. Asserting
>>> facts
>>> >> with mapclass or mapinstance creates facts that have
>>> >>
>>> >> > this "object/is-a" thing
>>> >>
>>> >> Usually this shouldn't interfere with the efficiency and
>>> possibilities
>>> >> of using Jess.
>>> >>
>>> >> Dona
>>> >>
>>> >> On Jun 21, 2006, at 6:47 AM, friedman_hill ernest j wrote:
>>> >>
>>> >> > This should work fine if the "resource sequence" multislot
>>> contains
>>> >> > the actual fact object; if you showed us where you assert the
>>> >> "Hello"
>>> >> > fact, then I could probably tell you what's gone wrong.
>>> >> >
>>> >> > While we're here, I should ask why you're doing this
>>> "object/is-a"
>>> >> > thing, rather than having a "hello" template and a "node spoof"
>>> >> > template; you're doing a lot of extra work to make sure Jess
>>> can't
>>> >> > work very efficiently. And I can tell you that the "and" is not
>>> >> needed
>>> >> > here; all the patterns on the LHS of a rule are implicitly
>>> "and"-ed
>>> >> > together. And finally, my goodness, you're going to drive
>>> yourself
>>> >> > nuts embedding spaces into symbols like this -- don't do that!
>>> >> >
>>> >> > I think John wrote:
>>> >> > [Charset iso-8859-1 unsupported, filtering to ASCII...]
>>> >> >> Hi all,
>>> >> >>
>>> >> >> I am a rookie to jess. I was stuck-up with this problem for the
>>> >> past
>>> >> >> 24-hrs.
>>> >> >> So kindly advice.
>>> >> >>
>>> >> >> I created two classes with multislots. The second class has a
>>> >> >> multislot of
>>> >> >> type - instance of the previous class. I am not able to pattern
>>> >> match
>>> >> >> the
>>> >> >> instance in the second class's object. Multislot pattern works
>>> well
>>>  >> >> for
>>> >>>> strings. How can i do it for multislot of instances? I have
>>> >> attached
>>> >> >> the
>>> >> >> snippet for your kind perusal. Please Help.
>>> >> >>
>>> >> >>
>>> >> >> (defrule testnest
>>> >> >> (and
>>> >>>>
>>> >> >> ?o<- (object (is-a Hello) (Neighbor\ Address $? " 10.0.0.1 "
>>> $?)
>>> >> >> (Resource\ ID
>>> >> >> ?rid))
>>> >> >>
>>> >> >> ?r2 <- (object (is-a Node\ Spoof) (resource\ sequence $? ?o $?)
>>> >> >> (Behavior\
>>>  >> >> ID ?bid))
>>> >> >> =>
>>> >> >>
>>> >> >> (printout t "Attack" crlf))
>>> >> >>
>>> >> >> The Two Classes: Hello and Node Spoof
>>> >> >>
>>> >> >> Multifield slots : Neighbor Address (type STRING) and resource
>>> >> >> sequence
>>> >> >> (is-a Hello)
>>> >> >>
>>> >> >> Thanx in Advance
>>> >> >
>>> >> >
>>> >> >
>>> >> > ---------------------------------------------------------
>>> >> > Ernest Friedman-Hill
>>> >> > Advanced Software ResearchPhone: (925) 294-2154
>>> >> > Sandia National LabsFAX: (925) 294-2234
>>>
>>> >> > PO Box 969, MS 9012 [EMAIL PROTECTED]
>>> >> > Livermore, CA 94550 http://herzberg.ca.sandia.gov
>>> >> >
>>> --------------------------------------------------------------------
>>> >> > To unsubscribe, send the words 'unsubscribe jess-users
>>> >> [EMAIL PROTECTED] '
>>> >> > in the BODY of a message to [EMAIL PROTECTED], NOT to the
>>> list
>>> >> > (use your own address!) List problems? Notify
>>> >> > [EMAIL PROTECTED].
>>> >> >
>>> --------------------------------------------------------------------
>>> >> >
>>> >>
>>>
>>>
>>
> <simple.zip>

Reply via email to