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;
}
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);
}
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()));
}
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()));
}
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();
}
}
Aggregations