use of org.wikidata.query.rdf.test.StatementHelper.StatementBuilder 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.wikidata.query.rdf.test.StatementHelper.StatementBuilder in project wikidata-query-rdf by wikimedia.
the class RdfRepositoryIntegrationTest method referenceWithExpandedValue.
@Test
public void referenceWithExpandedValue() throws QueryEvaluationException {
String statementUri = uris.statement() + "someotheruuid";
String referenceUri = uris.reference() + "8e0adc764d952b70662076cd296bd391e6e65a67";
String valueUri = uris.value() + "someuuid";
cleanupList.add(valueUri);
cleanupList.add(referenceUri);
List<Statement> george = new StatementBuilder("Q23").withStatement("P509", statementUri).withReferenceValue(referenceUri, "P509", valueUri).withReference(referenceUri, "P143", "Q328").withTimeCalendarValue(valueUri, "cat", "animals").build();
rdfRepository.sync("Q23", george);
List<Statement> enwiki = new ArrayList<>();
statement(enwiki, "Q328", "P509", "Q328");
rdfRepository.sync("Q328", enwiki);
assertTrue(rdfRepository.ask("ASK { wd:Q23 p:P509 [ prov:wasDerivedFrom [ prv:P509 [ wikibase:timeValue \"cat\" ] ] ] }"));
assertTrue(rdfRepository.ask("ASK { wd:Q23 p:P509 [ prov:wasDerivedFrom [ prv:P509 [ wikibase:timeCalendarModel \"animals\" ] ] ] }"));
assertTrue(rdfRepository.ask("ASK { wd:Q23 p:P509 [ prov:wasDerivedFrom [ pr:P143 [ p:P509 wd:Q328 ] ] ] }"));
assertTrue(rdfRepository.ask("ASK { wd:Q328 p:P509 wd:Q328 }"));
}
use of org.wikidata.query.rdf.test.StatementHelper.StatementBuilder in project wikidata-query-rdf by wikimedia.
the class RdfRepositoryIntegrationTest method cleanupUnusedValue.
/**
* Test cleaning up value node that is no more used.
* @throws QueryEvaluationException
*/
@Test
public void cleanupUnusedValue() throws QueryEvaluationException {
String statementUri = uris.statement() + randomizer.randomAsciiOfLength(10);
String valueUri = uris.value() + "changeduuid";
expandedStatementWithExpandedValue();
List<Statement> newdata = new StatementBuilder("Q23").withStatement("P509", statementUri).withStatementValue(valueUri).withTimeValue(valueUri, "dog").withEntityData("22", "2016-01-08T00:00:00Z").build();
rdfRepository.sync("Q23", newdata, makeCleanupList("Q23", newdata));
assertTrue(rdfRepository.ask("ASK { wd:Q23 p:P509 [ psv:P509 wdv:changeduuid ] }"));
assertTrue(rdfRepository.ask("ASK { wd:Q23 p:P509 [ psv:P509 [ wikibase:timeValue \"dog\" ] ] }"));
// Old one must be deleted
assertFalse(rdfRepository.ask("ASK { wdv:someuuid ?x ?y }"));
}
use of org.wikidata.query.rdf.test.StatementHelper.StatementBuilder in project wikidata-query-rdf by wikimedia.
the class RdfRepositoryUnitTest method batchUpdate.
@Test
public void batchUpdate() {
RdfClient mockClient = mock(RdfClient.class);
// 1.5M size means ~4k statements or 250K statement size max
long maxPostSize = 1572864L;
CollectedUpdateMetrics collectedUpdateMetrics = new CollectedUpdateMetrics();
collectedUpdateMetrics.setMutationCount(1);
collectedUpdateMetrics.merge(MultiSyncStep.INSERT_NEW_DATA, UpdateMetrics.builder().build());
when(mockClient.update(any(String.class), any(UpdateMetricsResponseHandler.class))).thenReturn(collectedUpdateMetrics);
RdfRepository repo = new RdfRepository(uris, mockClient, maxPostSize);
// 6000 statements - should go over the limit
Change change1 = new Change("Q1", 1, Instant.EPOCH, 1);
StatementBuilder sb = new StatementBuilder("Q1");
for (int i = 0; i < 6000; i++) {
sb.withPredicateObject(RDFS.LABEL, new LiteralImpl("some item " + i));
}
change1.setStatements(sb.build());
// One statement with 300K data - should go over the limit
Change change2 = new Change("Q2", 1, Instant.EPOCH, 1);
List<Statement> statements2 = new StatementBuilder("Q2").withPredicateObject(RDFS.LABEL, new LiteralImpl(randomizer.randomAsciiOfLength(300 * 1024))).build();
change2.setStatements(statements2);
// Just one statement - this will be separated anyway
Change change3 = new Change("Q3", 1, Instant.EPOCH, 1);
List<Statement> statements3 = new StatementBuilder("Q3").withPredicateObject(RDFS.LABEL, new LiteralImpl("third item")).build();
change3.setStatements(statements3);
List<Change> changes = ImmutableList.of(change1, change2, change3);
int count = repo.syncFromChanges(changes, false).getMutationCount();
assertThat(count).isEqualTo(3);
// We should get 3 calls to update
verify(mockClient, times(3)).update(any(), any());
}
use of org.wikidata.query.rdf.test.StatementHelper.StatementBuilder in project wikidata-query-rdf by wikimedia.
the class RdfRepositoryIntegrationTest method cleanupValueWithUsedByOld.
/**
* Test cleanup when one value is still used by other data.
* @throws QueryEvaluationException
*/
@Test
public void cleanupValueWithUsedByOld() throws QueryEvaluationException {
String statementUri = uris.statement() + randomizer.randomAsciiOfLength(10);
String oldValueUri = uris.value() + "someuuid";
String valueUri = uris.value() + "changeduuid";
cleanupList.add(valueUri);
List<Statement> olddata = new ArrayList<>();
statement(olddata, statementUri, uris.property(PropertyType.STATEMENT_VALUE) + "P222", oldValueUri);
rdfRepository.sync("Q2", olddata);
expandedStatementWithExpandedValue();
List<Statement> newdata = new StatementBuilder("Q23").withStatement("P509", statementUri).withStatementValue(valueUri).withTimeValue(valueUri, "duck").withEntityData("22", "2016-01-08T00:00:00Z").build();
rdfRepository.sync("Q23", newdata, makeCleanupList("Q23", newdata));
// New values are present
assertTrue(rdfRepository.ask("ASK { wd:Q23 p:P509 [ psv:P509 wdv:changeduuid ] }"));
assertTrue(rdfRepository.ask("ASK { wd:Q23 p:P509 [ psv:P509 [ wikibase:timeValue \"duck\" ] ] }"));
// Old value still used so keep it
assertTrue(rdfRepository.ask("ASK { wdv:someuuid ?x ?y }"));
}
Aggregations