Search in sources :

Example 6 with PropertyIdValue

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

the class QualifierCompatibilityScrutinizer method scrutinize.

@Override
public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {
    if (!added) {
        // not scrutinizing deleted statements
        return;
    }
    PropertyIdValue statementProperty = statement.getClaim().getMainSnak().getPropertyId();
    Set<PropertyIdValue> qualifiers = statement.getClaim().getQualifiers().stream().map(e -> e.getProperty()).collect(Collectors.toSet());
    Set<PropertyIdValue> missingQualifiers = mandatoryQualifiers(statementProperty).stream().filter(p -> !qualifiers.contains(p)).collect(Collectors.toSet());
    Set<PropertyIdValue> disallowedQualifiers = qualifiers.stream().filter(p -> !qualifierIsAllowed(statementProperty, p)).collect(Collectors.toSet());
    for (PropertyIdValue missing : missingQualifiers) {
        QAWarning issue = new QAWarning(missingMandatoryQualifiersType, statementProperty.getId() + "-" + missing.getId(), QAWarning.Severity.WARNING, 1);
        issue.setProperty("statement_property_entity", statementProperty);
        issue.setProperty("missing_property_entity", missing);
        issue.setProperty("example_item_entity", entityId);
        addIssue(issue);
    }
    for (PropertyIdValue disallowed : disallowedQualifiers) {
        QAWarning issue = new QAWarning(disallowedQualifiersType, statementProperty.getId() + "-" + disallowed.getId(), QAWarning.Severity.WARNING, 1);
        issue.setProperty("statement_property_entity", statementProperty);
        issue.setProperty("disallowed_property_entity", disallowed);
        issue.setProperty("example_item_entity", entityId);
        addIssue(issue);
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) Set(java.util.Set) HashMap(java.util.HashMap) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) Collectors(java.util.stream.Collectors) QAWarning(org.openrefine.wikidata.qa.QAWarning) Value(org.wikidata.wdtk.datamodel.interfaces.Value) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 7 with PropertyIdValue

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

the class FormatScrutinizer method scrutinize.

@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
    if (snak instanceof ValueSnak && ((ValueSnak) snak).getValue() instanceof StringValue) {
        String value = ((StringValue) ((ValueSnak) snak).getValue()).getString();
        PropertyIdValue pid = snak.getPropertyId();
        Set<Pattern> patterns = getPattern(pid);
        for (Pattern pattern : patterns) {
            if (!pattern.matcher(value).matches()) {
                if (added) {
                    QAWarning issue = new QAWarning(type, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
                    issue.setProperty("property_entity", pid);
                    issue.setProperty("regex", pattern.toString());
                    issue.setProperty("example_value", value);
                    issue.setProperty("example_item_entity", entityId);
                    addIssue(issue);
                } else {
                    info("remove-statements-with-invalid-format");
                }
            }
        }
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Pattern(java.util.regex.Pattern) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) StringValue(org.wikidata.wdtk.datamodel.interfaces.StringValue) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 8 with PropertyIdValue

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

the class TermedStatementEntityEdit method toStatementUpdate.

/**
 * Generates the statement update given the current statement groups on the entity.
 * @param currentDocument
 * @return
 */
protected StatementUpdate toStatementUpdate(StatementDocument currentDocument) {
    Map<PropertyIdValue, List<StatementEdit>> groupedEdits = statements.stream().collect(Collectors.groupingBy(StatementEdit::getPropertyId));
    StatementUpdateBuilder builder = StatementUpdateBuilder.create(currentDocument.getEntityId());
    for (Entry<PropertyIdValue, List<StatementEdit>> entry : groupedEdits.entrySet()) {
        StatementGroupEdit statementGroupEdit = new StatementGroupEdit(entry.getValue());
        StatementGroup statementGroup = currentDocument.findStatementGroup(entry.getKey().getId());
        statementGroupEdit.contributeToStatementUpdate(builder, statementGroup);
    }
    return builder.build();
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) StatementGroup(org.wikidata.wdtk.datamodel.interfaces.StatementGroup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) StatementUpdateBuilder(org.wikidata.wdtk.datamodel.helpers.StatementUpdateBuilder)

Example 9 with PropertyIdValue

use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue 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 10 with PropertyIdValue

use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue 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

PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)36 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)17 QAWarning (org.openrefine.wikidata.qa.QAWarning)16 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)12 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)11 Value (org.wikidata.wdtk.datamodel.interfaces.Value)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)9 ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)9 List (java.util.List)8 Set (java.util.Set)6 Claim (org.wikidata.wdtk.datamodel.interfaces.Claim)6 Reference (org.wikidata.wdtk.datamodel.interfaces.Reference)6 Collectors (java.util.stream.Collectors)5 StatementEdit (org.openrefine.wikidata.updates.StatementEdit)5 Test (org.testng.annotations.Test)5 SkipSchemaExpressionException (org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException)4 TermedStatementEntityEdit (org.openrefine.wikidata.updates.TermedStatementEntityEdit)4