# -----------------
# Beetle example 12
# -----------------
#
# See https://en.wikipedia.org/wiki/Disjunction_elimination

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix : <http://example.org/#>.

# beetle is a car
:beetle a :Car.

# all cars are green or blue
(_:A) log:onNegativeSurface [ log:graph (
    [ log:triple (_:A rdf:type :Car)]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :green)]
    )])]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :blue)]
    )])]
)].

# green things are nice or pretty
(_:A) log:onNegativeSurface [ log:graph (
    [ log:triple (_:A :is :green)]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :nice)]
    )])]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :pretty)]
    )])]
)].

# pretty things are pretty 1 or pretty 2
(_:A) log:onNegativeSurface [ log:graph (
    [ log:triple (_:A :is :pretty)]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :pretty1)]
    )])]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :pretty2)]
    )])]
)].

# nice things are nice 1 or nice 2
(_:A) log:onNegativeSurface [ log:graph (
    [ log:triple (_:A :is :nice)]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :nice1)]
    )])]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :nice2)]
    )])]
)].

# pretty 1 things are pretty 11 or pretty 12
(_:A) log:onNegativeSurface [ log:graph (
    [ log:triple (_:A :is :pretty1)]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :pretty11)]
    )])]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :pretty12)]
    )])]
)].

# pretty 2 things are pretty 21 or pretty 22
(_:A) log:onNegativeSurface [ log:graph (
    [ log:triple (_:A :is :pretty2)]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :pretty21)]
    )])]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :pretty22)]
    )])]
)].

# nice 1 things are nice 11 or nice 12
(_:A) log:onNegativeSurface [ log:graph (
    [ log:triple (_:A :is :nice1)]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :nice11)]
    )])]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :nice12)]
    )])]
)].

# nice 2 things are nice 21 or nice 22
(_:A) log:onNegativeSurface [ log:graph (
    [ log:triple (_:A :is :nice2)]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :nice21)]
    )])]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :nice22)]
    )])]
)].

# pretty or nice or blue things are beautiful
(_:A) log:onNegativeSurface [ log:graph (
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (() log:onNegativeSurface [ log:graph (
            [ log:triple (_:A :is :pretty11)]
        )])]
        [ log:triple (() log:onNegativeSurface [ log:graph (
            [ log:triple (_:A :is :pretty12)]
        )])]
        [ log:triple (() log:onNegativeSurface [ log:graph (
            [ log:triple (_:A :is :pretty21)]
        )])]
        [ log:triple (() log:onNegativeSurface [ log:graph (
            [ log:triple (_:A :is :pretty22)]
        )])]
        [ log:triple (() log:onNegativeSurface [ log:graph (
            [ log:triple (_:A :is :nice11)]
        )])]
        [ log:triple (() log:onNegativeSurface [ log:graph (
            [ log:triple (_:A :is :nice12)]
        )])]
        [ log:triple (() log:onNegativeSurface [ log:graph (
            [ log:triple (_:A :is :nice21)]
        )])]
        [ log:triple (() log:onNegativeSurface [ log:graph (
            [ log:triple (_:A :is :nice22)]
        )])]
        [ log:triple (() log:onNegativeSurface [ log:graph (
            [ log:triple (_:A :is :blue)]
        )])]
    )])]
    [ log:triple (() log:onNegativeSurface [ log:graph (
        [ log:triple (_:A :is :beautiful)]
    )])]
)].

# query
(_:S) log:onNegativeSurface [ log:graph (
    [ log:triple (_:S :is :beautiful)]
    [ log:triple (() log:onNegativeAnswerSurface [ log:graph (
        [ log:triple (_:S :is :beautiful)]
    )])]
)].
