@JsonProperty("redirect") String getTargetJson() { return targetId.getId(); }
@JsonProperty("entity") String getEntityJson() { return entityId.getId(); }
@JsonProperty("entity") String getEntityJson() { return entityId.getId(); }
@JsonProperty("redirect") String getTargetJson() { return targetId.getId(); }
/** * Constructor. * * @param id * the identifier of the subject of this document * @param revisionId * the id of the last revision of this document */ EntityDocumentImpl(EntityIdValue id, long revisionId) { Validate.notNull(id); this.entityId = id.getId(); this.siteIri = id.getSiteIri(); this.revisionId = revisionId; }
/** * Logs information about entities changed so far. * * @param entityId * the id of the modified item * @param numberLabel * the label written * @param languages * the list of languages for which the label was set */ protected void logEntityModification(EntityIdValue entityId, String numberLabel, ArrayList<String> languages) { modifiedEntities++; System.out.println(entityId.getId() + ": adding label " + numberLabel + " for languages " + languages.toString() + " (" + modifiedEntities + " entities modified so far)"); this.logfile.println(entityId.getId() + "," + numberLabel + ",\"" + languages.toString() + "\""); if (modifiedEntities % 10 == 0) { this.logfile.flush(); } } }
/** * Constructor. * * @param id * the identifier of the subject of this document * @param revisionId * the id of the last revision of this document */ EntityDocumentImpl(EntityIdValue id, long revisionId) { Validate.notNull(id); this.entityId = id.getId(); this.siteIri = id.getSiteIri(); this.revisionId = revisionId; }
/** * Logs information about entities changed so far. * * @param entityId * the id of the modified item * @param numberLabel * the label written * @param languages * the list of languages for which the label was set */ protected void logEntityModification(EntityIdValue entityId, String numberLabel, ArrayList<String> languages) { modifiedEntities++; System.out.println(entityId.getId() + ": adding label " + numberLabel + " for languages " + languages.toString() + " (" + modifiedEntities + " entities modified so far)"); this.logfile.println(entityId.getId() + "," + numberLabel + ",\"" + languages.toString() + "\""); if (modifiedEntities % 10 == 0) { this.logfile.flush(); } } }
/** * Returns a string that should be used as a label for the given item. The * method also ensures that each label is used for only one class. Other * classes with the same label will have their QID added for disambiguation. * * @param entityIdValue * the item to label * @return the label */ private String getClassLabel(EntityIdValue entityIdValue) { ClassRecord classRecord = this.classRecords.get(entityIdValue); String label; if (classRecord == null || classRecord.itemDocument == null) { label = entityIdValue.getId(); } else { label = getLabel(entityIdValue, classRecord.itemDocument); } EntityIdValue labelOwner = this.labels.get(label); if (labelOwner == null) { this.labels.put(label, entityIdValue); return label; } else if (labelOwner.equals(entityIdValue)) { return label; } else { return label + " (" + entityIdValue.getId() + ")"; } }
/** * Returns the IRI of the primitive Type of an Property for * {@link EntityIdValue} objects. * * @param propertyIdValue * @param value */ public String setPropertyTypeFromEntityIdValue( PropertyIdValue propertyIdValue, EntityIdValue value) { switch (value.getId().charAt(0)) { case 'Q': return DatatypeIdValue.DT_ITEM; case 'P': return DatatypeIdValue.DT_PROPERTY; default: logger.warn("Could not determine Type of " + propertyIdValue.getId() + ". It is not a valid EntityDocument Id"); return null; } }
@Override public WikidataValue visit(EntityIdValue value) { if (value.getEntityType().equals(EntityIdValue.ET_ITEM)) { return WikidataValue.forItem(Integer.valueOf(value.getId().substring(1))); } else if (value.getEntityType().equals(EntityIdValue.ET_PROPERTY)) { return WikidataValue.forProperty(Integer.valueOf(value.getId().substring(1))); } else { throw new IllegalArgumentException("Unknown entity type: " + value.getEntityType()); } }
/** * 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(EntityIdValue o) { int result; result = o.getId().hashCode(); result = prime * result + o.getSiteIri().hashCode(); result = prime * result + o.getEntityType().hashCode(); return result; }
@Override public WikidataValue visit(EntityIdValue value) { if (value.getEntityType().equals(EntityIdValue.ET_ITEM)) { return WikidataValue.forItem(Integer.valueOf(value.getId().substring(1))); } else if (value.getEntityType().equals(EntityIdValue.ET_PROPERTY)) { return WikidataValue.forProperty(Integer.valueOf(value.getId().substring(1))); } else { throw new IllegalArgumentException("Unknown entity type: " + value.getEntityType()); } }
/** * 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(EntityIdValue o) { int result; result = o.getId().hashCode(); result = prime * result + o.getSiteIri().hashCode(); result = prime * result + o.getEntityType().hashCode(); return result; }
/** * 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); }
/** * Returns the CSV-escaped label for the given entity based on the terms in * the given document. The returned string will have its quotes escaped, but * it will not be put in quotes (since this is not appropriate in all * contexts where this method is used). * * @param entityIdValue * the entity to label * @param termedDocument * the document to get labels from * @return the label */ private String getLabel(EntityIdValue entityIdValue, TermedDocument termedDocument) { MonolingualTextValue labelValue = termedDocument.getLabels().get("en"); if (labelValue != null) { return labelValue.getText().replace("\"", "\"\""); } else { return entityIdValue.getId(); } }
/** * Returns the CSV-escaped label for the given entity based on the terms in * the given document. The returned string will have its quotes escaped, but * it will not be put in quotes (since this is not appropriate in all * contexts where this method is used). * * @param entityIdValue * the entity to label * @param termedDocument * the document to get labels from * @return the label */ private String getLabel(EntityIdValue entityIdValue, TermedDocument termedDocument) { MonolingualTextValue labelValue = termedDocument.getLabels().get("en"); if (labelValue != null) { return labelValue.getText().replace("\"", "\"\""); } else { return entityIdValue.getId(); } }
/** * Returns true if the parameters are two {@link EntityIdValue} 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 equalsEntityIdValue(EntityIdValue o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } if (!(o2 instanceof EntityIdValue)) { return false; } EntityIdValue other = (EntityIdValue) o2; return o1.getId().equals(other.getId()) && o1.getSiteIri().equals(other.getSiteIri()) && o1.getEntityType().equals(other.getEntityType()); }
/** * Performs a null edit on an entity. This has some effects on Wikibase, * such as refreshing the labels of the referred items in the UI. * * @param currentDocument * the document to perform a null edit on * @throws MediaWikiApiErrorException * if the API returns errors * @throws IOException * if there are any IO errors, such as missing network connection */ @SuppressWarnings("unchecked") public <T extends StatementDocument> T nullEdit(T currentDocument) throws IOException, MediaWikiApiErrorException { StatementUpdate statementUpdate = new StatementUpdate(currentDocument, Collections.<Statement>emptyList(), Collections.<Statement>emptyList()); statementUpdate.setGuidGenerator(guidGenerator); return (T) this.wbEditingAction.wbEditEntity(currentDocument .getEntityId().getId(), null, null, null, statementUpdate .getJsonUpdateString(), false, this.editAsBot, currentDocument .getRevisionId(), null); } }
/** * Performs a null edit on an entity. This has some effects on Wikibase, * such as refreshing the labels of the referred items in the UI. * * @param currentDocument * the document to perform a null edit on * @throws MediaWikiApiErrorException * if the API returns errors * @throws IOException * if there are any IO errors, such as missing network connection */ @SuppressWarnings("unchecked") public <T extends StatementDocument> T nullEdit(T currentDocument) throws IOException, MediaWikiApiErrorException { StatementUpdate statementUpdate = new StatementUpdate(currentDocument, Collections.<Statement>emptyList(), Collections.<Statement>emptyList()); statementUpdate.setGuidGenerator(guidGenerator); return (T) this.wbEditingAction.wbEditEntity(currentDocument .getEntityId().getId(), null, null, null, statementUpdate .getJsonUpdateString(), false, this.editAsBot, currentDocument .getRevisionId(), null); } }