Search in sources :

Example 1 with Reference

use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.

the class RestrictedPositionScrutinizer method scrutinize.

@Override
public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {
    if (!added) {
        // not scrutinizing deleted statements
        return;
    }
    // Skip the main snak
    scrutinize(statement.getClaim().getMainSnak(), entityId, SnakPosition.MAINSNAK, added);
    // Qualifiers
    scrutinizeSnakSet(statement.getClaim().getAllQualifiers(), entityId, SnakPosition.QUALIFIER, added);
    // References
    for (Reference ref : statement.getReferences()) {
        scrutinizeSnakSet(ref.getAllSnaks(), entityId, SnakPosition.REFERENCE, added);
    }
}
Also used : Reference(org.wikidata.wdtk.datamodel.interfaces.Reference)

Example 2 with Reference

use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.

the class SnakOnlyStatementMerger method mergeReferences.

public List<Reference> mergeReferences(List<Reference> existing, List<Reference> added) {
    List<Reference> allReferences = new ArrayList<>(existing);
    Set<Reference> seenReferences = new HashSet<>(existing);
    for (Reference reference : added) {
        if (!seenReferences.contains(reference)) {
            seenReferences.add(reference);
            allReferences.add(reference);
        }
    }
    return allReferences;
}
Also used : Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 3 with Reference

use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.

the class WbStatementExpr method evaluate.

public StatementEdit evaluate(ExpressionContext ctxt, EntityIdValue subject, PropertyIdValue propertyId) throws SkipSchemaExpressionException {
    Snak mainSnak = null;
    if (mainSnakValueExpr != null) {
        Value mainSnakValue = mainSnakValueExpr.evaluate(ctxt);
        mainSnak = Datamodel.makeValueSnak(propertyId, mainSnakValue);
    } else {
        // hack to make sure we have a non-null snak
        mainSnak = Datamodel.makeNoValueSnak(propertyId);
    }
    // evaluate qualifiers
    List<Snak> qualifiers = new ArrayList<Snak>(getQualifiers().size());
    for (WbSnakExpr qExpr : getQualifiers()) {
        try {
            qualifiers.add(qExpr.evaluate(ctxt));
        } catch (SkipSchemaExpressionException e) {
            QAWarning warning = new QAWarning("ignored-qualifiers", null, QAWarning.Severity.INFO, 1);
            warning.setProperty("example_entity", subject);
            warning.setProperty("example_property_entity", mainSnak.getPropertyId());
            ctxt.addWarning(warning);
        }
    }
    List<SnakGroup> groupedQualifiers = groupSnaks(qualifiers);
    Claim claim = Datamodel.makeClaim(subject, mainSnak, groupedQualifiers);
    // evaluate references
    List<Reference> references = new ArrayList<Reference>();
    for (WbReferenceExpr rExpr : getReferences()) {
        try {
            references.add(rExpr.evaluate(ctxt));
        } catch (SkipSchemaExpressionException e) {
            QAWarning warning = new QAWarning("ignored-references", null, QAWarning.Severity.INFO, 1);
            warning.setProperty("example_entity", subject);
            warning.setProperty("example_property_entity", mainSnak.getPropertyId());
            ctxt.addWarning(warning);
        }
    }
    StatementRank rank = StatementRank.NORMAL;
    return new StatementEdit(Datamodel.makeStatement(claim, references, rank, ""), merger, mode);
}
Also used : Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) SkipSchemaExpressionException(org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) StatementRank(org.wikidata.wdtk.datamodel.interfaces.StatementRank) ArrayList(java.util.ArrayList) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) Value(org.wikidata.wdtk.datamodel.interfaces.Value) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) QAWarning(org.openrefine.wikidata.qa.QAWarning) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim)

Example 4 with Reference

use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.

the class SnakScrutinizer method scrutinize.

@Override
public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {
    // Main snak
    scrutinize(statement.getClaim().getMainSnak(), entityId, added);
    // Qualifiers
    scrutinizeSnakSet(statement.getClaim().getAllQualifiers(), entityId, added);
    // References
    for (Reference ref : statement.getReferences()) {
        scrutinizeSnakSet(ref.getAllSnaks(), entityId, added);
    }
}
Also used : Reference(org.wikidata.wdtk.datamodel.interfaces.Reference)

Example 5 with Reference

use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.

the class UnsourcedScrutinizer method scrutinize.

@Override
public void scrutinize(TermedStatementEntityEdit update) {
    for (Statement statement : update.getAddedStatements()) {
        PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
        List<Statement> constraintDefinitions = _fetcher.getConstraintsByType(pid, citationNeededConstraintQid);
        List<Reference> referenceList = statement.getReferences();
        if (referenceList.isEmpty()) {
            if (!constraintDefinitions.isEmpty()) {
                QAWarning issue = new QAWarning(constraintItemType, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
                issue.setProperty("property_entity", pid);
                issue.setProperty("example_entity", update.getEntityId());
                addIssue(issue);
            } else {
                warning(generalType);
            }
        }
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Aggregations

Reference (org.wikidata.wdtk.datamodel.interfaces.Reference)12 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)7 Claim (org.wikidata.wdtk.datamodel.interfaces.Claim)6 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)6 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)5 ArrayList (java.util.ArrayList)4 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)4 HashSet (java.util.HashSet)2 QAWarning (org.openrefine.wikidata.qa.QAWarning)2 StatementEdit (org.openrefine.wikidata.updates.StatementEdit)2 Test (org.testng.annotations.Test)2 NoValueSnak (org.wikidata.wdtk.datamodel.interfaces.NoValueSnak)2 SomeValueSnak (org.wikidata.wdtk.datamodel.interfaces.SomeValueSnak)2 Value (org.wikidata.wdtk.datamodel.interfaces.Value)2 ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1