use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.
the class GoalInstantiationTest method example2_allInfoInTwoGoalsAndMessage.
@Test
public void example2_allInfoInTwoGoalsAndMessage() throws IOException {
Dataset atom1 = loadDataset(baseFolder + "ex2_atom.trig");
Dataset atom2 = loadDataset(baseFolder + "ex2_atom_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(atom1, atom2, conversationWithoutPickupTime, "http://example.org/", "http://example.org/blended/");
Collection<GoalInstantiationResult> results = goalInstantiation.createAllGoalCombinationInstantiationResults();
Assert.assertEquals(1, results.size());
Assert.assertFalse(results.iterator().next().isConform());
// this conversation contains the missing pickup info so the goals can be
// fulfilled
goalInstantiation = new GoalInstantiationProducer(atom1, atom2, conversationWithPickupTime, "http://example.org/", "http://example.org/blended/");
results = goalInstantiation.createAllGoalCombinationInstantiationResults();
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.iterator().next().isConform());
// instantiation of goal of atom1 fails cause driver is missing
AtomModelWrapper atomWrapper1 = new AtomModelWrapper(atom1);
Resource goal = atomWrapper1.getGoals().iterator().next();
GoalInstantiationResult result = goalInstantiation.findInstantiationForGoal(goal);
Assert.assertFalse(result.isConform());
Assert.assertEquals("hasDriver", result.getShaclReportWrapper().getValidationResults().iterator().next().getResultPath().getLocalName());
// instantiation of goal of atom2 fails cause 3 attributes are missing:
// location, time, client
AtomModelWrapper atomWrapper2 = new AtomModelWrapper(atom2);
goal = atomWrapper2.getGoals().iterator().next();
result = goalInstantiation.findInstantiationForGoal(goal);
Assert.assertFalse(result.isConform());
Assert.assertEquals(3, result.getShaclReportWrapper().getValidationResults().size());
}
use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.
the class GoalInstantiationProducer method getAtomContentModelWithoutGoals.
private Model getAtomContentModelWithoutGoals(Dataset atom) {
AtomModelWrapper atomWrapper = new AtomModelWrapper(atom);
Model atom1Model = atomWrapper.copyAtomModel(AtomGraphType.ATOM);
for (Resource goal : atomWrapper.getGoals()) {
RdfUtils.removeResource(atom1Model, goal);
}
return atom1Model;
}
use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.
the class GoalInstantiationProducer method findInstantiationForGoalInDataset.
/**
* Create a goal instantiation result from the attempt to instantiate one goal
* with data given in the dataset The data is extracted and validated against
* the shacl shape of the goal.
*
* @param atom Dataset of the atom to retrieve the goalShapesModel from
* @param goal resource referencing goal from atom1 or atom2
* @param model Model that should be checked for goal validity
* @return a goal instantiation result whose input model can either conform to
* its shacl shapes or not
*/
public static GoalInstantiationResult findInstantiationForGoalInDataset(Dataset atom, Resource goal, Model model) {
AtomModelWrapper atomWrapper = new AtomModelWrapper(atom);
Model goalShapesModel;
if (atomWrapper.getGoals().contains(goal)) {
goalShapesModel = atomWrapper.getShapesGraph(goal);
} else {
throw new IllegalArgumentException("problem to identify goal resource in the atom model");
}
if (goalShapesModel == null) {
throw new IllegalArgumentException("shapes model for goal not found");
}
Model extractedModel = GoalUtils.extractGoalData(model, goalShapesModel);
return new GoalInstantiationResult(extractedModel, goalShapesModel);
}
use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.
the class GoalInstantiationProducer method findInstantiationForGoal.
/**
* Create a goal instantiation result from the attempt to instantiate one goal
* with data of two atoms using all the atom data, the conversation data and the
* shapes data of the goal. The data is extracted and validated against the
* shacl shape of the goal.
*
* @param goal resource referencing goal from atom1 or atom2
* @return a goal instantiation result whose input model can either conform to
* its shacl shapes or not
*/
public GoalInstantiationResult findInstantiationForGoal(Resource goal) {
AtomModelWrapper atomWrapper1 = new AtomModelWrapper(atom1);
AtomModelWrapper atomWrapper2 = new AtomModelWrapper(atom2);
Model goalShapesModel = null;
Model goalDataModel = null;
if (atomWrapper1.getGoals().contains(goal) && !atomWrapper2.getGoals().contains(goal)) {
goalShapesModel = atomWrapper1.getShapesGraph(goal);
goalDataModel = atomWrapper1.getDataGraph(goal);
} else if (atomWrapper2.getGoals().contains(goal) && !atomWrapper1.getGoals().contains(goal)) {
goalShapesModel = atomWrapper2.getShapesGraph(goal);
goalDataModel = atomWrapper2.getDataGraph(goal);
} else {
throw new IllegalArgumentException("problem to identify goal resource in one of the two atom models");
}
if (goalShapesModel == null) {
throw new IllegalArgumentException("shapes model for goal not found");
}
Model combinedModelWithGoalData = ModelFactory.createDefaultModel();
combinedModelWithGoalData.add(combinedModelWithoutGoals);
if (goalDataModel != null) {
combinedModelWithGoalData.add(goalDataModel);
}
Model extractedModel = GoalUtils.extractGoalData(combinedModelWithGoalData, goalShapesModel);
return new GoalInstantiationResult(extractedModel, goalShapesModel);
}
use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.
the class GoalInstantiationProducer method createAllGoalCombinationInstantiationResults.
/**
* create all possible goal instantiations between two atoms. That means trying
* to combine each two goals of the two atoms.
*
* @return
*/
public Collection<GoalInstantiationResult> createAllGoalCombinationInstantiationResults() {
AtomModelWrapper atomWrapper1 = new AtomModelWrapper(atom1);
AtomModelWrapper atomWrapper2 = new AtomModelWrapper(atom2);
Collection<GoalInstantiationResult> results = new LinkedList<>();
for (Resource goal1 : atomWrapper1.getGoals()) {
for (Resource goal2 : atomWrapper2.getGoals()) {
GoalInstantiationResult instantiationResult = findInstantiationForGoals(goal1, goal2);
results.add(instantiationResult);
}
}
return results;
}
Aggregations