/** * Returns an iterator that provides access to all statements, without * considering the statement groups. The order of statements is preserved. * * @return iterator over all statements */ default Iterator<Statement> getAllStatements() { return new NestedIterator<>(getStatementGroups()); }
protected static String toStringForStatementDocument(StatementDocument o) { StringBuilder sb = new StringBuilder(); sb.append("\n===Statements===\n"); for (StatementGroup sg : o.getStatementGroups()) { sb.append(toString(sg)); } sb.append("\n===End of statements===\n"); return sb.toString(); }
/** * Returns an iterator that provides access to all statements, without * considering the statement groups. The order of statements is preserved. * * @return iterator over all statements */ default Iterator<Statement> getAllStatements() { return new NestedIterator<>(getStatementGroups()); }
protected static String toStringForStatementDocument(StatementDocument o) { StringBuilder sb = new StringBuilder(); sb.append("\n===Statements===\n"); for (StatementGroup sg : o.getStatementGroups()) { sb.append(toString(sg)); } sb.append("\n===End of statements===\n"); return sb.toString(); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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); } } } }
void writeSimpleStatements(Resource subject, StatementDocument statementDocument) { for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { for (Statement statement : statementGroup) { if (statement.getQualifiers().size() == 0) { this.snakRdfConverter.setSnakContext(subject, PropertyContext.DIRECT); statement.getMainSnak() .accept(this.snakRdfConverter); } } } }
for (Statement statement : deleteStatements) { boolean found = false; for (StatementGroup sg : currentDocument.getStatementGroups()) { if (!sg.getProperty().equals(statement.getMainSnak().getPropertyId())) { continue;
/** * Marks a given list of statements for insertion into the current document. * Inserted statements can have an id if they should update an existing * statement, or use an empty string as id if they should be added. The * method removes duplicates and avoids unnecessary modifications by * checking the current content of the given document before marking * statements for being written. * * @param currentDocument * the document with the current statements * @param addStatements * the list of new statements to be added */ protected void markStatementsForInsertion( StatementDocument currentDocument, List<Statement> addStatements) { for (Statement statement : addStatements) { addStatement(statement, true); } for (StatementGroup sg : currentDocument.getStatementGroups()) { if (this.toKeep.containsKey(sg.getProperty())) { for (Statement statement : sg) { if (!this.toDelete.contains(statement.getStatementId())) { addStatement(statement, false); } } } } }
/** * Marks a given list of statements for insertion into the current document. * Inserted statements can have an id if they should update an existing * statement, or use an empty string as id if they should be added. The * method removes duplicates and avoids unnecessary modifications by * checking the current content of the given document before marking * statements for being written. * * @param currentDocument * the document with the current statements * @param addStatements * the list of new statements to be added */ protected void markStatementsForInsertion( StatementDocument currentDocument, List<Statement> addStatements) { for (Statement statement : addStatements) { addStatement(statement, true); } for (StatementGroup sg : currentDocument.getStatementGroups()) { if (this.toKeep.containsKey(sg.getProperty())) { for (Statement statement : sg) { if (!this.toDelete.contains(statement.getStatementId())) { addStatement(statement, 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); } } }
void writeSimpleStatements(Resource subject, StatementDocument statementDocument) { for (StatementGroup statementGroup : statementDocument .getStatementGroups()) { for (Statement statement : statementGroup.getStatements()) { if (statement.getClaim().getQualifiers().size() == 0) { this.snakRdfConverter.setSnakContext(subject, PropertyContext.SIMPLE_CLAIM); statement.getClaim().getMainSnak() .accept(this.snakRdfConverter); } } } }
StatementDocument statementDocument) { for (StatementGroup sg : statementDocument.getStatementGroups()) {
/** * 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()); } } } } }