/** * 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(MonolingualTextValue o) { return "\"" + o.getText().replace("\"", "\\\"") + "\" (" + o.getLanguageCode() + ")"; }
/** * Deletes an individual alias * * @param alias * the alias to delete */ protected void deleteAlias(MonolingualTextValue alias) { String lang = alias.getLanguageCode(); AliasesWithUpdate currentAliases = newAliases.get(lang); if (currentAliases != null) { currentAliases.aliases.remove(alias); currentAliases.deleted.add(alias); currentAliases.write = true; } }
/** * Returns the string label for the given language code, or null if there is * no label for this code. This is a convenience method for accessing the * data that can be obtained via {@link #getLabels()}. * * @param languageCode * a string that represents language * @return the label string or null if it does not exists */ default String findLabel(String languageCode) { MonolingualTextValue value = this.getLabels().get(languageCode); return (value != null) ? value.getText() : null; }
/** * Deletes an individual alias * * @param alias * the alias to delete */ protected void deleteAlias(MonolingualTextValue alias) { String lang = alias.getLanguageCode(); AliasesWithUpdate currentAliases = newAliases.get(lang); if (currentAliases != null) { currentAliases.aliases.remove(alias); currentAliases.deleted.add(alias); currentAliases.write = true; } }
/** * Returns the string description for the given language code, or null if * there is no description for this code. This is a convenience method for * accessing the data that can be obtained via {@link #getDescriptions()}. * * @param languageCode * a string that represents language * @return the description string or null if it does not exists */ default String findDescription(String languageCode) { MonolingualTextValue value = this.getDescriptions().get(languageCode); return (value != null) ? value.getText() : null; }
/** * 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(MonolingualTextValue o) { return "\"" + o.getText().replace("\"", "\\\"") + "\" (" + o.getLanguageCode() + ")"; }
/** * Adds descriptions to the item. * * @param descriptions * the descriptions to add */ protected void processDescriptions(List<MonolingualTextValue> descriptions) { for(MonolingualTextValue description : descriptions) { NameWithUpdate currentValue = newDescriptions.get(description.getLanguageCode()); // only mark the description as added if the value we are writing is different from the current one if (currentValue == null || !currentValue.value.equals(description)) { newDescriptions.put(description.getLanguageCode(), new NameWithUpdate(description, true)); } } }
/** * Returns the string description for the given language code, or null if * there is no description for this code. This is a convenience method for * accessing the data that can be obtained via {@link #getDescriptions()}. * * @param languageCode * a string that represents language * @return the description string or null if it does not exists */ default String findDescription(String languageCode) { MonolingualTextValue value = this.getDescriptions().get(languageCode); return (value != null) ? value.getText() : null; }
/** * Copy constructor. * * @param mltv * the object to copy the data from */ @Deprecated public TermImpl(MonolingualTextValue mltv) { this(mltv.getLanguageCode(), mltv.getText()); }
private static Map<String, List<MonolingualTextValue>> constructTermListMap(List<MonolingualTextValue> terms) { Map<String, List<MonolingualTextValue>> map = new HashMap<>(); for(MonolingualTextValue term : terms) { String language = term.getLanguageCode(); // We need to make sure the terms are of the right type, otherwise they will not // be serialized correctly. List<MonolingualTextValue> aliases = map.computeIfAbsent(language, (l) -> new ArrayList<>()); aliases.add(toTerm(term)); } return map; }
/** * Returns the string label for the given language code, or null if there is * no label for this code. This is a convenience method for accessing the * data that can be obtained via {@link #getLabels()}. * * @param languageCode * a string that represents language * @return the label string or null if it does not exists */ default String findLabel(String languageCode) { MonolingualTextValue value = this.getLabels().get(languageCode); return (value != null) ? value.getText() : null; }
/** * Copy constructor. * * @param mltv * the object to copy the data from */ @Deprecated public TermImpl(MonolingualTextValue mltv) { this(mltv.getLanguageCode(), mltv.getText()); }
/** * Adds descriptions to the item. * * @param descriptions * the descriptions to add */ protected void processDescriptions(List<MonolingualTextValue> descriptions) { for(MonolingualTextValue description : descriptions) { NameWithUpdate currentValue = newDescriptions.get(description.getLanguageCode()); // only mark the description as added if the value we are writing is different from the current one if (currentValue == null || !currentValue.value.equals(description)) { newDescriptions.put(description.getLanguageCode(), new NameWithUpdate(description, true)); } } }
@Override public WikidataValue visit(MonolingualTextValue value) { return WikidataValue.forString(value.getText()); }
/** * 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(MonolingualTextValue o) { int result; result = o.getLanguageCode().hashCode(); result = prime * result + o.getText().hashCode(); return result; }
protected static Map<String, MonolingualTextValue> constructTermMap(List<MonolingualTextValue> terms) { Map<String, MonolingualTextValue> map = new HashMap<>(); for(MonolingualTextValue term : terms) { String language = term.getLanguageCode(); if(map.containsKey(language)) { throw new IllegalArgumentException("Multiple terms provided for the same language."); } map.put(language, toTerm(term)); } return map; }
@Override public WikidataValue visit(MonolingualTextValue value) { return WikidataValue.forString(value.getText()); }
/** * 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(MonolingualTextValue o) { int result; result = o.getLanguageCode().hashCode(); result = prime * result + o.getText().hashCode(); return result; }
private static Map<String, List<MonolingualTextValue>> constructTermListMap(List<MonolingualTextValue> terms) { Map<String, List<MonolingualTextValue>> map = new HashMap<>(); for(MonolingualTextValue term : terms) { String language = term.getLanguageCode(); // We need to make sure the terms are of the right type, otherwise they will not // be serialized correctly. List<MonolingualTextValue> aliases = map.computeIfAbsent(language, (l) -> new ArrayList<>()); aliases.add(toTerm(term)); } return map; }
/** * 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(); } }