private void countCooccurringProperties(ItemDocument itemDocument, UsageRecord usageRecord, PropertyIdValue thisPropertyIdValue) { for (StatementGroup sg : itemDocument.getStatementGroups()) { if (!sg.getProperty().equals(thisPropertyIdValue)) { if (!usageRecord.propertyCoCounts.containsKey(sg.getProperty())) { usageRecord.propertyCoCounts.put(sg.getProperty(), 1); } else { usageRecord.propertyCoCounts .put(sg.getProperty(), usageRecord.propertyCoCounts .get(sg.getProperty()) + 1); } } } }
private void countCooccurringProperties(ItemDocument itemDocument, UsageRecord usageRecord, PropertyIdValue thisPropertyIdValue) { for (StatementGroup sg : itemDocument.getStatementGroups()) { if (!sg.getProperty().equals(thisPropertyIdValue)) { if (!usageRecord.propertyCoCounts.containsKey(sg.getProperty())) { usageRecord.propertyCoCounts.put(sg.getProperty(), 1); } else { usageRecord.propertyCoCounts .put(sg.getProperty(), usageRecord.propertyCoCounts .get(sg.getProperty()) + 1); } } } }
/** * Returns the {@link StatementGroup} for the given property, or null if * there are no statements for this property. This is a convenience method * for accessing the data that can be obtained via * {@link #getStatementGroups()}. * * @param propertyIdValue * the property to search for * @return {@link StatementGroup} or null */ default StatementGroup findStatementGroup(PropertyIdValue propertyIdValue) { for (StatementGroup sg : getStatementGroups()) { if (propertyIdValue.equals(sg.getProperty())) { return sg; } } return null; }
/** * Returns the {@link StatementGroup} for the given property, or null if * there are no statements for this property. This is a convenience method * for accessing the data that can be obtained via * {@link #getStatementGroups()}. * * @param propertyIdValue * the property to search for * @return {@link StatementGroup} or null */ default StatementGroup findStatementGroup(PropertyIdValue propertyIdValue) { for (StatementGroup sg : getStatementGroups()) { if (propertyIdValue.equals(sg.getProperty())) { return sg; } } return null; }
/** * Finds the {@link StatementGroup} for the given property in a document. * * @param pid * the property to look for * @param document * the document to search * @return the {@link StatementGroup} with this property, or null if there * is none */ protected static StatementGroup findStatementGroup(PropertyIdValue pid, StatementDocument document) { for (StatementGroup sg : document.getStatementGroups()) { if (pid.equals(sg.getProperty())) { return sg; } } return null; }
/** * Finds the {@link StatementGroup} for the given property in a document. * * @param pid * the property to look for * @param document * the document to search * @return the {@link StatementGroup} with this property, or null if there * is none */ protected static StatementGroup findStatementGroup(PropertyIdValue pid, StatementDocument document) { for (StatementGroup sg : document.getStatementGroups()) { if (pid.equals(sg.getProperty())) { return sg; } } return null; }
private List<StatementGroup> filterStatementGroups(List<StatementGroup> statementGroups) { if (filter.getPropertyFilter() == null) { return statementGroups; } if (filter.getPropertyFilter().isEmpty()) { return Collections.emptyList(); } List<StatementGroup> output = new ArrayList<>(statementGroups.size()); for(StatementGroup statementGroup : statementGroups) { if(filter.getPropertyFilter().contains(statementGroup.getProperty())) { output.add(statementGroup); } } return output; }
private List<StatementGroup> filterStatementGroups(List<StatementGroup> statementGroups) { if (filter.getPropertyFilter() == null) { return statementGroups; } if (filter.getPropertyFilter().isEmpty()) { return Collections.emptyList(); } List<StatementGroup> output = new ArrayList<>(statementGroups.size()); for(StatementGroup statementGroup : statementGroups) { if(filter.getPropertyFilter().contains(statementGroup.getProperty())) { output.add(statementGroup); } } return output; }
/** * Counts each property for which there is a statement in the given item * document, ignoring the property thisPropertyIdValue to avoid properties * counting themselves. * * @param statementDocument * @param usageRecord * @param thisPropertyIdValue */ private void countCooccurringProperties( StatementDocument statementDocument, UsageRecord usageRecord, PropertyIdValue thisPropertyIdValue) { for (StatementGroup sg : statementDocument.getStatementGroups()) { if (!sg.getProperty().equals(thisPropertyIdValue)) { Integer propertyId = getNumId(sg.getProperty().getId(), false); if (!usageRecord.propertyCoCounts.containsKey(propertyId)) { usageRecord.propertyCoCounts.put(propertyId, 1); } else { usageRecord.propertyCoCounts.put(propertyId, usageRecord.propertyCoCounts.get(propertyId) + 1); } } } }
/** * Returns the {@link StatementGroup} for the given property, or null if * there are no statements for this property. Only the string id of the * property is compared, not the site id. This is useful in situations where * all data is known to come from a single site. * <p> * This is a convenience method for accessing the data that can be obtained * via {@link #getStatementGroups()}. * * @param propertyId * the property to search for * @return {@link StatementGroup} or null */ default StatementGroup findStatementGroup(String propertyId) { for (StatementGroup sg : getStatementGroups()) { if (propertyId.equals(sg.getProperty().getId())) { return sg; } } return null; }
/** * Copies a list of {@link StatementGroup} objects. * * @param statementGroups * object to copy * @return the copied object */ private List<StatementGroup> copyStatementGroups(List<StatementGroup> statementGroups) { if (filter.excludeAllProperties()) { return Collections.emptyList(); } List<StatementGroup> result = new ArrayList<>(statementGroups.size()); for (StatementGroup statementGroup : statementGroups) { if (filter.includePropertyId(statementGroup.getProperty())) { result.add(copy(statementGroup)); } } return result; }
/** * Copies a list of {@link StatementGroup} objects. * * @param statementGroups * object to copy * @return the copied object */ private List<StatementGroup> copyStatementGroups(List<StatementGroup> statementGroups) { if (filter.excludeAllProperties()) { return Collections.emptyList(); } List<StatementGroup> result = new ArrayList<>(statementGroups.size()); for (StatementGroup statementGroup : statementGroups) { if (filter.includePropertyId(statementGroup.getProperty())) { result.add(copy(statementGroup)); } } return result; }
@Override public void processItemDocument(ItemDocument itemDocument) { for (StatementGroup sg : itemDocument.getStatementGroups()) { if (COORD_PROPERTY.equals(sg.getProperty().getId())) { for (Statement s : sg) { countCoordinateStatement(s, itemDocument); } } } }
/** * Returns the {@link StatementGroup} for the given property, or null if * there are no statements for this property. Only the string id of the * property is compared, not the site id. This is useful in situations where * all data is known to come from a single site. * <p> * This is a convenience method for accessing the data that can be obtained * via {@link #getStatementGroups()}. * * @param propertyId * the property to search for * @return {@link StatementGroup} or null */ default StatementGroup findStatementGroup(String propertyId) { for (StatementGroup sg : getStatementGroups()) { if (propertyId.equals(sg.getProperty().getId())) { return sg; } } return null; }
/** * Constructor. * * @param id * the identifier of the subject of this document * @param claims * the statement groups contained in this document * @param revisionId * the id of the last revision of this document */ StatementDocumentImpl( EntityIdValue id, List<StatementGroup> claims, long revisionId) { super(id, revisionId); this.claims = new HashMap<>(); if(claims != null) { for(StatementGroup group : claims) { EntityIdValue otherId = group.getSubject(); otherId.getIri(); Validate.isTrue(group.getSubject().equals(id), "Subject for the statement group and the document are different: "+otherId.toString()+" vs "+id.toString()); this.claims.put(group.getProperty().getId(), group.getStatements()); } } }
@Override public void processItemDocument(ItemDocument itemDocument) { for (StatementGroup sg : itemDocument.getStatementGroups()) { if (COORD_PROPERTY.equals(sg.getProperty().getId())) { for (Statement s : sg.getStatements()) { countCoordinateStatement(s, itemDocument); } } } }
/** * Returns true if the given document should be included in the * serialization. * * @param itemDocument * the document to check * @return true if the document should be serialized */ private boolean includeDocument(ItemDocument itemDocument) { for (StatementGroup sg : itemDocument.getStatementGroups()) { // "P19" is "place of birth" on Wikidata if (!"P19".equals(sg.getProperty().getId())) { continue; } for (Statement s : sg) { if (s.getMainSnak() instanceof ValueSnak) { Value v = s.getValue(); // "Q1731" is "Dresden" on Wikidata if (v instanceof ItemIdValue && "Q1731".equals(((ItemIdValue) v).getId())) { return true; } } } } return false; } }
void writeStatements(Resource subject, StatementDocument statementDocument) throws RDFHandlerException { for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { IRI property = this.rdfWriter.getUri(Vocabulary.getPropertyUri( statementGroup.getProperty(), PropertyContext.STATEMENT)); for (Statement statement : statementGroup) { this.rdfWriter.writeTripleUriObject(subject, property, Vocabulary.getStatementUri(statement)); } } for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { for (Statement statement : statementGroup) { writeStatement(statement); } writeBestRankTriples(); } }
void writeStatements(Resource subject, StatementDocument statementDocument) throws RDFHandlerException { for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { URI property = this.rdfWriter.getUri(Vocabulary.getPropertyUri( statementGroup.getProperty(), PropertyContext.STATEMENT)); for (Statement statement : statementGroup.getStatements()) { this.rdfWriter.writeTripleUriObject(subject, property, Vocabulary.getStatementUri(statement)); } } for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { for (Statement statement : statementGroup.getStatements()) { writeStatement(statement); } } }
/** * Count the statements and property uses of an item or property document. * * @param usageStatistics * statistics object to store counters in * @param statementDocument * document to count the statements of */ protected void countStatements(UsageStatistics usageStatistics, StatementDocument statementDocument) { // Count Statement data: for (StatementGroup sg : statementDocument.getStatementGroups()) { // Count Statements: usageStatistics.countStatements += sg.size(); // Count uses of properties in Statements: countPropertyMain(usageStatistics, sg.getProperty(), sg.size()); for (Statement s : sg) { for (SnakGroup q : s.getQualifiers()) { countPropertyQualifier(usageStatistics, q.getProperty(), q.size()); } for (Reference r : s.getReferences()) { usageStatistics.countReferencedStatements++; for (SnakGroup snakGroup : r.getSnakGroups()) { countPropertyReference(usageStatistics, snakGroup.getProperty(), snakGroup.size()); } } } } }