Search in sources :

Example 1 with MonolingualTextValue

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);
    }
}
Also used : NewEntityNotCreatedYetException(org.openrefine.wikidata.schema.exceptions.NewEntityNotCreatedYetException) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) DataObjectFactoryImpl(org.wikidata.wdtk.datamodel.implementation.DataObjectFactoryImpl) ReconMediaInfoIdValue(org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Set(java.util.Set) ReconPropertyIdValue(org.openrefine.wikidata.schema.entityvalues.ReconPropertyIdValue) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) Collectors(java.util.stream.Collectors) MediaInfoIdValue(org.wikidata.wdtk.datamodel.interfaces.MediaInfoIdValue) StatementUpdate(org.wikidata.wdtk.datamodel.interfaces.StatementUpdate) List(java.util.List) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) ReconItemIdValue(org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue) ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) Datamodel(org.wikidata.wdtk.datamodel.helpers.Datamodel) DatamodelConverter(org.wikidata.wdtk.datamodel.helpers.DatamodelConverter) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) MonolingualTextValue(org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue) NewEntityNotCreatedYetException(org.openrefine.wikidata.schema.exceptions.NewEntityNotCreatedYetException) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) MonolingualTextValue(org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue) StatementEdit(org.openrefine.wikidata.updates.StatementEdit)

Example 2 with MonolingualTextValue

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");
    }
}
Also used : MonolingualTextValue(org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue)

Example 3 with MonolingualTextValue

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;
        }
    }
}
Also used : MonolingualTextValue(org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 4 with MonolingualTextValue

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());
    }
}
Also used : MonolingualTextValue(org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue)

Example 5 with MonolingualTextValue

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MonolingualTextValue(org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue)

Aggregations

MonolingualTextValue (org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue)23 Test (org.testng.annotations.Test)13 ArrayList (java.util.ArrayList)6 List (java.util.List)6 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 TermedStatementEntityEdit (org.openrefine.wikidata.updates.TermedStatementEntityEdit)4 Datamodel (org.wikidata.wdtk.datamodel.helpers.Datamodel)4 ItemDocument (org.wikidata.wdtk.datamodel.interfaces.ItemDocument)4 ItemIdValue (org.wikidata.wdtk.datamodel.interfaces.ItemIdValue)4 MediaInfoIdValue (org.wikidata.wdtk.datamodel.interfaces.MediaInfoIdValue)4 StatementUpdate (org.wikidata.wdtk.datamodel.interfaces.StatementUpdate)4 Collections (java.util.Collections)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 WikidataRefineTest (org.openrefine.wikidata.testing.WikidataRefineTest)3 TermedStatementEntityEditBuilder (org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder)3 EntityDocument (org.wikidata.wdtk.datamodel.interfaces.EntityDocument)3 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)3 MediaInfoDocument (org.wikidata.wdtk.datamodel.interfaces.MediaInfoDocument)3