Search in sources :

Example 6 with NeedModelWrapper

use of won.protocol.util.NeedModelWrapper in project webofneeds by researchstudio-sat.

the class GoalInstantiationProducer method createAllGoalCombinationInstantiationResults.

/**
 * create all possible goal instantiations between two needs.
 * That means trying to combine each two goals of the two needs.
 *
 * @return
 */
public Collection<GoalInstantiationResult> createAllGoalCombinationInstantiationResults() {
    NeedModelWrapper needWrapper1 = new NeedModelWrapper(need1);
    NeedModelWrapper needWrapper2 = new NeedModelWrapper(need2);
    Collection<GoalInstantiationResult> results = new LinkedList<>();
    for (Resource goal1 : needWrapper1.getGoals()) {
        for (Resource goal2 : needWrapper2.getGoals()) {
            GoalInstantiationResult instantiationResult = findInstantiationForGoals(goal1, goal2);
            results.add(instantiationResult);
        }
    }
    return results;
}
Also used : Resource(org.apache.jena.rdf.model.Resource) NeedModelWrapper(won.protocol.util.NeedModelWrapper) LinkedList(java.util.LinkedList)

Example 7 with NeedModelWrapper

use of won.protocol.util.NeedModelWrapper in project webofneeds by researchstudio-sat.

the class GoalInstantiationProducer method createGoalInstantiationResults.

private Collection<GoalInstantiationResult> createGoalInstantiationResults(Dataset need) {
    NeedModelWrapper needWrapper = new NeedModelWrapper(need);
    Collection<GoalInstantiationResult> results = new LinkedList<>();
    for (Resource goal : needWrapper.getGoals()) {
        results.add(findInstantiationForGoal(goal));
    }
    return results;
}
Also used : Resource(org.apache.jena.rdf.model.Resource) NeedModelWrapper(won.protocol.util.NeedModelWrapper) LinkedList(java.util.LinkedList)

Example 8 with NeedModelWrapper

use of won.protocol.util.NeedModelWrapper 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 9 with NeedModelWrapper

use of won.protocol.util.NeedModelWrapper 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 10 with NeedModelWrapper

use of won.protocol.util.NeedModelWrapper 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)

Aggregations

NeedModelWrapper (won.protocol.util.NeedModelWrapper)27 Dataset (org.apache.jena.query.Dataset)14 Resource (org.apache.jena.rdf.model.Resource)12 Model (org.apache.jena.rdf.model.Model)9 DefaultNeedModelWrapper (won.protocol.util.DefaultNeedModelWrapper)6 URI (java.net.URI)5 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)5 GoalInstantiationProducer (won.utils.goals.GoalInstantiationProducer)4 GoalInstantiationResult (won.utils.goals.GoalInstantiationResult)4 WonMessage (won.protocol.message.WonMessage)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 Event (won.bot.framework.eventbot.event.Event)2 FailureResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent)2 EventListener (won.bot.framework.eventbot.listener.EventListener)2 Coordinate (won.protocol.model.Coordinate)2 WonNodeInformationService (won.protocol.service.WonNodeInformationService)2 DistributedPubSubMediator (akka.cluster.pubsub.DistributedPubSubMediator)1 StringWriter (java.io.StringWriter)1