Difference between revisions of "MappingOntology"

From Protege Wiki
Jump to: navigation, search
m
Line 110: Line 110:
 
== Functional mapping: i.e. convert a slot of type Farenheit to type Celsius ==
 
== Functional mapping: i.e. convert a slot of type Farenheit to type Celsius ==
  
See [http://protegewiki.stanford.edu/images/8/85/PromptExamples.zip funtion example].
+
See [http://protegewiki.stanford.edu/images/8/85/PromptExamples.zip function example].
  
  

Revision as of 13:58, June 24, 2014

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.

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> (7SU)

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 (7T1)

<LANG:PYTHON> *<Person:age>* > 65    (7SV)

Note two things: (7SW)

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

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' (7SZ)

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. (83C)

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

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. (83E)

An example of a relationship mapping can be found here: (83F)


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. (7MM)

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. (7MN)

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. (7MO)

The tools that PROMPT provides for mapping are the following: (7MP)

  • slot mapping (the terminology for mapping attributes) (7MQ)
    • renaming slot mapping (7MR)
    • functional slot mapping (7MS)
    • constant slot mapping (7MT)
    • lexical slot mapping (7MU)
    • recursive slot mapping (7MV)
  • instance mapping (this is how one class is mapped to another class) (7MW)

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

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. (7MY)

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'. (7MZ)

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. (7N0)

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. (7T2)

NOTE: colon separated (7T3)

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

Example: (7T5)

C to F: functional mapping (7T6)

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

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

*<Person:drives.model>*    (7T9)

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. (7TA)


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.