Search in sources :

Example 31 with AtomModelWrapper

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());
}
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) AtomModelWrapper(won.protocol.util.AtomModelWrapper) Test(org.junit.Test)

Example 32 with AtomModelWrapper

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 }))));
}
Also used : SparqlMatcherConfig(won.matcher.sparql.config.SparqlMatcherConfig) LinkedDataSource(won.protocol.util.linkeddata.LinkedDataSource) java.util(java.util) ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl) won.matcher.service.common.event(won.matcher.service.common.event) BasicPattern(org.apache.jena.sparql.core.BasicPattern) Autowired(org.springframework.beans.factory.annotation.Autowired) OpProject(org.apache.jena.sparql.algebra.op.OpProject) OpUnion(org.apache.jena.sparql.algebra.op.OpUnion) Logging(akka.event.Logging) Algebra(org.apache.jena.sparql.algebra.Algebra) OpDistinct(org.apache.jena.sparql.algebra.op.OpDistinct) Scope(org.springframework.context.annotation.Scope) ActorRef(akka.actor.ActorRef) Op(org.apache.jena.sparql.algebra.Op) JsonLdError(com.github.jsonldjava.core.JsonLdError) DistributedPubSub(akka.cluster.pubsub.DistributedPubSub) UntypedActor(akka.actor.UntypedActor) StreamSupport(java.util.stream.StreamSupport) SupervisorStrategy(akka.actor.SupervisorStrategy) URI(java.net.URI) WONMATCH(won.protocol.vocabulary.WONMATCH) org.apache.jena.query(org.apache.jena.query) OpAsQuery(org.apache.jena.sparql.algebra.OpAsQuery) LoggingAdapter(akka.event.LoggingAdapter) Function(akka.japi.Function) BindingHashMap(org.apache.jena.sparql.engine.binding.BindingHashMap) Triple(org.apache.jena.graph.Triple) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) DistributedPubSubMediator(akka.cluster.pubsub.DistributedPubSubMediator) org.apache.jena.rdf.model(org.apache.jena.rdf.model) AtomState(won.protocol.model.AtomState) AtomModelWrapper(won.protocol.util.AtomModelWrapper) Component(org.springframework.stereotype.Component) Duration(scala.concurrent.duration.Duration) Stream(java.util.stream.Stream) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) OneForOneStrategy(akka.actor.OneForOneStrategy) Op(org.apache.jena.sparql.algebra.Op) OpUnion(org.apache.jena.sparql.algebra.op.OpUnion) OpProject(org.apache.jena.sparql.algebra.op.OpProject) Var(org.apache.jena.sparql.core.Var) OpDistinct(org.apache.jena.sparql.algebra.op.OpDistinct)

Example 33 with AtomModelWrapper

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;
    }
}
Also used : Model(org.apache.jena.rdf.model.Model) AtomModelWrapper(won.protocol.util.AtomModelWrapper) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 34 with AtomModelWrapper

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();
}
Also used : AtomModelWrapper(won.protocol.util.AtomModelWrapper)

Example 35 with AtomModelWrapper

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);
    }
}
Also used : Model(org.apache.jena.rdf.model.Model) DefaultAtomModelWrapper(won.protocol.util.DefaultAtomModelWrapper) AtomModelWrapper(won.protocol.util.AtomModelWrapper)

Aggregations

AtomModelWrapper (won.protocol.util.AtomModelWrapper)37 Dataset (org.apache.jena.query.Dataset)19 Resource (org.apache.jena.rdf.model.Resource)15 URI (java.net.URI)9 Model (org.apache.jena.rdf.model.Model)8 WonMessage (won.protocol.message.WonMessage)6 RdfUtils (won.protocol.util.RdfUtils)6 IOException (java.io.IOException)5 MethodHandles (java.lang.invoke.MethodHandles)5 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 GoalInstantiationProducer (won.utils.goals.GoalInstantiationProducer)5 GoalInstantiationResult (won.utils.goals.GoalInstantiationResult)5 DistributedPubSubMediator (akka.cluster.pubsub.DistributedPubSubMediator)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 StringUtils (org.apache.commons.lang3.StringUtils)4 ActorRef (akka.actor.ActorRef)3