[CLIPS] Most specific superclass

20 views
Skip to first unread message

baylor

unread,
Mar 30, 2009, 6:12:30 PM3/30/09
to CLIPSESG
We're doing some NLP work using your standard hierarchy of concepts.
We use multiple inheritance. When we want to find a matching
superclass and there are multiple matches, we want to use the one
closest to the object in question

The only way i know to get superclasses is the function class-
superclasses. The resulting array is ordered by depth, not breadth. If
you have the hierarchies C-B-A and Z-Y-X, a class Q that inherits from
C and Z and matches in A and Z, walking the hierarchy will match A,
the great-grandfather, rather than Z, the parent

My preference is to not use multiple inheritance but the boss says it
came in handy on the last several ontologies so i need to support it

Is there an easy to walk the superclass hierarchy breadthwise rather
than depth?

-b

CLIPS Support

unread,
Mar 31, 2009, 6:58:17 PM3/31/09
to CLIPSESG
How are you programatically walking the hierarchy to get a match in A?

CLIPS> (defclass A (is-a USER))
CLIPS> (defclass B (is-a A))
CLIPS> (defclass C (is-a B))
CLIPS> (defclass X (is-a USER))
CLIPS> (defclass Y (is-a X))
CLIPS> (defclass Z (is-a Y))
CLIPS> (defclass Q (is-a C Z))
CLIPS> (class-superclasses Q)
(C Z)
CLIPS>

baylor

unread,
Mar 31, 2009, 7:10:45 PM3/31/09
to CLIP...@googlegroups.com

> How are you programatically walking the hierarchy to get a
> match in A?

i'm trying to figure out what my options are. The easiest was

CLIPS> (class-superclasses Q inherit)

which gives me the list of superclasses as an array, so i can pop one off, check it and if it fails, try the next. The issue here is that class-superclasses returns the classes in depth order - (C B A Z Y X). So A (great grandfather) would match before Z (direct parent)

i have a different solution that i think works where i call class-superclasses without the inherit flag, post those as facts and then let the rule engine run through one or two dozen rules until it finds a match but the code seems... big and complicated and possibly error prone (in CLIPS i'm never quite sure when i get good results because i wrote the rules correctly and when it's an artifact of my build and machine, especially when i use complexity for conflict resolution and the all the facts go through the same rule, hence equal number of antecedents and no guarantee of evaluation order under complexity)

i've considered writing a foreach loop to get the immediate parents and then calling the function on those but the most obvious recursive solution also results in a depth ordering, so i need to think of a way to handle that

With enough thought and code, i can get the ordering i want, but i want to make sure i'm not missing some really simple way, like an alternative to class-superclasses or a flag i didn't notice

-b


--- On Tue, 3/31/09, CLIPS Support <gdronl...@swbell.net> wrote:

CLIPSLurker

unread,
Mar 31, 2009, 10:45:25 PM3/31/09
to CLIPSESG
CLIPS> (defclass A (is-a USER))
CLIPS> (defclass B (is-a A))
CLIPS> (defclass C (is-a B))
CLIPS> (defclass D (is-a C))
CLIPS> (defclass E (is-a D))
CLIPS> (defclass X (is-a USER))
CLIPS> (defclass Y (is-a X))
CLIPS> (defclass Z (is-a Y))
CLIPS> (defclass Q (is-a E Z))
CLIPS>
(deffunction class-superclasses-breadth* (?classes $?chain)

(if (= (length$ ?classes) 0) then (return ?chain))

(bind ?next-classes (create$))

(progn$ (?c ?classes)
(bind ?add (class-superclasses ?c))
(progn$ (?a ?add)
(if (not (member$ ?a ?chain))
then
(bind ?chain (create$ ?chain ?a))
(bind ?next-classes (create$ ?next-classes ?a)))))

(bind ?chain (class-superclasses-breadth* ?next-classes ?chain))

(return ?chain))
CLIPS>
(deffunction class-superclasses-breadth (?class)
(return (class-superclasses-breadth* (create$ ?class))))
CLIPS> (class-superclasses-breadth Q)
(E Z D Y C X B USER A OBJECT)
CLIPS>

On Mar 31, 6:10 pm, baylor <bayl...@yahoo.com> wrote:
> > How are you programatically walking the hierarchy to get a
> > match in A?
>
> i'm trying to figure out what my options are. The easiest was
>
> CLIPS> (class-superclasses Q inherit)
>
> which gives me the list of superclasses as an array, so i can pop one off, check it and if it fails, try the next. The issue here is that class-superclasses returns the classes in depth order - (C B A Z Y X). So A (great grandfather) would match before Z (direct parent)
>
> i have a different solution that i think works where i call class-superclasses without the inherit flag, post those as facts and then let the rule engine run through one or two dozen rules until it finds a match but the code seems... big and complicated and possibly error prone (in CLIPS i'm never quite sure when i get good results because i wrote the rules correctly and when it's an artifact of my build and machine, especially when i use complexity for conflict resolution and the all the facts go through the same rule, hence equal number of antecedents and no guarantee of evaluation order under complexity)
>
> i've considered writing a foreach loop to get the immediate parents and then calling the function on those but the most obvious recursive solution also results in a depth ordering, so i need to think of a way to handle that
>
> With enough thought and code, i can get the ordering i want, but i want to make sure i'm not missing some really simple way, like an alternative to class-superclasses or a flag i didn't notice
>
> -b
>
> --- On Tue, 3/31/09, CLIPS Support <gdronline2...@swbell.net> wrote:
Reply all
Reply to author
Forward
0 new messages