MappingOntology

From Protege Wiki
Jump to: navigation, search

Mapping Ontology

Prompt saves the mappings in a mapping ontology developed over the years at SMI. (Contributors include John Park, John Gennari, and Monica Crubezy). Here are some tips on representing complex mapping in this ontology.


Go back to PROMPT wiki page

Specifying a conditional mapping

Conditions are evaluated in a language. The default language is TCL. To use Python as the language, prefix the condition with <LANG:PYTHON>

The default condition is t If you want a more complex condition, such as mapping a person to another class depending on age, you need to do a more complex condition, such as

<LANG:PYTHON> *<Person:age>* > 65    

Note two things:

  • as always, the *< ... >* syntax is a string replacement for the actual value.
  • this is a numerical comparison. Which means Person:age should be a number, otherwise the interpreter will throw an error

There is a subtlety here when you want to do string comparisons: strings should be quoted in Python. So, if you want to do a string operation, you should quote the replacement value: <LANG:PYTHON> '*<Person:name>*' != 'Bob'

Note well: PYTHON means Jython. Latest version of Jython, as of this writing, is equivalent to Python 2.1


Map a relationship i.e. map an object propert

Relationship mapping is a direct use of the recursive slot mapping. The recursive slot mapping goes from the relationship slot in the source ontology to the equivalent relationship slot in the target ontology. The recursive instance map should be the mapping that converts the type on the range end of the object relationship.

For example: in ontology A we have Person ‘drives’ Car and in ontology B we have Employee ‘uses’ Vehicle

There are two instance maps: Person to Employee (P2E) and Car to Vehicle (C2V). The P2E map is associated to a recursive slot map that maps ‘drives’ to ‘uses’. The recursive instance map is C2V.

An example of a relationship mapping can be found here:


Splitting a class into two classes with a link between them

Note: At the time of writing, PROMPT itself is lacking some of the power of the underlying mapping ontology. So, in our descriptions here, we will assume that you are editing the mapping ontology directly, either because you are a masochist, or because I haven't had time to add more user-friendly operations to the PROMPT interface.

One of the simple kinds of changes you might make when editing an ontology is to take one class (say, Person) and create a new class based on some attribute.

Our slot2Frame example has a Person class in one ontology with the attributes (name, car). The new ontology (imaginitively called PersonCar) has the class Person(name, drives) and Car(model). The Person.drives attribute is an object attribute (also known as a link) 'drives', which points to Car.

The tools that PROMPT provides for mapping are the following:

  • slot mapping (the terminology for mapping attributes)
    • renaming slot mapping
    • functional slot mapping
    • constant slot mapping
    • lexical slot mapping
    • recursive slot mapping
  • instance mapping (this is how one class is mapped to another class)

There is no obvious way to create new classes or to create links. This is mostly due to a terminology issue, however.

To map Person to Person, you create a new instance mapping. To map the 'name' attribute, all you have to do is create a new 'renamingSlotMapping' and add it to the Person instance mapping.

To create the Car object, based on the Person.car attribute, you add a 'recursive slot mapping' from '<SELF>' to 'drives'. You then create a new instance mapping (as a child of the recursive slot mapping) that maps Person to Car, which has a renaming slot mapping to map 'car' to 'model'.

The trick here is the '<SELF>' syntax. What this means is that the mapping for the Person class will be placed in the object property 'drives'. Note that this Person mapping (the Person-to-Car instance mapping) should have the 'on-demand' checkbox marked. This means that this mapping will only be executed when the recursive slot mapping (from <SELF> to drives) is executed. If this box is not checked, then this mapping will end up being executed twice: once for every Person, and once for every recursive slot mapping for the 'drives' target slot.

This trick also works for creating new classes that have multiple slots that are all required to create a unique Car object. The compound example shows an example of this where Car has the key attributes 'model' and 'year'.


Syntax to access values from an instance

In order to access the value of a slot, the mapping interpreter included with PROMPT has a special syntax: a slot is referred to by *<Frame:slot>* where Frame is the name of the frame and slot is the name of the slot.

NOTE: colon separated

The frame is optional; if it is omitted, it defaults to the current frame in context.

Example:

C to F: functional mapping

*<Person:temp>* * (9/5) + 32   

This also works for object properties (also known as links). Example:

*<Person:drives.model>*    

Here, drives is an object property with the domain Person, and the range Car. model is a data type property of Car. The thing to notice is that everything except for the first frame is separated by dots. The first field is the frame and establishes context; following fields are all with respect to the initial context.


Rename a Frame

See renameFrame example.


Rename a slot

See renameSlot example.


Add slot of constant value

See constant example.


Convert a slot into a frame; convert a datatype to an object type slot (i.e. attribute to link)

See slotToFrame example.


Convert a frame to a slot; convert a object type slot into a datatype (i.e. convert a link to an attribute)

See FrameToSlot example.


Functional mapping: i.e. convert a slot of type Farenheit to type Celsius

See function example.


aggregate two slot values into one slot value (e.g. first name, last name -> full name)

See dcMapping example.


conditional mapping based on attribute value ( =, <, !null)

See conditional_1 example.


conditional mapping based on object property (link) existence

See conditional_2 example.


Go back to PROMPT wiki page