%%ontology
@uses: configOptions
%

%%namespace
dco http://denkbares.com/ConfigOptions/
%


!! Definitions Configuration Options

%%turtle
dco:ConfigOption a owl:Class .
dco:ChoiceConfigOption rdfs:subClassOf ConfigOption .
dco:NumConfigOption rdfs:subClassOf ConfigOption .
dco:ConfigOptionAssignment a owl:Class .
dco:option a owl:ObjectProperty .
dco:is a owl:ObjectProperty .
dco:ChoiceValue a owl:Class .
dco:availableChoice a owl:ObjectProperty .

%


!! Definitions Constraints

%%turtle
dco:Constraint a owl:Class .
dco:ContradictingConstraint rdfs:subClassOf Constraint .
dco:hasDisjointSet a owl:ObjectProperty .
dco:hasValueA a owl:ObjectProperty .
dco:hasValueB a owl:ObjectProperty .
dco:contradicts a owl:ObjectProperty .
dco:largerOrEqual a owl:DatatypeProperty .
dco:smallerOrEqual a owl:DatatypeProperty .

% 


!! Definitions Car configuration set

%%turtle
dco:CarConfigSet a owl:Class.
dco:hasConfigAssignment a owl:ObjectProperty .

%


! Option Engine

%%turtle
dco:Engine a dco:ChoiceConfigOption ; 
	dco:availableChoice dco:SmallEngine, dco:MediumEngine, dco:Turbo .
	
dco:SmallEngine a ChoiceValue .
dco:MediumEngine a ChoiceValue .  
dco:Turbo a ChoiceValue .

%


! Option Hitch

%%turtle
dco:Hitch a dco:ChoiceConfigOption ; 
	dco:availableChoice WithHitch, WithoutHitch .
	
dco:WithHitch a ChoiceValue .
dco:WithoutHitch a ChoiceValue .  

%


! Option Edition

%%turtle
dco:Edition a dco:ChoiceConfigOption ; 
	dco:availableChoice FamilyEdition, SportsEdition, OffroadEdition .
	
dco:FamilyEdition a ChoiceValue .
dco:SportsEdition a ChoiceValue . 
dco:OffroadEdition a ChoiceValue .   

%


! Option Number of Doors

%%turtle
dco:NumberOfDoors a dco:NumConfigOption ;
	dco:largerOrEqual "3" ;
	dco:smallerOrEqual "5" .
	
%


! Constraint 1 : Hitch contradicts Small Engine

%%

%%turtle
dco:HitchConstradictsSmallEngine a ContradictingConstraint ; 
	hasValueA [ option Hitch; is WithHitch] ;
	hasValueB [ option Engine; is SmallEngine ] .

%


! Constraint 2 : Family Edition contradict 3 doors

%%turtle
dco:FamilyConstradicts3Doors a ContradictingConstraint ; 
	hasValueA [ option Edition; is FamilyEdition] ;
	hasValueB [ option NumberOfDoors; smallerOrEqual "4" ] .

%


! Constraint 3 : Offroad Edition contradicts Small Engine

%%turtle
dco:OffroadConstradictsSmallEngine a ContradictingConstraint ; 
	hasValueA [ option Edition; is OffroadEdition] ;
	hasValueB [ option Engine; is SmallEngine ] .

%


!! Car 1

%%turtle
dco:Car1 a CarConfigSet ;
	hasConfigAssignment 
	[ option Engine; is MediumEngine ] ,
	[ option Hitch; is WithHitch] .
%

%%sparql
SELECT ?option ?value WHERE {
dco:Car1 dco:hasConfigAssignment ?assignment.
?assignment dco:option ?option .
?assignment dco:is ?value .
}

%


!! Car 2

%%turtle
dco:Car2 a CarConfigSet ;
	hasConfigAssignment 
	[ option Engine; is SmallEngine ] ,
	[ option Edition; is OffroadEdition ] ,
	[ option Hitch; is WithHitch] .
%

%%sparql
SELECT ?option ?value WHERE {
dco:Car2 dco:hasConfigAssignment ?assignment.
?assignment dco:option ?option .
?assignment dco:is ?value .
}

%


! Car 3

%%turtle
dco:Car3 a CarConfigSet ;
	hasConfigAssignment 
	[ option Edition; is FamilyEdition ] ,
	[ option NumberOfDoors; is "3"] .
%

%%sparql
SELECT ?option ?value WHERE {
dco:Car3 dco:hasConfigAssignment ?assignment.
?assignment dco:option ?option .
?assignment dco:is ?value .
}

%


! Car 4

%%turtle
dco:Car4 a CarConfigSet ;
	hasConfigAssignment 
	[ option Edition; is FamilyEdition ] ,
	[ option NumberOfDoors; is "5"] .
%

%%sparql
SELECT ?option ?value WHERE {
dco:Car4 dco:hasConfigAssignment ?assignment.
?assignment dco:option ?option .
?assignment dco:is ?value .
}

%


! Ill-defined Car

%%turtle
dco:CarX a CarConfigSet ;
	hasConfigAssignment 
	[ option Engine; is WithHitch ] ,
	[ option NumberOfDoors; is "99" ] ,
	[ option Hitch; is SportsEdition] .
%

%%sparql
SELECT ?option ?value WHERE {
dco:CarX dco:hasConfigAssignment ?assignment.
?assignment dco:option ?option .
?assignment dco:is ?value .
}

%


!! Assignment Consistency Query 

%%Sparql
SELECT ?car ?option ?value {

{
	?car rdf:type dco:CarConfigSet .
	?car dco:hasConfigAssignment ?assignment .
	?assignment dco:option ?option .
	?assignment dco:is ?value .
	?option rdf:type dco:ChoiceConfigOption .
	FILTER NOT EXISTS {
		?option dco:availableChoice ?value .
	}
}

UNION {
	?car rdf:type dco:CarConfigSet .
	?car dco:hasConfigAssignment ?assignment .
	?assignment dco:option ?option .
	?assignment dco:is ?value .
	?option rdf:type dco:NumConfigOption .
	?option dco:largerOrEqual ?minValue .
	?option dco:smallerOrEqual ?maxValue .
	FILTER (xsd:integer(?value) < xsd:integer(?minValue) 
		|| xsd:integer(?value) > xsd:integer(?maxValue) )

}


}
%


!! Constraint Validation Query

__Violated Constraints:__

%%sparql
SELECT ?car ?constraint WHERE {
{
?constraint rdf:type dco:Constraint .
?constraint dco:hasValueA ?constraintAssignmentA .
?constraintAssignmentA dco:is ?valueA .
?constraint dco:hasValueB ?constraintAssignmentB .
?constraintAssignmentB dco:is ?valueB .

?car rdf:type dco:CarConfigSet .
?car dco:hasConfigAssignment ?assignment1 .
?assignment1 dco:is ?valueA .
?car dco:hasConfigAssignment ?assignment2 .
?assignment2 dco:is ?valueB .

}


%

%%package configOptions