Search in sources :

Example 1 with GoalInstantiationResult

use of won.utils.goals.GoalInstantiationResult 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());
}
Also used : GoalInstantiationResult(won.utils.goals.GoalInstantiationResult) Dataset(org.apache.jena.query.Dataset) GoalInstantiationProducer(won.utils.goals.GoalInstantiationProducer) Resource(org.apache.jena.rdf.model.Resource) NeedModelWrapper(won.protocol.util.NeedModelWrapper) DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) Test(org.junit.Test)

Example 2 with GoalInstantiationResult

use of won.utils.goals.GoalInstantiationResult 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());
}
Also used : GoalInstantiationResult(won.utils.goals.GoalInstantiationResult) Dataset(org.apache.jena.query.Dataset) GoalInstantiationProducer(won.utils.goals.GoalInstantiationProducer) Resource(org.apache.jena.rdf.model.Resource) NeedModelWrapper(won.protocol.util.NeedModelWrapper) DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) Test(org.junit.Test)

Example 3 with GoalInstantiationResult

use of won.utils.goals.GoalInstantiationResult 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());
}
Also used : GoalInstantiationResult(won.utils.goals.GoalInstantiationResult) Dataset(org.apache.jena.query.Dataset) GoalInstantiationProducer(won.utils.goals.GoalInstantiationProducer) Resource(org.apache.jena.rdf.model.Resource) NeedModelWrapper(won.protocol.util.NeedModelWrapper) DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) Test(org.junit.Test)

Example 4 with GoalInstantiationResult

use of won.utils.goals.GoalInstantiationResult 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());
    }
}
Also used : GoalInstantiationResult(won.utils.goals.GoalInstantiationResult) Coordinate(won.protocol.model.Coordinate) Dataset(org.apache.jena.query.Dataset) GoalInstantiationProducer(won.utils.goals.GoalInstantiationProducer) Resource(org.apache.jena.rdf.model.Resource) NeedModelWrapper(won.protocol.util.NeedModelWrapper) DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) Test(org.junit.Test)

Example 5 with GoalInstantiationResult

use of won.utils.goals.GoalInstantiationResult 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());
}
Also used : GoalInstantiationResult(won.utils.goals.GoalInstantiationResult) Dataset(org.apache.jena.query.Dataset) GoalInstantiationProducer(won.utils.goals.GoalInstantiationProducer) Model(org.apache.jena.rdf.model.Model) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Dataset (org.apache.jena.query.Dataset)7 Test (org.junit.Test)7 GoalInstantiationProducer (won.utils.goals.GoalInstantiationProducer)7 GoalInstantiationResult (won.utils.goals.GoalInstantiationResult)7 Resource (org.apache.jena.rdf.model.Resource)5 DefaultNeedModelWrapper (won.protocol.util.DefaultNeedModelWrapper)5 NeedModelWrapper (won.protocol.util.NeedModelWrapper)5 LinkedList (java.util.LinkedList)2 Model (org.apache.jena.rdf.model.Model)2 Coordinate (won.protocol.model.Coordinate)2