Search in sources :

Example 6 with AtomEvent

use of won.matcher.service.common.event.AtomEvent in project webofneeds by researchstudio-sat.

the class CrawlSparqlService method retrieveActiveAtomEvents.

public BulkAtomEvent retrieveActiveAtomEvents(long fromDate, long toDate, int offset, int limit, boolean sortAscending) {
    // query template to retrieve all alctive cralwed/saved atoms in a certain date
    // range
    String orderClause = sortAscending ? "ORDER BY ?date\n" : "ORDER BY DESC(?date)\n";
    logger.debug("bulk load atom data from sparql endpoint in date range: [{},{}]", fromDate, toDate);
    String queryTemplate = "SELECT ?atomUri ?wonNodeUri ?date WHERE {  \n" + "  ?atomUri a won:Atom. \n" + "  ?atomUri won:crawlDate ?date.  \n" + "  ?atomUri won:atomState won:Active. \n" + "  ?atomUri won:wonNode ?wonNodeUri. \n" + "  {?atomUri won:crawlStatus 'SAVE'.} UNION {?atomUri won:crawlStatus 'DONE'.}\n" + "  FILTER (?date >= ?fromDate && ?date < ?toDate ) \n" + "} " + orderClause + " OFFSET ?offset\n" + " LIMIT ?limit";
    ParameterizedSparqlString pps = new ParameterizedSparqlString();
    pps.setNsPrefix("won", "https://w3id.org/won/core#");
    pps.setCommandText(queryTemplate);
    pps.setLiteral("fromDate", fromDate);
    pps.setLiteral("toDate", toDate);
    pps.setLiteral("offset", offset);
    pps.setLiteral("limit", limit);
    logger.debug("Query SPARQL Endpoint: {}", sparqlEndpoint);
    logger.debug("Execute query: {}", pps.toString());
    try (QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlEndpoint, pps.asQuery())) {
        ResultSet results = qexec.execSelect();
        // load all the atoms into one bulk atom event
        BulkAtomEvent bulkAtomEvent = new BulkAtomEvent();
        while (results.hasNext()) {
            QuerySolution qs = results.nextSolution();
            String atomUri = qs.get("atomUri").asResource().getURI();
            String wonNodeUri = qs.get("wonNodeUri").asResource().getURI();
            long crawlDate = qs.getLiteral("date").getLong();
            Dataset ds = retrieveAtomDataset(atomUri);
            if (AtomModelWrapper.isAAtom(ds)) {
                StringWriter sw = new StringWriter();
                RDFDataMgr.write(sw, ds, RDFFormat.TRIG.getLang());
                AtomEvent atomEvent = new AtomEvent(atomUri, wonNodeUri, AtomEvent.TYPE.ACTIVE, crawlDate, sw.toString(), RDFFormat.TRIG.getLang(), Cause.CRAWLED);
                bulkAtomEvent.addAtomEvent(atomEvent);
            }
        }
        logger.debug("number of atom events created: " + bulkAtomEvent.getAtomEvents().size());
        return bulkAtomEvent;
    }
}
Also used : BulkAtomEvent(won.matcher.service.common.event.BulkAtomEvent) StringWriter(java.io.StringWriter) BulkAtomEvent(won.matcher.service.common.event.BulkAtomEvent) AtomEvent(won.matcher.service.common.event.AtomEvent)

Example 7 with AtomEvent

use of won.matcher.service.common.event.AtomEvent in project webofneeds by researchstudio-sat.

the class SparqlMatcherActorExperiment method main.

public static void main(String[] args) throws IOException, InterruptedException {
    // init basic Akka
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MatcherSparqlAppConfiguration.class);
    ActorSystem system = ctx.getBean(ActorSystem.class);
    ActorRef solrMatcherActor = system.actorOf(SpringExtension.SpringExtProvider.get(system).props(SparqlMatcherActor.class), "SolrMatcherActor");
    AtomEvent ne1 = createAtomEvent("/atommodel/atom1.trig");
    AtomEvent ne2 = createAtomEvent("/atommodel/atom2.trig");
    solrMatcherActor.tell(ne1, null);
    Thread.sleep(5000);
    solrMatcherActor.tell(ne2, null);
}
Also used : ActorSystem(akka.actor.ActorSystem) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ActorRef(akka.actor.ActorRef) AtomEvent(won.matcher.service.common.event.AtomEvent) SparqlMatcherActor(won.matcher.sparql.actor.SparqlMatcherActor)

Example 8 with AtomEvent

use of won.matcher.service.common.event.AtomEvent in project webofneeds by researchstudio-sat.

the class SolrTest method createAtomEvent.

private static AtomEvent createAtomEvent(String path) throws IOException {
    InputStream is = null;
    Dataset dataset = null;
    try {
        try {
            is = SolrTest.class.getResourceAsStream(path);
            dataset = DatasetFactory.create();
            RDFDataMgr.read(dataset, is, RDFFormat.TRIG.getLang());
        } finally {
            if (is != null) {
                is.close();
            }
        }
    } catch (IOException e) {
        System.err.println(e);
        return null;
    }
    String atomUri = WonRdfUtils.AtomUtils.getAtomURI(dataset).toString();
    return new AtomEvent(atomUri, "no_uri", AtomEvent.TYPE.ACTIVE, System.currentTimeMillis(), dataset, Cause.PUSHED);
}
Also used : InputStream(java.io.InputStream) Dataset(org.apache.jena.query.Dataset) AtomEvent(won.matcher.service.common.event.AtomEvent) IOException(java.io.IOException)

Example 9 with AtomEvent

use of won.matcher.service.common.event.AtomEvent in project webofneeds by researchstudio-sat.

the class SolrTest method main.

public static void main(String[] args) throws IOException, InterruptedException {
    // init basic Akka
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MatcherSolrAppConfiguration.class);
    ActorSystem system = ctx.getBean(ActorSystem.class);
    ActorRef solrMatcherActor = system.actorOf(SpringExtension.SpringExtProvider.get(system).props(SolrMatcherActor.class), "SolrMatcherActor");
    AtomEvent ne1 = createAtomEvent("/atommodel/atom1.trig");
    AtomEvent ne2 = createAtomEvent("/atommodel/atom2.trig");
    solrMatcherActor.tell(ne1, null);
    Thread.sleep(5000);
    solrMatcherActor.tell(ne2, null);
}
Also used : ActorSystem(akka.actor.ActorSystem) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SolrMatcherActor(won.matcher.solr.actor.SolrMatcherActor) ActorRef(akka.actor.ActorRef) AtomEvent(won.matcher.service.common.event.AtomEvent)

Example 10 with AtomEvent

use of won.matcher.service.common.event.AtomEvent in project webofneeds by researchstudio-sat.

the class SparqlMatcherActorExperiment method createAtomEvent.

private static AtomEvent createAtomEvent(String path) throws IOException {
    InputStream is = null;
    Dataset dataset = null;
    try {
        try {
            is = SparqlMatcherActorExperiment.class.getResourceAsStream(path);
            dataset = DatasetFactory.create();
            RDFDataMgr.read(dataset, is, RDFFormat.TRIG.getLang());
        } finally {
            if (is != null) {
                is.close();
            }
        }
    } catch (IOException e) {
        System.err.println(e);
        return null;
    }
    String atomUri = WonRdfUtils.AtomUtils.getAtomURI(dataset).toString();
    return new AtomEvent(atomUri, "no_uri", AtomEvent.TYPE.ACTIVE, System.currentTimeMillis(), dataset, Cause.PUSHED);
}
Also used : InputStream(java.io.InputStream) Dataset(org.apache.jena.query.Dataset) AtomEvent(won.matcher.service.common.event.AtomEvent) IOException(java.io.IOException)

Aggregations

AtomEvent (won.matcher.service.common.event.AtomEvent)14 BulkAtomEvent (won.matcher.service.common.event.BulkAtomEvent)6 Dataset (org.apache.jena.query.Dataset)5 DistributedPubSubMediator (akka.cluster.pubsub.DistributedPubSubMediator)4 IOException (java.io.IOException)3 ActorRef (akka.actor.ActorRef)2 ActorSystem (akka.actor.ActorSystem)2 InputStream (java.io.InputStream)2 StringWriter (java.io.StringWriter)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 BulkHintEvent (won.matcher.service.common.event.BulkHintEvent)2 HintEvent (won.matcher.service.common.event.HintEvent)2 LoadAtomEvent (won.matcher.service.common.event.LoadAtomEvent)2 ResourceCrawlUriMessage (won.matcher.service.crawler.msg.ResourceCrawlUriMessage)2 LinkedDataFetchingException (won.protocol.rest.LinkedDataFetchingException)2 CamelMessage (akka.camel.CamelMessage)1 HashSet (java.util.HashSet)1 Lock (org.apache.jena.shared.Lock)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 HttpHeaders (org.springframework.http.HttpHeaders)1