本文整理汇总了Java中org.deri.cqels.engine.ContinuousConstruct类的典型用法代码示例。如果您正苦于以下问题:Java ContinuousConstruct类的具体用法?Java ContinuousConstruct怎么用?Java ContinuousConstruct使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContinuousConstruct类属于org.deri.cqels.engine包,在下文中一共展示了ContinuousConstruct类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeQuery
import org.deri.cqels.engine.ContinuousConstruct; //导入依赖的package包/类
@Override
public void removeQuery(int query_id) {
if (queries.containsKey(query_id)) {
logger.debug("Removing query");
OpRouter1 op = queries.get(query_id);
if (op instanceof ContinuousConstruct) {
context.unregisterConstruct((ContinuousConstruct) op);
} else {
context.unregisterSelect((ContinuousSelect) op);
}
queries.remove(query_id, op);
} else {
logger.error("Select not found!");
logger.debug(queries.keySet().toString());
}
}
示例2: simpleConstruct
import org.deri.cqels.engine.ContinuousConstruct; //导入依赖的package包/类
@Test(timeout = 5000)
public void simpleConstruct() {
final String STREAM_ID = STREAM_ID_PREFIX + "_1";
RDFStream stream = new DefaultRDFStream(context, STREAM_ID);
ContinuousConstruct query = context.registerConstruct(""
+ "CONSTRUCT{?x ?y ?z} WHERE {"
+ "STREAM <" + STREAM_ID + "> [NOW] {?x ?y ?z}"
+ "}");
ConstructAssertListener listener = new ConstructAssertListener(
context, STREAM_ID);
query.register(listener);
stream.stream(new Triple(
Node.createURI("http://example.org/resource/1"),
Node.createURI("http://example.org/ontology#hasValue"),
Node.createLiteral("123")));
List<Triple> graph = await().until(listener, hasSize(1));
assertEquals("http://example.org/resource/1",
graph.get(0).getSubject().getURI());
assertEquals("http://example.org/ontology#hasValue",
graph.get(0).getPredicate().getURI());
assertEquals("123", graph.get(0).getObject().getLiteralLexicalForm());
}
示例3: registerQuery
import org.deri.cqels.engine.ContinuousConstruct; //导入依赖的package包/类
@Override
public boolean registerQuery(int query_id) {
String query = db.getQuery(query_id).getString("text");
try {
if (query.toLowerCase().contains("select") || query.toLowerCase().contains("construct")) {
if (query.toLowerCase().contains("construct")) {
ContinuousConstruct cc = context.registerConstruct(query);
cc.register(new ConstructListener(context) {
@Override
public void update(List<Triple> graph) {
String message = getString(graph);
sendToWAMP(message);
//appendData(message);
}
});
queries.put(query_id, cc);
} else {
ContinuousSelect cs = context.registerSelect(query);
cs.register(new ContinuousListener() {
@Override
public void update(Mapping m) {
sendToWAMP(getString(m));
}
});
queries.put(query_id, cs);
}
}
} catch (com.hp.hpl.jena.query.QueryException e) {
logger.debug("Query \n" + query + "\n has ERROR!\n + " + e.getMessage());
return false;
}
return true;
}
示例4: registerConstruct
import org.deri.cqels.engine.ContinuousConstruct; //导入依赖的package包/类
@Override
public int registerConstruct(final String query) {
ContinuousConstruct construct = cqelsEngine.getContext()
.registerConstruct(query);
construct.register(new ConstructListener(cqelsEngine.getContext()) {
@Override
public void update(List<Triple> graph) {
Model model = ModelFactory.createDefaultModel();
graph.stream().forEach((t) -> {
Resource subject = ResourceFactory
.createResource(t.getSubject().getURI());
Property predicate = ResourceFactory
.createProperty(t.getPredicate().getURI());
RDFNode object = null;
if (t.getObject().isLiteral()) {
object = ResourceFactory.createTypedLiteral(
t.getObject().getLiteralValue());
} else {
object = ResourceFactory.createResource(
t.getObject().getURI());
}
model.add(subject, predicate, object);
});
ByteArrayOutputStream out = new ByteArrayOutputStream();
model.write(out, "TTL");
streamService.publish(STREAM_URI, out.toString());
}
});
return 0;
}
示例5: unregisterConstruct
import org.deri.cqels.engine.ContinuousConstruct; //导入依赖的package包/类
@Test
public void unregisterConstruct() throws InterruptedException {
System.out.println("simpleUnregisterConstructTest");
final String STREAM_ID = STREAM_ID_PREFIX + "_1";
RDFStream stream = new DefaultRDFStream(context, STREAM_ID);
ContinuousConstruct query = context.registerConstruct(""
+ "CONSTRUCT{?x ?y ?z} WHERE {"
+ "STREAM <" + STREAM_ID + "> [NOW] {?x ?y ?z}"
+ "}");
ConstructAssertListener listener = new ConstructAssertListener(context,
STREAM_ID);
query.register(listener);
stream.stream(new Triple(
ResourceFactory.createResource(
"http://example.org/resource/1").asNode(),
ResourceFactory.createProperty(
"http://example.org/ontology#hasValue").asNode(),
ResourceFactory.createPlainLiteral("456").asNode()));
List<Triple> triples = await().until(listener, hasSize(1));
Helpers.print(triples);
assertEquals("http://example.org/resource/1",
triples.get(0).getSubject().getURI());
assertEquals("http://example.org/ontology#hasValue",
triples.get(0).getPredicate().getURI());
assertEquals("456", triples.get(0).getObject().getLiteralLexicalForm());
context.unregisterConstruct(query);
stream.stream(new Triple(
ResourceFactory.createResource(
"http://example.org/resource/1").asNode(),
ResourceFactory.createProperty(
"http://example.org/ontology#hasValue").asNode(),
ResourceFactory.createPlainLiteral("987789").asNode()));
triples = await()
.timeout(Duration.TWO_HUNDRED_MILLISECONDS)
.until(listener, hasSize(1));
Helpers.print(triples);
assertTrue(triples.size() == 1);
}
示例6: complexUnregisterConstruct
import org.deri.cqels.engine.ContinuousConstruct; //导入依赖的package包/类
@Test
public void complexUnregisterConstruct() {
System.out.println("complexUnregisterConstructTest");
final String STREAM_ID
= "amqp://192.168.134.114?exchangeName=meter_exchange&routingKey=meter.location.mercury230_14759537";
DefaultRDFStream stream = new DefaultRDFStream(context, STREAM_ID);
context.loadDefaultDataset(
"src/test/resources/org/deri/cqels/QueryTest/complexConstruct/dataset.ttl");
ContinuousConstruct query = context.registerConstruct(
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ "PREFIX em: <http://purl.org/NET/ssnext/electricmeters#> \n"
+ "PREFIX pne: <http://data.press.net/ontology/event/> \n"
+ "PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#> \n"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n"
+ "PREFIX dul: <http://www.loa-cnr.it/ontologies/DUL.owl#> \n"
+ "CONSTRUCT {\n"
+ " ?alert a <http://purl.org/daafse/alerts#TooHighVoltageValue> ;\n"
+ " dul:hasEventDate ?time ;\n"
+ " dul:involvesAgent ?meter .\n"
+ "}\n"
+ "WHERE {\n"
+ " ?meter em:hasStream ?stream .\n"
+ " STREAM ?stream [NOW] {\n"
+ " ?observation a em:PolyphaseVoltageObservation ;\n"
+ " ssn:observationResultTime ?time ;\n"
+ " ssn:observationResult ?output ."
+ " ?output a em:PolyphaseVoltageSensorOutput ;\n"
+ " ssn:isProducedBy ?meter ;\n"
+ " ssn:hasValue ?value .\n"
+ " ?value em:hasQuantityValue ?qvalue .\n"
+ " }\n"
+ " FILTER(?qvalue > 220)\n"
+ " BIND(IRI(CONCAT(STR(?meter), '/alerts/', STR(?time))) AS ?alert)\n"
+ "}");
ConstructAssertListener listener = new ConstructAssertListener(
context, STREAM_ID);
query.register(listener);
Model model = ModelFactory.createDefaultModel();
InputStream input = this.getClass().getResourceAsStream(
"QueryTest/complexConstruct/observation.ttl");
model.read(input, null, "TURTLE");
stream.stream(model);
List<Triple> graph = await().until(listener, hasSize(3));
assertTrue(graph.contains(new Triple(
Node.createURI("http://purl.org/meters/mercury230_14759537/alerts/2014-07-16T05:50:20.890Z"),
Node.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
Node.createURI("http://purl.org/daafse/alerts#TooHighVoltageValue"))));
assertTrue(graph.contains(new Triple(
Node.createURI("http://purl.org/meters/mercury230_14759537/alerts/2014-07-16T05:50:20.890Z"),
Node.createURI("http://www.loa-cnr.it/ontologies/DUL.owl#hasEventDate"),
Node.createLiteral("2014-07-16T05:50:20.890Z", XSDDatatype.XSDdateTime))));
assertTrue(graph.contains(new Triple(
Node.createURI("http://purl.org/meters/mercury230_14759537/alerts/2014-07-16T05:50:20.890Z"),
Node.createURI("http://www.loa-cnr.it/ontologies/DUL.owl#involvesAgent"),
Node.createURI("http://purl.org/meters/mercury230_14759537"))));
context.unregisterConstruct(query);
stream.stream(model);
graph = await().timeout(Duration.TWO_HUNDRED_MILLISECONDS).until(listener, hasSize(3));
assertTrue(graph.size()==3);
}
示例7: complexConstruct
import org.deri.cqels.engine.ContinuousConstruct; //导入依赖的package包/类
@Test(timeout = 10000)
public void complexConstruct() {
final String STREAM_ID
= "amqp://192.168.134.114?exchangeName=meter_exchange&routingKey=meter.location.mercury230_14759537";
DefaultRDFStream stream = new DefaultRDFStream(context, STREAM_ID);
context.loadDefaultDataset(
"src/test/resources/org/deri/cqels/QueryTest/complexConstruct/dataset.ttl");
ContinuousConstruct query = context.registerConstruct(
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ "PREFIX em: <http://purl.org/NET/ssnext/electricmeters#> \n"
+ "PREFIX pne: <http://data.press.net/ontology/event/> \n"
+ "PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#> \n"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n"
+ "PREFIX dul: <http://www.loa-cnr.it/ontologies/DUL.owl#> \n"
+ "CONSTRUCT {\n"
+ " ?alert a <http://purl.org/daafse/alerts#TooHighVoltageValue> ;\n"
+ " dul:hasEventDate ?time ;\n"
+ " dul:involvesAgent ?meter .\n"
+ "}\n"
+ "WHERE {\n"
+ " ?meter em:hasStream ?stream .\n"
+ " STREAM ?stream [NOW] {\n"
+ " ?observation a em:PolyphaseVoltageObservation ;\n"
+ " ssn:observationResultTime ?time ;\n"
+ " ssn:observationResult ?output ."
+ " ?output a em:PolyphaseVoltageSensorOutput ;\n"
+ " ssn:isProducedBy ?meter ;\n"
+ " ssn:hasValue ?value .\n"
+ " ?value em:hasQuantityValue ?qvalue .\n"
+ " }\n"
+ " FILTER(?qvalue > 220)\n"
+ " BIND(IRI(CONCAT(STR(?meter), '/alerts/', STR(?time))) AS ?alert)\n"
+ "}");
ConstructAssertListener listener = new ConstructAssertListener(
context, STREAM_ID);
query.register(listener);
Model model = ModelFactory.createDefaultModel();
InputStream input = this.getClass().getResourceAsStream(
"QueryTest/complexConstruct/observation.ttl");
model.read(input, null, "TURTLE");
stream.stream(model);
List<Triple> graph = await().until(listener, hasSize(3));
System.out.println(Arrays.toString(graph.toArray()));
assertTrue(graph.contains(new Triple(
Node.createURI("http://purl.org/meters/mercury230_14759537/alerts/2014-07-16T05:50:20.890Z"),
Node.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
Node.createURI("http://purl.org/daafse/alerts#TooHighVoltageValue"))));
assertTrue(graph.contains(new Triple(
Node.createURI("http://purl.org/meters/mercury230_14759537/alerts/2014-07-16T05:50:20.890Z"),
Node.createURI("http://www.loa-cnr.it/ontologies/DUL.owl#hasEventDate"),
Node.createLiteral("2014-07-16T05:50:20.890Z", XSDDatatype.XSDdateTime))));
assertTrue(graph.contains(new Triple(
Node.createURI("http://purl.org/meters/mercury230_14759537/alerts/2014-07-16T05:50:20.890Z"),
Node.createURI("http://www.loa-cnr.it/ontologies/DUL.owl#involvesAgent"),
Node.createURI("http://purl.org/meters/mercury230_14759537"))));
}