use of won.protocol.util.AtomModelWrapper 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.createGoalInstantiationResultsForAtom1();
for (GoalInstantiationResult res : results) {
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));
}
AtomModelWrapper atomWrapper1 = new AtomModelWrapper(taxiOffer);
Resource goal = atomWrapper1.getGoals().iterator().next();
GoalInstantiationResult result = goalInstantiation.findInstantiationForGoal(goal);
Assert.assertTrue(result.isConform());
GoalInstantiationResult recheckResultModel = GoalInstantiationProducer.findInstantiationForGoalInDataset(taxiOffer, goal, result.getInstanceModel());
Assert.assertTrue(recheckResultModel.isConform());
}
use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.
the class SparqlMatcherActor method defaultQuery.
private Optional<Op> defaultQuery(AtomModelWrapper atom) {
Model model = atom.getAtomModel();
String atomURI = atom.getAtomUri();
ArrayList<Op> queries = new ArrayList<>(3);
Statement seeks = model.getProperty(model.createResource(atomURI), model.createProperty("https://w3id.org/won/matching#seeks"));
if (seeks != null) {
Op seeksQuery = createAtomQuery(model, seeks);
if (seeksQuery != null) {
queries.add(seeksQuery);
}
}
Statement search = model.getProperty(model.createResource(atomURI), model.createProperty("https://w3id.org/won/matching#searchString"));
if (search != null) {
String searchString = search.getString();
queries.add(SparqlMatcherUtils.createSearchQuery(searchString, resultName, 2, true, true));
}
return queries.stream().reduce((left, right) -> new OpUnion(left, right)).map((union) -> new OpDistinct(new OpProject(union, Arrays.asList(new Var[] { resultName }))));
}
use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.
the class TurtleFileAtomProducer method readAtomFromFile.
@Override
public synchronized Dataset readAtomFromFile(final File file) throws IOException {
logger.debug("processing as turtle file: {} ", file);
try (FileInputStream fis = new FileInputStream(file)) {
Model model = ModelFactory.createDefaultModel();
RDFDataMgr.read(model, fis, RDFFormat.TURTLE.getLang());
// Use atomModelWrapper to ensure
AtomModelWrapper atomModelWrapper = new AtomModelWrapper(model, null);
// sysinfo graph is added already
return atomModelWrapper.copyDatasetWithoutSysinfo();
} catch (Exception e) {
logger.error("could not parse turtle from file {} ", file, e);
throw e;
}
}
use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.
the class AbstractCreateAtomAction method createWonMessage.
protected WonMessage createWonMessage(URI atomURI, Dataset atomDataset) throws WonMessageBuilderException {
AtomModelWrapper atomModelWrapper = new AtomModelWrapper(atomDataset);
RdfUtils.replaceBaseURI(atomDataset, atomURI.toString(), true);
return WonMessageBuilder.createAtom().atom(atomURI).content().dataset(atomModelWrapper.copyDatasetWithoutSysinfo()).build();
}
use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.
the class AtomIndexer method index.
public void index(Dataset dataset) throws IOException, JsonLdError {
// serialize the atom Dataset to jsonld
Query query = QueryFactory.create(ATOM_INDEX_QUERY);
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
Model atomModel = qexec.execConstruct();
// normalize the atom model for solr indexing
AtomModelWrapper atomModelWrapper = new AtomModelWrapper(atomModel, null);
String atomUri = atomModelWrapper.getAtomUri();
atomModel = atomModelWrapper.normalizeAtomModel();
// check if test index should be used for atom
boolean usedForTesting = atomModelWrapper.flag(WONMATCH.UsedForTesting);
indexAtomModel(atomModel, atomUri, usedForTesting);
}
}
Aggregations