Title: Ontologies
1Ontologies
2Outline
- Ontologies
- What is an ontology?
- Elements of an ontology
- Services provided by an ontology
- The pluridisciplinary origin of ontological
engineering - Typology of ontologies
- Sub-fields and general issues in ontological
engineering - The Object Constraint Language (OCL)
- What is OCL?
- Motivating examples
- OCL expression contexts
- The link between the OCL and UML metamodels
- The OCL metamodel
- OCL Types
- Inheritance and encapsulation in OCL
- Local variale definitions
- The OCL operator library
- OCL vs. UML
- OCL vs. Java
3What is an Ontology?
- Definition explicit, formal (or semi-formal)
specification of a shared conceptualization - Conceptualization model of entities, relations,
constraints and rules of a given domain or field - Formal
- Machine-processable
- Allowing automated reasoning
- With declarative semantics
- 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 - Related concepts
- Reusable knowledge base
- Database schema
4Elements of an OntologyConcept 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
5Elements of an OntologyConstraints 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
6Elements of an OntologyConstraints 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
7Computation Services to Provide to Make an
Ontology Useful
- Insertion or deletion of element
- Entity class, generic relation, constraint,
derivation rule - Simple queries
- Entity attribute value local retrieval
- Relation navigation
- Queries involving automated reasoning
- Entity attribute value retrieval with inheritance
- Instance classification from its attribute
values - Subsumption between two entity or relation
classes - Input constraint verification over an entity
class - Search for entity classes that satisfy a given
input constraint - Verification of instance sets against ontology
constraints - Overall ontology consistency
- Derivability of given formula
8Cross-Disciplinary History of Ontologies
Organization Knowledge Management since 1990
Data Integration since 1995
Ontologies
Software Engineering (Business Modeling) since
1990
Philosophy since 350 A.C.
Multi-Agent Systems since 1995
Web Information Retrieval since 2000
9Ontology Classification Dimensions
- Specialist x General
- Specialist Models a restricted domain or field
- ex. geometry, stock market, soccer, viral
infections, etc. - General
- Models common sense knowledge
- Most generic cognitive categories, reusable in
multiple domains, with domain-specific concepts
specializing - Common sense ontology provide sound guidance to
avoid - Conceptual x Linguistic
- Conceptual
- Based on distinctions useful for automated
reasoning executing variety of tasks - Linguistic
- Based on the vocabulary of one or several
natural languages - A concept is defined by the synonyms to express
it - A relation is defined by recurrent, deep
thematico-lexical relations among these synonyms
10Ontology Classification Dimensions
- Structural x Behavioral
- Behavioral ontology reify as concepts reasoning
and problem solving methods - Domain-Level x Meta-Level
- Meta-Level ontology defines the computational
concepts with which to model the domain or common
sense concepts
11Skeleton of aTop-Level Common SenseOntology
12Ontology Engineering Issues
- Domain partitioning
- How to delimit concepts?
- What are the distinctions that bring added value?
- Scope
- What knowledge to include?
- What is the domain frontier?
- Granularity
- Down to which level to detail the model?
- Validation
- How to evaluate the model quality?
- Why to prefer one modeling solution over another?
- How to identify key missing concepts?
- Since an ontology is by definition meant to be
application independent, application requirements
cannot be used as guidance - These issues are particularly vexing for
conceptual, common sense ontology that can
neither fall back on linguistics nor on common
requirement of application family for guidance
13What is OCL? Definition 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 complements MOF2 diagrams to make MOF2
- An object-oriented declarative abstract syntax
and semantics specification language that is
self-sufficient at the meta-knowledge/meta-modelin
g level - 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 reused in the left-hand side
and right-hand side 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
14What is OCL?Characteristics
- 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
15What is OCL?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
16OCL 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
17OCL Motivating Examples
context Flightinv passengers -gt size()
lt plane.numberOfSeats
1
context Personinv PersonallInstances() -gt
isUnique(socSecNr) context PersongetMortgage(su
mMoney,securityHouse) pre self.mortgages.monthl
yPayment -gt sum() lt self.salary 0.3
context Mortgage inv security.owner
borrower inv startDate lt endDate
2
18OCL Expression Contexts
19OCL Contexts Default Value and Query
Specifications
- Initial values
- context LoyaltyAccountpoints integer init
0 - context LoyaltyAccounttransactions
Set(Transaction) init Set - Query operations
- context LoyaltyAccountgetCustomerName()
Stringbody Membership.card.owner.name - context LoyaltyProgramgetServices()
Set(Services)body partner.deliveredServices
-gt asSet()
20OCL ContextsSpecifying Invariants on Attributes
- 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 LoyaltyAccountinv oneOwner
transaction.card.owner -gt asSet() -gt size()
1 - In some context self keyword is required
- context Membershipinv participants.cards.Members
hip.includes(self)
21Association Navigation
- Association navigation
- context Transaction def getCustomer()Custome
r self.card.owner - Attribute access
- context Transaction def getCustomerName()Str
ing self.card.owner.name - Abbreviation of collect operator that creates
new collection from existing one, for example
result of navigating association with plural
multiplicity - context LoyaltyAccount inv transactions -gt
collect(points) -gt exists(pInteger
p500) - context LoyaltyAccount inv
transactions.points -gt
exists(pInteger p500) - Use target class name to navigate roleless
association - context LoyaltyProgram inv levels -gt
includesAll(Membership.currentLevel) - Call UML model and OCL library operations
22Generalization 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 -gt sum() lt 10,000 - adds both Earning and Burning points
- Operator oclIsTypeOf allows hybrid navigation
following associations and specialization links - context ProgramPartner inv totalPoints
deliveredServices.transactions -gt
select(oclIsTypeOf(Earning)) .points -gt
sum() lt 10,000
23OCL Contexts Specifying Attribute Derivation
Rules
- context CustomerCardprintedName
- derive owner.title.concat(
).concat(owner.name) - context TransactionReportLine String derive
self.date transaction.date - ...
- context TransactionReport inv dates lines.date
-gt forAll(d d.isBefore(until) and
d.isAfter(from)) - ...
24OCL ContextsSpecifying Pre and Post Conditions
- context LoyaltyAccountisEmpty() Booleanpre
-- nonepost result (points 0) - Keyword _at_pre used to refer in post-condition to
the value of a property before the execution of
the operation - context LoyaltyProgramenroll(cCustomer)pre
c.name ltgt post participants
participants_at_pre -gt including(c) - Keyword oclIsNew used to specify creation of a
new instance (objects or primitive data) - context LoyaltyProgramenrollAndCreateCustomer(n
String,dDate)Customerpost result.oclIsNew()
and result.name n and
result.dateOfBirth d and participant
-gt includes(result) - oclIsNew only specifies that the operation
created the new instance, but not how it did it
which cannot be expressed in OCL
25Links BetweenOCL and UML Meta-Models
26The OCL Expressions Meta-Model
27The OCL Types Meta-Model
28OCL Types
- Value Types
- UML primitive types (including user-defined
enumerations) - OCL collection types (even of user-defined
classifiers ?) - Their instances never change value
- ex, Integer instance 1 cannot be changed to
instance 2, nor can string instance Lew
Alcindor be changed to string instance Kareem
Abdul-Jabbar, nor can enumeration Grade instance
A can be changed to enumeration instance C. - Object types UML classifiers
- Their instances can change value, i.e., the
Person instance p1 can have its name attribute
Lew Alcindor changed to Kareem Abdul-Jabbar
yet remain the same instance p1 - OclAny
- Most generic OCL type, subsuming all others
- General reflective operations are defined for
this type and inherited by all other OCL types
29OCL Types
- Primitive data types (from UML) boolean,
string, integer, real - Type conformance rules
- t1 conforms to t2 if t1 lt t2 in type hierarchy
- t1 collection(t2) conforms to t3
collection(t4) if t2 conforms to t4 - integer lt real
- Type casting
- Operation oclAsType(s) can be invoked on an
expression of type g to recast it as a type s - s must conform to g
- OclVoid
- Undefined value (similar to null values of SQL)
- Tested by oclIsUndefined operation of OclAny type
30OCL Types Collections
- Collection constants can be specified in
extension - Set1, 2, 5, 88, Setapple, orange,
strawberry - OrderedSetblack, brown, red, orange,
yellow, green, blue, purple - Sequence1, 3, 45, 2, 3, Bag1, 3, 4, 3, 5
- Sequence of consecutive integers can be
specified in intension - Sequence1..4 Sequence1,2,3,4
- Collection operations are called using -gt 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, flattenSet1,2,Set3,Set4,5
Set1,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
31OCL Semantics Encapsulation 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 lt 200
- context ElectricStove inv temperature lt 300
- context Stoveopen()
- pre status StoveStateoff
- post status StoveStateoff and isOpen
- context ElectricStoveopen()
- pre status StoveStateoff and temperature
lt 100 - post isOpen
32OCL Expressions Local Variables
- Let constructor allows creation of aliases for
recurring sub-expressions - context CustomerCard
- inv let correctDate Boolean
validFrom.isBefore(Datenow) and
goodThru.isAfter(Datenow) - in if valid then correctDate false
else correctDate true endif - Syntactic sugar that improves constraint
legibility
33OCL Library Generic Operators
- Operators that apply to expressions of any type
- Defined at the top-level of OclAny
34OCL Library Primitive Type Operators
- Boolean host, parameter and return type boolean
- Unary not
- Binary or, and, xor, , ltgt, implies
- Ternary if-then-else
- Arithmetic host and parameters integer or real
- Comparison (return type boolean) , ltgt, lt, gt
lt, gt, - Operations (return type integer or real) , -,
, /, mod, div, abs, max, min, round, floor - String host string
- Comparison (return type boolean) , ltgt
- Operation concat(String), size(), toLower(),
toUpper(), substring(ninteger,minteger)
35OCL Library Generic Collection Operators
36OCL LibrarySpecialized Collection Operators
37OCL Constraints vs. UML Constraints
context ClassicalGuitar inv strings-gt forAll(s
s.oclIsType(plasticStrings))
context ElectricGuitar inv strings -gt forAll(s
\ s.oclIsType(MetalStrings))
context ClassicGuitar inv strings -gt
forAll(type StringTypeplastic)
context Guitar inv type GuitarTypeclassic
implies strings -gt forAll(type
StringTypeplastic inv type
GuitarTypeclassic implies strings -gt
forAll(type StringTypeplastic
context ElectricGuitar inv strings -gt
forAll(type StringTypemetal)
38OCL vs. Java
- Declarative specification of operation
post-conditions in OCL is far more concise than
corresponding implementation in mainstream
imperative OO language such as Java - This is due mainly to OCLs powerful collection
operators - Example OCL expression self.parters -gt
select(deliveredServices -gt forAll(pointsEarned
0)) - Corresponding Java code
- Iterator it this.getPartners().iterator()
- Set selectResult new HashSet()
- while( it.hasNext() )
- ProgramPartner p (ProgramPartner) it.next()
- Iterator services p.getDeliveredServices().ite
rator() - boolean forAllresult true
- while( services.hasNext() )
- Service s (Service) services.next()
- forAllResult forAllResult
(s.getPointsEarned() 0) -
- if ( forAllResult )
- selectResult.add(p)
-
-
- return result