33
Ontologi es Reasonin g Component s Agents Simulatio ns Ontologies and the Ontologies and the Object-Constraint Language Object-Constraint Language (OCL) (OCL) Jacques Robin

Ontologies and the Object-Constraint Language (OCL)

  • Upload
    garran

  • View
    50

  • Download
    0

Embed Size (px)

DESCRIPTION

Ontologies and the Object-Constraint Language (OCL). Jacques Robin. Outline. Ontologies Definition and purpose The elements of an ontology Different kinds of ontologies The Object Constraint Language (OCL) Definition, purpose, characteristics OCL Expression contexts - PowerPoint PPT Presentation

Citation preview

Page 1: Ontologies and the Object-Constraint Language (OCL)

OntologiesReasoningComponentsAgentsSimulations

Ontologies and theOntologies and theObject-Constraint Language (OCL)Object-Constraint Language (OCL)

Jacques Robin

Page 2: Ontologies and the Object-Constraint Language (OCL)

OutlineOutline

Ontologies Definition and purpose The elements of an ontology Different kinds of ontologies

The Object Constraint Language (OCL) Definition, purpose, characteristics OCL Expression contexts

Specifying class invariants Specifying default and derived attribute values Specifying query operation bodies Specifying operation pre and post conditions

Navigating associations and generalizations OCL visibility and inheritance Local variables UML and OCL OCL Types OCL Library

UML/OCL as an ontology representation language

Page 3: Ontologies and the Object-Constraint Language (OCL)

What is an Ontology?What is an Ontology?

Definition: explicit, formal (or semi-formal) specification of a shared conceptualization

Conceptualization:Conceptualization: model of entities, relations, constraints and rules of a given domain or field

Formal:Formal: Machine-processable; Allowing automated reasoning; With declarative semantics;

Shared:Shared: By a knowledge community; Allowing common understanding and effective communication of

largely implicitly specified content, completed by inference based on the shared explicit knowledge in

the ontology

Page 4: Ontologies and the Object-Constraint Language (OCL)

What is an Ontology?What is an Ontology?

Explicit, formal (or semi-formal) specification of a shared conceptualization Conceptualization:Conceptualization: model of entities, relations, constraints and rules of a

given domain or field; Formal:Formal: machine-processable, allowing automated reasoning, with

declarative semantics; Shared: Shared: by a knowledge community, allowing common understanding and

effective communication of largely implicitly specified content, completed by inference based on the shared explicit knowledge in the ontology

Knowledge base reusable across AI applications Independent from any specific application requirement

LinguisticLinguistic ontology ontology: based on vocabulary and deep syntactic roles of one or several natural languages (ex, http://wordnet.princeton.edu/)

Domain conceptualDomain conceptual ontology ontology: common core of KB from application family in a given domain

Common-sense conceptualCommon-sense conceptual ontology ontology: domain-independent, high-level concepts from one or several common sense knowledge aspects

Page 5: Ontologies and the Object-Constraint Language (OCL)

Elements of an Ontology:Elements of an Ontology:Concept Generalization HierarchyConcept Generalization Hierarchy

Entity Classes: Each entity class defined by a set of slot-facet-value triple Correspond to:

Classes of OO models Entities of relational models Terms of logical models

Property slots x relational slots Filled by atomic values (primitive data types) x by other concepts

Epistemological status of the value (defined by the facet) Precisely known, default, possibilistic, plausibilistic, probabilistic

Generic Relations: With or without generalization hierarchy running parallel to concept

generalization hierarchy Correspond to:

Associations, aggregations, compositions and complex object filled attributes of OO models

Relations of relational model Predicates of logical models

Page 6: Ontologies and the Object-Constraint Language (OCL)

Elements of an Ontology:Elements of an Ontology:Constraints and Derivation RulesConstraints and Derivation Rules

Constraints: On the domain values of attributes from

One concept (type constraints) Several related concepts (integrity constraints)

To prohibit semantically invalid concepts instances or semantically inconsistent concept instance set

Correspond to: Class signatures and invariants in OO models Typing predicates, sorts (partition of constant symbol alphabet) and integrity

constraints in logical models Typing and integrity constraints in database schemas

Rules to derive: The value of attribute concepts from set of other such values The existence of concept instances from the existence of other such

instances Correspond to:

Declarative methods in OO models Implicative clauses of logical models Database views

Page 7: Ontologies and the Object-Constraint Language (OCL)

Elements of an Ontology:Elements of an Ontology:Constraints x Derivation RulesConstraints x Derivation Rules

As a constraint, the formula: C, person(C) ! M, person(M) mother(M,C) prohibits the creation of person concept instances with zero or multiple mothers;

As a derivation rule, this same formula allows inferring:- From the existence of each instance C of the person concept the existence of another instance M of that concept, related to C by an instance of the mother relation;

- From the existence of two instances M and M’ of the person concept, both related to the same third instance C of that concept by the mother relation, that M = M’

Concept instances generally not part of an ontology Exception: special values that correspond to constant value declaration in programming language as opposed to variable binding

Page 8: Ontologies and the Object-Constraint Language (OCL)

Cross-Disciplinary History of Cross-Disciplinary History of OntologiesOntologies

OrganizationKnowledge

Managementsince 1990

DataIntegrationsince 1995

Multi-AgentSystems

since 1995

WebInformation

Retrievalsince 2000

CognitivePsychologysince 1960

Linguisticssince 1960

ExpertSystems

since 1980

Natural LanguageProcessingsince 1980

OntologiesPhilosophy

since 350 A.C.

SoftwareEngineering

(Business Modeling)since 1990

Page 9: Ontologies and the Object-Constraint Language (OCL)

Anything

AbstractObjectsEvents

Sets Numbers RepresentationalObjects

Categories

Sentences Measurements

Intervals PlacesPhysicalObjects Processes

MomentsThings Stuff

Animals Agents

Humans

Solid Liquid Gas

Skeleton of aSkeleton of aTop-Level Common Top-Level Common

SenseSenseConceptual OntologyConceptual Ontology

Page 10: Ontologies and the Object-Constraint Language (OCL)

What is OCL? What is OCL? Definition and RoleDefinition and Role

A textual specification language to adorn UML and MOF diagrams and make them far more semantically precise and detailed

OCL2 integral part of the UML2 standard OCL complements UML2 diagrams to make UML2:

A domain ontology language that is self-sufficient at the knowledge level to completely specify both structure and behaviors

A complete input for the automated generation of a formal specification at the formalization level to be verified by theorem provers

A complete input for the automated generation of source code at the implementation level to be executed by a deployment platform

OCL forms the basis of model transformation languages such as Atlas Transformation Language (ATL) or Query-View-Transform

(QVT) which declaratively specify through rewrite transformation rules the

automated generation of formal specifications and implementations from a knowledge level ontology

OCL expressions are used in the left-hand and right-hand sides of such rules

To specify objects to match in the source ontology of the transformation To specify objects to create in the target formal specification or code of the

transformation

Page 11: Ontologies and the Object-Constraint Language (OCL)

What is OCL?What is OCL?CharacteristicsCharacteristics

Formal language with well-defined semantics based on set theory and first-order predicate logic, yet free of mathematical notation and thus friendly to mainstream programmers

Object-oriented functional language: constructors syntactically combined using functional nesting and object-oriented navigation in expressions that take objects and/or object collections as parameters and evaluates to an object and/or an object collection as return value

Strongly typed language where all expression and sub-expression has a well-defined type that can be an UML primitive data type, a UML model classifier or a collection of these

Semantics of an expression defined by its type mapping Declarative language that specifies what properties the software

under construction must satisfy, not how it shall satisfy them Side effect free language that cannot alter model elements, but only

specify relations between them (some possibly new but not created by OCL expressions)

Pure specification language that cannot alone execute nor program models but only describe them

Both a constraint and query language for UML models and MOF meta-models

Page 12: Ontologies and the Object-Constraint Language (OCL)

What is OCL?What is OCL?How does it complement UML?How does it complement UML?

Structural adornments: Specify complex invariant constraints (value, multiplicity, type,

etc) between multiple attributes and associations Specify deductive rules to define derived attributes, associations

and classes from primitive ones Disambiguates association cycles

Behavioral adornments: Specify operation pre-conditions Specify write operation post-conditions Specify read/query operation bodies Specify read/query operation initial/default value

Page 13: Ontologies and the Object-Constraint Language (OCL)

OCL: Motivating ExamplesOCL: Motivating Examples

Diagram 1 allows Flight with unlimited number of passengers

No way using UML only to express restriction that the number of passengers is limited to the number of seats of the Airplane used for the Flight

Similarly, diagram 2 allows: A Person to Mortgage the house of

another Person A Mortgage start date to be after

its end date Two Persons to share same social

security number A Person with insufficient income to

Mortgage a house

1

2

Page 14: Ontologies and the Object-Constraint Language (OCL)

OCL: Motivating ExamplesOCL: Motivating Examples

1

2

context Flightinv: passengers -> size() <= plane.numberOfSeats

context Mortgage inv: security.owner = borrowerinv: startDate < endDate

context Personinv: Person::allInstances() -> isUnique(socSecNr)

context Person::getMortgage(sum:Money,security:House)pre: self.mortgages.monthlyPayment -> sum() <= self.salary * 0.3

Page 15: Ontologies and the Object-Constraint Language (OCL)

OCL Expression ContextsOCL Expression Contexts

Operation

Page 16: Ontologies and the Object-Constraint Language (OCL)

OCL Contexts:OCL Contexts:Specifying Class InvariantsSpecifying Class Invariants

The context of an invariant constraint is a class

When it occurs as navigation path prefix, the self keyword can be omitted:

context Customer inv: self.name = ‘Edward’

context Customer inv: name = ‘Edward’

Invariants can be named: context Customer inv myInvariant23:

self.name = ‘Edward’ context LoyaltyAccount

inv oneOwner: transaction.card.owner -> asSet() -> size() = 1

In some context self keyword is required: context Membership

inv: participants.cards.Membership.includes(self)

Page 17: Ontologies and the Object-Constraint Language (OCL)

Specifying Default Attribute ValuesSpecifying Default Attribute Values

Initial values: context LoyaltyAccount::points : integer

init: 0 context LoyaltyAccount::transactions

: Set(Transaction) init: Set{}

Page 18: Ontologies and the Object-Constraint Language (OCL)

Specifying Attribute Derivation RulesSpecifying Attribute Derivation Rules

context CustomerCard::printedName derive: owner.title.concat(‘

‘).concat(owner.name) context TransactionReportLine: String

derive self.date = transaction.date ... context TransactionReport

inv dates: lines.date -> forAll(d | d.isBefore(until) and d.isAfter(from))

...

Page 19: Ontologies and the Object-Constraint Language (OCL)

Specifying Query Operation BodiesSpecifying Query Operation Bodies

Query operations: context

LoyaltyAccount::getCustomerName() : Stringbody: Membership.card.owner.name

context LoyaltyProgram::getServices(): Set(Services)body: partner.deliveredServices -> asSet()

Page 20: Ontologies and the Object-Constraint Language (OCL)

Specifying Operations Pre and Post Specifying Operations Pre and Post ConditionsConditions

context LoyaltyAccount::isEmpty(): Booleanpre: -- nonepost: result = (points = 0)

Keyword @pre used to refer in post-condition to the value of a property before the execution of the operation:

context LoyaltyProgram::enroll(c:Customer)pre: c.name <> ‘ ‘post: participants = participants@pre -> including(c)

Keyword oclIsNew used to specify creation of a new instance (objects or primitive data):

context LoyaltyProgram::enrollAndCreateCustomer(n:String,d:Date):Customerpost: result.oclIsNew() and result.name = n and result.dateOfBirth = d and participant -> includes(result)

oclIsNew only specifies that the operation created the new instance, but not how it did it which cannot be expressed in OCL

Page 21: Ontologies and the Object-Constraint Language (OCL)

Association NavigationAssociation Navigation

Abbreviation of collect operator that creates new collection from existing one, for example result of navigating association with plural multiplicity:

context LoyaltyAccount inv: transactions -> collect(points) ->

exists(p:Integer | p=500) context LoyaltyAccount

inv: transactions.points -> exists(p:Integer | p=500)

Use target class name to navigate roleless association:

context LoyaltyProgram inv: levels -> includesAll(Membership.currentLevel)

Call UML model and OCL library operations

Page 22: Ontologies and the Object-Constraint Language (OCL)

Generalization NavigationGeneralization Navigation

OCL constraint to limit points earned from single service to 10,000 Cannot be correctly specified using association navigation: context ProgramPartner inv totalPoints: deliveredServices.transactions .points -> sum() < 10,000adds both Earning and Burning points Operator oclIsTypeOf allows hybrid navigation following associations and specialization linkscontext ProgramPartner inv totalPoints: deliveredServices.transactions -> select(oclIsTypeOf(Earning)) .points -> sum() < 10,000

Page 23: Ontologies and the Object-Constraint Language (OCL)

OCL Visibility and InheritanceOCL Visibility and Inheritance

By default, OCL expressions ignore attribute visibility i.e., an expression that access a

private attribute from another class is not syntactically rejected

OCL constraints are inherited down the classifier hierarchy

OCL constraints redefined down the classifier hierarchy must follow substituability principle Invariants and post-condition

can only become more restrictive

Preconditions can only become less restrictive

Examples violating substituability principle:

context Stove inv: temperature <= 200

context ElectricStove inv: temperature <= 300

context Stove::open()pre: status = StoveState::offpost: status = StoveState::off and isOpen

context ElectricStove::open()pre: status = StoveState::off and temperature <= 100post: isOpen

Page 24: Ontologies and the Object-Constraint Language (OCL)

OCL Expressions: Local VariablesOCL Expressions: Local Variables

Let constructor allows creation of aliases for recurring sub-expressions

context CustomerCardinv: let correctDate : Boolean =

validFrom.isBefore(Date::now) and goodThru.isAfter(Date::now)

in if valid then correctDate = false else correctDate = true endif

Syntactic sugar that improves constraint legibility

Page 25: Ontologies and the Object-Constraint Language (OCL)

Links BetweenLinks BetweenOCL and UML Meta-ModelsOCL and UML Meta-Models

ModelElement

Classifier

Constraint

Expression

ExpressionInOcl OclExpression

0..1

+body1

+bodyExpression

1

+constrainedElement

0..*

+constraint

0..*

Page 26: Ontologies and the Object-Constraint Language (OCL)

Simplified OCL Meta-ModelSimplified OCL Meta-Model

Page 27: Ontologies and the Object-Constraint Language (OCL)

The OCL Types Meta-ModelThe OCL Types Meta-ModelStructuralFeature Classifier

OclMessageType OclModelElementType DataType VoidType

TupleType Primitive CollectionType

SetType SequenceType BagType

OrderedSetType

OperationSignal

+elementType

1

+collectionTypes

0..4

0..*

+type

1

+referredSignal0..1 +referredOperation0..1

OCL MetaclassUML Metaclass

Page 28: Ontologies and the Object-Constraint Language (OCL)

OCL Types: CollectionsOCL Types: Collections

Collection constants can be specified in extension: Set{1, 2, 5, 88}, Set{‘apple’, ‘orange’, ‘strawberry’} OrderedSet{‘black’, ‘brown’, ‘red’, ‘orange’, ‘yellow’, ‘green’, ‘blue’,

‘purple’} Sequence{1, 3, 45, 2, 3}, Bag{1, 3, 4, 3, 5}

Sequence of consecutive integers can be specified in intension: Sequence{1..4} = Sequence{1,2,3,4}

Collection operations are called using -> instead of . Collection operations have value types:

They do not alter their input only output a new collection which may contain copies of some input elements

Most collections operations return flattened collections ex, flatten{Set{1,2},Set{3,Set{4,5}}} = Set{1,2,3,4,5}

Operation collectNested must be used to preserve embedded sub-structures

Navigating through several associations with plural multiplicity results in a bag

Page 29: Ontologies and the Object-Constraint Language (OCL)

OCL Library: Generic OperatorsOCL Library: Generic Operators

Operators that apply to expressions of any type Defined at the top-level of OclAny

Page 30: Ontologies and the Object-Constraint Language (OCL)

OCL Library: Primitive Type OCL Library: Primitive Type OperatorsOperators

Boolean: host, parameter and return type boolean Unary: not Binary: or, and, xor, =, <>, implies Ternary: if-then-else

Arithmetic: host and parameters integer or real Comparison (return type boolean): =, <>, <, > <=, >=, Operations (return type integer or real): +, -, *, /, mod, div, abs,

max, min, round, floor

String: host string Comparison (return type boolean): =, <> Operation: concat(String), size(), toLower(), toUpper(),

substring(n:integer,m:integer)

Page 31: Ontologies and the Object-Constraint Language (OCL)

OCL Library: Generic Collection OperatorsOCL Library: Generic Collection Operators

Page 32: Ontologies and the Object-Constraint Language (OCL)

OCL Library:OCL Library:Specialized Collection OperatorsSpecialized Collection Operators

Page 33: Ontologies and the Object-Constraint Language (OCL)

OCL Constraints OCL Constraints vs.vs. UML Constraints UML Constraints

context ElectricGuitar inv: strings -> forAll(s \ s.oclIsType(MetalStrings))

context: ClassicalGuitar inv: strings-> forAll(s | s.oclIsType(plasticStrings))

context ElectricGuitar inv: strings -> forAll(type = StringType::metal)

context ClassicGuitar inv: strings -> forAll(type = StringType::plastic)

context Guitar inv: type = GuitarType::classic implies strings -> forAll(type = StringType::plasticinv: type = GuitarType::classic implies strings -> forAll(type = StringType::plastic