Knowledge Engineering for Hybrid Deductive Databases DietmarSeipel UniversityofWürzburg,InstituteforComputerScience,Germany [email protected] Modern knowledge base systems frequently need to combine a collection of databases in different formats: e.g., relational databases, XML databases, rule bases, ontologies, etc.. In the deductive database system DDBASE, we can manage these different formats of knowledge and reason about them. Eventhefilesystemsondifferentcomputerscanbepartoftheknowledgebase. Often, itis necessarytohandledifferentversionsofaknowledgebase. E.g.,wemightwanttofindoutcommon partsordifferencesoftwoversionsofarelationaldatabase. Wewillexaminetheuseofabstractionsofrulebasesbypredicatedependencyandrulepredicate graphs. Alsotheprooftreesofderivedatomscanhelptocomparedifferentversionsofarulebase. Moreover,itmightbepossibletohavederivationsjoiningruleswithotherformalismsofknowledge representation. Ontologieshaveshowntheirbenefitsinmanyapplicationsofintelligentsystems,andtherehave been many proposals for rule languages compatible with the semantic web stack, e.g., SWRL, the semantic web rule language. Recently, ontologies are used in hybrid systems for specifying the provenanceofthedifferentcomponents. Keywords. hybridknowledgebases,deductivedatabases,rules,ontologies 1 Introduction Relationaldatabasesanddeductivedatabaseswithrulebaseshavebeenprominentformalismsofknowl- edgerepresentationforalongtime[3]. Astrongresearchinterestindeductivedatabasetechnologyand its applications has reemerged in the recent years, leading to what has been called a resurgence [6] or evenarenaissance[1]forDATALOG. Thisrevivalispropelledbyimportantnewapplicationsareas,such asdistributedcomputationsandbig–dataapplications,thesuccessofafirstcommercial DATALOG Sys- tem,andprogressinsemanticsextensionstosupportnon–monotonicconstructssuchasdefaultnegation andaggregates–atheoreticalthreadthathadactuallycontinuedthroughtheyears[10]. In the last years, the use of ontologies has shown its benefits in many applications of intelligent systems. There have been many proposals for rule languages compatible with the semantic web stack, e.g., the definition of SWRL (semantic web rule language) originating from RULEML and similar ap- proaches[7]. Itiswellagreedthatthecombinationofontologieswithrule–basedknowledgeisessential formanyinterestingsemanticwebtasks,e.g.,therealizationofsemanticwebagentsandservices. SWRL allows for the combination of a high–level abstract syntax for Horn–like rules with OWL, and a model theoreticsemanticsisgivenforthecombinationofOWLwithSWRLrules. AnXMLsyntaxderivedfrom RULEML allowsforasyntacticalcompatibilitywith OWL. However,withtheincreasedexpressiveness ofsuchontologiesnewdemandsforthedevelopmentandformaintenanceguidelinesarise. S.SchwarzandJ.Voigtländer(Eds.):29thand30thWorkshops on(Constraint)LogicProgrammingand24thInternational (cid:13)c DietmarSeipel WorkshoponFunctionaland(Constraint)LogicProgramming Thisworkislicensedunderthe (WLP’15/’16/WFLP’16). CreativeCommonsAttributionLicense. EPTCS234,2017,pp.1–12,doi:10.4204/EPTCS.234.1 2 KnowledgeEngineeringforHybridDeductiveDatabases Thus, approaches for evaluating and maintaining hybrid knowledge bases need to be extended and revisedtoworkwithdifferentkindsofknowledgeincludingrules,relationaldatabases,XMLdocuments, and ontologies. In this paper, we are interested in various types of knowledge bases including a collec- tionofrelationaldatabasesorontologies,orthehierarchyinafilesystem. Here,theinteractionbetween theknowledgebasescanbeveryimportant. E.g., therecouldbeacallfromalogicalruletoabayesian network. TheabstractionofknowledgebasesisrelatedtotheschemasofrelationalandXMLdatabases, thepredicatedependencyandrulepredicategraphsofdeductivedatabasesandrule–basedsystems. Ob- viously, w.r.t. versioning, there is a relationship to synchronisation and diff for programs and files. For filesystems,well–knowncharacteristicsarethesizeparameters,suchaswords,lines,characters. Organization of the Paper. The rest of this paper is organized as follows: Section 2 shows how rule bases can be abstracted and visualized in DDBASE using different types of dependency graphs. Derivationscanbeexplainedbyprooftrees. Section3investigatesontologieswithrulesinSWRL,andit showshowtheprovenanceofontologiescanbemodelledandreasonedabout. Hybridknowledgebases canalsobequeriedincombinedPROLOGstatementsinDDBASE,seeSection4. Thepaperisconcluded withsomefinalremarks. 2 Graphs for Rule Bases Inadeductivedatabase,alogicprogramcanbeabstractedbyapredicatedependencyorarulepredicate graph, and a derivation can be visualized by its proof tree, cf. [3]. It should also be possible to have bottom–upandtop–downevaluationinonesystem. DATALOG(cid:63) canevaluatelogicprogramswith PRO- LOG syntax (extended DATALOG programs) in a bottom–up style; it is designed to evaluate embedded PROLOGcallsinatop–downmanner[14]. DependencyGraphs WecandefinetwosortsofdependencygraphsforanormallogicprogramP. Bothreflect,whichpredi- catescallotherpredicatesinP. Let p bethepredicatesymbolofaliteralL. Thepredicatedependency L graphGd =(cid:104)Vd,Ed(cid:105)ofPisgivenby: P P P • thenodesetVd isthesetofpredicatesymbolsinP, P • Ed containsanedge(cid:104)p ,p (cid:105)foreveryruleA←L ∧...∧L ofPand1≤i≤m. P A Li 1 m rg rg rg TherulepredicategraphG =(cid:104)V ,E (cid:105)ofPisgivenby: P P P rg • V containsanodeforeverypredicatesymbol p inPandeveryrulerinP, P L rg • E contains an edge (cid:104)p ,r(cid:105) and an edge (cid:104)r,p (cid:105) for every rule r = A←L ∧...∧L of P and P A Li 1 m 1≤i≤m. In both graphs, the edges (cid:104)p ,p (cid:105) ∈ Ed and (cid:104)r,p (cid:105) ∈ Erg, respectively, which come from default A Li P Li P negated body literals L =notC, are marked by “not”. We get the following dependency graphs for a i i normalrule r=A←B ∧...∧B ∧notC ∧...∧notC . 1 m 1 n TherulepredicategraphGrg ismorerefinedthanthepredicatedependencygraphGd,seeFigure1. P P The following definite logic programs have the same predicate dependency graph Gd but different P rg rg rulepredicategraphsG andG : P P 1 2 DietmarSeipel 3 (cid:19)(cid:16) p A (cid:18)(cid:17) (cid:17) (cid:81) (cid:1) (cid:65) (cid:17) (cid:81) (cid:17) (cid:1) (cid:65) (cid:81) not not (cid:17) (cid:81) (cid:19)(cid:16)(cid:17)(cid:43) (cid:19)(cid:1)(cid:11)(cid:1)(cid:16) (cid:65)(cid:19)(cid:65)(cid:85) (cid:16)(cid:81)(cid:115)(cid:19)(cid:16) p ... p p ... p (cid:18)B1(cid:17) (cid:18)Bm(cid:17) (cid:18)C1(cid:17) (cid:18)Cn(cid:17) Figure1: PredicateDependencyGraph. P ={p←q ,p←q }, 1 1 2 P ={p←q ∧q }, 2 1 2 Thepredicatedependencygraphcanbeobtainedfromtherulepredicategraphbytransitivelyconnecting the head and body predicate symbols and omitting the rule nodes between. Restricted to the predicate symbols, both graphs habe the same paths. They are typically used for analysing logic programs of softwarepackagesandforrefactoringandslicing. DependencyGraphswithHelperRules Dependencygraphscanhelptodetectthattwologicprogramsareequivalentapartfromhelperrules: r =A←B ∧...∧B ∧B ∧B ∧...∧B 1 1 i−1 i i+1 n r =B←C ∧...∧C 2 1 m Withthemostgeneralunifierθ =MGU(Bi,B)wecanobtainthefollowingresolventofthetworules: r =Aθ ←B θ∧...∧B θ∧C θ∧...∧C θ∧B θ∧...∧B θ 3 1 i−1 1 m i+1 n Apartfromthehelperpredicatesymbol p = p ,thesetofpredicatesymbolsthatisreachablefrom p B Bi A in the predicate dependency or rule predicate graph is the same for the two programs {r ,r } and {r }. 1 2 3 Fortheformer,wegetΠ={p ,...,p }∪{p ,...,p },forthelatterwegetΠ\{p }. B1 Bn C1 Cm B DependencyGraphswithMeta–Predicates InDDBASE,weuseanextranodeforeverycallofameta–predicatetocorrectlyreflectapredicate. The specificdifferencebetweennormalpredicatesandmeta–predicatesinourextensionoftherulepredicate graphisthattherecanbeseveralnodeslabelledwiththesamemeta–predicate. Thefollowingexamplecontainstwosuchcalls,i.e.tothemeta–predicatesnot/1andfindall/3. Thepredicateancestor_list/2derivesthelistXsofancestorsofapersonX. ancestor_list(X, [X]) :- not(parent(X, _)), !. ancestor_list(X, Xs) :- findall( Ys, ( parent(X, Y), ancestor_list(Y, Ys) ), Yss ), append(Yss, Xs). 4 KnowledgeEngineeringforHybridDeductiveDatabases The PROLOG program is recursive, since ancestor_list/2 calls itself through findall/2, see Figure2. Afterthat,thepredicateappend/2appendsthelistYssofderivedliststoaregularlistXs. (cid:11) (cid:8) (cid:10)ancestor_list/2 (cid:9) (cid:0) (cid:65)(cid:75) (cid:64) (cid:65) (cid:0)(cid:9)(cid:0) (cid:65) (cid:64)(cid:64)(cid:82) r (cid:65) r 1 2 (cid:65) (cid:65) (cid:64) (cid:63) (cid:65) (cid:63) (cid:64) (cid:64) not/1 findall/3 (cid:8) (cid:64) (cid:8)(cid:8) (cid:64) (cid:63) (cid:8)(cid:25)(cid:8) (cid:64)(cid:82) (cid:11) (cid:8) (cid:11) (cid:8) (cid:10)parent/2 (cid:9) (cid:10)append/2 (cid:9) Figure2: RulePredicateGraphwithMetaPredicates. Obviously, the PROLOG program above only terminates for top–down evaluation on acyclic predi- catesparent/2. Thenodesforthemeta–prediactesarenecessarytoshowthatancestor_list/2 depends on parent/2 and ancestor_list/2 itself. If we would use ordinary predicate depen- dencyorrulepredicategraphs,thenwewouldlosethisinformation. DerivationsandProofTrees We are developing a deductive database system DDBASE, which can manage hybrid rule bases and embed PROLOG calls into DATALOG rules. The underlying language DATALOG(cid:63) has PROLOG syntax; its mixing of bottom–up and top–down evaluation is described in [14]. The following logic program dealswithawell–knownextensionoftheroutefindingproblemfromdeductivedatabases. Inadditionto thelengthsofderivedroutes(3rdargumentofroute/4),wecanconstructaprooftree(4thargument). An atom prolog:A leads to an embedded top–down call of the goal A in PROLOG. The goal (L is N+M) computes the sum L of the path lengths N and M in PROLOG. A goal of the form pt(T, ...) constructsaprooftreeT. route(X, Y, L, T) :- street(X, Y, L, T1), prolog:pt(T, t(route(X, Y, L), e, T1)). route(X, Y, L, T) :- street(X, Z, N, T1), route(Z, Y, M, T2), prolog:(L is N+M), prolog:pt(T, t(route(X, Y, L), r, T1, T2, (L is N+M))). street(’KT’, ’Wue’, 15, T) :- prolog:pt(T, t(street(’KT’, ’Wue’, 15), f1)). street(’Wue’, ’Mue’, 280, T) :- prolog:pt(T, t(street(’Wue’, ’Mue’, 280), f2)). DietmarSeipel 5 InDDBASE,wehaveimplementedageneralizedTP–operator,whichcanderivethefollowingatom by a bottom–up evaluation. It can be seen, that the evaluation derives a proof tree in the last argument ofthepredicatesroute/4andstreet/4. Thistreeservesasanexplanationofthederivedatoms, a very useful concept known from expert systems. E.g., this program will derive the atom shown in the following. Thelastargumentoftheatomcontainstheprooftree,whichwasautomaticallylayoutedand visualizedin DDBASE,seeFigure3. route(KT, Mue, 295, t(route(KT, Mue, 295), r, t(street(KT, Wue, 15), f1), t(route(Wue, Mue, 280), e, t(street(Wue, Mue, 280), f2)))) Figure3: ProofTree. 3 Ontologies with Rules in SWRL A hybrid information system can include ontologies of various origins. Before working with and – and for designing such ontologies – the knowledge engineer has to anaylse them and check them for anomalies. InDDBASE,weusemethodsfordetectinganomaliesinontologieswithrules,suchasSWRL ontologies, which we have investigated in [2]. For handling different versions of an ontology, it is also possibletousewell–knownalignmentmethodstofindoutcommonpartsanddifferences. 3.1 SchemaGraphfor XML SWRLontologiescanberepresentedin XMLnotation: <swrlx:Ontology swrlx:name="people"> <swrlx:classAtom> <owlx:Class owlx:name="person"/> <ruleml:var>X</ruleml:var> 6 KnowledgeEngineeringforHybridDeductiveDatabases </swrlx:classAtom> <swrlx:classAtom> <owlx:IntersectionOf> <owlx:Class owlx:name="person"/> <owlx:ObjectRestriction owlx:property="parent"> <owlx:someValuesFrom owlx:class="Physician"/> </owlx:ObjectRestriction> </owlx:IntersectionOf> <ruleml:var>Y</ruleml:var> </swrlx:classAtom> <ruleml:imp> ... </ruleml:imp> </swrlx:Ontology> In DDBASE,a SWRL ontologycanbevisualizedbytheschemagraphofits XML representation. Since ontologies–or XML filesingeneral–canbeverylarge,itishelpfultogetashortoverviewinadvance, seeFigure4. Figure4: SchemaGraphfor XML. 3.2 Rulesin SWRL SWRL ontologiescanhaverulesin RULEML. E.g.,thefollowingrule,whichstatesthatthebrotherofa parentisanuncle,canberepresentedin RULEML: uncle(X,Z)← parent(X,Y)∧brother(Y,Z). DietmarSeipel 7 Inthe XMLrepresentation,thiscouldlooklikefollows: <ruleml:imp> <ruleml:_body> <swrlx:individualPropertyAtom swrlx:property="parent"> <ruleml:var>X</ruleml:var> <ruleml:var>Y</ruleml:var> </swrlx:individualPropertyAtom> <swrlx:individualPropertyAtom swrlx:property="brother"> ... </ruleml:_body> <ruleml:_head> <swrlx:individualPropertyAtom swrlx:property="uncle"> ... </ruleml:_head> </ruleml:imp> 3.3 SyntaxandSemantics The syntax for SWRL in this section abstracts from any exchange syntax for OWL and thus facilitates access to and evaluation of the language. This syntax extends the abstract syntax of OWL described in theOWLSemanticsandAbstractSyntaxdocument[11]. Thisabstractsyntaxisnotparticularlyreadable forrules. Thus,exampleswillthusoftenbegiveninaninformalsyntax,whichwillneitherbegivenan exactsyntaxnoramappingtoanyofthefully–specifiedsyntaxesfor SWRL. The abstract syntax is specified here by means of a version of Extended BNF, very similar to the EBNF notation used for XML. Terminals are quoted; non-terminals are bold and not quoted. Alterna- tives are either separated by vertical bars (|) or are given in different productions. Components that can occur at most once are enclosed in square brackets; components that can occur any number of times (including zero) are enclosed in curly braces. Whitespace is ignored in the productions here. Names in theabstractsyntaxareRDFURIreferences. Themeaningofsomeconstructsintheabstractsyntaxwill beinformallydescribed. Theformalmeaningoftheseconstructscanbedefinedviaanextensionofthe OWLDLmodel–theoreticsemantics[11]. AnOWLontologyintheabstractsyntaxcontainsasequenceofaxiomsandfacts. Axiomsmaybeof variouskinds,e.g.,subClassaxiomsandequivalentClassaxioms. Itisproposedtoextendthiswithrule axioms. Similar to what is usual in logic programming, a rule axiom consists of an antecedent (body) and a consequent (head), each of which consists of a (possibly empty) set of atoms. Antecedents and consequentsaretreatedastheconjunctionsoftheiratoms. rule ::= ’Implies(’ { annotation } antecedent consequent ’)’ antecedent ::= ’Antecedent(’ { atom } ’)’ consequent ::= ’Consequent(’ { atom } ’)’ Ruleswithanemptyantecedentcanbeusedtoprovideunconditionalfacts;howeversuchunconditional facts are better stated in OWL itself, i.e., without the use of the rule construct. Rules with conjunctive 8 KnowledgeEngineeringforHybridDeductiveDatabases consequentscouldeasilybetransformed–viatheLloyd–Toportransformations[8]–intomultiplerules each with an atomic consequent. Atoms can be of the form c(X), p(X,Y), same_as(X,Y) or different_- from(X,Y), where c is an OWL description, p is an OWL property, and X,Y are either variables, OWL individualsor OWL datavalues. Inthecontextof OWL Lite,descriptionsinatomsoftheformc(X)may berestrictedtoclassnames. Informally, • anatomc(X)holds,ifXisaninstanceoftheclassdescriptionc, • anatomp(X,Y)holds,ifXisrelatedtoYbypropertyp, • anatomsame_as(X,Y)holds,ifXisinterpretedasthesameobjectasY,and • anatomdifferent_from(X,Y)holdsifXandYareinterpretedasdifferentobjects. Thelattertwoformscanbeseenassyntacticsugar: theyareconvenient,butdonotincreasetheexpres- sive power of the language. Atoms may refer to individuals, data literals, individual variables or data variables. As in PROLOG or DATALOG, variables are treated as universally quantified, with their scope limitedtoagivenrule. Onlyvariablesoccuringintheantecedentofarulemayoccurintheconsequent (range–restrictedness). This condition does not, in fact, restrict the expressive power of the language, becauseexistentialscanalreadybecapturedin OWLusingsomeValuesFromrestrictions. WhiletheabstractEBNFsyntaxisconsistentwiththe OWL specification,andisusefulfordefining XML and RDFserialisations, itis ratherverbose andnot particularlyeasy toread. Deductivedatabases thereforeoftenusearelativelyinformalhumanreadableform. Inthissyntax,arulehastheformα ←β, where the antecedent β is a conjunction of atoms and the consequent α is a single atom. In standard convention, variables are indicated by prefixing them with a question mark; in this paper, however, we represent them in PROLOG convention with strings starting with a capital letter. Then, a rule asserting thatthecompositionofparentandbrotherpropertiesimpliestheunclepropertywouldbewrittenas uncle(X,Z)← parent(X,Y)∧brother(Y,Z). Anevensimplerrulewouldbetoassertthatstudentsarepersons: person(X)←student(X). However, this kind of use for rules in OWL just duplicates the OWL subclass facility. It is logically equivalent to write instead Class(Student partial Person) or SubClassOf(Student Person) which would make the information directly available to an OWL reasoner. A very common use for rules is to move propertyvaluesfromoneindividualtoarelatedindividual. 3.4 HybridInformationSystems For collaborations across disciplines, hybrid information systems using data and techniques from many different sources with no preexisting agreement about the semantics of the processes or data is impor- tant. Theinfrastructuremustprovidegeneralpurposemechanismsforannotating(i.e.,makingassertions about), discovering, and reasoning about processes and data. Some of the inferences require additional reasoning beyond that supported by OWL and SWRL. Also graphs such as the provenance graph are veryusefulhereforrepresentingcausalrelationships. TheOpenProvenanceModel(OPM)defineslog- icalconstraintsontheprovenancegraph[9]. Someconstraintscannotbeexpressedin OWL, butcanbe expressedbasedon SWRLrules. PROVisaspecificationthatprovidesavocabularytointerchangeprovenanceinformation. Itdefines acoredatamodelfortheinterchangeofprovenanceontheweb;itallowsforbuildingrepresentationsof theentities,peopleandprocessesinvolvedinproducingapieceofdataintheworld. Theprovenanceof DietmarSeipel 9 digitalobjectsrepresentstheirorigins;therecordsofaPROVspecificationcandescribetheentitiesand activities involved in producing and delivering or otherwise influencing a given object. Provenance can beusedformanypurposes,suchasunderstandinghowdatawascollectedsoitcanbemeaningfullyused, determining ownership and rights over an object, making judgements about information to determine whether to trust it, verifying that the process and steps used to obtain a result complies with given requirements,andreproducinghowsomethingwasgenerated. TheOpenProvenanceModel(OPM)providesacasestudyforhowtouseSemanticWebtechnology andrulestoimplementsemanticmetadata. [9]discussesabindingoftheOPMwritteninOWLwithrules written in SWRL. This allows for the development of hybrid systems that use OWL, SWRL, and other semantic software, interoperating through a shared space of RDF triples. E.g., four derived relations betweentwoartifacts(e.g.,inputandoutputdatasets)canbeinferredfromusedandgenerated_bytothe sameprocess: derived_sink(B,H)∧derived_source(B,Y)∧ derived_account(B,D)∧derived_account(B,G)← artifact(Y)∧generated_by_artifact(C,Y)∧ process(X)∧generated_by_process(C,X)∧ account(D)∧generated_by_account(C,D)∧ relation(E)∧used_process(E,X)∧ artifact(H)∧used_artifact(E,H)∧ account(G)∧used_account(E,G)∧ swrlx:create_owl_thing(B,X,C,E) But several of the key constraints and inferences of the OPM cannot be expressed in OWL and SWRL, due to fundamental limits of the semantics of these languages. E.g., it is not possible to modify the valueofanassertedproperty,ortowritearulediscoveringthenumberoftimesanartifactisused,orto detectacycleintheprovenancegraph. StoringtheOPMrecordsintriplesmakesitpossibletouseother reasoningenginesorlanguagessuchas PROLOGor DATALOGtoimplementqueriesorinferences. OWL and SWRL’s RDF representations provide a simple and well–understood means of exchang- ing provenance information with other tools, such as RDF databases and declarative programming lan- guages. This hybrid system shows that Semantic Web technologies are not only useful for provenance information but also provide a base level of interoperability that can enable loosely–coupled tools with varyinglevelsofcapabilityandexpressiveness. 4 Querying Hybrid Knowledge Bases in DDBASE Hybrid knowledge bases can be managed and queried using logic programming techniques. In the de- ductivedatabasesystem DDBASE, variousrepresentationsofknowledgecanbeaccessed, seeFigure5. The database query language DATALOG(cid:63) is an extension of DATALOG [14], where logic programs in PROLOG syntax are evaluated bottom–up, and embedded calls to PROLOG are evaluated top–down. XML data from XML databases or documents can be stored in a term representation; calls to XML data basedonpathexpressionsareevaluatedinPROLOGusingthequery,transformationandupdatelanguage FNQuery[13]. In DDBASE, we can compute joins of relational databases and XML documents in PROLOG. The following example is a modified version of the well–known example from the book of Elmasri and Navathe[4]. Theatomsforemployee/8could,e.g.,bederivedusingODBCfromarelationaldatabase; 10 KnowledgeEngineeringforHybridDeductiveDatabases (cid:27) (cid:45) JAVA PROLOG ProgrammingLanguages (cid:63) (cid:16)DATALOG(cid:63) (cid:16) (cid:16)(cid:16)(cid:16) (cid:10) (cid:74) DBQueryLanguages (cid:63)(cid:16)(cid:41)(cid:16)(cid:16) (cid:10) (cid:74) SQL (cid:10) (cid:74) (cid:10) (cid:74) (cid:11) (cid:63) (cid:8) (cid:11) (cid:29)(cid:10)(cid:8) (cid:11) (cid:63) (cid:8) (cid:11)(cid:94)(cid:74) (cid:8) (cid:10) (cid:9) (cid:10) (cid:9) (cid:10) (cid:9) (cid:10) (cid:9) Relational XML, Excel Text DataSources Database OWL (.csv) File (cid:10) (cid:9) (cid:10) (cid:9) (cid:10) (cid:9) (cid:10) (cid:9) Figure5: HybridKnowledgeBasesin DDBASE. theycouldalsostemfromanontology; SWI PROLOG [15]offersaloaderproducing RDF triples,which canbetransformedto PROLOGfactseasily. % employee(Name, SSN, Date, SEX, Salary, Super_SSN, DNO) employee(’Borg’, 11, date(1927,11,10), ’M’, 55000, null, 1). employee(’Wong’, 22, date(1945,12,08), ’M’, 40000, 11, 5). employee(’Wallace’, 33, date(1931,6,20), ’F’, 43000, 11, 4). employee(’Smith’, 44, date(1955,1,09), ’M’, 30000, 22, 5). ... Additionally,weworkwiththefollowing XML versionofthetableworks_on/3; arowrepresentsan employeeESSNworkingonaprojectPNOanumberofHOURS. <table name="works_on"> <row ESSN="11" PNO="20" HOURS="NULL"/> <row ESSN="22" PNO="2" HOURS="10.0"/> ... </table> Thefollowingqueryjoinstheatomsforemployee/8withtherowsintheXMLdocumentworks_- on.xmlin DDBASE. TheattributevalueHoftheattribute’HOURS’ofRowisanatomthathastobe converted to a number HOURS. Clearly, this predicate fails for HOURS = null, which is desired to ignorenullvaluesinaggregationsin SQL. Thehandlingofpathexpressionsappliedto XML documents hasbeendescribedin[13]. Thetemplate[DNO, sum(HOURS)]leadstoagroupingonthedepartment numbers. ForeveryDNO,thelistXsofallcorrespondingHOURSiscomputed,andthesumbysum(Xs, Sum);thus,weobtainastandardresulttuple[DNO, Sum]. ?- ddbase_aggregate( [DNO, sum(HOURS)], ( employee(_, SSN, _,_,_,_,_, DNO), Row := doc(’works_on.xml’)/row::[@’ESSN’=SSN], H := Row@’HOURS’, atom_number(H, HOURS) ), Tuples ). Tuples = [[1, 0.0], [4, 115.5], [5, 140.0]]