Search in sources :

Example 21 with StatementMetadata

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);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Test(org.junit.Test)

Example 22 with StatementMetadata

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Resource(org.openrdf.model.Resource) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) SailException(org.openrdf.sail.SailException)

Example 23 with StatementMetadata

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);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) StatementPattern(org.openrdf.query.algebra.StatementPattern) RyaURI(org.apache.rya.api.domain.RyaURI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Test(org.junit.Test)

Example 24 with StatementMetadata

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);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) StatementPattern(org.openrdf.query.algebra.StatementPattern) RyaURI(org.apache.rya.api.domain.RyaURI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with StatementMetadata

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;
}
Also used : StatementMetadata(org.apache.rya.api.domain.StatementMetadata) Rule(org.apache.rya.forwardchain.rule.Rule) RyaType(org.apache.rya.api.domain.RyaType)

Aggregations

StatementMetadata (org.apache.rya.api.domain.StatementMetadata)37 RyaStatement (org.apache.rya.api.domain.RyaStatement)36 RyaURI (org.apache.rya.api.domain.RyaURI)35 RyaType (org.apache.rya.api.domain.RyaType)34 Test (org.junit.Test)30 BindingSet (org.openrdf.query.BindingSet)28 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)28 ArrayList (java.util.ArrayList)25 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)20 StatementPattern (org.openrdf.query.algebra.StatementPattern)20 ParsedQuery (org.openrdf.query.parser.ParsedQuery)20 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)20 LiteralImpl (org.openrdf.model.impl.LiteralImpl)17 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)15 URIImpl (org.openrdf.model.impl.URIImpl)11 MongoDBRyaDAO (org.apache.rya.mongodb.MongoDBRyaDAO)10 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)8 TupleQueryResult (org.openrdf.query.TupleQueryResult)8 HashSet (java.util.HashSet)7 MongoDBRdfConfiguration (org.apache.rya.mongodb.MongoDBRdfConfiguration)5