use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class RdfRepositoryIntegrationTest method formWithStatement.
private void formWithStatement(List<Statement> statements, String formId, String repr, String statementUri, String propertyId, String value) {
statement(statements, formId, Ontolex.REPRESENTATION, new LiteralImpl(repr));
statements.addAll(expandedStatement(statementUri, formId, propertyId, new LiteralImpl(value), Ontology.NORMAL_RANK));
}
use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class RdfRepositoryIntegrationTest method repeatedSiteLinksArentModified.
/**
* Updating items with lots of sitelinks shouldn't be painfully slow.
*/
@Test
public void repeatedSiteLinksArentModified() throws QueryEvaluationException {
/*
* Note that this used to verify that noop updates for site links was
* fast and now it just verifies that they don't cause any reported
* modifications. Its not as strong an assertion but its less dependent
* on external conditions.
*/
List<Statement> statements = new ArrayList<>();
for (int i = 0; i < 10; i++) {
String link = String.format(Locale.ROOT, "http://%s.example.com/wiki/tbl", i);
statements.add(statement(link, RDF.TYPE, SchemaDotOrg.ARTICLE));
statements.add(statement(link, SchemaDotOrg.IN_LANGUAGE, new LiteralImpl(Integer.toString(i))));
statements.add(statement(link, SchemaDotOrg.ABOUT, "Q80"));
}
rdfRepository.sync("Q80", statements);
assertEquals(0, rdfRepository.sync("Q80", statements));
TupleQueryResult r = rdfRepository.query("PREFIX wd: <http://www.wikidata.org/entity/>\nSELECT (COUNT(?s) as ?sc) WHERE {?s ?p wd:Q80}");
assertTrue(r.hasNext());
assertThat(r.next(), binds("sc", new IntegerLiteralImpl(BigInteger.valueOf(10))));
assertFalse(r.hasNext());
}
use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class RdfRepositoryIntegrationTest method lexemeUpdate.
/**
* Test lexemes updating & cleanup of old values.
*/
@Test
public void lexemeUpdate() throws QueryEvaluationException {
String statementUri = uris.statement() + randomizer.randomAsciiOfLength(10);
String statementUri2 = uris.statement() + randomizer.randomAsciiOfLength(10);
String statementUri3 = uris.statement() + randomizer.randomAsciiOfLength(10);
String statementUri4 = uris.statement() + randomizer.randomAsciiOfLength(10);
String statementUri5 = uris.statement() + randomizer.randomAsciiOfLength(10);
List<Statement> olddata = new StatementBuilder("L123").withPredicateObject(Ontology.Lexeme.LEMMA, new LiteralImpl("testlemma")).withPredicateObject(Ontolex.LEXICAL_FORM, "L123-F1").withPredicateObject(Ontolex.LEXICAL_FORM, "L123-F2").withPredicateObject(Ontolex.SENSE_PREDICATE, "L123-S1").build();
formWithStatement(olddata, "L123-F1", "form1test", statementUri, "P12", "formvalue");
formWithStatement(olddata, "L123-F2", "form2test", statementUri2, "P23", "formvalue2");
senseWithStatement(olddata, "L123-S1", "sensetest", statementUri3, "P12", "sensevalue");
rdfRepository.sync("L123", olddata);
List<Statement> newdata = new StatementBuilder("L123").withPredicateObject(Ontology.Lexeme.LEMMA, new LiteralImpl("test2lemma")).withPredicateObject(Ontolex.LEXICAL_FORM, "L123-F1").withPredicateObject(Ontolex.SENSE_PREDICATE, "L123-S1").withPredicateObject(Ontolex.SENSE_PREDICATE, "L123-S2").build();
formWithStatement(newdata, "L123-F1", "form1new", statementUri5, "P12", "formnewvalue");
senseWithStatement(newdata, "L123-S1", "sense1new", statementUri3, "P34", "sensenewvalue");
senseWithStatement(newdata, "L123-S2", "sense2new", statementUri4, "P123", "sensenew2value");
rdfRepository.sync("L123", newdata);
// New data is here
assertTrue(rdfRepository.ask("ASK { wd:L123 wikibase:lemma \"test2lemma\" }"));
assertTrue(rdfRepository.ask("ASK { wd:L123 ontolex:lexicalForm/ontolex:representation \"form1new\" }"));
assertTrue(rdfRepository.ask("ASK { wd:L123 ontolex:lexicalForm/p:P12 [ ps:P12 \"formnewvalue\" ] }"));
assertTrue(rdfRepository.ask("ASK { wd:L123 ontolex:sense/skos:definition \"sense1new\" }"));
assertTrue(rdfRepository.ask("ASK { wd:L123 ontolex:sense/skos:definition \"sense2new\" }"));
assertTrue(rdfRepository.ask("ASK { wd:L123 ontolex:sense/p:P34 [ ps:P34 \"sensenewvalue\" ] }"));
assertTrue(rdfRepository.ask("ASK { wd:L123 ontolex:sense/p:P123 [ ps:P123 \"sensenew2value\" ] }"));
// Old data is not
assertFalse(rdfRepository.ask("ASK { wd:L123 wikibase:lemma \"testlemma\" }"));
assertFalse(rdfRepository.ask("ASK { wd:L123 ontolex:lexicalForm/ontolex:representation \"form1test\" }"));
assertFalse(rdfRepository.ask("ASK { wd:L123 ontolex:lexicalForm/ontolex:representation \"form2test\" }"));
assertFalse(rdfRepository.ask("ASK { wd:L123 ontolex:lexicalForm/p:P12 [ ps:P12 \"formvalue\" ] }"));
assertFalse(rdfRepository.ask("ASK { wd:L123 ontolex:lexicalForm/p:P23 [ ] }"));
assertFalse(rdfRepository.ask("ASK { wd:L123 ontolex:sense/skos:definition \"sensetest\" }"));
assertFalse(rdfRepository.ask("ASK { wd:L123 ontolex:sense/p:P12 [ ] }"));
}
use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class RdfRepositoryIntegrationTest method newLabelLanguage.
@Test
public void newLabelLanguage() throws QueryEvaluationException {
newLabel();
rdfRepository.sync("Q23", //
ImmutableList.of(//
statement("Q23", RDFS.LABEL, new LiteralImpl("George Washington", "en")), statement("Q23", RDFS.LABEL, new LiteralImpl("George Washington", "de"))));
TupleQueryResult r = rdfRepository.query("SELECT * WHERE {?s ?p ?o} ORDER BY ?o");
assertTrue(r.hasNext());
assertThat(r.next(), allOf(//
binds("s", "Q23"), //
binds("p", RDFS.LABEL), binds("o", new LiteralImpl("George Washington", "de"))));
assertTrue(r.hasNext());
assertThat(r.next(), allOf(//
binds("s", "Q23"), //
binds("p", RDFS.LABEL), binds("o", new LiteralImpl("George Washington", "en"))));
assertFalse(r.hasNext());
}
use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class EntityMungingRdfHandlerUnitTest method testEntityBoundary.
@Test
public void testEntityBoundary() throws RDFHandlerException {
UrisScheme uriScheme = UrisSchemeFactory.WIKIDATA;
Munger munger = Munger.builder(uriScheme).build();
RDFHandler childHandler = mock(RDFHandler.class);
AtomicLong nbEntities = new AtomicLong();
EntityMungingRdfHandler handler = new EntityMungingRdfHandler(uriScheme, munger, childHandler, nbEntities::set);
handler.startRDF();
handler.handleStatement(statement(uriScheme.entityDataHttps() + "Q1", SchemaDotOrg.ABOUT, uriScheme.entityIdToURI("Q1")));
handler.handleStatement(statement(uriScheme.entityDataHttps() + "Q1", SchemaDotOrg.VERSION, 123));
handler.handleStatement(statement(uriScheme.entityDataHttps() + "Q1", SchemaDotOrg.SOFTWARE_VERSION, 2));
handler.handleStatement(statement(uriScheme.entityDataHttps() + "Q1", SchemaDotOrg.DATE_MODIFIED, new LiteralImpl("2019-11-19T15:53:28Z")));
for (Statement statement : siteLink("Q1", "https://en.wikipedia.org/wiki/Thing", "en")) {
handler.handleStatement(statement);
}
// It buffers everything until it reaches another entoty
assertThat(nbEntities.get()).isEqualTo(0);
verify(childHandler).startRDF();
verify(childHandler, never()).handleStatement(any());
// Send another data:entity statement so that we flush the buffer to the munger
handler.handleStatement(statement(uriScheme.entityDataHttps() + "Q2", SchemaDotOrg.ABOUT, uriScheme.entityIdToURI("Q2")));
assertThat(nbEntities.get()).isEqualTo(1);
}
Aggregations