Search in sources :

Example 81 with URIImpl

use of org.openrdf.model.impl.URIImpl 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 82 with URIImpl

use of org.openrdf.model.impl.URIImpl 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 83 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class RdfFileInputFormatTest method testStatementInput.

@Test
public void testStatementInput() throws Exception {
    RdfFileInputFormat.setRDFFormat(job, RDFFormat.NTRIPLES);
    init(NT_INPUT);
    String prefix = "urn:lubm:rdfts#";
    URI[] gs = { new URIImpl(prefix + "GraduateStudent01"), new URIImpl(prefix + "GraduateStudent02"), new URIImpl(prefix + "GraduateStudent03"), new URIImpl(prefix + "GraduateStudent04") };
    URI hasFriend = new URIImpl(prefix + "hasFriend");
    Statement[] statements = { new StatementImpl(gs[0], hasFriend, gs[1]), new StatementImpl(gs[1], hasFriend, gs[2]), new StatementImpl(gs[2], hasFriend, gs[3]) };
    int count = 0;
    while (reader.nextKeyValue()) {
        Assert.assertEquals(statements[count], RyaToRdfConversions.convertStatement(reader.getCurrentValue().getRyaStatement()));
        count++;
        Assert.assertEquals(count, reader.getCurrentKey().get());
    }
    Assert.assertEquals(3, count);
}
Also used : Statement(org.openrdf.model.Statement) StatementImpl(org.openrdf.model.impl.StatementImpl) ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 84 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class FluoStringConverterTest method stringToStatementPattern.

@Test
public void stringToStatementPattern() {
    // Setup the String representation of a statement pattern.
    final String patternString = "x:::" + "-const-http://worksAt<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" + "-const-http://Chipotle<<~>>http://www.w3.org/2001/XMLSchema#anyURI";
    // Convert it to a StatementPattern.
    final StatementPattern statementPattern = FluoStringConverter.toStatementPattern(patternString);
    // Enusre it converted to the expected result.
    final Var subject = new Var("x");
    final Var predicate = new Var("-const-http://worksAt", new URIImpl("http://worksAt"));
    predicate.setConstant(true);
    final Var object = new Var("-const-http://Chipotle", new URIImpl("http://Chipotle"));
    object.setConstant(true);
    final StatementPattern expected = new StatementPattern(subject, predicate, object);
    assertEquals(expected, statementPattern);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) URIImpl(org.openrdf.model.impl.URIImpl) Test(org.junit.Test)

Example 85 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class FluoStringConverterTest method toVar_uri.

@Test
public void toVar_uri() {
    // Setup the string representation of the variable.
    final String varString = "-const-http://Chipotle<<~>>http://www.w3.org/2001/XMLSchema#anyURI";
    // Convert it to a Var object.
    final Var var = FluoStringConverter.toVar(varString);
    // Ensure it converted to the expected result.
    final Var expected = new Var("-const-http://Chipotle", new URIImpl("http://Chipotle"));
    expected.setConstant(true);
    assertEquals(expected, var);
}
Also used : Var(org.openrdf.query.algebra.Var) URIImpl(org.openrdf.model.impl.URIImpl) Test(org.junit.Test)

Aggregations

URIImpl (org.openrdf.model.impl.URIImpl)170 Test (org.junit.Test)120 LiteralImpl (org.openrdf.model.impl.LiteralImpl)62 URI (org.openrdf.model.URI)58 BindingSet (org.openrdf.query.BindingSet)50 MapBindingSet (org.openrdf.query.impl.MapBindingSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)33 HashSet (java.util.HashSet)31 Statement (org.openrdf.model.Statement)30 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)30 ArrayList (java.util.ArrayList)29 RyaType (org.apache.rya.api.domain.RyaType)25 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)24 RyaStatement (org.apache.rya.api.domain.RyaStatement)23 Value (org.openrdf.model.Value)22 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)22 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)21 StatementPattern (org.openrdf.query.algebra.StatementPattern)20 StatementImpl (org.openrdf.model.impl.StatementImpl)19 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)16