Search in sources :

Example 81 with LiteralImpl

use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.

the class StatementHelper method randomStatementsAbout.

/**
 * Construct a bunch of random statements about the given subject.
 */
public static List<Statement> randomStatementsAbout(String s, int count) {
    List<Statement> statements = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        String p = "P" + randomInt();
        LiteralImpl o = randomDate();
        statements.add(statement(s, p, o));
    }
    return statements;
}
Also used : IntegerLiteralImpl(org.openrdf.model.impl.IntegerLiteralImpl) LiteralImpl(org.openrdf.model.impl.LiteralImpl) Statement(org.openrdf.model.Statement) ArrayList(java.util.ArrayList)

Example 82 with LiteralImpl

use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.

the class RdfRepositoryIntegrationTest method expandedStatementWithExpandedValue.

@Test
public void expandedStatementWithExpandedValue() throws QueryEvaluationException {
    String statementUri = uris.statement() + "someotheruuid";
    String valueUri = uris.value() + "someuuid";
    cleanupList.add(valueUri);
    List<Statement> george = new ArrayList<>();
    statement(george, "Q23", "P509", statementUri);
    statement(george, statementUri, uris.property(PropertyType.STATEMENT_VALUE) + "P509", valueUri);
    statement(george, valueUri, Ontology.Time.VALUE, new LiteralImpl("cat"));
    statement(george, valueUri, Ontology.Time.CALENDAR_MODEL, new LiteralImpl("animals"));
    rdfRepository.sync("Q23", george);
    assertTrue(rdfRepository.ask(Ontology.prefix(uris.prefixes(new StringBuilder())).append("ASK { wd:Q23 p:P509 [ psv:P509 [ ontology:timeValue \"cat\" ] ] }").toString()));
    assertTrue(rdfRepository.ask(Ontology.prefix(uris.prefixes(new StringBuilder())).append("ASK { wd:Q23 p:P509 [ psv:P509 [ ontology:timeCalendarModel \"animals\" ] ] }").toString()));
}
Also used : IntegerLiteralImpl(org.openrdf.model.impl.IntegerLiteralImpl) LiteralImpl(org.openrdf.model.impl.LiteralImpl) Statement(org.openrdf.model.Statement) ArrayList(java.util.ArrayList) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 83 with LiteralImpl

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

the class FluoStringConverter method toVar.

/**
 * Converts the String representation of a {@link Var} back into the object version.
 *
 * @param varString - The {@link Var} represented as a String. (not null)
 * @return A {@link Var} built from the string.
 */
public static Var toVar(final String varString) {
    checkNotNull(varString);
    final String[] varParts = varString.split(TYPE_DELIM);
    final String name = varParts[0];
    // The variable is a constant value.
    if (varParts.length > 1) {
        final String dataTypeString = varParts[1];
        if (dataTypeString.equals(URI_TYPE)) {
            // Handle a URI object.
            Preconditions.checkArgument(varParts.length == 2);
            final String valueString = name.substring("-const-".length());
            final Var var = new Var(name, new URIImpl(valueString));
            var.setConstant(true);
            return var;
        } else if (dataTypeString.equals(RyaSchema.BNODE_NAMESPACE)) {
            // Handle a BNode object
            Preconditions.checkArgument(varParts.length == 3);
            Var var = new Var(name);
            var.setValue(new BNodeImpl(varParts[2]));
            return var;
        } else {
            // Handle a Literal Value.
            Preconditions.checkArgument(varParts.length == 2);
            final String valueString = name.substring("-const-".length());
            final URI dataType = new URIImpl(dataTypeString);
            final Literal value = new LiteralImpl(valueString, dataType);
            final Var var = new Var(name, value);
            var.setConstant(true);
            return var;
        }
    } else {
        // The variable is a named variable.
        return new Var(varString);
    }
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) Var(org.openrdf.query.algebra.Var) Literal(org.openrdf.model.Literal) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) BNodeImpl(org.openrdf.model.impl.BNodeImpl)

Example 84 with LiteralImpl

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

the class FluoStringConverterTest method toVar_int.

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

Example 85 with LiteralImpl

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

the class FluoStringConverterTest method toVar_string.

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

Aggregations

LiteralImpl (org.openrdf.model.impl.LiteralImpl)155 Test (org.junit.Test)124 URIImpl (org.openrdf.model.impl.URIImpl)62 BindingSet (org.openrdf.query.BindingSet)58 Statement (org.openrdf.model.Statement)40 ArrayList (java.util.ArrayList)34 TupleQueryResult (org.openrdf.query.TupleQueryResult)34 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)33 URI (org.openrdf.model.URI)29 IntegerLiteralImpl (org.openrdf.model.impl.IntegerLiteralImpl)23 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)22 HashSet (java.util.HashSet)21 RyaStatement (org.apache.rya.api.domain.RyaStatement)19 RyaType (org.apache.rya.api.domain.RyaType)19 RyaURI (org.apache.rya.api.domain.RyaURI)19 ParsedQuery (org.openrdf.query.parser.ParsedQuery)19 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)19 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)17 StatementImpl (org.openrdf.model.impl.StatementImpl)16 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)15