Search in sources :

Example 51 with LiteralImpl

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

the class StatementHelper method basicEntity.

/**
 * Construct statements about a basic entity.
 */
public static List<Statement> basicEntity(UrisScheme uris, String id, String versionString, String dateString) {
    Literal version = new LiteralImpl(versionString);
    List<Statement> statements = new ArrayList<>();
    String entityDataUri = uris.entityData() + id;
    // EntityData is all munged onto Entity
    statement(statements, entityDataUri, SchemaDotOrg.ABOUT, id);
    statement(statements, entityDataUri, SchemaDotOrg.VERSION, version);
    statement(statements, entityDataUri, SchemaDotOrg.DATE_MODIFIED, new LiteralImpl(dateString));
    return statements;
}
Also used : IntegerLiteralImpl(org.openrdf.model.impl.IntegerLiteralImpl) LiteralImpl(org.openrdf.model.impl.LiteralImpl) Statement(org.openrdf.model.Statement) Literal(org.openrdf.model.Literal) ArrayList(java.util.ArrayList)

Example 52 with LiteralImpl

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

the class MWApiServiceQueryUnitTest method mwAPI_T168876.

// @Test // disabled test, need to be discussed it it is safe to run in in CI
public void mwAPI_T168876() {
    // MWAPI service throws “could not find binding for parameter” if optimizer is not disabled
    // https://phabricator.wikimedia.org/T168876
    StringBuilder query = uris().prefixes(Ontology.prefix(new StringBuilder()));
    add("wd:Q168876", "wdt:P18", new LiteralImpl("http://commons.wikimedia.org/wiki/Special:FilePath/U8%20Berlin%20Leinestrasse%2012-2017.jpg"));
    query.append("SELECT * WHERE {\n" + "  BIND(wd:Q168876 as ?leinestr) # random item with picture\n" + "  ?leinestr wdt:P18 ?picture.\n" + "\n" + "  BIND(STRAFTER(str(?picture), \"Special:FilePath/\") AS ?filename)\n" + "  BIND(ontology:decodeUri(CONCAT(\"File:\", ?filename)) AS ?file)\n" + "\n" + "  SERVICE ontology:mwapi {\n" + "    bd:serviceParam ontology:api \"Categories\".\n" + "    bd:serviceParam ontology:endpoint \"commons.wikipedia.org\".\n" + "    bd:serviceParam mwapi:titles ?file. # throws IllegalArgumentException: Could not find binding for parameter titles\n" + "    ?cat ontology:apiOutput mwapi:category.\n" + "  }\n" + "}");
    assertQueryResult(query.toString(), binds("cat", Literal.class), binds("cat", Literal.class), binds("cat", Literal.class), binds("cat", Literal.class), binds("cat", Literal.class), binds("cat", Literal.class), binds("cat", Literal.class), binds("cat", Literal.class), binds("cat", Literal.class), binds("cat", Literal.class));
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) Literal(org.openrdf.model.Literal)

Example 53 with LiteralImpl

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

the class LabelServiceUnitTest method addSimpleLabels.

private void addSimpleLabels(String entity) {
    for (String language : new String[] { "en", "de", "ru" }) {
        add("wd:" + entity, RDFS.LABEL, new LiteralImpl("in " + language, language));
    }
    add("wd:" + entity, SKOS.ALT_LABEL, new LiteralImpl("alt label in en", "en"));
    add("wd:" + entity, SKOS.ALT_LABEL, new LiteralImpl("alt label in en2", "en"));
    add("wd:" + entity, SKOS.ALT_LABEL, new LiteralImpl("alt label in de", "de"));
    for (String language : new String[] { "en", "de", "ru" }) {
        add("wd:" + entity, SchemaDotOrg.DESCRIPTION, new LiteralImpl("description in " + language, language));
    }
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 54 with LiteralImpl

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

the class LabelServiceUnitTest method many.

@Test
public void many() throws QueryEvaluationException {
    for (int i = 1; i <= 10; i++) {
        addSimpleLabels("Q" + i);
        add("ontology:dummy", "ontology:dummy", "wd:Q" + i);
    }
    TupleQueryResult result = lookupLabel("ontology:dummy ontology:dummy ?o", "en", "?o", "rdfs:label");
    for (int i = 1; i <= 10; i++) {
        assertTrue(result.hasNext());
        assertThat(result.next(), binds("oLabel", new LiteralImpl("in en", "en")));
    }
    assertFalse(result.hasNext());
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) TupleQueryResult(org.openrdf.query.TupleQueryResult) Test(org.junit.Test)

Example 55 with LiteralImpl

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

the class WikibaseVocabularyUnitTest method entityPAndQAreBytes.

/**
 * Make sure the "P" and "Q" suffixed versions of entity are a byte because
 * if they aren't then inline uris are more bloated.
 */
@Test
public void entityPAndQAreBytes() {
    BigdataStatement statement = roundTrip(uris().entityIdToURI("P"), uris().entityIdToURI("Q"), new LiteralImpl("cat"));
    assertThat(statement.getSubject().getIV(), instanceOf(VocabURIByteIV.class));
    assertThat(statement.getPredicate().getIV(), instanceOf(VocabURIByteIV.class));
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) BigdataStatement(com.bigdata.rdf.model.BigdataStatement) VocabURIByteIV(com.bigdata.rdf.internal.impl.uri.VocabURIByteIV) 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