This README explains how to generate an OWL format of a semantic map from an output
of the enviroment modelling module that stores the result of the segmentation to the
kitchen*.conf file (see registration and surface_modelling stack for that).


1)Generate semantic map in OWL format:
Run the conversion server:
$$ rosrun mod_semantic_map SemanticMapToOWL
Change the following line in export_to_sem_map.cpp if needed and re-compile:
std::string map = "http://ias.cs.tum.edu/kb/bosch_semantic_map.owl#";
$$ rosrun pr2_door_opening_app export_to_sem_map kitchen*.conf <cabinet_number1 cabinet_number2 ...>
The map will get saved to a kitchen.owl file.


2)Move owl map to bosch_semantic_map package
cp kitchen.owl  `rospack find bosch_semantic_map'/owl/your_map_name.owl.in


3)Change preample in bosch_semantic_map'/owl/yourname.owl.in to correspond to the following (note "local_path" variable):
<!DOCTYPE rdf:RDF [
    <!ENTITY local_path 'file://@OWL_PATH_PREFIX@/owl/'>
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY owl2 "http://www.w3.org/2006/12/owl2#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" >
    <!ENTITY knowrob "http://ias.cs.tum.edu/kb/knowrob.owl#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY protege "http://protege.stanford.edu/plugins/owl/protege#" >
]>


<rdf:RDF xmlns="http://ias.cs.tum.edu/kb/bosch_semantic_map.owl#"
     xml:base="http://ias.cs.tum.edu/kb/bosch_semantic_map.owl"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
     xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl2="http://www.w3.org/2006/12/owl2#"
     xmlns:knowrob="http://ias.cs.tum.edu/kb/knowrob.owl#">
    <owl:Ontology rdf:about="http://ias.cs.tum.edu/kb/bosch_semantic_map.owl">
        <owl:imports rdf:resource="&local_path;knowrob.owl"/>
    </owl:Ontology>


4)Get the taxonomy of objects into a separate owl file (e.g. `rospack find bosch_semantic_map'/owl/your_objects_map_name.owl.in)
At the moment this amounts to:
a)manually annotating the objects in the kitchen;
b)creating the taxonomy of objects and the instances of thereof using Protege (to install: http://ias.in.tum.de/kb/wiki/index.php/Tutorial:_KnowRob_basics);
c)placing the objects into containers/locations.
For part B and C you proceed as following:
Open protege and load both owl files (your_map_name.owl.in and your_objects_map_name.owl.in) into it.

For each annotated object, create an object instance. In protege, click on the tab "Individuals": in the left column, select your class (e.g. using the search on the top right corner of the screen), then in the middle column, click on the violet diamon to add a new member.
e.g. search for "milk", select on the left "Aro-HVollMilch", click on the "add individual" button and name the individual "milk3".

To assign it to a location, click on the instance "milk3" in the middle column, then in the right column, click on the "plus" (+) next to "object property assertions". add a object property of the type "in-ContGeneric", which is to be found under topObjectProperty->spatiallyRelated->topologicalRelations->in-ContGeneric. In the right column in the popup window, select the location, e.g. "Refrigerator67", which is defined in your semantic map (you might change this from the ccrl-semantic map to your own one by changing/adding the include files)

4)Change prolog/init.pl.in file in bosch_semantic_map pkg to load your (new) maps

6)Load the maps into prolog database
$$ rosrun rosprolog rosprolog bosch_semantic_map

7)Run various queries that show the power of the semantic map
Get all instances of Beer:
?- owl_has(A, rdf:type, 'http://ias.cs.tum.edu/kb/kitchenobjects.owl#Beer').
Get all instances of Fork (note namespace):
?- owl_subclass_of(A, knowrob:'FoodOrDrink').

What do you know about BeerPaleAle2:
?- owl_has('http://ias.cs.tum.edu/kb/kitchenobjects.owl#BeerPaleAle2', P, O).

Where is BeerPaleAle2:
?- rdf_triple(knowrob:'in-ContGeneric', 'http://ias.cs.tum.edu/kb/kitchenobjects.owl#BeerPaleAle2', B).

Which objects are in Cupboard 1:
?- owl_has(A, knowrob:'in-ContGeneric', knowrob:'Cupboard1').

%TODO: Replace with my object
Check if the buttermilk is placed correctly (i.e. at its storage location)
?- rdf_triple(knowrob:'in-ContGeneric', knowrob:'Buttermilk205', B),
storagePlaceFor(B, knowrob:'Buttermilk205').

Read opening trajectory for Cupboard1
?- register_ros_package(mod_vis).
?- visualisation_canvas(C).
?- rdf_has(knowrob:'Cupboard1', knowrob:openingTrajectory, Traj), findall(P, rdf_has(Traj, knowrob:pointOnTrajectory, P), Ps), mod_vis:add_trajectory(Ps, _).

Query opening trajectory:
?- rdf_has(knowrob:'Cupboard1', knowrob:openingTrajectory, Traj), findall(P, rdf_has(Traj, knowrob:pointOnTrajectory, P), Ps).

Check computables, e.g. Top, Bottom
?- rdf_triple(knowrob:'on-Physical', Top, 'http://ias.cs.tum.edu/kb/knowrob.owl#Cupboard1').
?- rdf_triple(knowrob:'on-Physical', Bottom, 'http://ias.cs.tum.edu/kb/knowrob.owl#Cupboard1').


Appendix:
OpenCyc (helps you shape out taxonomy of your objects by following their inheritance style, see genls for Arg1 and Arg2):
http://atbeetz9.informatik.tu-muenchen.de:3602/cgi-bin/cyccgi/cg?cb-start



