Search in sources :

Example 6 with GoalInstantiationResult

use of won.utils.goals.GoalInstantiationResult in project webofneeds by researchstudio-sat.

the class GoalInstantiationTest method example4_geoCoordinatesFulfilled.

@Test
public void example4_geoCoordinatesFulfilled() throws IOException {
    Dataset need1 = loadDataset(baseFolder + "ex4_need.trig");
    Dataset need2 = loadDataset(baseFolder + "ex4_need_debug.trig");
    Dataset conversation = loadDataset(baseFolder + "ex4_conversation.trig");
    GoalInstantiationProducer goalInstantiation = new GoalInstantiationProducer(need1, need2, conversation, "http://example.org/", "http://example.org/blended/");
    Collection<GoalInstantiationResult> results = goalInstantiation.createAllGoalCombinationInstantiationResults();
    // We have only one goal on each side so we expect only one result
    Assert.assertEquals(1, results.size());
    // We expect also one valid result
    Collection<Model> validResults = new LinkedList<>();
    for (GoalInstantiationResult result : results) {
        if (result.isConform()) {
            validResults.add(result.getInstanceModel());
        }
    }
    Assert.assertEquals(1, validResults.size());
    for (Model valid : validResults) {
        valid.write(System.out, "TRIG");
    }
}
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)

Example 7 with GoalInstantiationResult

use of won.utils.goals.GoalInstantiationResult in project webofneeds by researchstudio-sat.

the class GoalInstantiationTest method exampleTaxiFakeLocation_validity.

@Test
public void exampleTaxiFakeLocation_validity() throws IOException {
    Dataset taxiOffer = loadDataset(baseFolder + "ex7_taxioffer.trig");
    Dataset taxiDemand = loadDataset(baseFolder + "ex7_taxi.trig");
    GoalInstantiationProducer goalInstantiation = new GoalInstantiationProducer(taxiOffer, taxiDemand, null, "http://example.org/", "http://example.org/blended/");
    Collection<GoalInstantiationResult> results = goalInstantiation.createGoalInstantiationResultsForNeed1();
    for (GoalInstantiationResult res : results) {
        res.getInstanceModel().write(System.out, "TRIG");
        Assert.assertTrue(res.isConform());
        Coordinate departureAddress = getAddress(loadSparqlQuery("/won/utils/goals/extraction/address/northWestCornerQuery.rq"), res.getInstanceModel());
        Coordinate destinationAddress = getAddress(loadSparqlQuery("/won/utils/goals/extraction/address/southEastCornerQuery.rq"), res.getInstanceModel());
        Assert.assertEquals(departureAddress, new Coordinate(48.218727f, 16.360141f));
        Assert.assertEquals(destinationAddress, new Coordinate(48.218828f, 16.360241f));
    }
    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());
}
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)

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