use of org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue in project OpenRefine by OpenRefine.
the class ReconEntityRewriter method rewrite.
/**
* Rewrite an edit, replacing references to all entities already
* created by their fresh identifiers. The subject id might not have been
* created already, in which case it will be left untouched. All the other
* entities need to have been created already.
*
* @param edit
* the edit to rewrite
* @return
* the rewritten update
* @throws NewEntityNotCreatedYetException
* if any non-subject entity had not been created yet
*/
public TermedStatementEntityEdit rewrite(TermedStatementEntityEdit edit) throws NewEntityNotCreatedYetException {
try {
EntityIdValue subject = (EntityIdValue) copyValue(edit.getEntityId());
Set<MonolingualTextValue> labels = edit.getLabels().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> labelsIfNew = edit.getLabelsIfNew().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> descriptions = edit.getDescriptions().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> descriptionsIfNew = edit.getDescriptionsIfNew().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> aliases = edit.getAliases().stream().map(l -> copy(l)).collect(Collectors.toSet());
List<StatementEdit> addedStatements = edit.getStatementEdits().stream().map(l -> copy(l)).collect(Collectors.toList());
return new TermedStatementEntityEdit(subject, addedStatements, labels, labelsIfNew, descriptions, descriptionsIfNew, aliases);
} catch (MissingEntityIdFound e) {
throw new NewEntityNotCreatedYetException(e.value);
}
}
use of org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue in project OpenRefine by OpenRefine.
the class QuickStatementsExporter method translateNameDescr.
protected void translateNameDescr(String qid, Set<MonolingualTextValue> values, String prefix, EntityIdValue id, Writer writer) throws IOException {
for (MonolingualTextValue value : values) {
writer.write(qid + "\t");
writer.write(prefix);
writer.write(value.getLanguageCode());
writer.write("\t\"");
writer.write(value.getText());
writer.write("\"\n");
}
}
use of org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue in project OpenRefine by OpenRefine.
the class CommonDescriptionScrutinizer method checkLabel.
// Description are expected to be more specific than labels.
protected void checkLabel(TermedStatementEntityEdit update, String descText, String lang) {
Set<MonolingualTextValue> labels = update.getLabels();
// merge
labels.addAll(update.getLabelsIfNew());
for (MonolingualTextValue label : labels) {
String labelText = label.getText();
if (labelText == null) {
continue;
}
labelText = labelText.trim();
if (labelText.equals(descText)) {
QAWarning issue = new QAWarning(descIdenticalWithLabel, null, QAWarning.Severity.WARNING, 1);
issue.setProperty("example_entity", update.getEntityId());
issue.setProperty("description", descText);
issue.setProperty("lang", lang);
issue.setProperty("label_lang", label.getLanguageCode());
addIssue(issue);
break;
}
}
}
use of org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue in project OpenRefine by OpenRefine.
the class DescriptionScrutinizer method scrutinize.
@Override
public void scrutinize(TermedStatementEntityEdit update) {
Set<MonolingualTextValue> descriptions = update.getDescriptions();
// merge
descriptions.addAll(update.getDescriptionsIfNew());
for (MonolingualTextValue description : descriptions) {
String descText = description.getText();
if (descText == null) {
continue;
}
descText = descText.trim();
if (descText.length() == 0) {
// avoid NullPointerException
continue;
}
scrutinize(update, descText, description.getLanguageCode());
}
}
use of org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue in project OpenRefine by OpenRefine.
the class TermedStatementEntityEdit method constructTermListMap.
protected Map<String, List<MonolingualTextValue>> constructTermListMap(Collection<MonolingualTextValue> mltvs) {
Map<String, List<MonolingualTextValue>> result = new HashMap<>();
for (MonolingualTextValue mltv : mltvs) {
List<MonolingualTextValue> values = result.get(mltv.getLanguageCode());
if (values == null) {
values = new LinkedList<>();
result.put(mltv.getLanguageCode(), values);
}
values.add(mltv);
}
return result;
}
Aggregations