use of org.openrdf.model.Statement in project gocd by gocd.
the class SesameGraph method dumpTriplesNotInContext.
private void dumpTriplesNotInContext(Writer writer) {
try {
writer.append("Statements not in any context: \n");
} catch (IOException e) {
throw new RuntimeException(e);
}
RDFXMLWriter xmlWriter = new RDFXMLWriter(writer);
xmlWriter.startRDF();
try {
RepositoryResult<Statement> result = conn.getStatements(null, null, null, false);
while (result.hasNext()) {
Statement statement = result.next();
if (statement.getContext() == null) {
xmlWriter.handleStatement(statement);
}
}
} catch (RepositoryException | RDFHandlerException e) {
throw new RuntimeException(e);
} finally {
try {
xmlWriter.endRDF();
} catch (RDFHandlerException e) {
throw new RuntimeException(e);
}
}
}
use of org.openrdf.model.Statement 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.Statement in project wikidata-query-rdf by wikimedia.
the class RdfRepository method syncFromChanges.
/**
* Sync repository from changes list.
* @param changes List of changes.
* @return Number of triples modified.
*/
public int syncFromChanges(Collection<Change> changes, boolean verifyResult) {
if (changes.isEmpty()) {
// no changes, we're done
return 0;
}
UpdateBuilder b = new UpdateBuilder(msyncBody);
b.bindUri("schema:about", SchemaDotOrg.ABOUT);
b.bindUri("prov:wasDerivedFrom", Provenance.WAS_DERIVED_FROM);
b.bind("uris.value", uris.value());
b.bind("uris.statement", uris.statement());
Set<String> entityIds = newHashSetWithExpectedSize(changes.size());
List<Statement> insertStatements = new ArrayList<>();
List<Statement> entityStatements = new ArrayList<>();
List<Statement> statementStatements = new ArrayList<>();
Set<Statement> aboutStatements = new HashSet<>();
Set<String> valueSet = new HashSet<>();
for (final Change change : changes) {
if (change.getStatements() == null) {
// broken change, probably failed retrieval
continue;
}
entityIds.add(change.entityId());
insertStatements.addAll(change.getStatements());
classifyStatements(change.getStatements(), change.entityId(), entityStatements, statementStatements, aboutStatements);
valueSet.addAll(change.getCleanupList());
}
if (entityIds.isEmpty()) {
// If we've got no IDs, this means all change retrieval failed
log.debug("Got no valid changes, we're done");
return 0;
}
b.bindUris("entityList", entityIds, uris.entity());
b.bindStatements("insertStatements", insertStatements);
b.bindValues("entityStatements", entityStatements);
b.bindValues("statementStatements", statementStatements);
b.bindValues("aboutStatements", aboutStatements);
if (!valueSet.isEmpty()) {
UpdateBuilder cleanup = new UpdateBuilder(cleanUnused);
cleanup.bindUris("values", valueSet);
b.bind("cleanupQuery", cleanup.toString());
} else {
b.bind("cleanupQuery", "");
}
long start = System.currentTimeMillis();
int modified = execute("update", UPDATE_COUNT_RESPONSE, b.toString());
log.debug("Update query took {} millis and modified {} statements", System.currentTimeMillis() - start, modified);
if (verifyResult) {
try {
verifyStatements(entityIds, insertStatements);
} catch (QueryEvaluationException e) {
throw new FatalException("Can't load verify results: " + e, e);
}
}
return modified;
}
use of org.openrdf.model.Statement 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.Statement 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()));
}
Aggregations