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); } } } }
@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 the unique {@link Statement} for the given property, or null if * there are zero or many 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 Statement} or null */ default Statement findStatement(PropertyIdValue propertyIdValue) { StatementGroup statementGroup = findStatementGroup(propertyIdValue); return (statementGroup != null && statementGroup.size() == 1) ? statementGroup.getStatements().get(0) : 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()); } } }
/** * 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()); } } } } }
/** * Returns a hash code for the given object. * * @see java.lang.Object#hashCode() * @param o * the object to create a hash for * @return the hash code of the object */ public static int hashCode(StatementGroup o) { return o.getStatements().hashCode(); }
/** * Helper method that extracts the list of all {@link ItemIdValue} objects * that are used as values in the given statement group. * * @param statementGroup * the {@link StatementGroup} to extract the data from * @return the list of values */ private List<EntityIdValue> getItemIdValueList(StatementGroup statementGroup) { List<EntityIdValue> result = new ArrayList<>(statementGroup.size()); for (Statement s : statementGroup) { Value v = s.getValue(); if (v instanceof EntityIdValue) { result.add((EntityIdValue) v); } } return result; }
entityStatistics.countStatements += sg.size(); PropertyRecord propertyRecord = getPropertyRecord(sg.getProperty()); propertyRecord.itemCount++; countCooccurringProperties(statementDocument, propertyRecord, sg.getProperty());
/** * 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()); } } }
/** * Returns a hash code for the given object. * * @see java.lang.Object#hashCode() * @param o * the object to create a hash for * @return the hash code of the object */ public static int hashCode(StatementGroup o) { return o.getStatements().hashCode(); }
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); } } } }
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); } } }
PropertyRecord propertyRecord = getPropertyRecord(sg.getProperty()); propertyRecord.itemCount++; propertyRecord.statementCount += sg.size(); boolean isInstanceOf = "P31".equals(sg.getProperty().getId()); boolean isSubclassOf = "P279".equals(sg.getProperty().getId()); if (isSubclassOf && classRecord == null) { classRecord = getClassRecord(itemDocument.getEntityId()); sg.getProperty());
/** * Returns true if the parameters are two {@link StatementGroup} objects * with exactly the same data. It does not matter if they are different * implementations of the interface as long as their content is the same. * Note that this includes the statement id, so that two statement objects * that "say the same thing" might still be unequal if they have different * ids. * * @param o1 * the first object to compare * @param o2 * the second object to compare * @return true if both objects are equal */ public static boolean equalsStatementGroup(StatementGroup o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } return o2 instanceof StatementGroup && o1.getStatements().equals(((StatementGroup) o2).getStatements()); }
/** * Returns the unique {@link Statement} for the given property, or null if * there are zero or many 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 Statement} or null */ default Statement findStatement(PropertyIdValue propertyIdValue) { StatementGroup statementGroup = findStatementGroup(propertyIdValue); return (statementGroup != null && statementGroup.size() == 1) ? statementGroup.getStatements().get(0) : 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; }
usageStatistics.countStatements += sg.getStatements().size(); countPropertyMain(usageStatistics, sg.getProperty(), sg .getStatements().size()); for (Statement s : sg.getStatements()) { for (SnakGroup q : s.getClaim().getQualifiers()) { countPropertyQualifier(usageStatistics, q.getProperty(), q
/** * Returns true if the parameters are two {@link StatementGroup} objects * with exactly the same data. It does not matter if they are different * implementations of the interface as long as their content is the same. * Note that this includes the statement id, so that two statement objects * that "say the same thing" might still be unequal if they have different * ids. * * @param o1 * the first object to compare * @param o2 * the second object to compare * @return true if both objects are equal */ public static boolean equalsStatementGroup(StatementGroup o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } return o2 instanceof StatementGroup && o1.getStatements().equals(((StatementGroup) o2).getStatements()); }
/** * Returns the unique {@link Statement} for the given property, or null if * there are zero or many 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 Statement} or null */ default Statement findStatement(String propertyId) { StatementGroup statementGroup = findStatementGroup(propertyId); return (statementGroup != null && statementGroup.size() == 1) ? statementGroup.getStatements().get(0) : 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; }