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;
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations