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,Computer Science Department Vogt-KOlln-Str.30, D-22527Hamburg, Germany moeller@in formatik,uni-hamburg, de

Abstract:The main thesis of this paperis that in order to tional programmingpoint of view it is irrelevant useDescription Logics in practical applications, a seamless whether a result of a function call is defined by integration with object-oriented systemdevelopment meth- merely looking up a set of instances in a relation odologiesmust be realized. It presents an object-oriented table or by actually computinginstances with com- programminglayer for CLASSIC. plex algorithms and auxiliary data structures. Sec- 1. Introduction ond, using genetic accesser functions for retrieving the objects that are directly set into relation to a spe- Althoughthe logical semantics of Description Logics cific individual allows a lot of error checkingcode to (DL)modeling constructs is a big plus, to ensure deci- be automatically generated. A unified interface for dability of the subsumptionproblem, the expressive- accessing the services that an object provides hides ness of the logical language must be limited. The manyrepresentation details whichare irrelevant from consequenceis that in a real application without toy a moreabstract perspective. problems, currently not all aspects can be formally modeled with DL constructs. This means that pro- For example,in a graphical user interface, the draw- grammingis still necessary. As a DL we use the ing function for an object might depend on the CLASSICsystem [9]. Reducing CLASSICto practice object’s concepts. User interface programmingis one [1] means that the DL can be integrated into the of the best examplesfor the application of object-ori- whole system development approach which, at the ented programmingtechniques. For rapid user inter- current state of the art, uses object-oriented modeling. face development however, an existing UIMSmust In this paper, the CLOSOOP perspective will be used be reused. UIMSsprovide powerful programming [10]. Thepaper presents an object-oriented programming abstractions which are modeledwith the object-ori- layer for CLASSIC.It assumes basic knowledgeabout ented representation techniques (e.g. for CLOSthe CLOS1 [3]. UIMSCLIM might be used [7]). There is no way to rebuild these software libraries with CLASSICor The integration of CLASSICand 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 CLASSICindividu- of an application is inadequate as well. Unfortu- als just like CLOSinstances. The "services" of an nately, managing multiple "copies" of the same object are accessed only by the use of generic func- object is a direct contradiction to the principles of tions. This meansthat the relational part of CLASSIC object-otiented programming.Thus, for rapid appli- should be hidden behind a functional layer because, cation development, object-oriented programming from a software engineering point of view, dealing techniques must be made available to CLASSICindi- with individuals and relations earl be quite cumber- viduals. The next chapter discusses an approach that somefor at least two reasons: First of all, froma func- demonstrates how this can be achieved with an extension to CLASSICthat uses CLOS-like genetic 1. Thispaper is a shortenedand rewritten version of a paperpre- functions to access information about an individual. sentedat OOPSLA’96[5]. Theextensions for the CLASSICsys- It will be shownthat the implementation of CLAS- tempresented in this paperare availablefrom the author[6]. SIC methoddispatch can be surprisingly simple.

- 170- 2. Integrating OOP and DL ated. If they do not already exist, corresponding generic2 functions are automatically generated. Generic functions for Description Logics have also been developed in the LoomSystem [2]. Methoddis- The first role option :single-value-p specifies patch for individuals is provided by specific genetic whether a single value or a set of values should be functions which dispatch on ABoxobjects but not on returned by the role reader function. The other option CLOSobjects. Loomalso supports CLOSclasses for :error-if-null is used to insert code for error the implementation of ABoxindividuals but only a checking to avoid an empty set to be returned. The limited sort of reasoning is implemented on these following example illustrates the use of define- instances (no dynamic reclassification by forward accessor. For concept and role declarations the inferences). KRSSsyntax is used [8]. (define-primitive-conceptship classic-thing) Theapproach presented in this paper clearly separates (define-primitive-rolehas-position-x nil) CLASSICand CLOSbut provides a unified way to (define-primitive-rolehas-position-y nil) access the services of both systems. (define-accessorsship (has-position-xposition-x : single-value-pt 2.1. Accessors: A Functional Interface to a :error-if-nullt) Knowledge Base (has-position-yposition-y CLASSICitself provides a relational interface for : single-value-pt :error-if-nullt) retrieving and adding role fillers. Givenan individual and a role, the set of fillers can be retrieved: (cl- As in CLOS,for accessing information of an object, fillers ). In manycases only one define-accessors defines methods for generic filler is returned. However,the result will alwaysbe a functions. Additional methods might be written by set (actually a list) and the function first must the programmer(e.g. around methods or after and applied to get the list element itself. To hide the before methods). CLASSICindividuals require repeating access to the first element, an additional another dispatch mechanismwhich is realized by extended generic functions. function will have to be written. Furthermore,in some circumstances,it will be considered as an error if the 2.2. Generic Functions and Methods filler is not known. Unfortunately, additional code mustbe written to checkthis. If nil (the emptyset) The extended generic functions presented in this returned, an error is likely to occur in subsequent paper can dispatch on CLASSICconcepts or CLOS function calls whenan individual is expected. Again, classes or both. The form define-generic- func- code must be written to avoid this. Instead of writing tion is used to define a generic function with dis- this code manually, a more general mechanismis patching extended to CLASSICindividuals. advantageous. The way to access individuals should The argument list of define-generic-function be declaratively defined using generic functions and indicates which arguments expect CLASSICdispatch corresponding low-level code for methods should be and which arguments use standard CLOSdispatch. automatically generated. The declaration form (define-generic-function define- acces sors has been introduced to specify (... the access to individuals in that way. [ ... ] ) [

For each role description mentionedafter the concept 2. The explicit declaration of a generic aeeessor function is nee- name, a reader method and a serf writer method for essary, for instance, whena special methodcombination that dif- the generic function is gener- fers from the standard methodcombination is to be used [10].

- 171- (either :clos or :classic). Just as defgeneric function can be defined as follows (comparethis to from CLOS,define-generic-function alSO sup- initialize- instance from CLOS). ports ordinary argumentswithout specializer (called (define-methodinitialize-individual :after other-arguments). The optionsfor define- ((ind )&rest initargs) generic-function are the same as for defge- ., ,) neric.Note that method combinations are also sup- Initialization arguments can also be given to cre- ported. ate-individual.The list of "initargs" is a sequenceof rolenames and corresponding setsof ini- Methodscan be definedwith the form define- tialfillers) method. (define-method [ 2.4. Computation of the Concept Precedence ( ... [ ... ] ) List ¯ 0 0 ) The TBoxdefines a partial order relation between The syntax of a dispatched argument in a method concepts (subsumption relation). In order to define parameter list is identical to the syntax of arguments howmethod dispatch is handled, the multiple inherit- for defmethod of CLOS. The indi- ance lattice must be serialized by a concept prece- cates 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 func- from above. tion call is computed(see the detailed introduction in (define-generic-functionpos ( (ship :classic) [3]). A valid concept precedence list is any total (deflne-methodpos ( (s ship) ordering that obeys all partial orders defined by the (values(position-x s) (position-ys) TBox. However,by this requirement only a small set of constraints are defined. There are still several dif- (define-generic-functiondraw ((ship :classic) (stream :clos))) ferent approaches to serialize a concept lattice. In (deflne-methoddraw ((ship ship) CLOSthe notational order of superclasses in a class (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 subsu- graphic- stream is a CLOSclass. mers) are unordered. Therefore, in the approach pre- sented in this paper, the relation of parents with 2.3. Individual Creation and Initialization respect to methoddispatch is left undefined. Proce- Creating individuals using the primitives supplied by dural code must not depend on any notational order CLASSIC(or KRSS)is somewhatcrude. From a soft- between concept parents. ware engineering point of view, a protocol for indi- vidual initialization is needed. For individual 3. Implementation of Method Dispatch creation, a function create-individualwith A straightforward implementation for method dis- parameters(concept-name &optional ( ind- patch with individuals can be provided. CLASSIC name (gensym)) &rest initargs) has dispatch is reduced to CLOSdispatch. supplied. Whenan individual is created with create-indi- vidual, the generic function initialize-indi- vidual 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 to CLOS (DEFMETHOD F-METHOD dispatch ( (A The implementation of generic functions and method (# : TYPE6807 ) dispatch for CLASSICis quite simple. 4 The form (B ) define-generic-function is used to declare ...) which parameters are handled as ordinary CLOS The methodis defined for the "real" generic function instances and which parameters are CLASSICindi- with suffix METHOD.In the example, the specializer viduals. As a side effect of this declaration, a new ship has been "moved"to the second parameter. For function is created (a simple CommonLisp function). the original parameter no specializer is defined. It 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 "discrimi- This 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 instance, the macroform: method, the CLASSICindividual must be bound to IND. (define-generic-function The corresponding additional parameter is used ( (a :classic) only for dispatching (its system-generated name is (b :clos))) unintemed). Since the substitute specializer must be expands into CLOSclass (here the class A is used), for every ( PROGN named CLASSICconcept a corresponding CLOS (SETF (GET ’F :ARGUMENT-SIGNATURE) class is automatically created. The set of superclasses ’ ( :CLASSIC:CLOS) of such a class is computedon the basis of the TBox (DEFGENERIC F-METHOD (A # :TYPE6806 B) classification process. Note that the list of super- (DBFUN F (A (FUNCALL (FUNCTION F-METHOD) classes of a class might dynamically change when a A defined concept is automatically inserted into the (COMPUTE- TYPE-ARG A) subsumptionhierarchy by TBoxclassification. B))) The function compute-type-arg(see the expan- The internal function F-METHODis applied to the sion of define-generic-function) computesa same arguments as the wrapperfunction, but for each CLOSplaceholder for a CLASSICindividual. The parameter, which uses CLASSICdispatch, an addi- ideabehind compute- type- arg is to get the con- tional parameter is inserted (for a this will be cept of a CLASSICindividual (classic:cl-ind- #:type6806). For each CLASSICindividual, an parents), to derive a correspondingCLOS class, associated CLOSinstance is computed with com- andto use the class prototype ofthis class. One prob- pute-type-arg. In a method definition, the addi- lem is thata CLASSICindividual may be subsumed tional argumentsare used for the "real dispatching". by more than one named concept, i.e. classic : cl- Note that normal CLOSarguments are treated as ind-parentsreturns a list of concepts. Whenthis usual. The methoddefinition happens, a new anonymous CLOSclass with corre- (define-method ( (a ) sponding superclasses must be created on the fly. The (b ) prototype object of this class will then be used. A ,,,) memoization scheme (with a hash-table *class- expands into table*) is used to avoid inflationary class creation. (defun compute-type-arg (ind) (or (classic: :di-clos-instance ind) (let ( (class-names 4. Themain~eaisinspiredby~eimplemenmfion ~p~senm- (mapcar # ’ classic : cl-name fiontypedispamh M CUM(define-presentation- (classic:cl-ind-parentsind) ) generic-function ~ddefine-presentation- (if (null (rest class-names)) method). ( find-class -prototype

- 173- (find-class(first class-names) three times slower than directly using CLASSIC’s (let ((class (gethash class-names retrieval functions on the sameprocessor. *class-table*) ) ( if class (find-class-prototypeclass) 4. Summary (let* ( (class-name(gensym)) The main thesis of this paper is that in order to use (class (find-class class-name)) Description Logics in practical applications, a seam- (ensure-clos-class less integration with object-oriented system develop- : name class-name ment methodologies must be realized. Extended : superclassesclass-names) generic functions and multimethods with CLASSIC (setf(classic : : di-clos-instance ind) dispatch not only allow an incremental way of soft- ( find-class -prototype ware definition. In addition to this, they can even (find-classtype-name) ) been seen as a form of defining assertions that (setf (gethash class-names *class-table* ) enforce a safer systemarchitecture also for the proce- class) dural parts (the sameholds for CLOS[4]). (find-class-prototypeclass) ) ) ) References With access to the internal data structures of CLAS- SIC (classic: : di- clos- instance), an individ- [1] Brachman,.J., "Reducing"CLASSIC to Practice: KnowledgeRepresentation Theory Meets Reality, in: ual can be directly associated with its CLOS Prec. KR’92Principles of Knowledge counterpart, i.e. the procedure compute- type- arg Representationand Reasoning,Nebel, B., Rich, C., is used only when the individual is reclassified. Swartout,W. (F_xls.) MorganKaufrnann Publ., 1992, pp. 247-258. CLASSIChas been extended to reset the association [2] Brill, D., LoomReference Manual, Version 2.0, between an individual and its CLOSrepresentative USC/ISI,4676 AdmiraltyWay, Marina del Rey, CA whenthe individual is reclassified. 90292, December,1993. [3] Keene,S.E., Object-OrientedProgramming in The definition of compute-type-argindicates that CLOS:A Programmer’sGuide to CLOS,Addison- the straightforward implementation of CLASSICdis- Wesley,1989. [4] Lamping,J., Abadi,M., Methodsas Assertions, patch comesat a certain cost. In addition to static XeroxPale Alto ResearchCenter, available as: costs for the definition of CLOSclasses for named ftp ://parcftp. xerox, com/pub/ openimp I ementat ion s/methods - as - CLASSICconcepts, there are some initial dynamic assertions, ps. Z. costs: [5] M611er,R., A FunctionalLayer for Description Logics: KnowledgeRepresentation Meets Object- ¯ some calls to retrievalfunctions (classic:cl- Oriented Programming,in: Prec. OOPSLA’96,in name, classic : cl- ind-parents), press. [6] MOiler,R., ExtendingCLASSIC with Generic ¯ a complex hashing operation over a list of sym- Functions and Methods, http://kogs - bols, www. informatik, uni-hamburg, de/ ~moeller/, 1996. ¯ possibly a dynamiccreation of a CLOSclass, [7] M611er,R., User Interface ManagementSystems: ¯ The CLIMPerspective, http ://kegs- the access to the CLOSclass prototype, w-w-w, informatik,uni-hamburg, de/ ¯ and an additional CLOSdispatch step for the sub- ~moeller/uims-clim/clim- intro, html, 1996. stitute argument. [8] Patel-Sclmeider,P.F., Swartout,B., Description Furthermore, a lot of garbage is created (mapcar). LogicSpecification from the KRSSEffort, ksl. stanford, edu :/pub/knowledge- Measurements on a Symbolies MacIvory-Model-3 sharing/papers/dl- spec. ps. indicate that a dispatched access to a relation with a [9] Resnick,L.A., Borgida,A., Brachman,R.J., generic function created by define-accessors McGuiness,D.L., Patel-Schneider,P.F., Zalondek, K.C., CLASSICDescription and Reference Manual takes less than one millisecond. This is approximately for the CommonLisp Implementation,Version 2.2, 1993. [10] Steele, G.L., CommonLisp - The Language,Second Edition, Digital Press, 1990. - 174-