Search in sources :

Example 1 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(WikibaseUris uris, String id) {
    Literal version = new LiteralImpl("a revision number I promise");
    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("a date I promise"));
    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 2 with LiteralImpl

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

the class StatementHelper method randomDate.

/**
 * Construct a random date literal.
 */
public static LiteralImpl randomDate() {
    StringBuilder sb = new StringBuilder();
    Formatter formatter = new Formatter(sb, Locale.US);
    formatter.format("%04d-%02d-%02d", randomIntBetween(1, 9999), randomIntBetween(1, 12), randomIntBetween(1, 28));
    formatter.close();
    return new LiteralImpl(sb.toString(), XMLSchema.DATE);
}
Also used : IntegerLiteralImpl(org.openrdf.model.impl.IntegerLiteralImpl) LiteralImpl(org.openrdf.model.impl.LiteralImpl) Formatter(java.util.Formatter)

Example 3 with LiteralImpl

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

the class RdfRepositoryIntegrationTest method referenceWithExpandedValueChanged.

@Test
public void referenceWithExpandedValueChanged() throws QueryEvaluationException {
    referenceWithExpandedValue();
    String statementUri = uris.statement() + "someotheruuid";
    String referenceUri = uris.reference() + "andanotheruri";
    String valueUri = uris.value() + "someuuid2";
    cleanupList.add(valueUri);
    cleanupList.add(referenceUri);
    List<Statement> george = new ArrayList<>();
    statement(george, "Q23", "P509", statementUri);
    statement(george, statementUri, Provenance.WAS_DERIVED_FROM, referenceUri);
    statement(george, referenceUri, uris.property(PropertyType.REFERENCE_VALUE) + "P509", valueUri);
    statement(george, valueUri, Ontology.Time.VALUE, new LiteralImpl("dog"));
    statement(george, valueUri, Ontology.Time.CALENDAR_MODEL, new LiteralImpl("animals"));
    rdfRepository.sync("Q23", george, cleanupList);
    assertTrue(rdfRepository.ask(Provenance.prefix(Ontology.prefix(uris.prefixes(new StringBuilder()))).append("ASK { wd:Q23 p:P509 [ prov:wasDerivedFrom [ prv:P509 [ ontology:timeValue \"dog\" ] ] ] }").toString()));
    assertTrue(rdfRepository.ask(Provenance.prefix(Ontology.prefix(uris.prefixes(new StringBuilder()))).append("ASK { wd:Q23 p:P509 [ prov:wasDerivedFrom [ prv:P509 [ ontology:timeCalendarModel \"animals\" ] ] ] }").toString()));
    assertFalse(rdfRepository.ask(Provenance.prefix(Ontology.prefix(uris.prefixes(new StringBuilder()))).append("ASK { wd:Q23 p:P509 [ prov:wasDerivedFrom [ prv:P509 [ ontology:timeTime \"cat\" ] ] ] }").toString()));
    // We've unlinked enwiki
    assertFalse(rdfRepository.ask(Provenance.prefix(Ontology.prefix(uris.prefixes(new StringBuilder()))).append("ASK { wd:Q23 p:P509 [ prov:wasDerivedFrom [ pr:P143 [ p:P509 wd:Q328 ] ] ] }").toString()));
    assertTrue(rdfRepository.ask(Provenance.prefix(uris.prefixes(new StringBuilder())).append("ASK { wd:Q328 p:P509 wd:Q328 }").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 4 with LiteralImpl

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

the class RdfRepositoryIntegrationTest method expandedStatementWithExpandedValueChanged.

@Test
public void expandedStatementWithExpandedValueChanged() throws QueryEvaluationException {
    expandedStatementWithExpandedValue();
    String statementUri = uris.statement() + "someotheruuid";
    String valueUri = uris.value() + "newuuid";
    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("dog"));
    statement(george, valueUri, Ontology.Time.CALENDAR_MODEL, new LiteralImpl("animals"));
    Collection<String> cleanupList = new ArrayList<String>();
    cleanupList.add(valueUri);
    cleanupList.add(uris.value() + "someuuid");
    rdfRepository.sync("Q23", george);
    assertTrue(rdfRepository.ask(Ontology.prefix(uris.prefixes(new StringBuilder())).append("ASK { wd:Q23 p:P509 [ psv:P509 [ ontology:timeValue \"dog\" ] ] }").toString()));
    assertTrue(rdfRepository.ask(Ontology.prefix(uris.prefixes(new StringBuilder())).append("ASK { wd:Q23 p:P509 [ psv:P509 [ ontology:timeCalendarModel \"animals\" ] ] }").toString()));
    assertFalse(rdfRepository.ask(Ontology.prefix(uris.prefixes(new StringBuilder())).append("ASK { wd:Q23 p:P509 [ psv:P509 [ ontology:timeValue \"cat\" ] ] }").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 5 with LiteralImpl

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

the class MongoPcjIntegrationTest method testEvaluateTwoIndexValidate.

@Test
public void testEvaluateTwoIndexValidate() throws Exception {
    final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
    final MongoDBRdfConfiguration pcjConf = conf.clone();
    pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
    final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
    final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
    final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
    addPCJS(pcjConn);
    try {
        final URI superclass = new URIImpl("uri:superclass");
        final URI superclass2 = new URIImpl("uri:superclass2");
        conn.add(subclass, RDF.TYPE, superclass);
        conn.add(subclass2, RDF.TYPE, superclass2);
        conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
        conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
        final String indexSparqlString = // 
        "" + // 
        "SELECT ?dog ?pig ?duck  " + // 
        "{" + // 
        "  ?pig a ?dog . " + // 
        "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
        "}";
        final String indexSparqlString2 = // 
        "" + // 
        "SELECT ?o ?f ?e ?c ?l  " + // 
        "{" + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "}";
        final String queryString = // 
        "" + // 
        "SELECT ?e ?c ?l ?f ?o " + // 
        "{" + // 
        "  ?e a ?c . " + // 
        "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "}";
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        final MongoPcjQueryNode ais1 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 1);
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 2, conf.getRyaInstanceName(), indexSparqlString2);
        final MongoPcjQueryNode ais2 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 2);
        final List<ExternalTupleSet> index = new ArrayList<>();
        index.add(ais1);
        index.add(ais2);
        ParsedQuery pq = null;
        final SPARQLParser sp = new SPARQLParser();
        pq = sp.parseQuery(queryString, null);
        final List<TupleExpr> teList = Lists.newArrayList();
        final TupleExpr te = pq.getTupleExpr();
        final PCJOptimizer pcj = new PCJOptimizer(index, false, new MongoPcjIndexSetProvider(new StatefulMongoDBRdfConfiguration(conf, getMongoClient())));
        pcj.optimize(te, null, null);
        teList.add(te);
        final IndexPlanValidator ipv = new IndexPlanValidator(false);
        assertTrue(ipv.isValid(te));
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoPcjQueryNode(org.apache.rya.indexing.mongodb.pcj.MongoPcjQueryNode) SailRepository(org.openrdf.repository.sail.SailRepository) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) IndexPlanValidator(org.apache.rya.indexing.IndexPlanValidator.IndexPlanValidator) URIImpl(org.openrdf.model.impl.URIImpl) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) URI(org.openrdf.model.URI) TupleExpr(org.openrdf.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Sail(org.openrdf.sail.Sail) MongoPcjIndexSetProvider(org.apache.rya.indexing.mongodb.pcj.MongoPcjIndexSetProvider) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) 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