use of won.utils.goals.GoalInstantiationProducer in project webofneeds by researchstudio-sat.
the class GoalInstantiationTest method example5_singleGoalsValidity.
@Test
public void example5_singleGoalsValidity() throws IOException {
// check that the goals from each need can be validated successfully without each other
Dataset need1 = loadDataset(baseFolder + "ex5_need.trig");
Dataset need2 = loadDataset(baseFolder + "ex5_need_debug.trig");
Dataset conversation = loadDataset(baseFolder + "ex5_conversation.trig");
GoalInstantiationProducer goalInstantiation = new GoalInstantiationProducer(need1, need2, conversation, "http://example.org/", "http://example.org/blended/");
Collection<GoalInstantiationResult> results = goalInstantiation.createAllGoalCombinationInstantiationResults();
NeedModelWrapper needWrapper1 = new NeedModelWrapper(need1);
Resource goal = needWrapper1.getGoals().iterator().next();
GoalInstantiationResult result = goalInstantiation.findInstantiationForGoal(goal);
Assert.assertTrue(result.isConform());
NeedModelWrapper needWrapper2 = new NeedModelWrapper(need2);
goal = needWrapper1.getGoals().iterator().next();
result = goalInstantiation.findInstantiationForGoal(goal);
Assert.assertTrue(result.isConform());
}
use of won.utils.goals.GoalInstantiationProducer in project webofneeds by researchstudio-sat.
the class GoalInstantiationTest method example1_allInfoInTwoGoals.
@Test
public void example1_allInfoInTwoGoals() throws IOException {
Dataset need1 = loadDataset(baseFolder + "ex1_need.trig");
Dataset need2 = loadDataset(baseFolder + "ex1_need_debug.trig");
Dataset conversation = loadDataset(baseFolder + "ex1_conversation.trig");
GoalInstantiationProducer goalInstantiation = new GoalInstantiationProducer(need1, need2, conversation, "http://example.org/", "http://example.org/blended/");
Collection<GoalInstantiationResult> results = goalInstantiation.createAllGoalCombinationInstantiationResults();
// instantiation of combined goals must be conform
Assert.assertEquals(1, results.size());
System.out.println(results.iterator().next().toString());
Assert.assertTrue(results.iterator().next().isConform());
// instantiation of goal of need1 fails cause driver is missing
NeedModelWrapper needWrapper1 = new NeedModelWrapper(need1);
Resource goal = needWrapper1.getGoals().iterator().next();
GoalInstantiationResult result = goalInstantiation.findInstantiationForGoal(goal);
System.out.println(result.toString());
Assert.assertFalse(result.isConform());
Assert.assertEquals("hasDriver", result.getShaclReportWrapper().getValidationResults().iterator().next().getResultPath().getLocalName());
// instantiation of goal of need2 fails cause 3 attributes are missing: location, time, client
NeedModelWrapper needWrapper2 = new NeedModelWrapper(need2);
goal = needWrapper2.getGoals().iterator().next();
result = goalInstantiation.findInstantiationForGoal(goal);
System.out.println(result.toString());
Assert.assertFalse(result.isConform());
Assert.assertEquals(3, result.getShaclReportWrapper().getValidationResults().size());
}
use of won.utils.goals.GoalInstantiationProducer in project webofneeds by researchstudio-sat.
the class GoalInstantiationTest method example2_allInfoInTwoGoalsAndMessage.
@Test
public void example2_allInfoInTwoGoalsAndMessage() throws IOException {
Dataset need1 = loadDataset(baseFolder + "ex2_need.trig");
Dataset need2 = loadDataset(baseFolder + "ex2_need_debug.trig");
Dataset conversationWithoutPickupTime = loadDataset(baseFolder + "ex1_conversation.trig");
Dataset conversationWithPickupTime = loadDataset(baseFolder + "ex2_conversation.trig");
// this conversation doas not contain the missing pickup time info so the goals cannot be fulfilled
GoalInstantiationProducer goalInstantiation = new GoalInstantiationProducer(need1, need2, conversationWithoutPickupTime, "http://example.org/", "http://example.org/blended/");
Collection<GoalInstantiationResult> results = goalInstantiation.createAllGoalCombinationInstantiationResults();
Assert.assertEquals(1, results.size());
System.out.println(results.iterator().next().toString());
Assert.assertFalse(results.iterator().next().isConform());
// this conversation contains the missing pickup info so the goals can be fulfilled
goalInstantiation = new GoalInstantiationProducer(need1, need2, conversationWithPickupTime, "http://example.org/", "http://example.org/blended/");
results = goalInstantiation.createAllGoalCombinationInstantiationResults();
Assert.assertEquals(1, results.size());
System.out.println(results.iterator().next().toString());
Assert.assertTrue(results.iterator().next().isConform());
// instantiation of goal of need1 fails cause driver is missing
NeedModelWrapper needWrapper1 = new NeedModelWrapper(need1);
Resource goal = needWrapper1.getGoals().iterator().next();
GoalInstantiationResult result = goalInstantiation.findInstantiationForGoal(goal);
System.out.println(result.toString());
Assert.assertFalse(result.isConform());
Assert.assertEquals("hasDriver", result.getShaclReportWrapper().getValidationResults().iterator().next().getResultPath().getLocalName());
// instantiation of goal of need2 fails cause 3 attributes are missing: location, time, client
NeedModelWrapper needWrapper2 = new NeedModelWrapper(need2);
goal = needWrapper2.getGoals().iterator().next();
result = goalInstantiation.findInstantiationForGoal(goal);
System.out.println(result.toString());
Assert.assertFalse(result.isConform());
Assert.assertEquals(3, result.getShaclReportWrapper().getValidationResults().size());
}
use of won.utils.goals.GoalInstantiationProducer in project webofneeds by researchstudio-sat.
the class GoalInstantiationTest method exampleTaxi_validity.
@Test
public void exampleTaxi_validity() throws IOException {
Dataset taxiOffer = loadDataset(baseFolder + "ex6_taxioffer.trig");
Dataset taxiDemand = loadDataset(baseFolder + "ex6_taxi.trig");
Dataset taxiDemandNoLoc = loadDataset(baseFolder + "ex6_taxi_noloc.trig");
Dataset taxiDemandTwoLoc = loadDataset(baseFolder + "ex6_taxi_twoloc.trig");
GoalInstantiationProducer goalInstantiation = new GoalInstantiationProducer(taxiOffer, taxiDemand, null, "http://example.org/", "http://example.org/blended/");
Collection<GoalInstantiationResult> results = goalInstantiation.createGoalInstantiationResultsForNeed1();
for (GoalInstantiationResult res : results) {
System.out.println("Result::::::::::::::::::::::::::::::" + res.isConform());
System.out.println(res.toString());
if (res.isConform()) {
Coordinate departureAddress = getAddress(loadSparqlQuery("/won/utils/goals/extraction/address/fromLocationQuery.rq"), res.getInstanceModel());
Coordinate destinationAddress = getAddress(loadSparqlQuery("/won/utils/goals/extraction/address/toLocationQuery.rq"), res.getInstanceModel());
Assert.assertEquals(departureAddress, new Coordinate(10.0f, 11.0f));
Assert.assertEquals(destinationAddress, new Coordinate(12.0f, 13.0f));
}
}
NeedModelWrapper needWrapper1 = new NeedModelWrapper(taxiOffer);
Resource goal = needWrapper1.getGoals().iterator().next();
GoalInstantiationResult result = goalInstantiation.findInstantiationForGoal(goal);
Assert.assertTrue(result.isConform());
GoalInstantiationResult recheckResultModel = GoalInstantiationProducer.findInstantiationForGoalInDataset(taxiOffer, goal, result.getInstanceModel());
Assert.assertTrue(recheckResultModel.isConform());
goalInstantiation = new GoalInstantiationProducer(taxiOffer, taxiDemandNoLoc, null, "http://example.org/", "http://example.org/blended/");
results = goalInstantiation.createGoalInstantiationResultsForNeed1();
for (GoalInstantiationResult res : results) {
Assert.assertFalse(res.isConform());
}
goalInstantiation = new GoalInstantiationProducer(taxiOffer, taxiDemandTwoLoc, null, "http://example.org/", "http://example.org/blended/");
results = goalInstantiation.createGoalInstantiationResultsForNeed1();
for (GoalInstantiationResult res : results) {
Assert.assertFalse(res.isConform());
}
}
use of won.utils.goals.GoalInstantiationProducer in project webofneeds by researchstudio-sat.
the class GoalInstantiationTest method example3_multipleGoalsFulfilled.
@Test
public void example3_multipleGoalsFulfilled() throws IOException {
Dataset need1 = loadDataset(baseFolder + "ex3_need.trig");
Dataset need2 = loadDataset(baseFolder + "ex3_need_debug.trig");
Dataset conversation = loadDataset(baseFolder + "ex3_conversation.trig");
GoalInstantiationProducer goalInstantiation = new GoalInstantiationProducer(need1, need2, conversation, "http://example.org/", "http://example.org/blended/");
Collection<GoalInstantiationResult> results = goalInstantiation.createAllGoalCombinationInstantiationResults();
// We have 4 and 2 goals so we expected 8 results
Assert.assertEquals(8, results.size());
// We expected three valid results
Collection<Model> validResults = new LinkedList<>();
for (GoalInstantiationResult result : results) {
if (result.isConform()) {
validResults.add(result.getInstanceModel());
}
}
for (Model valid : validResults) {
valid.write(System.out, "TRIG");
}
Assert.assertEquals(3, validResults.size());
}
Aggregations