/** * Returns true if the parameters are two {@link Statement} objects with * exactly the same data. It does not matter if they are different * implementations of the interface as long as their content is the same. * * @param o1 * the first object to compare * @param o2 * the second object to compare * @return true if both objects are equal */ public static boolean equalsStatement(Statement o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } if (!(o2 instanceof Statement)) { return false; } Statement other = (Statement) o2; return o1.getSubject().equals(other.getSubject()) && o1.getMainSnak().equals(other.getMainSnak()) && o1.getQualifiers().equals(other.getQualifiers()) && o1.getReferences().equals(other.getReferences()) && o1.getRank() == other.getRank() && o1.getStatementId().equals(other.getStatementId()); }
if (!equivalentClaims(statement1.getClaim(), statement2.getClaim())) { return null; StatementRank newRank = statement1.getRank(); if (newRank == StatementRank.NORMAL) { newRank = statement2.getRank(); } else if (statement2.getRank() != StatementRank.NORMAL && newRank != statement2.getRank()) { return null; String newStatementId = statement1.getStatementId(); if ("".equals(newStatementId)) { newStatementId = statement2.getStatementId(); statement1.getReferences(), statement2.getReferences()); return Datamodel.makeStatement(statement1.getClaim(), newReferences, newRank, newStatementId);
@Override public Value getValue() { return statement.getValue(); }
/** * Get the URI for the given statement. * * @param statement * the statement for which to create a URI * @return the URI */ public static String getStatementUri(Statement statement) { int i = statement.getStatementId().indexOf('$') + 1; return PREFIX_WIKIDATA_STATEMENT + statement.getSubject().getId() + "-" + statement.getStatementId().substring(i); }
/** * Get the URI for the given statement. * * @param statement * the statement for which to create a URI * @return the URI */ public static String getStatementUri(Statement statement) { int i = statement.getStatementId().indexOf('$') + 1; return statement.getClaim().getSubject().getIri() + "S" + statement.getStatementId().substring(i); }
List<Statement> updateStatements = new ArrayList<>(); for (Statement s : editPropertyStatements) { QuantityValue qv = (QuantityValue) s.getValue(); if (qv != null && isPlusMinusOneValue(qv)) { QuantityValue exactValue = Datamodel.makeQuantityValue( Statement exactStatement = StatementBuilder .forSubjectAndProperty(itemIdValue, property) .withValue(exactValue).withId(s.getStatementId()) .withQualifiers(s.getQualifiers()) .withReferences(s.getReferences()) .withRank(s.getRank()).build(); updateStatements.add(exactStatement);
String pid = statement.getMainSnak().getPropertyId().getId(); if(newGroups.containsKey(pid)) { List<Statement> newGroup = new ArrayList<>(newGroups.get(pid).size()); boolean statementReplaced = false; for(Statement existingStatement : newGroups.get(pid)) { if(existingStatement.getStatementId().equals(statement.getStatementId()) && !existingStatement.getStatementId().isEmpty()) { statementReplaced = true; newGroup.add(statement);
void writeStatement(Statement statement) throws RDFHandlerException { String statementUri = Vocabulary.getStatementUri(statement); Resource statementResource = this.rdfWriter.getUri(statementUri); this.rdfWriter.writeTripleValueObject(statementResource, RdfWriter.RDF_TYPE, RdfWriter.WB_STATEMENT); writeClaim(statementResource, statement.getClaim()); writeReferences(statementResource, statement.getReferences()); writeStatementRankTriple(statementResource, statement.getRank()); }
for (SnakGroup q : s.getQualifiers()) { countPropertyQualifier(q.getProperty(), q.size()); if (s.getQualifiers().size() > 0) { propertyRecord.statementWithQualifierCount++; for (Reference r : s.getReferences()) { for (SnakGroup snakGroup : r.getSnakGroups()) { countPropertyReference(snakGroup.getProperty(), snakGroup.size()); && s.getMainSnak() instanceof ValueSnak) { Value value = s.getValue(); if (value instanceof EntityIdValue) { ClassRecord otherClassRecord = getClassRecord((EntityIdValue) value);
void writeStatement(Statement statement) throws RDFHandlerException { String statementUri = Vocabulary.getStatementUri(statement); Resource statementResource = this.rdfWriter.getUri(statementUri); this.rdfWriter.writeTripleValueObject(statementResource, RdfWriter.RDF_TYPE, RdfWriter.WB_STATEMENT); writeClaim(statementResource, statement.getClaim()); writeReferences(statementResource, statement.getReferences()); // TODO What about the RANK? }
Statement statement = statements.get(0); if (statement.getStatementId() == null || statement.getStatementId().isEmpty()) { statement = statement.withStatementId(guidGenerator.freshStatementId(currentDocument.getEntityId().getId())); Statement returnedStatement = preStatement.withSubject(statement.getClaim().getSubject()); long revisionId = getRevisionIdFromResponse(response);
.withId(statementToModify.getStatementId()) .withValue(Datamodel.makeStringValue("Updated string value 1")) .withReferences(statementToModify.getReferences()).build();
if (urlPatterns != null) { for (Statement s : urlPatterns) { Value v = s.getValue(); if (v == null) { continue; pr.urlPattern = urlPattern; } else if (!foundGacUrl && s.getRank() == StatementRank.PREFERRED) { pr.urlPattern = urlPattern; } else if (!foundGacUrl) { Iterator<Snak> snaks = s.getAllQualifiers(); while (snaks.hasNext()) { Snak snak = snaks.next(); if (instanceClasses != null) { for (Statement s : instanceClasses) { Value v = s.getValue(); if (v != null) { pr.classes.add(Integer.parseInt(((ItemIdValue) v).getId()
@Override public StatementGroup withStatement(Statement statement) { String statementId = statement.getStatementId(); boolean statementAdded = false; List<Statement> newStatements = new ArrayList<>(this.statements); if (!statementId.isEmpty()) { for(int i = 0; i != newStatements.size(); i++) { String currentStatementId = newStatements.get(i).getStatementId(); if (currentStatementId.equals(statementId)) { newStatements.set(i, statement); statementAdded = true; } } } if (!statementAdded) { newStatements.add(statement); } return new StatementGroupImpl(newStatements); } }
@Override public Claim getClaim(EntityIdValue subject, Snak mainSnak, List<SnakGroup> qualifiers) { // Jackson claims cannot exist without a statement. return getStatement( subject, mainSnak, qualifiers, Collections. emptyList(), StatementRank.NORMAL, "empty id 12345").getClaim(); }
/** * Returns true if the given document should be included in the * serialization. * * @param itemDocument * the document to check * @return true if the document should be serialized */ private boolean includeDocument(ItemDocument itemDocument) { for (StatementGroup sg : itemDocument.getStatementGroups()) { // "P19" is "place of birth" on Wikidata if (!"P19".equals(sg.getProperty().getId())) { continue; } for (Statement s : sg) { if (s.getMainSnak() instanceof ValueSnak) { Value v = s.getValue(); // "Q1731" is "Dresden" on Wikidata if (v instanceof ItemIdValue && "Q1731".equals(((ItemIdValue) v).getId())) { return true; } } } } return false; } }
/** * Count the statements and property uses of an item or property document. * * @param usageStatistics * statistics object to store counters in * @param statementDocument * document to count the statements of */ protected void countStatements(UsageStatistics usageStatistics, StatementDocument statementDocument) { // Count Statement data: for (StatementGroup sg : statementDocument.getStatementGroups()) { // Count Statements: usageStatistics.countStatements += sg.size(); // Count uses of properties in Statements: countPropertyMain(usageStatistics, sg.getProperty(), sg.size()); for (Statement s : sg) { for (SnakGroup q : s.getQualifiers()) { countPropertyQualifier(usageStatistics, q.getProperty(), q.size()); } for (Reference r : s.getReferences()) { usageStatistics.countReferencedStatements++; for (SnakGroup snakGroup : r.getSnakGroups()) { countPropertyReference(usageStatistics, snakGroup.getProperty(), snakGroup.size()); } } } } }
@Override public Snak getMainSnak() { return statement.getMainSnak(); }
void writeSimpleStatements(Resource subject, StatementDocument statementDocument) { for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { for (Statement statement : statementGroup) { if (statement.getQualifiers().size() == 0) { this.snakRdfConverter.setSnakContext(subject, PropertyContext.DIRECT); statement.getMainSnak() .accept(this.snakRdfConverter); } } } }
Value v = s.getValue(); if (v instanceof ItemIdValue) { Integer vId = getNumId(((ItemIdValue) v).getId(), false); for (SnakGroup snakGroup : s.getQualifiers()) { Integer qualifierId = getNumId(snakGroup.getProperty() .getId(), false);