Search in sources :

Example 1 with Function

use of akka.japi.Function in project webofneeds by researchstudio-sat.

the class SparqlMatcherActor method processActiveAtomEvent.

/**
 * Produces hints for the atom. The score is calculated as a function of scores
 * provided by the embedded sparql queries: the range of those scores is
 * projected on a range of 0-1. For inverse matches, the score is always 100%,
 * because there is only one possible match - the original atom. Note: this
 * could be improved by remembering reported match scores in the matcher and
 * using historic scores for normalization, but that's a lot more work.
 */
protected void processActiveAtomEvent(AtomEvent atomEvent) throws IOException {
    AtomModelWrapper atom = new AtomModelWrapper(atomEvent.deserializeAtomDataset());
    log.debug("starting sparql-based matching for atom {}, cause: {}", atom.getAtomUri(), atomEvent.getCause());
    List<ScoredAtom> matches = queryAtom(atom);
    log.debug("found {} match candidates", matches.size());
    // produce hints after post-filtering the matches we found:
    Collection<HintEvent> hintEvents = produceHints(atom, // we
    matches.stream().filter(foundAtom -> foundAtom.atom.getAtomState() == AtomState.ACTIVE).filter(foundAtom -> postFilter(atom, foundAtom.atom)).collect(Collectors.toList()), atomEvent.getCause());
    publishHintEvents(hintEvents, atom.getAtomUri());
    log.debug("finished sparql-based matching for atom {}", atom.getAtomUri());
}
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) AtomModelWrapper(won.protocol.util.AtomModelWrapper)

Aggregations

ActorRef (akka.actor.ActorRef)1 OneForOneStrategy (akka.actor.OneForOneStrategy)1 SupervisorStrategy (akka.actor.SupervisorStrategy)1 UntypedActor (akka.actor.UntypedActor)1 DistributedPubSub (akka.cluster.pubsub.DistributedPubSub)1 DistributedPubSubMediator (akka.cluster.pubsub.DistributedPubSubMediator)1 Logging (akka.event.Logging)1 LoggingAdapter (akka.event.LoggingAdapter)1 Function (akka.japi.Function)1 JsonLdError (com.github.jsonldjava.core.JsonLdError)1 IOException (java.io.IOException)1 URI (java.net.URI)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 org.apache.jena.query (org.apache.jena.query)1 org.apache.jena.rdf.model (org.apache.jena.rdf.model)1