/** * Checks if two claims are equivalent in the sense that they have the same * main snak and the same qualifiers, but possibly in a different order. * * @param claim1 * @param claim2 * @return true if claims are equivalent */ protected boolean equivalentClaims(Claim claim1, Claim claim2) { return claim1.getMainSnak().equals(claim2.getMainSnak()) && isSameSnakSet(claim1.getAllQualifiers(), claim2.getAllQualifiers()); }
/** * Checks if two claims are equivalent in the sense that they have the same * main snak and the same qualifiers, but possibly in a different order. * * @param claim1 * @param claim2 * @return true if claims are equivalent */ protected boolean equivalentClaims(Claim claim1, Claim claim2) { return claim1.getMainSnak().equals(claim2.getMainSnak()) && isSameSnakSet(claim1.getAllQualifiers(), claim2.getAllQualifiers()); }
/** * 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(Claim o) { int result; result = o.getSubject().hashCode(); result = prime * result + o.getMainSnak().hashCode(); result = prime * result + o.getQualifiers().hashCode(); return result; }
/** * Returns a human-readable string representation of the given object. * * @see java.lang.Object#toString() * @param o * the object to represent as string * @return a string representation of the object */ public static String toString(Claim o) { StringBuilder sb = new StringBuilder(); sb.append(o.getSubject()).append(": "); sb.append(o.getMainSnak().toString()).append("\n"); for (SnakGroup s : o.getQualifiers()) { sb.append(toString(s)); } return sb.toString(); }
/** * 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(Claim o) { int result; result = o.getSubject().hashCode(); result = prime * result + o.getMainSnak().hashCode(); result = prime * result + o.getQualifiers().hashCode(); return result; }
/** * Returns a human-readable string representation of the given object. * * @see java.lang.Object#toString() * @param o * the object to represent as string * @return a string representation of the object */ public static String toString(Claim o) { StringBuilder sb = new StringBuilder(); sb.append(o.getSubject()).append(": "); sb.append(o.getMainSnak().toString()).append("\n"); for (SnakGroup s : o.getQualifiers()) { sb.append(toString(s)); } return sb.toString(); }
/** * Returns true if the parameters are two {@link Claim} 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 equalsClaim(Claim o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } if (!(o2 instanceof Claim)) { return false; } Claim other = (Claim) o2; return o1.getSubject().equals(other.getSubject()) && o1.getMainSnak().equals(other.getMainSnak()) && o1.getQualifiers().equals(other.getQualifiers()); }
/** * Returns true if the parameters are two {@link Claim} 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 equalsClaim(Claim o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } if (!(o2 instanceof Claim)) { return false; } Claim other = (Claim) o2; return o1.getSubject().equals(other.getSubject()) && o1.getMainSnak().equals(other.getMainSnak()) && o1.getQualifiers().equals(other.getQualifiers()); }
@Override public Statement getStatement(Claim claim, List<Reference> references, StatementRank rank, String statementId) { return getStatement(claim.getSubject(), claim.getMainSnak(), claim.getQualifiers(), references, rank, statementId); }
@Override public Statement getStatement(Claim claim, List<Reference> references, StatementRank rank, String statementId) { return getStatement(claim.getSubject(), claim.getMainSnak(), claim.getQualifiers(), references, rank, statementId); }
if (s.getClaim().getMainSnak() instanceof ValueSnak) { Value value = ((ValueSnak) s.getClaim().getMainSnak()) .getValue(); if (value instanceof StringValue) {
/** * 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; } }
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); } } } } }
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); } } } }
/** * Copies a {@link Claim}. * * @param object * object to copy * @return copied object */ public Claim copy(Claim object) { return dataObjectFactory.getClaim( (EntityIdValue) visit(object.getSubject()), copy(object.getMainSnak()), copy(object.getQualifiers())); }
void writeClaim(Resource claimResource, Claim claim) { this.snakRdfConverter.setSnakContext(claimResource, PropertyContext.VALUE); claim.getMainSnak().accept(this.snakRdfConverter); this.snakRdfConverter.setSnakContext(claimResource, PropertyContext.QUALIFIER); for (SnakGroup snakGroup : claim.getQualifiers()) { for (Snak snak : snakGroup.getSnaks()) { snak.accept(this.snakRdfConverter); } } }
/** * Copies a {@link Claim}. * * @param object * object to copy * @return copied object */ public Claim copy(Claim object) { return dataObjectFactory.getClaim( (EntityIdValue) visit(object.getSubject()), copy(object.getMainSnak()), copy(object.getQualifiers())); }
void writeClaim(Resource claimResource, Claim claim) { // write main snak this.snakRdfConverter.setSnakContext(claimResource, PropertyContext.VALUE); claim.getMainSnak().accept(this.snakRdfConverter); this.snakRdfConverter.setSnakContext(claimResource, PropertyContext.VALUE_SIMPLE); claim.getMainSnak().accept(this.snakRdfConverter); // write qualifier this.snakRdfConverter.setSnakContext(claimResource, PropertyContext.QUALIFIER); for (SnakGroup snakGroup : claim.getQualifiers()) { for (Snak snak : snakGroup) { snak.accept(this.snakRdfConverter); } } this.snakRdfConverter.setSnakContext(claimResource, PropertyContext.QUALIFIER_SIMPLE); for (SnakGroup snakGroup : claim.getQualifiers()) { for (Snak snak : snakGroup) { snak.accept(this.snakRdfConverter); } } }
if (statement.getClaim().getMainSnak() instanceof ValueSnak) { ValueSnak mainSnak = (ValueSnak) statement.getClaim() .getMainSnak();
&& s.getClaim().getMainSnak() instanceof ValueSnak) { Value value = ((ValueSnak) s.getClaim().getMainSnak()) .getValue(); if (value instanceof EntityIdValue) {