Search in sources :

Example 1 with StatementGroup

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

the class ConstraintFetcher method getConstraintStatements.

/**
 * Gets all the constraint statements for a given property
 *
 * @param pid
 *             the id of the property to retrieve the constraints for
 * @return the list of constraint statements
 */
private List<Statement> getConstraintStatements(PropertyIdValue pid) {
    PropertyDocument doc = (PropertyDocument) entityCache.get(pid);
    StatementGroup group = doc.findStatementGroup(wikibaseConstraintPid);
    if (group != null) {
        return group.getStatements().stream().filter(s -> s.getValue() != null && s.getValue() instanceof EntityIdValue).collect(Collectors.toList());
    } else {
        return Collections.emptyList();
    }
}
Also used : StatementRank(org.wikidata.wdtk.datamodel.interfaces.StatementRank) List(java.util.List) Stream(java.util.stream.Stream) PropertyDocument(org.wikidata.wdtk.datamodel.interfaces.PropertyDocument) EntityCache(org.openrefine.wikidata.utils.EntityCache) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) StatementGroup(org.wikidata.wdtk.datamodel.interfaces.StatementGroup) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) StatementGroup(org.wikidata.wdtk.datamodel.interfaces.StatementGroup) PropertyDocument(org.wikidata.wdtk.datamodel.interfaces.PropertyDocument)

Example 2 with StatementGroup

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

Aggregations

List (java.util.List)2 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)2 StatementGroup (org.wikidata.wdtk.datamodel.interfaces.StatementGroup)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 EntityCache (org.openrefine.wikidata.utils.EntityCache)1 StatementUpdateBuilder (org.wikidata.wdtk.datamodel.helpers.StatementUpdateBuilder)1 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)1 PropertyDocument (org.wikidata.wdtk.datamodel.interfaces.PropertyDocument)1 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)1 StatementRank (org.wikidata.wdtk.datamodel.interfaces.StatementRank)1