Search in sources :

Example 1 with WbStatementGroupExpr

use of org.openrefine.wikidata.schema.WbStatementGroupExpr in project OpenRefine by OpenRefine.

the class SchemaPropertyExtractor method getAllProperties.

public Set<PropertyIdValue> getAllProperties(WikibaseSchema schema) {
    Set<PropertyIdValue> properties = new HashSet<>();
    List<WbEntityDocumentExpr> entityDocumentExprs = schema.getEntityDocumentExpressions();
    for (WbEntityDocumentExpr entityDocumentExpr : entityDocumentExprs) {
        List<WbStatementGroupExpr> statementGroups = entityDocumentExpr.getStatementGroups();
        for (WbStatementGroupExpr statementGroup : statementGroups) {
            WbExpression<? extends PropertyIdValue> statementGroupProperty = statementGroup.getProperty();
            if (statementGroupProperty instanceof WbPropConstant) {
                properties.add(Datamodel.makeWikidataPropertyIdValue(((WbPropConstant) statementGroupProperty).getPid()));
            }
            List<WbStatementExpr> statementExprs = statementGroup.getStatements();
            for (WbStatementExpr statementExpr : statementExprs) {
                List<WbSnakExpr> snakExprs = new ArrayList<>(statementExpr.getQualifiers());
                List<WbReferenceExpr> referenceExprs = statementExpr.getReferences();
                for (WbReferenceExpr referenceExpr : referenceExprs) {
                    snakExprs.addAll(referenceExpr.getSnaks());
                }
                for (WbSnakExpr snakExpr : snakExprs) {
                    WbExpression<? extends PropertyIdValue> qualifierProperty = snakExpr.getProp();
                    if (qualifierProperty instanceof WbPropConstant) {
                        properties.add(Datamodel.makeWikidataPropertyIdValue(((WbPropConstant) qualifierProperty).getPid()));
                    }
                }
            }
        }
    }
    return properties;
}
Also used : WbSnakExpr(org.openrefine.wikidata.schema.WbSnakExpr) ArrayList(java.util.ArrayList) WbReferenceExpr(org.openrefine.wikidata.schema.WbReferenceExpr) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) WbStatementGroupExpr(org.openrefine.wikidata.schema.WbStatementGroupExpr) WbStatementExpr(org.openrefine.wikidata.schema.WbStatementExpr) WbEntityDocumentExpr(org.openrefine.wikidata.schema.WbEntityDocumentExpr) WbPropConstant(org.openrefine.wikidata.schema.WbPropConstant) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 WbEntityDocumentExpr (org.openrefine.wikidata.schema.WbEntityDocumentExpr)1 WbPropConstant (org.openrefine.wikidata.schema.WbPropConstant)1 WbReferenceExpr (org.openrefine.wikidata.schema.WbReferenceExpr)1 WbSnakExpr (org.openrefine.wikidata.schema.WbSnakExpr)1 WbStatementExpr (org.openrefine.wikidata.schema.WbStatementExpr)1 WbStatementGroupExpr (org.openrefine.wikidata.schema.WbStatementGroupExpr)1 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)1