Object-Oriented Programming Support for CLASSIC

From: AAAI Technical Report WS-96-05. Compilation copyright © 1996, AAAI (www.aaai.org). All rights reserved.
Object-Oriented ProgrammingSupport for CLASSIC
Ralf M~iller
University of Hamburg,ComputerScience Department
Vogt-KOlln-Str.30, D-22527Hamburg,Germany
moeller@in formatik,uni-hamburg,
Abstract:Themainthesis of this paperis that in order to
useDescriptionLogicsinpractical applications,a seamless
integration with object-oriented systemdevelopment
methodologiesmustbe realized. It presents an object-oriented
layer for CLASSIC.
1. Introduction
tional programmingpoint of view it is irrelevant
whether a result of a function call is defined by
merely looking up a set of instances in a relation
table or by actually computinginstances with complex algorithms and auxiliary data structures. Second, using genetic accesser functions for retrieving
the objects that are directly set into relation to a specific individual allows a lot of error checkingcodeto
be automatically generated. A unified interface for
accessing the services that an object provides hides
manyrepresentation details whichare irrelevant from
a moreabstract perspective.
Althoughthe logical semantics of Description Logics
(DL)modelingconstructs is a big plus, to ensure decidability of the subsumptionproblem, the expressiveness of the logical language must be limited. The
consequenceis that in a real application without toy
problems, currently not all aspects can be formally
For example,in a graphical user interface, the drawmodeled with DL constructs. This means that proing function for an object might depend on the
grammingis still necessary. As a DL we use the
object’s concepts. User interface programmingis one
system [9]. Reducing CLASSICto practice
of the best examplesfor the application of object-ori[1] means that the DL can be integrated into the
ented programmingtechniques. For rapid user interwhole system development approach which, at the
current state of the art, uses object-oriented modeling. face development however, an existing UIMSmust
In this paper, the CLOSOOPperspective will be used be reused. UIMSsprovide powerful programming
[10]. Thepaper presents an object-oriented programming abstractions which are modeledwith the object-orilayer for CLASSIC.
It assumes basic knowledgeabout ented representation techniques (e.g. for CLOSthe
UIMSCLIMmight be used [7]). There is no way to
rebuild these software libraries with CLASSIC
The integration of CLASSIC
and CLOSrequires that
any other DLin a reasonable time. So what can be
genetic functions and methods can be written for
done? Copying information associated with a DL
CLASSICindividuals. The procedural parts of an
object into a CLOSobject which is used for UI part
application should be able to use CLASSIC
individuof an application is inadequate as well. Unfortuals just like CLOSinstances. The "services" of an
nately, managing multiple "copies" of the same
object are accessed only by the use of generic funcobject is a direct contradiction to the principles of
tions. This meansthat the relational part of CLASSIC
object-otiented programming.Thus, for rapid applishould be hidden behind a functional layer because,
cation development, object-oriented programming
from a software engineering point of view, dealing
techniques must be madeavailable to CLASSIC
indiwith individuals and relations earl be quite cumberviduals. The next chapter discusses an approach that
somefor at least two reasons: First of all, froma funcdemonstrates how this can be achieved with an
extension to CLASSICthat uses CLOS-like genetic
1. Thispaperis a shortened
andrewrittenversionof a paperpre- functions to access information about an individual.
sentedat OOPSLA’96
[5]. Theextensionsfor the CLASSIC
sysIt will be shownthat the implementation of CLAStempresented
in this paperare availablefromthe author[6].
SIC methoddispatch can be surprisingly simple.
- 170-
2. Integrating
ated. If they do not already exist, corresponding
2generic functions are automatically generated.
Generic functions for Description Logics have also
been developed in the LoomSystem [2]. Methoddispatch for individuals is provided by specific genetic
functions which dispatch on ABoxobjects but not on
CLOSobjects. Loomalso supports CLOSclasses for
the implementation of ABoxindividuals but only a
limited sort of reasoning is implemented on these
instances (no dynamic reclassification by forward
The first role option :single-value-p specifies
whether a single value or a set of values should be
returned by the role reader function. The other option
is used to insert code for error
checking to avoid an empty set to be returned. The
following example illustrates the use of defineaccessor. For concept and role declarations the
KRSSsyntax is used [8].
Theapproachpresented in this paper clearly separates
CLASSICand CLOSbut provides a unified way to
access the services of both systems.
2.1. Accessors: A Functional Interface to a
Knowledge Base
itself provides a relational interface for
retrieving and addingrole fillers. Givenan individual
and a role, the set of fillers can be retrieved: (clfillers<ind><role>). In manycasesonlyone
filler is returned. However,the result will alwaysbe a
set (actually a list) and the function first must
applied to get the list element itself. To hide the
repeating access to the first element, an additional
function will have to be written. Furthermore,in some
circumstances,it will be considered as an error if the
filler is not known.Unfortunately, additional code
mustbe written to checkthis. If nil (the emptyset)
returned, an error is likely to occur in subsequent
function calls whenan individual is expected. Again,
code must be written to avoid this. Instead of writing
this code manually, a more general mechanismis
advantageous. The way to access individuals should
be declaratively defined using generic functions and
corresponding low-level code for methods should be
automatically generated. The declaration form
defineacces sors has been introduced to specify
the access to individuals in that way.
[ :single-value-p<boolean> ]
[ :error-lf-null<boolean> ] )
ship classic-thing)
: single-value-p
: single-value-p
As in CLOS,for accessing information of an object,
defines methods for generic
functions. Additional methods might be written by
the programmer(e.g. around methods or after and
before methods). CLASSICindividuals require
another dispatch mechanismwhich is realized by
extended generic functions.
Generic Functions and Methods
The extended generic functions presented in this
paper can dispatch on CLASSICconcepts or CLOS
classes or both. The form define-generic- function is used to define a generic function with dispatching extended to CLASSIC
The argument list of define-generic-function
indicates which arguments expect CLASSIC
and which arguments use standard CLOSdispatch.
[ <other-argument>... ] )
[ <option>...] )
A description for a dispatchingargumentis a list consisting of an argumentnameand a dispatch indicator
For each role description mentionedafter the concept
name, a reader method and a serf writer method for
the generic function <accessor-name> is gener-
2. Theexplicit declaration of a generic aeeessor function is neeessary, for instance, whena special methodcombinationthat differs from the standard methodcombinationis to be used [10].
- 171-
(either :clos or :classic). Just as defgeneric
CLOS,define-generic-function alSO supports ordinary argumentswithout specializer (called
other-arguments). The optionsfor definefrom
generic-function are the same as for defge-
function can be defined as follows (comparethis to
initialize- instance from CLOS).
((ind <concept-name>)&rest initargs)
., ,)
Initialization arguments can also be given to create-individual.
The list of "initargs" is a
setsof iniMethodscan be definedwith the form definetial
Note that methodcombinations are also supported.
(define-method<function-name>[ <qualifier>
( <dispatched-argument>
[ <other-argument>... ] )
2.4. Computation of the Concept Precedence
The TBoxdefines a partial order relation between
The syntax of a dispatched argument in a method concepts (subsumptionrelation). In order to define
parameterlist is identical to the syntax of arguments howmethoddispatch is handled, the multiple inheritfor defmethod of CLOS. The <qualifier> indiance lattice must be serialized by a concept prececates the kind of methodcombination. In addition to dence list which represents a total order between
names for CLOSclasses, CLASSICconcept names concepts. A concept precedence list is used for the
can be used as specializers.
same purposes as a CLOSclass precedence list, it
The following declarations continue the example defines howan effective methodfor a specific function call is computed(see the detailed introduction in
from above.
[3]). A valid concept precedence list is any total
pos ( (ship :classic)
that obeys all partial orders defined by the
pos ( (s ship)
(values(position-xs) (position-ys)
TBox.However,by this requirement only a small set
of constraints are defined. There are still several dif(define-generic-function
draw ((ship :classic)
ferent approaches to serialize a concept lattice. In
(stream :clos)))
the notational order of superclasses in a class
(deflne-methoddraw ((ship ship)
(stream graphic-stream))
definition defines a set of additional order constraints.
, ,,)
However,from the viewpoint of Description Logics,
Ship is a CLASSICconcept(see above) and the direct superconcepts (the least general subsugraphic- stream is a CLOSclass.
mers) are unordered. Therefore, in the approach presented in this paper, the relation of parents with
2.3. Individual Creation and Initialization
respect to methoddispatch is left undefined. ProceCreating individuals using the primitives supplied by dural code must not depend on any notational order
between concept parents.
(or KRSS)is somewhatcrude. From a software engineering point of view, a protocol for indi3. Implementation of Method Dispatch
vidual initialization
is needed. For individual
a function create-individual
A straightforward implementation for method disparameters(concept-name
&optional ( indpatch with individuals can be provided. CLASSIC
name (gensym)) &rest initargs) has
dispatch is reduced to CLOSdispatch.
¯0 0 )
Whenan individual is created with create-individual,
the generic function initialize-individual is automatically called. A method for this
3. Theset of initial fillers for a role is representedby a list. If a
non-list is used, a singleton list is automaticallycreated.
- 172-
3.1. Reducing CLASSIC dispatch
( (A
The implementation of generic functions and method
dispatch for CLASSICis quite simple. 4 The form
is used to declare
which parameters are handled as ordinary CLOS The methodis defined for the "real" generic function
with suffix METHOD.
In the example, the specializer
instances and which parameters are CLASSICindiship
to the second parameter. For
viduals. As a side effect of this declaration, a new
the original parameter no specializer is defined. It
function is created (a simple Common
Lisp function).
This "wrapper" function calls another function with specializes on t, the most general type in Common
the same nameconcatenated with the suffix METHOD. Lisp, and therefore, this parameter has no "discrimiThis function internally represents the generic func- nating power". Nevertheless, the original instance
tion and implements the method dispatch. For must be passed as an argument. In the body of the
method, the CLASSICindividual must be bound to
instance, the macroform:
IND.The corresponding additional parameter is used
for dispatching (its system-generated nameis
( (a :classic)
(b :clos)))
unintemed).Since the substitute specializer must be
CLOSclass (here the class A is used), for every
expands into
named CLASSICconcept a corresponding CLOS
class is automaticallycreated. The set of superclasses
of such a class is computedon the basis of the TBox
classification process. Note that the list of super(DBFUN F (A
classes of a class might dynamically change whena
defined concept is automatically inserted into the
subsumptionhierarchy by TBoxclassification.
The internal function F-METHOD
is applied to the
same argumentsas the wrapperfunction, but for each
parameter, which uses CLASSIC
dispatch, an additional parameter is inserted (for a this will be
#:type6806). For each CLASSICindividual,
associated CLOSinstance is computed with compute-type-arg. In a method definition, the additional argumentsare used for the "real dispatching".
Note that normal CLOSarguments are treated as
usual. The methoddefinition
The function compute-type-arg
(see the expansion of define-generic-function)
fora CLASSICindividual.
compute- type- arg is to get the concept of a CLASSIC
(classic:cl-indparents), to derive a corresponding
Oneproblemis thata CLASSIC
maybe subsumed
by more than one named concept, i.e. classic : cl-
expands into
ind-parentsreturns a list of concepts. Whenthis
happens, a new anonymousCLOSclass with corresponding superclasses must be created on the fly. The
prototype object of this class will then be used. A
memoization scheme (with a hash-table *classtable*) is used to avoid inflationary class creation.
4. Themain~eaisinspiredby~eimplemenmfion
M CUM(define-presentationgeneric-function
(defun compute-type-arg (ind)
(or (classic: :di-clos-instance ind)
(let ( (class-names
(mapcar # ’ classic : cl-name
(classic:cl-ind-parentsind) )
(if (null (rest class-names))
( find-class -prototype
( (a <concept-name>)
(b <clos-class>)
- 173-
(find-class(first class-names)
(let ((class (gethash class-names
( if class
(let* ( (class-name(gensym))
(class (find-class
: name class-name
: superclassesclass-names)
(setf(classic: : di-clos-instance
( find-class-prototype
(setf (gethash class-names
class)) ) )
three times slower than directly using CLASSIC’s
retrieval functions on the sameprocessor.
The mainthesis of this paper is that in order to use
Description Logics in practical applications, a seamless integration with object-oriented system development methodologies must be realized. Extended
generic functions and multimethods with CLASSIC
dispatch not only allow an incremental way of software definition. In addition to this, they can even
been seen as a form of defining assertions that
enforce a safer systemarchitecture also for the procedural parts (the sameholds for CLOS
With access to the internal data structures of CLASto Practice:
SIC (classic: : di- clos- instance),an individ- [1] Brachman,R.J., "Reducing"CLASSIC
RepresentationTheoryMeetsReality, in:
ual can be directly associated with its CLOS
Prec. KR’92Principles of Knowledge
counterpart, i.e. the procedure compute- type- arg
RepresentationandReasoning,Nebel,B., Rich, C.,
Swartout,W.(F_xls.) Morgan
Publ., 1992,
is used only whenthe individual is reclassified.
pp. 247-258.
has been extended to reset the association
[2] Brill, D., LoomReferenceManual,Version2.0,
between an individual and its CLOSrepresentative
USC/ISI,4676AdmiraltyWay,Marinadel Rey, CA
90292, December,1993.
whenthe individual is reclassified.
[3] Keene,S.E., Object-OrientedProgramming
The definition of compute-type-arg
indicates that
CLOS:A Programmer’sGuide to CLOS,AddisonWesley,1989.
the straightforward implementation of CLASSIC
dis[4] Lamping,J., Abadi,M., Methodsas Assertions,
patch comesat a certain cost. In addition to static
XeroxPale Alto ResearchCenter, available as:
ftp ://parcftp. xerox, com/pub/
costs for the definition of CLOSclasses for named
openimp I ementat ion s/methods - as CLASSIC
concepts, there are some initial dynamic
assertions, ps. Z.
[5] M611er,R., A FunctionalLayerfor Description
Logics: KnowledgeRepresentationMeetsObject¯ some calls to retrievalfunctions (classic:clOriented Programming,
in: Prec. OOPSLA’96,
name, classic : cl- ind-parents),
R., ExtendingCLASSIC
with Generic
¯ a complexhashing operation over a list of sym- [6] MOiler,
Functions and Methods, http://kogs bols,
www. informatik,
uni-hamburg, de/
~moeller/, 1996.
¯ possibly a dynamiccreation of a CLOSclass,
[7] M611er,R., User Interface Management
://kegs¯ the access to the CLOSclass prototype,
w-w-w, informatik,
¯ and an additional CLOS
dispatch step for the sub1996.
stitute argument.
P.F., Swartout,B., Description
[8] Patel-Sclmeider,
fromthe KRSSEffort,
Furthermore, a lot of garbage is created (mapcar).
Measurements on a Symbolies MacIvory-Model-3
indicate that a dispatched access to a relation with a [9]
generic function created by define-accessors
takes less than one millisecond. This is approximately
ksl. stanford, edu :/pub/knowledgesharing/papers/dl- spec. ps.
Resnick,L.A., Borgida,A., Brachman,
D.L., Patel-Schneider,P.F., Zalondek,
Description and ReferenceManual
for the Common
Lisp Implementation,Version2.2,
Lisp - The Language,Second
[10] Steele, G.L., Common
Edition, Digital Press, 1990.
- 174-