use of org.apache.rya.api.domain.StatementMetadata in project incubator-rya by apache.
the class AccumuloRyaDAOTest method testAddCv.
@Test
public void testAddCv() throws Exception {
RyaURI cpu = new RyaURI(litdupsNS + "cpu");
RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
RyaURI uri1 = new RyaURI(litdupsNS + "uri1");
RyaURI uri2 = new RyaURI(litdupsNS + "uri2");
RyaURI uri3 = new RyaURI(litdupsNS + "uri3");
byte[] colVisABC = "A|B|C".getBytes();
byte[] colVisAB = "A|B".getBytes();
byte[] colVisA = "A".getBytes();
dao.add(new RyaStatement(cpu, loadPerc, uri1, null, null, new StatementMetadata(), colVisABC));
dao.add(new RyaStatement(cpu, loadPerc, uri2, null, null, new StatementMetadata(), colVisAB));
dao.add(new RyaStatement(cpu, loadPerc, uri3, null, null, new StatementMetadata(), colVisA));
AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
// query with no auth
CloseableIteration<RyaStatement, RyaDAOException> iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), conf);
int count = 0;
while (iter.hasNext()) {
count++;
iter.next();
}
assertEquals(0, count);
iter.close();
AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration();
queryConf.setAuth("B");
iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), queryConf);
count = 0;
while (iter.hasNext()) {
iter.next();
count++;
}
iter.close();
assertEquals(2, count);
queryConf.setAuth("A");
iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), queryConf);
count = 0;
while (iter.hasNext()) {
iter.next();
count++;
}
iter.close();
assertEquals(3, count);
}
use of org.apache.rya.api.domain.StatementMetadata in project incubator-rya by apache.
the class RdfCloudTripleStoreConnection method addStatementInternal.
@Override
protected void addStatementInternal(final Resource subject, final URI predicate, final Value object, final Resource... contexts) throws SailException {
try {
final String cv_s = conf.getCv();
final byte[] cv = cv_s == null ? null : cv_s.getBytes(StandardCharsets.UTF_8);
final List<RyaStatement> ryaStatements = new ArrayList<>();
if (contexts != null && contexts.length > 0) {
for (final Resource context : contexts) {
final RyaStatement statement = new RyaStatement(RdfToRyaConversions.convertResource(subject), RdfToRyaConversions.convertURI(predicate), RdfToRyaConversions.convertValue(object), RdfToRyaConversions.convertResource(context), null, new StatementMetadata(), cv);
ryaStatements.add(statement);
}
} else {
final RyaStatement statement = new RyaStatement(RdfToRyaConversions.convertResource(subject), RdfToRyaConversions.convertURI(predicate), RdfToRyaConversions.convertValue(object), null, null, new StatementMetadata(), cv);
ryaStatements.add(statement);
}
ryaDAO.add(ryaStatements.iterator());
} catch (final RyaDAOException e) {
throw new SailException(e);
}
}
use of org.apache.rya.api.domain.StatementMetadata in project incubator-rya by apache.
the class StatementPatternEvalTest method simpleQueryWithBindingSetConstantContext.
@Test
public void simpleQueryWithBindingSetConstantContext() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
// query is used to build statement that will be evaluated
String query = "select ?x ?c where{ graph <uri:context1> {?x <uri:talksTo> <uri:Bob>. }}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
dao.add(statement1);
RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
dao.add(statement2);
RyaStatement statement3 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context2"), "", new StatementMetadata());
dao.add(statement3);
QueryBindingSet bsConstraint1 = new QueryBindingSet();
bsConstraint1.addBinding("x", new URIImpl("uri:Doug"));
CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("x", new URIImpl("uri:Doug"));
Assert.assertEquals(expected, bsList.get(0));
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
use of org.apache.rya.api.domain.StatementMetadata in project incubator-rya by apache.
the class StatementPatternEvalTest method simpleQueryWithBindingSets.
@Test
public void simpleQueryWithBindingSets() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
// query is used to build statement that will be evaluated
String query = "select ?x ?c where{ graph ?c {?x <uri:talksTo> <uri:Bob>. }}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
dao.add(statement1);
RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context2"), "", new StatementMetadata());
dao.add(statement2);
RyaStatement statement3 = new RyaStatement(new RyaURI("uri:Eric"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context3"), "", new StatementMetadata());
dao.add(statement3);
QueryBindingSet bsConstraint1 = new QueryBindingSet();
bsConstraint1.addBinding("c", new URIImpl("uri:context2"));
QueryBindingSet bsConstraint2 = new QueryBindingSet();
bsConstraint2.addBinding("c", new URIImpl("uri:context1"));
CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1, bsConstraint2));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(2, bsList.size());
QueryBindingSet expected1 = new QueryBindingSet();
expected1.addBinding("x", new URIImpl("uri:Joe"));
expected1.addBinding("c", new URIImpl("uri:context1"));
QueryBindingSet expected2 = new QueryBindingSet();
expected2.addBinding("x", new URIImpl("uri:Doug"));
expected2.addBinding("c", new URIImpl("uri:context2"));
Set<BindingSet> expected = new HashSet<>(Arrays.asList(expected1, expected2));
Set<BindingSet> actual = new HashSet<>(bsList);
Assert.assertEquals(expected, actual);
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
use of org.apache.rya.api.domain.StatementMetadata in project incubator-rya by apache.
the class RoundRobinStrategy method executeNext.
@Override
public long executeNext() throws ForwardChainException {
if (!initialized.get()) {
return 0;
}
Rule rule = getNextRule();
if (rule == null) {
return 0;
}
StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(ForwardChainConstants.RYA_DERIVATION_TIME, new RyaType(XMLSchema.INT, Integer.toString(iteration)));
long inferences = rule.execute(ruleStrategy, metadata);
inferencesThisIteration += inferences;
if (inferences > 0) {
for (Rule successor : ruleset.getSuccessorsOf(rule)) {
// it may not need to be checked in the next one.
if (!activeNow.contains(successor)) {
activeNextIteration.add(successor);
}
}
}
prepareQueue();
return inferences;
}
Aggregations