@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix : <foo:bla#>.

# 00. Fuenf Haeuser stehen in einer Reihe.mit je einer Farbe
# 01. Jedes Haus hat eine andere Farbe
# 02. In jedem Haus wohnt eine Person einer anderen Nationalitaet
# 03. Jeder Hausbewohner bevorzugt ein bestimmtes Getraenk, raucht eine
#  bestimmte Zigarettenmarke und haelt ein bestimmtes Haustier
# 04. KEINE der 5 Personen trinkt das gleiche Getraenk, raucht die gleichen
#  Zigaretten oder haelt das gleiche Tier, wie einer seiner Nachbarn

# Frage: Wem gehoert der Fisch????

:Houses a owl:Class;
  owl:oneOf (:one :two :three :four :five);
  rdfs:subClassOf
  [ a owl:Restriction; owl:onProperty :nextTo; owl:maxCardinality 2 ].
owl:AllDifferent owl:distinctMembers (:one :two :three :four :five).

:one :leftOf :two.
:two :leftOf :three.
:three :leftOf :four.
:four :leftOf :five.

:OuterHouse a owl:Class; owl:equivalentClass
  [ a owl:Restriction; owl:onProperty :nextTo; owl:cardinality 1 ].
:NoRight a owl:Class ; owl:intersectionOf 
  ( [ a owl:Restriction; owl:onProperty :leftOf; owl:cardinality 0 ] 
    :OuterHouse ).
:five a :NoRight.

:NoLeft rdf:type owl:Class ; owl:intersectionOf 
  ( [ a owl:Restriction; owl:onProperty :rightOf; owl:cardinality 0 ] 
    :OuterHouse ).
:one a :NoLeft.

:rightOf a owl:ObjectProperty; a owl:FunctionalProperty; 
   owl:inverseOf :leftOf;
   rdfs:subPropertyOf :nextTo.
:leftOf a owl:ObjectProperty; a owl:FunctionalProperty; 
   rdfs:subPropertyOf :nextTo.
:nextTo a owl:ObjectProperty; 
   rdfs:domain :House; rdfs:range :House.


:Nationalities a owl:Class;  ### these are the persons
  owl:equivalentClass [ owl:oneOf (:gb :s :dk :n :d) ];
  rdfs:subClassOf
  [ a owl:Restriction; owl:onProperty :livesIn; owl:cardinality 1 ];
  rdfs:subClassOf
  [ a owl:Restriction; owl:onProperty :drinks; owl:cardinality 1 ];
  rdfs:subClassOf
  [ a owl:Restriction; owl:onProperty :smokes; owl:cardinality 1 ];
  rdfs:subClassOf
  [ a owl:Restriction; owl:onProperty :keepsAnimal; owl:cardinality 1 ].
owl:AllDifferent owl:distinctMembers (:gb :s :dk :n :d).

:Colors a owl:Class; 
  owl:equivalentClass [ owl:oneOf (:red :green :white :yellow :blue) ].
owl:AllDifferent owl:distinctMembers (:red :green :white :yellow :blue).

:Cigarettes a owl:Class; 
  owl:equivalentClass 
    [ owl:oneOf (:pallmall :dunhill :marlboro :winfield :rothmans) ].
owl:AllDifferent owl:distinctMembers 
      (:pallmall :dunhill :marlboro :winfield :rothmans).

:Drinks a owl:Class;
  owl:equivalentClass [ owl:oneOf (:tea :coffee :water :milk :beer) ].
owl:AllDifferent owl:distinctMembers (:tea :coffee :water :milk :beer).

:Animals a owl:Class; 
  owl:equivalentClass [ owl:oneOf (:dog :bird :fish :cat :horse) ].
owl:AllDifferent owl:distinctMembers (:dog :bird :fish :cat :horse).

#### 

:livesIn a owl:FunctionalProperty; a owl:ObjectProperty;
  a owl:InverseFunctionalProperty;
  owl:inverseOf :ownedBy;
  rdfs:domain :Nationalities;
  rdfs:range :Houses.
:ownedBy a owl:ObjectProperty.
:hasColor a owl:FunctionalProperty; a owl:ObjectProperty;
  a owl:InverseFunctionalProperty;
  rdfs:domain :Houses;
  rdfs:range :Colors.
:smokes a owl:FunctionalProperty; a owl:ObjectProperty;
  a owl:InverseFunctionalProperty;
  rdfs:domain :Nationalities;
  rdfs:range :Cigarettes.
:drinks a owl:FunctionalProperty; a owl:ObjectProperty;
  a owl:InverseFunctionalProperty;
  rdfs:domain :Nationalities;
  rdfs:range :Drinks.
:keepsAnimal a owl:FunctionalProperty; a owl:ObjectProperty;
  a owl:InverseFunctionalProperty;
  rdfs:domain :Nationalities;
  rdfs:range :Animals.

# Alternative: dann sind die untenstehenden Ausdruecke 
#  [ a [restriction ... color ... xy]] 
# kuerzer.
#  :greenHouse :hasColor :green.
#  :whiteHouse :hasColor :white.
#  :redHouse :hasColor :red.
#  :yellowHouse :hasColor :yellow.
#  :blueHouse :hasColor :blue.

# Hinweise
# 01. Der Brite lebt im roten Haus
  :gb :livesIn 
  [ a [ a owl:Restriction;
        owl:onProperty :hasColor; owl:hasValue :red] ].
# 02. Der Schwede haelt einen Hund
  :s :keepsAnimal :dog.
# 03. Der Daene trinkt gerne Tee
  :dk :drinks :tea.
# 04. Das gruene Haus steht direkt links vom weissen Haus
  [ a [ a owl:Restriction;
        owl:onProperty :hasColor; owl:hasValue :green] ]
  :leftOf 
  [ a [ a owl:Restriction;
        owl:onProperty :hasColor; owl:hasValue :white] ].
# 05. Der Besitzer des gruenen Hauses trinkt gerne Kaffee
  [ a owl:Restriction; 
    owl:onProperty :livesIn; owl:hasValue
     [ a [ a owl:Restriction;
           owl:onProperty :hasColor; owl:hasValue :green] ] ]
  owl:equivalentClass
  [ a owl:Restriction;
    owl:onProperty :drinks; owl:hasValue :coffee].
# 06. Die Person, die Pall Mall raucht, haelt einen Vogel
  [ a owl:Restriction; 
    owl:onProperty :smokes; owl:hasValue :pallmall]
  owl:equivalentClass
  [ a owl:Restriction;
    owl:onProperty :keepsAnimal; owl:hasValue :bird].
# 07. Der Mann, der im mittleren Haus wohnt, trinkt gerne Milch
  [ a owl:Restriction; 
    owl:onProperty :livesIn; owl:hasValue :three]
  owl:equivalentClass
  [ a owl:Restriction; 
    owl:onProperty :drinks; owl:hasValue :milk].
# 08. Der Besitzer des gelben Hauses raucht Dunhill
  [ a owl:Restriction; 
    owl:onProperty :livesIn; owl:hasValue   [ a [ a owl:Restriction;
        owl:onProperty :hasColor; owl:hasValue :yellow] ] ]
  owl:equivalentClass
  [ a owl:Restriction; 
    owl:onProperty :smokes; owl:hasValue :dunhill].
# 09. Der Norweger wohnt in dem ganz links stehenden Haus
  :n :livesIn :one.
# 10. Der Marlboro-Raucher wohnt neben dem, der eine Katze haelt
  [ a owl:Restriction; 
    owl:onProperty :smokes; owl:hasValue :marlboro]
  rdfs:subClassOf
  [ a owl:Restriction; 
    owl:onProperty :livesIn; owl:someValuesFrom 
    [ a owl:Restriction;
      owl:onProperty :nextTo; owl:someValuesFrom 
      [ a owl:Restriction; 
        owl:onProperty :ownedBy; owl:someValuesFrom
        [ a owl:Restriction; 
          owl:onProperty :keepsAnimal; owl:hasValue :cat]]]].
# 11. Der Mann, der ein Pferd haelt, wohnt neben dem, der Dunhill raucht
  [ a owl:Restriction; 
    owl:onProperty :smokes; owl:hasValue :dunhill]
  rdfs:subClassOf
  [ a owl:Restriction; 
    owl:onProperty :livesIn; owl:someValuesFrom 
    [ a owl:Restriction;
      owl:onProperty :nextTo; owl:someValuesFrom 
      [ a owl:Restriction; 
        owl:onProperty :ownedBy; owl:someValuesFrom
        [ a owl:Restriction; 
          owl:onProperty :keepsAnimal; owl:hasValue :horse]]]].
# 12. Der Winfield-Raucher trinkt gerne Bier
  [ a owl:Restriction;
    owl:onProperty :smokes; owl:hasValue :winfield]
  owl:equivalentClass
  [ a owl:Restriction; 
    owl:onProperty :drinks; owl:hasValue :beer].
# 13. Neben dem blauen Haus wohnt der Norweger
  :n a 
  [ a owl:Restriction; 
    owl:onProperty :livesIn; owl:someValuesFrom 
    [ a owl:Restriction;
      owl:onProperty :nextTo; owl:hasValue 
      [ a [ a owl:Restriction;
            owl:onProperty :hasColor; owl:hasValue :blue] ] ]].
# 14. Der Deutsche raucht Rothmans
  :d :smokes :rothmans.
# 15. Derjenige, der Marlboro raucht, hat einen Nachbarn, der Wasser trinkt
  [ a owl:Restriction; 
    owl:onProperty :smokes; owl:hasValue :marlboro]
  rdfs:subClassOf
  [ a owl:Restriction; 
    owl:onProperty :livesIn; owl:someValuesFrom 
    [ a owl:Restriction;
      owl:onProperty :nextTo; owl:someValuesFrom 
      [ a owl:Restriction; 
        owl:onProperty :ownedBy; owl:someValuesFrom
        [ a owl:Restriction; 
          owl:onProperty :drinks; owl:hasValue :water]]]].
