/** * Returns a hash code for the given object. * * @see java.lang.Object#hashCode() * @param o * the object to create a hash for * @return the hash code of the object */ public static int hashCode(StatementGroup o) { return o.getStatements().hashCode(); }
/** * Returns a hash code for the given object. * * @see java.lang.Object#hashCode() * @param o * the object to create a hash for * @return the hash code of the object */ public static int hashCode(StatementGroup o) { return o.getStatements().hashCode(); }
/** * Returns true if the parameters are two {@link StatementGroup} 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. * Note that this includes the statement id, so that two statement objects * that "say the same thing" might still be unequal if they have different * ids. * * @param o1 * the first object to compare * @param o2 * the second object to compare * @return true if both objects are equal */ public static boolean equalsStatementGroup(StatementGroup o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } return o2 instanceof StatementGroup && o1.getStatements().equals(((StatementGroup) o2).getStatements()); }
/** * Returns true if the parameters are two {@link StatementGroup} 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. * Note that this includes the statement id, so that two statement objects * that "say the same thing" might still be unequal if they have different * ids. * * @param o1 * the first object to compare * @param o2 * the second object to compare * @return true if both objects are equal */ public static boolean equalsStatementGroup(StatementGroup o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } return o2 instanceof StatementGroup && o1.getStatements().equals(((StatementGroup) o2).getStatements()); }
/** * Helper method that extracts the list of all {@link ItemIdValue} objects * that are used as values in the given statement group. * * @param statementGroup * the {@link StatementGroup} to extract the data from * @return the list of values */ private List<EntityIdValue> getItemIdValueList(StatementGroup statementGroup) { List<EntityIdValue> result = new ArrayList<>(statementGroup .getStatements().size()); for (Statement s : statementGroup.getStatements()) { Value v = s.getValue(); if (v instanceof EntityIdValue) { result.add((EntityIdValue) v); } } return result; }
/** * Copies a {@link StatementGroup}. * <p> * This method ignores filters set via {@link #setOptionPropertyFilter(Set)}. * * @param object * object to copy * @return copied object */ public StatementGroup copy(StatementGroup object) { List<Statement> statements = new ArrayList<>(object.getStatements().size()); for (Statement statement : object.getStatements()) { statements.add(copy(statement)); } return dataObjectFactory.getStatementGroup(statements); }
/** * Copies a {@link StatementGroup}. * <p> * This method ignores filters set via {@link #setOptionPropertyFilter(Set)}. * * @param object * object to copy * @return copied object */ public StatementGroup copy(StatementGroup object) { List<Statement> statements = new ArrayList<>(object.getStatements().size()); for (Statement statement : object.getStatements()) { statements.add(copy(statement)); } return dataObjectFactory.getStatementGroup(statements); }
/** * Checks if the given group of statements contains the given value as the * value of a main snak of some statement. * * @param statementGroup * the statement group to scan * @param value * the value to scan for * @return true if value was found */ private boolean containsValue(StatementGroup statementGroup, Value value) { for (Statement s : statementGroup.getStatements()) { if (value.equals(s.getValue())) { return true; } } return false; }
/** * Returns the unique {@link Statement} for the given property, or null if * there are zero or many statements for this property. This is a * convenience method for accessing the data that can be obtained via * {@link #getStatementGroups()}. * * @param propertyIdValue * the property to search for * @return {@link Statement} or null */ default Statement findStatement(PropertyIdValue propertyIdValue) { StatementGroup statementGroup = findStatementGroup(propertyIdValue); return (statementGroup != null && statementGroup.size() == 1) ? statementGroup.getStatements().get(0) : null; }
/** * Returns the unique {@link Statement} for the given property, or null if * there are zero or many statements for this property. This is a * convenience method for accessing the data that can be obtained via * {@link #getStatementGroups()}. * * @param propertyIdValue * the property to search for * @return {@link Statement} or null */ default Statement findStatement(PropertyIdValue propertyIdValue) { StatementGroup statementGroup = findStatementGroup(propertyIdValue); return (statementGroup != null && statementGroup.size() == 1) ? statementGroup.getStatements().get(0) : null; }
/** * Returns the unique {@link Statement} for the given property, or null if * there are zero or many statements for this property. Only the string id * of the property is compared, not the site id. This is useful in * situations where all data is known to come from a single site. * <p> * This is a convenience method for accessing the data that can be obtained * via {@link #getStatementGroups()}. * * @param propertyId * the property to search for * @return {@link Statement} or null */ default Statement findStatement(String propertyId) { StatementGroup statementGroup = findStatementGroup(propertyId); return (statementGroup != null && statementGroup.size() == 1) ? statementGroup.getStatements().get(0) : null; }
/** * Returns the unique {@link Statement} for the given property, or null if * there are zero or many statements for this property. Only the string id * of the property is compared, not the site id. This is useful in * situations where all data is known to come from a single site. * <p> * This is a convenience method for accessing the data that can be obtained * via {@link #getStatementGroups()}. * * @param propertyId * the property to search for * @return {@link Statement} or null */ default Statement findStatement(String propertyId) { StatementGroup statementGroup = findStatementGroup(propertyId); return (statementGroup != null && statementGroup.size() == 1) ? statementGroup.getStatements().get(0) : null; }
/** * Checks if the given statement group contains at least one value of * precision +/-1. * * @param statementGroup * @return */ protected boolean hasPlusMinusOneValues(StatementGroup statementGroup) { if (statementGroup == null) { return false; } for (Statement s : statementGroup.getStatements()) { QuantityValue qv = (QuantityValue) s.getValue(); if (qv != null && isPlusMinusOneValue(qv)) { return true; } } return false; } }
/** * Constructor. * * @param id * the identifier of the subject of this document * @param claims * the statement groups contained in this document * @param revisionId * the id of the last revision of this document */ StatementDocumentImpl( EntityIdValue id, List<StatementGroup> claims, long revisionId) { super(id, revisionId); this.claims = new HashMap<>(); if(claims != null) { for(StatementGroup group : claims) { EntityIdValue otherId = group.getSubject(); otherId.getIri(); Validate.isTrue(group.getSubject().equals(id), "Subject for the statement group and the document are different: "+otherId.toString()+" vs "+id.toString()); this.claims.put(group.getProperty().getId(), group.getStatements()); } } }
/** * Constructor. * * @param id * the identifier of the subject of this document * @param claims * the statement groups contained in this document * @param revisionId * the id of the last revision of this document */ StatementDocumentImpl( EntityIdValue id, List<StatementGroup> claims, long revisionId) { super(id, revisionId); this.claims = new HashMap<>(); if(claims != null) { for(StatementGroup group : claims) { EntityIdValue otherId = group.getSubject(); otherId.getIri(); Validate.isTrue(group.getSubject().equals(id), "Subject for the statement group and the document are different: "+otherId.toString()+" vs "+id.toString()); this.claims.put(group.getProperty().getId(), group.getStatements()); } } }
@Override public void processItemDocument(ItemDocument itemDocument) { for (StatementGroup sg : itemDocument.getStatementGroups()) { if (COORD_PROPERTY.equals(sg.getProperty().getId())) { for (Statement s : sg.getStatements()) { countCoordinateStatement(s, itemDocument); } } } }
void writeStatements(Resource subject, StatementDocument statementDocument) throws RDFHandlerException { for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { URI property = this.rdfWriter.getUri(Vocabulary.getPropertyUri( statementGroup.getProperty(), PropertyContext.STATEMENT)); for (Statement statement : statementGroup.getStatements()) { this.rdfWriter.writeTripleUriObject(subject, property, Vocabulary.getStatementUri(statement)); } } for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { for (Statement statement : statementGroup.getStatements()) { writeStatement(statement); } } }
void writeSimpleStatements(Resource subject, StatementDocument statementDocument) { for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { for (Statement statement : statementGroup.getStatements()) { if (statement.getClaim().getQualifiers().size() == 0) { this.snakRdfConverter.setSnakContext(subject, PropertyContext.SIMPLE_CLAIM); statement.getClaim().getMainSnak() .accept(this.snakRdfConverter); } } } }
void writeInstanceOfStatements(Resource subject, ItemDocument itemDocument) { for (StatementGroup statementGroup : itemDocument.getStatementGroups()) { if (!"P31".equals(statementGroup.getProperty().getId())) { continue; } for (Statement statement : statementGroup.getStatements()) { if (statement.getClaim().getMainSnak() instanceof ValueSnak && statement.getClaim().getQualifiers().size() == 0) { ValueSnak mainSnak = (ValueSnak) statement.getClaim() .getMainSnak(); Value value = this.valueRdfConverter .getRdfValue(mainSnak.getValue(), mainSnak.getPropertyId(), true); if (value == null) { logger.error("Could not serialize instance of snak: missing value (Snak: " + mainSnak.toString() + ")"); continue; } try { this.rdfWriter.writeTripleValueObject(subject, RdfWriter.RDF_TYPE, value); } catch (RDFHandlerException e) { throw new RuntimeException(e.toString(), e); } } } } }
/** * 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.getStatements()) { if (s.getClaim().getMainSnak() instanceof ValueSnak) { Value v = ((ValueSnak) s.getClaim().getMainSnak()) .getValue(); // "Q1731" is "Dresden" on Wikidata if (v instanceof ItemIdValue && "Q1731".equals(((ItemIdValue) v).getId())) { return true; } } } } return false; } }