id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
161,300
Wikidata/Wikidata-Toolkit
wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/RdfConverter.java
RdfConverter.writeBestRankTriples
void writeBestRankTriples() { for (Resource resource : this.rankBuffer.getBestRankedStatements()) { try { this.rdfWriter.writeTripleUriObject(resource, RdfWriter.RDF_TYPE, RdfWriter.WB_BEST_RANK.toString()); } catch (RDFHandlerException e) { throw new RuntimeException(e.getMessage(), e); } } this.rankBuffer.clear(); }
java
void writeBestRankTriples() { for (Resource resource : this.rankBuffer.getBestRankedStatements()) { try { this.rdfWriter.writeTripleUriObject(resource, RdfWriter.RDF_TYPE, RdfWriter.WB_BEST_RANK.toString()); } catch (RDFHandlerException e) { throw new RuntimeException(e.getMessage(), e); } } this.rankBuffer.clear(); }
[ "void", "writeBestRankTriples", "(", ")", "{", "for", "(", "Resource", "resource", ":", "this", ".", "rankBuffer", ".", "getBestRankedStatements", "(", ")", ")", "{", "try", "{", "this", ".", "rdfWriter", ".", "writeTripleUriObject", "(", "resource", ",", "RdfWriter", ".", "RDF_TYPE", ",", "RdfWriter", ".", "WB_BEST_RANK", ".", "toString", "(", ")", ")", ";", "}", "catch", "(", "RDFHandlerException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}", "this", ".", "rankBuffer", ".", "clear", "(", ")", ";", "}" ]
Writes triples to determine the statements with the highest rank.
[ "Writes", "triples", "to", "determine", "the", "statements", "with", "the", "highest", "rank", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/RdfConverter.java#L351-L361
161,301
Wikidata/Wikidata-Toolkit
wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/RdfConverter.java
RdfConverter.getUriStringForRank
String getUriStringForRank(StatementRank rank) { switch (rank) { case NORMAL: return Vocabulary.WB_NORMAL_RANK; case PREFERRED: return Vocabulary.WB_PREFERRED_RANK; case DEPRECATED: return Vocabulary.WB_DEPRECATED_RANK; default: throw new IllegalArgumentException(); } }
java
String getUriStringForRank(StatementRank rank) { switch (rank) { case NORMAL: return Vocabulary.WB_NORMAL_RANK; case PREFERRED: return Vocabulary.WB_PREFERRED_RANK; case DEPRECATED: return Vocabulary.WB_DEPRECATED_RANK; default: throw new IllegalArgumentException(); } }
[ "String", "getUriStringForRank", "(", "StatementRank", "rank", ")", "{", "switch", "(", "rank", ")", "{", "case", "NORMAL", ":", "return", "Vocabulary", ".", "WB_NORMAL_RANK", ";", "case", "PREFERRED", ":", "return", "Vocabulary", ".", "WB_PREFERRED_RANK", ";", "case", "DEPRECATED", ":", "return", "Vocabulary", ".", "WB_DEPRECATED_RANK", ";", "default", ":", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "}" ]
Returns an URI which represents the statement rank in a triple. @param rank @return
[ "Returns", "an", "URI", "which", "represents", "the", "statement", "rank", "in", "a", "triple", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/RdfConverter.java#L494-L505
161,302
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/interfaces/WikimediaLanguageCodes.java
WikimediaLanguageCodes.fixLanguageCodeIfDeprecated
public static String fixLanguageCodeIfDeprecated(String wikimediaLanguageCode) { if (DEPRECATED_LANGUAGE_CODES.containsKey(wikimediaLanguageCode)) { return DEPRECATED_LANGUAGE_CODES.get(wikimediaLanguageCode); } else { return wikimediaLanguageCode; } }
java
public static String fixLanguageCodeIfDeprecated(String wikimediaLanguageCode) { if (DEPRECATED_LANGUAGE_CODES.containsKey(wikimediaLanguageCode)) { return DEPRECATED_LANGUAGE_CODES.get(wikimediaLanguageCode); } else { return wikimediaLanguageCode; } }
[ "public", "static", "String", "fixLanguageCodeIfDeprecated", "(", "String", "wikimediaLanguageCode", ")", "{", "if", "(", "DEPRECATED_LANGUAGE_CODES", ".", "containsKey", "(", "wikimediaLanguageCode", ")", ")", "{", "return", "DEPRECATED_LANGUAGE_CODES", ".", "get", "(", "wikimediaLanguageCode", ")", ";", "}", "else", "{", "return", "wikimediaLanguageCode", ";", "}", "}" ]
Translate a Wikimedia language code to its preferred value if this code is deprecated, or return it untouched if the string is not a known deprecated Wikimedia language code @param wikimediaLanguageCode the language code as used by Wikimedia @return the preferred language code corresponding to the original language code
[ "Translate", "a", "Wikimedia", "language", "code", "to", "its", "preferred", "value", "if", "this", "code", "is", "deprecated", "or", "return", "it", "untouched", "if", "the", "string", "is", "not", "a", "known", "deprecated", "Wikimedia", "language", "code" ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/interfaces/WikimediaLanguageCodes.java#L618-L624
161,303
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/EntityDocumentBuilder.java
EntityDocumentBuilder.withLabel
public T withLabel(String text, String languageCode) { withLabel(factory.getMonolingualTextValue(text, languageCode)); return getThis(); }
java
public T withLabel(String text, String languageCode) { withLabel(factory.getMonolingualTextValue(text, languageCode)); return getThis(); }
[ "public", "T", "withLabel", "(", "String", "text", ",", "String", "languageCode", ")", "{", "withLabel", "(", "factory", ".", "getMonolingualTextValue", "(", "text", ",", "languageCode", ")", ")", ";", "return", "getThis", "(", ")", ";", "}" ]
Adds an additional label to the constructed document. @param text the text of the label @param languageCode the language code of the label @return builder object to continue construction
[ "Adds", "an", "additional", "label", "to", "the", "constructed", "document", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/EntityDocumentBuilder.java#L123-L126
161,304
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/EntityDocumentBuilder.java
EntityDocumentBuilder.withDescription
public T withDescription(String text, String languageCode) { withDescription(factory.getMonolingualTextValue(text, languageCode)); return getThis(); }
java
public T withDescription(String text, String languageCode) { withDescription(factory.getMonolingualTextValue(text, languageCode)); return getThis(); }
[ "public", "T", "withDescription", "(", "String", "text", ",", "String", "languageCode", ")", "{", "withDescription", "(", "factory", ".", "getMonolingualTextValue", "(", "text", ",", "languageCode", ")", ")", ";", "return", "getThis", "(", ")", ";", "}" ]
Adds an additional description to the constructed document. @param text the text of the description @param languageCode the language code of the description @return builder object to continue construction
[ "Adds", "an", "additional", "description", "to", "the", "constructed", "document", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/EntityDocumentBuilder.java#L149-L152
161,305
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/EntityDocumentBuilder.java
EntityDocumentBuilder.withAlias
public T withAlias(String text, String languageCode) { withAlias(factory.getMonolingualTextValue(text, languageCode)); return getThis(); }
java
public T withAlias(String text, String languageCode) { withAlias(factory.getMonolingualTextValue(text, languageCode)); return getThis(); }
[ "public", "T", "withAlias", "(", "String", "text", ",", "String", "languageCode", ")", "{", "withAlias", "(", "factory", ".", "getMonolingualTextValue", "(", "text", ",", "languageCode", ")", ")", ";", "return", "getThis", "(", ")", ";", "}" ]
Adds an additional alias to the constructed document. @param text the text of the alias @param languageCode the language code of the alias @return builder object to continue construction
[ "Adds", "an", "additional", "alias", "to", "the", "constructed", "document", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/EntityDocumentBuilder.java#L175-L178
161,306
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/EntityDocumentBuilder.java
EntityDocumentBuilder.withStatement
public T withStatement(Statement statement) { PropertyIdValue pid = statement.getMainSnak() .getPropertyId(); ArrayList<Statement> pidStatements = this.statements.get(pid); if (pidStatements == null) { pidStatements = new ArrayList<Statement>(); this.statements.put(pid, pidStatements); } pidStatements.add(statement); return getThis(); }
java
public T withStatement(Statement statement) { PropertyIdValue pid = statement.getMainSnak() .getPropertyId(); ArrayList<Statement> pidStatements = this.statements.get(pid); if (pidStatements == null) { pidStatements = new ArrayList<Statement>(); this.statements.put(pid, pidStatements); } pidStatements.add(statement); return getThis(); }
[ "public", "T", "withStatement", "(", "Statement", "statement", ")", "{", "PropertyIdValue", "pid", "=", "statement", ".", "getMainSnak", "(", ")", ".", "getPropertyId", "(", ")", ";", "ArrayList", "<", "Statement", ">", "pidStatements", "=", "this", ".", "statements", ".", "get", "(", "pid", ")", ";", "if", "(", "pidStatements", "==", "null", ")", "{", "pidStatements", "=", "new", "ArrayList", "<", "Statement", ">", "(", ")", ";", "this", ".", "statements", ".", "put", "(", "pid", ",", "pidStatements", ")", ";", "}", "pidStatements", ".", "add", "(", "statement", ")", ";", "return", "getThis", "(", ")", ";", "}" ]
Adds an additional statement to the constructed document. @param statement the additional statement @return builder object to continue construction
[ "Adds", "an", "additional", "statement", "to", "the", "constructed", "document", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/EntityDocumentBuilder.java#L187-L198
161,307
Wikidata/Wikidata-Toolkit
wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/values/AbstractValueConverter.java
AbstractValueConverter.logIncompatibleValueError
protected void logIncompatibleValueError(PropertyIdValue propertyIdValue, String datatype, String valueType) { logger.warn("Property " + propertyIdValue.getId() + " has type \"" + datatype + "\" but a value of type " + valueType + ". Data ignored."); }
java
protected void logIncompatibleValueError(PropertyIdValue propertyIdValue, String datatype, String valueType) { logger.warn("Property " + propertyIdValue.getId() + " has type \"" + datatype + "\" but a value of type " + valueType + ". Data ignored."); }
[ "protected", "void", "logIncompatibleValueError", "(", "PropertyIdValue", "propertyIdValue", ",", "String", "datatype", ",", "String", "valueType", ")", "{", "logger", ".", "warn", "(", "\"Property \"", "+", "propertyIdValue", ".", "getId", "(", ")", "+", "\" has type \\\"\"", "+", "datatype", "+", "\"\\\" but a value of type \"", "+", "valueType", "+", "\". Data ignored.\"", ")", ";", "}" ]
Logs a message for a case where the value of a property does not fit to its declared datatype. @param propertyIdValue the property that was used @param datatype the declared type of the property @param valueType a string to denote the type of value
[ "Logs", "a", "message", "for", "a", "case", "where", "the", "value", "of", "a", "property", "does", "not", "fit", "to", "its", "declared", "datatype", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/values/AbstractValueConverter.java#L64-L69
161,308
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/EntityDocumentImpl.java
EntityDocumentImpl.getJsonId
@JsonInclude(Include.NON_EMPTY) @JsonProperty("id") public String getJsonId() { if (!EntityIdValue.SITE_LOCAL.equals(this.siteIri)) { return this.entityId; } else { return null; } }
java
@JsonInclude(Include.NON_EMPTY) @JsonProperty("id") public String getJsonId() { if (!EntityIdValue.SITE_LOCAL.equals(this.siteIri)) { return this.entityId; } else { return null; } }
[ "@", "JsonInclude", "(", "Include", ".", "NON_EMPTY", ")", "@", "JsonProperty", "(", "\"id\"", ")", "public", "String", "getJsonId", "(", ")", "{", "if", "(", "!", "EntityIdValue", ".", "SITE_LOCAL", ".", "equals", "(", "this", ".", "siteIri", ")", ")", "{", "return", "this", ".", "entityId", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Returns the string id of the entity that this document refers to. Only for use by Jackson during serialization. @return string id
[ "Returns", "the", "string", "id", "of", "the", "entity", "that", "this", "document", "refers", "to", ".", "Only", "for", "use", "by", "Jackson", "during", "serialization", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/EntityDocumentImpl.java#L135-L143
161,309
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbGetEntitiesAction.java
WbGetEntitiesAction.wbGetEntities
public Map<String, EntityDocument> wbGetEntities( WbGetEntitiesActionData properties) throws MediaWikiApiErrorException, IOException { return wbGetEntities(properties.ids, properties.sites, properties.titles, properties.props, properties.languages, properties.sitefilter); }
java
public Map<String, EntityDocument> wbGetEntities( WbGetEntitiesActionData properties) throws MediaWikiApiErrorException, IOException { return wbGetEntities(properties.ids, properties.sites, properties.titles, properties.props, properties.languages, properties.sitefilter); }
[ "public", "Map", "<", "String", ",", "EntityDocument", ">", "wbGetEntities", "(", "WbGetEntitiesActionData", "properties", ")", "throws", "MediaWikiApiErrorException", ",", "IOException", "{", "return", "wbGetEntities", "(", "properties", ".", "ids", ",", "properties", ".", "sites", ",", "properties", ".", "titles", ",", "properties", ".", "props", ",", "properties", ".", "languages", ",", "properties", ".", "sitefilter", ")", ";", "}" ]
Creates a map of identifiers or page titles to documents retrieved via the API URL @param properties parameter setting for wbgetentities @return map of document identifiers or titles to documents retrieved via the API URL @throws MediaWikiApiErrorException if the API returns an error @throws IOException if we encounter network issues or HTTP 500 errors from Wikibase
[ "Creates", "a", "map", "of", "identifiers", "or", "page", "titles", "to", "documents", "retrieved", "via", "the", "API", "URL" ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbGetEntitiesAction.java#L98-L104
161,310
Wikidata/Wikidata-Toolkit
wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/Vocabulary.java
Vocabulary.getStatementUri
public static String getStatementUri(Statement statement) { int i = statement.getStatementId().indexOf('$') + 1; return PREFIX_WIKIDATA_STATEMENT + statement.getSubject().getId() + "-" + statement.getStatementId().substring(i); }
java
public static String getStatementUri(Statement statement) { int i = statement.getStatementId().indexOf('$') + 1; return PREFIX_WIKIDATA_STATEMENT + statement.getSubject().getId() + "-" + statement.getStatementId().substring(i); }
[ "public", "static", "String", "getStatementUri", "(", "Statement", "statement", ")", "{", "int", "i", "=", "statement", ".", "getStatementId", "(", ")", ".", "indexOf", "(", "'", "'", ")", "+", "1", ";", "return", "PREFIX_WIKIDATA_STATEMENT", "+", "statement", ".", "getSubject", "(", ")", ".", "getId", "(", ")", "+", "\"-\"", "+", "statement", ".", "getStatementId", "(", ")", ".", "substring", "(", "i", ")", ";", "}" ]
Get the URI for the given statement. @param statement the statement for which to create a URI @return the URI
[ "Get", "the", "URI", "for", "the", "given", "statement", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/Vocabulary.java#L501-L506
161,311
Wikidata/Wikidata-Toolkit
wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/Vocabulary.java
Vocabulary.getPropertyUri
public static String getPropertyUri(PropertyIdValue propertyIdValue, PropertyContext propertyContext) { switch (propertyContext) { case DIRECT: return PREFIX_PROPERTY_DIRECT + propertyIdValue.getId(); case STATEMENT: return PREFIX_PROPERTY + propertyIdValue.getId(); case VALUE_SIMPLE: return PREFIX_PROPERTY_STATEMENT + propertyIdValue.getId(); case VALUE: return PREFIX_PROPERTY_STATEMENT_VALUE + propertyIdValue.getId(); case QUALIFIER: return PREFIX_PROPERTY_QUALIFIER_VALUE + propertyIdValue.getId(); case QUALIFIER_SIMPLE: return PREFIX_PROPERTY_QUALIFIER + propertyIdValue.getId(); case REFERENCE: return PREFIX_PROPERTY_REFERENCE_VALUE + propertyIdValue.getId(); case REFERENCE_SIMPLE: return PREFIX_PROPERTY_REFERENCE + propertyIdValue.getId(); case NO_VALUE: return PREFIX_WIKIDATA_NO_VALUE + propertyIdValue.getId(); case NO_QUALIFIER_VALUE: return PREFIX_WIKIDATA_NO_QUALIFIER_VALUE + propertyIdValue.getId(); default: return null; } }
java
public static String getPropertyUri(PropertyIdValue propertyIdValue, PropertyContext propertyContext) { switch (propertyContext) { case DIRECT: return PREFIX_PROPERTY_DIRECT + propertyIdValue.getId(); case STATEMENT: return PREFIX_PROPERTY + propertyIdValue.getId(); case VALUE_SIMPLE: return PREFIX_PROPERTY_STATEMENT + propertyIdValue.getId(); case VALUE: return PREFIX_PROPERTY_STATEMENT_VALUE + propertyIdValue.getId(); case QUALIFIER: return PREFIX_PROPERTY_QUALIFIER_VALUE + propertyIdValue.getId(); case QUALIFIER_SIMPLE: return PREFIX_PROPERTY_QUALIFIER + propertyIdValue.getId(); case REFERENCE: return PREFIX_PROPERTY_REFERENCE_VALUE + propertyIdValue.getId(); case REFERENCE_SIMPLE: return PREFIX_PROPERTY_REFERENCE + propertyIdValue.getId(); case NO_VALUE: return PREFIX_WIKIDATA_NO_VALUE + propertyIdValue.getId(); case NO_QUALIFIER_VALUE: return PREFIX_WIKIDATA_NO_QUALIFIER_VALUE + propertyIdValue.getId(); default: return null; } }
[ "public", "static", "String", "getPropertyUri", "(", "PropertyIdValue", "propertyIdValue", ",", "PropertyContext", "propertyContext", ")", "{", "switch", "(", "propertyContext", ")", "{", "case", "DIRECT", ":", "return", "PREFIX_PROPERTY_DIRECT", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "case", "STATEMENT", ":", "return", "PREFIX_PROPERTY", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "case", "VALUE_SIMPLE", ":", "return", "PREFIX_PROPERTY_STATEMENT", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "case", "VALUE", ":", "return", "PREFIX_PROPERTY_STATEMENT_VALUE", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "case", "QUALIFIER", ":", "return", "PREFIX_PROPERTY_QUALIFIER_VALUE", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "case", "QUALIFIER_SIMPLE", ":", "return", "PREFIX_PROPERTY_QUALIFIER", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "case", "REFERENCE", ":", "return", "PREFIX_PROPERTY_REFERENCE_VALUE", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "case", "REFERENCE_SIMPLE", ":", "return", "PREFIX_PROPERTY_REFERENCE", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "case", "NO_VALUE", ":", "return", "PREFIX_WIKIDATA_NO_VALUE", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "case", "NO_QUALIFIER_VALUE", ":", "return", "PREFIX_WIKIDATA_NO_QUALIFIER_VALUE", "+", "propertyIdValue", ".", "getId", "(", ")", ";", "default", ":", "return", "null", ";", "}", "}" ]
Get the URI for the given property in the given context. @param propertyIdValue the property id for which to create a URI @param propertyContext the context for which the URI will be needed @return the URI
[ "Get", "the", "URI", "for", "the", "given", "property", "in", "the", "given", "context", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/Vocabulary.java#L517-L543
161,312
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementDocumentImpl.java
StatementDocumentImpl.findStatementGroup
public StatementGroup findStatementGroup(String propertyIdValue) { if (this.claims.containsKey(propertyIdValue)) { return new StatementGroupImpl(this.claims.get(propertyIdValue)); } return null; }
java
public StatementGroup findStatementGroup(String propertyIdValue) { if (this.claims.containsKey(propertyIdValue)) { return new StatementGroupImpl(this.claims.get(propertyIdValue)); } return null; }
[ "public", "StatementGroup", "findStatementGroup", "(", "String", "propertyIdValue", ")", "{", "if", "(", "this", ".", "claims", ".", "containsKey", "(", "propertyIdValue", ")", ")", "{", "return", "new", "StatementGroupImpl", "(", "this", ".", "claims", ".", "get", "(", "propertyIdValue", ")", ")", ";", "}", "return", "null", ";", "}" ]
Find a statement group by its property id, without checking for equality with the site IRI. More efficient implementation than the default one.
[ "Find", "a", "statement", "group", "by", "its", "property", "id", "without", "checking", "for", "equality", "with", "the", "site", "IRI", ".", "More", "efficient", "implementation", "than", "the", "default", "one", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementDocumentImpl.java#L143-L148
161,313
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementDocumentImpl.java
StatementDocumentImpl.addStatementToGroups
protected static Map<String, List<Statement>> addStatementToGroups(Statement statement, Map<String, List<Statement>> claims) { Map<String, List<Statement>> newGroups = new HashMap<>(claims); String pid = statement.getMainSnak().getPropertyId().getId(); if(newGroups.containsKey(pid)) { List<Statement> newGroup = new ArrayList<>(newGroups.get(pid).size()); boolean statementReplaced = false; for(Statement existingStatement : newGroups.get(pid)) { if(existingStatement.getStatementId().equals(statement.getStatementId()) && !existingStatement.getStatementId().isEmpty()) { statementReplaced = true; newGroup.add(statement); } else { newGroup.add(existingStatement); } } if(!statementReplaced) { newGroup.add(statement); } newGroups.put(pid, newGroup); } else { newGroups.put(pid, Collections.singletonList(statement)); } return newGroups; }
java
protected static Map<String, List<Statement>> addStatementToGroups(Statement statement, Map<String, List<Statement>> claims) { Map<String, List<Statement>> newGroups = new HashMap<>(claims); String pid = statement.getMainSnak().getPropertyId().getId(); if(newGroups.containsKey(pid)) { List<Statement> newGroup = new ArrayList<>(newGroups.get(pid).size()); boolean statementReplaced = false; for(Statement existingStatement : newGroups.get(pid)) { if(existingStatement.getStatementId().equals(statement.getStatementId()) && !existingStatement.getStatementId().isEmpty()) { statementReplaced = true; newGroup.add(statement); } else { newGroup.add(existingStatement); } } if(!statementReplaced) { newGroup.add(statement); } newGroups.put(pid, newGroup); } else { newGroups.put(pid, Collections.singletonList(statement)); } return newGroups; }
[ "protected", "static", "Map", "<", "String", ",", "List", "<", "Statement", ">", ">", "addStatementToGroups", "(", "Statement", "statement", ",", "Map", "<", "String", ",", "List", "<", "Statement", ">", ">", "claims", ")", "{", "Map", "<", "String", ",", "List", "<", "Statement", ">", ">", "newGroups", "=", "new", "HashMap", "<>", "(", "claims", ")", ";", "String", "pid", "=", "statement", ".", "getMainSnak", "(", ")", ".", "getPropertyId", "(", ")", ".", "getId", "(", ")", ";", "if", "(", "newGroups", ".", "containsKey", "(", "pid", ")", ")", "{", "List", "<", "Statement", ">", "newGroup", "=", "new", "ArrayList", "<>", "(", "newGroups", ".", "get", "(", "pid", ")", ".", "size", "(", ")", ")", ";", "boolean", "statementReplaced", "=", "false", ";", "for", "(", "Statement", "existingStatement", ":", "newGroups", ".", "get", "(", "pid", ")", ")", "{", "if", "(", "existingStatement", ".", "getStatementId", "(", ")", ".", "equals", "(", "statement", ".", "getStatementId", "(", ")", ")", "&&", "!", "existingStatement", ".", "getStatementId", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "statementReplaced", "=", "true", ";", "newGroup", ".", "add", "(", "statement", ")", ";", "}", "else", "{", "newGroup", ".", "add", "(", "existingStatement", ")", ";", "}", "}", "if", "(", "!", "statementReplaced", ")", "{", "newGroup", ".", "add", "(", "statement", ")", ";", "}", "newGroups", ".", "put", "(", "pid", ",", "newGroup", ")", ";", "}", "else", "{", "newGroups", ".", "put", "(", "pid", ",", "Collections", ".", "singletonList", "(", "statement", ")", ")", ";", "}", "return", "newGroups", ";", "}" ]
Adds a Statement to a given collection of statement groups. If the statement id is not null and matches that of an existing statement, this statement will be replaced. @param statement @param claims @return
[ "Adds", "a", "Statement", "to", "a", "given", "collection", "of", "statement", "groups", ".", "If", "the", "statement", "id", "is", "not", "null", "and", "matches", "that", "of", "an", "existing", "statement", "this", "statement", "will", "be", "replaced", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementDocumentImpl.java#L179-L202
161,314
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementDocumentImpl.java
StatementDocumentImpl.removeStatements
protected static Map<String, List<Statement>> removeStatements(Set<String> statementIds, Map<String, List<Statement>> claims) { Map<String, List<Statement>> newClaims = new HashMap<>(claims.size()); for(Entry<String, List<Statement>> entry : claims.entrySet()) { List<Statement> filteredStatements = new ArrayList<>(); for(Statement s : entry.getValue()) { if(!statementIds.contains(s.getStatementId())) { filteredStatements.add(s); } } if(!filteredStatements.isEmpty()) { newClaims.put(entry.getKey(), filteredStatements); } } return newClaims; }
java
protected static Map<String, List<Statement>> removeStatements(Set<String> statementIds, Map<String, List<Statement>> claims) { Map<String, List<Statement>> newClaims = new HashMap<>(claims.size()); for(Entry<String, List<Statement>> entry : claims.entrySet()) { List<Statement> filteredStatements = new ArrayList<>(); for(Statement s : entry.getValue()) { if(!statementIds.contains(s.getStatementId())) { filteredStatements.add(s); } } if(!filteredStatements.isEmpty()) { newClaims.put(entry.getKey(), filteredStatements); } } return newClaims; }
[ "protected", "static", "Map", "<", "String", ",", "List", "<", "Statement", ">", ">", "removeStatements", "(", "Set", "<", "String", ">", "statementIds", ",", "Map", "<", "String", ",", "List", "<", "Statement", ">", ">", "claims", ")", "{", "Map", "<", "String", ",", "List", "<", "Statement", ">", ">", "newClaims", "=", "new", "HashMap", "<>", "(", "claims", ".", "size", "(", ")", ")", ";", "for", "(", "Entry", "<", "String", ",", "List", "<", "Statement", ">", ">", "entry", ":", "claims", ".", "entrySet", "(", ")", ")", "{", "List", "<", "Statement", ">", "filteredStatements", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "Statement", "s", ":", "entry", ".", "getValue", "(", ")", ")", "{", "if", "(", "!", "statementIds", ".", "contains", "(", "s", ".", "getStatementId", "(", ")", ")", ")", "{", "filteredStatements", ".", "add", "(", "s", ")", ";", "}", "}", "if", "(", "!", "filteredStatements", ".", "isEmpty", "(", ")", ")", "{", "newClaims", ".", "put", "(", "entry", ".", "getKey", "(", ")", ",", "filteredStatements", ")", ";", "}", "}", "return", "newClaims", ";", "}" ]
Removes statement ids from a collection of statement groups. @param statementIds @param claims @return
[ "Removes", "statement", "ids", "from", "a", "collection", "of", "statement", "groups", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementDocumentImpl.java#L210-L225
161,315
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImpl.java
DatatypeIdImpl.getDatatypeIriFromJsonDatatype
public static String getDatatypeIriFromJsonDatatype(String jsonDatatype) { switch (jsonDatatype) { case JSON_DT_ITEM: return DT_ITEM; case JSON_DT_PROPERTY: return DT_PROPERTY; case JSON_DT_GLOBE_COORDINATES: return DT_GLOBE_COORDINATES; case JSON_DT_URL: return DT_URL; case JSON_DT_COMMONS_MEDIA: return DT_COMMONS_MEDIA; case JSON_DT_TIME: return DT_TIME; case JSON_DT_QUANTITY: return DT_QUANTITY; case JSON_DT_STRING: return DT_STRING; case JSON_DT_MONOLINGUAL_TEXT: return DT_MONOLINGUAL_TEXT; default: if(!JSON_DATATYPE_PATTERN.matcher(jsonDatatype).matches()) { throw new IllegalArgumentException("Invalid JSON datatype \"" + jsonDatatype + "\""); } String[] parts = jsonDatatype.split("-"); for(int i = 0; i < parts.length; i++) { parts[i] = StringUtils.capitalize(parts[i]); } return "http://wikiba.se/ontology#" + StringUtils.join(parts); } }
java
public static String getDatatypeIriFromJsonDatatype(String jsonDatatype) { switch (jsonDatatype) { case JSON_DT_ITEM: return DT_ITEM; case JSON_DT_PROPERTY: return DT_PROPERTY; case JSON_DT_GLOBE_COORDINATES: return DT_GLOBE_COORDINATES; case JSON_DT_URL: return DT_URL; case JSON_DT_COMMONS_MEDIA: return DT_COMMONS_MEDIA; case JSON_DT_TIME: return DT_TIME; case JSON_DT_QUANTITY: return DT_QUANTITY; case JSON_DT_STRING: return DT_STRING; case JSON_DT_MONOLINGUAL_TEXT: return DT_MONOLINGUAL_TEXT; default: if(!JSON_DATATYPE_PATTERN.matcher(jsonDatatype).matches()) { throw new IllegalArgumentException("Invalid JSON datatype \"" + jsonDatatype + "\""); } String[] parts = jsonDatatype.split("-"); for(int i = 0; i < parts.length; i++) { parts[i] = StringUtils.capitalize(parts[i]); } return "http://wikiba.se/ontology#" + StringUtils.join(parts); } }
[ "public", "static", "String", "getDatatypeIriFromJsonDatatype", "(", "String", "jsonDatatype", ")", "{", "switch", "(", "jsonDatatype", ")", "{", "case", "JSON_DT_ITEM", ":", "return", "DT_ITEM", ";", "case", "JSON_DT_PROPERTY", ":", "return", "DT_PROPERTY", ";", "case", "JSON_DT_GLOBE_COORDINATES", ":", "return", "DT_GLOBE_COORDINATES", ";", "case", "JSON_DT_URL", ":", "return", "DT_URL", ";", "case", "JSON_DT_COMMONS_MEDIA", ":", "return", "DT_COMMONS_MEDIA", ";", "case", "JSON_DT_TIME", ":", "return", "DT_TIME", ";", "case", "JSON_DT_QUANTITY", ":", "return", "DT_QUANTITY", ";", "case", "JSON_DT_STRING", ":", "return", "DT_STRING", ";", "case", "JSON_DT_MONOLINGUAL_TEXT", ":", "return", "DT_MONOLINGUAL_TEXT", ";", "default", ":", "if", "(", "!", "JSON_DATATYPE_PATTERN", ".", "matcher", "(", "jsonDatatype", ")", ".", "matches", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid JSON datatype \\\"\"", "+", "jsonDatatype", "+", "\"\\\"\"", ")", ";", "}", "String", "[", "]", "parts", "=", "jsonDatatype", ".", "split", "(", "\"-\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "parts", ".", "length", ";", "i", "++", ")", "{", "parts", "[", "i", "]", "=", "StringUtils", ".", "capitalize", "(", "parts", "[", "i", "]", ")", ";", "}", "return", "\"http://wikiba.se/ontology#\"", "+", "StringUtils", ".", "join", "(", "parts", ")", ";", "}", "}" ]
Returns the WDTK datatype IRI for the property datatype as represented by the given JSON datatype string. @param jsonDatatype the JSON datatype string; case-sensitive @throws IllegalArgumentException if the given datatype string is not known
[ "Returns", "the", "WDTK", "datatype", "IRI", "for", "the", "property", "datatype", "as", "represented", "by", "the", "given", "JSON", "datatype", "string", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImpl.java#L123-L154
161,316
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImpl.java
DatatypeIdImpl.getJsonDatatypeFromDatatypeIri
public static String getJsonDatatypeFromDatatypeIri(String datatypeIri) { switch (datatypeIri) { case DatatypeIdValue.DT_ITEM: return DatatypeIdImpl.JSON_DT_ITEM; case DatatypeIdValue.DT_GLOBE_COORDINATES: return DatatypeIdImpl.JSON_DT_GLOBE_COORDINATES; case DatatypeIdValue.DT_URL: return DatatypeIdImpl.JSON_DT_URL; case DatatypeIdValue.DT_COMMONS_MEDIA: return DatatypeIdImpl.JSON_DT_COMMONS_MEDIA; case DatatypeIdValue.DT_TIME: return DatatypeIdImpl.JSON_DT_TIME; case DatatypeIdValue.DT_QUANTITY: return DatatypeIdImpl.JSON_DT_QUANTITY; case DatatypeIdValue.DT_STRING: return DatatypeIdImpl.JSON_DT_STRING; case DatatypeIdValue.DT_MONOLINGUAL_TEXT: return DatatypeIdImpl.JSON_DT_MONOLINGUAL_TEXT; case DatatypeIdValue.DT_PROPERTY: return DatatypeIdImpl.JSON_DT_PROPERTY; default: //We apply the reverse algorithm of JacksonDatatypeId::getDatatypeIriFromJsonDatatype Matcher matcher = DATATYPE_ID_PATTERN.matcher(datatypeIri); if(!matcher.matches()) { throw new IllegalArgumentException("Unknown datatype: " + datatypeIri); } StringBuilder jsonDatatypeBuilder = new StringBuilder(); for(char ch : StringUtils.uncapitalize(matcher.group(1)).toCharArray()) { if(Character.isUpperCase(ch)) { jsonDatatypeBuilder .append('-') .append(Character.toLowerCase(ch)); } else { jsonDatatypeBuilder.append(ch); } } return jsonDatatypeBuilder.toString(); } }
java
public static String getJsonDatatypeFromDatatypeIri(String datatypeIri) { switch (datatypeIri) { case DatatypeIdValue.DT_ITEM: return DatatypeIdImpl.JSON_DT_ITEM; case DatatypeIdValue.DT_GLOBE_COORDINATES: return DatatypeIdImpl.JSON_DT_GLOBE_COORDINATES; case DatatypeIdValue.DT_URL: return DatatypeIdImpl.JSON_DT_URL; case DatatypeIdValue.DT_COMMONS_MEDIA: return DatatypeIdImpl.JSON_DT_COMMONS_MEDIA; case DatatypeIdValue.DT_TIME: return DatatypeIdImpl.JSON_DT_TIME; case DatatypeIdValue.DT_QUANTITY: return DatatypeIdImpl.JSON_DT_QUANTITY; case DatatypeIdValue.DT_STRING: return DatatypeIdImpl.JSON_DT_STRING; case DatatypeIdValue.DT_MONOLINGUAL_TEXT: return DatatypeIdImpl.JSON_DT_MONOLINGUAL_TEXT; case DatatypeIdValue.DT_PROPERTY: return DatatypeIdImpl.JSON_DT_PROPERTY; default: //We apply the reverse algorithm of JacksonDatatypeId::getDatatypeIriFromJsonDatatype Matcher matcher = DATATYPE_ID_PATTERN.matcher(datatypeIri); if(!matcher.matches()) { throw new IllegalArgumentException("Unknown datatype: " + datatypeIri); } StringBuilder jsonDatatypeBuilder = new StringBuilder(); for(char ch : StringUtils.uncapitalize(matcher.group(1)).toCharArray()) { if(Character.isUpperCase(ch)) { jsonDatatypeBuilder .append('-') .append(Character.toLowerCase(ch)); } else { jsonDatatypeBuilder.append(ch); } } return jsonDatatypeBuilder.toString(); } }
[ "public", "static", "String", "getJsonDatatypeFromDatatypeIri", "(", "String", "datatypeIri", ")", "{", "switch", "(", "datatypeIri", ")", "{", "case", "DatatypeIdValue", ".", "DT_ITEM", ":", "return", "DatatypeIdImpl", ".", "JSON_DT_ITEM", ";", "case", "DatatypeIdValue", ".", "DT_GLOBE_COORDINATES", ":", "return", "DatatypeIdImpl", ".", "JSON_DT_GLOBE_COORDINATES", ";", "case", "DatatypeIdValue", ".", "DT_URL", ":", "return", "DatatypeIdImpl", ".", "JSON_DT_URL", ";", "case", "DatatypeIdValue", ".", "DT_COMMONS_MEDIA", ":", "return", "DatatypeIdImpl", ".", "JSON_DT_COMMONS_MEDIA", ";", "case", "DatatypeIdValue", ".", "DT_TIME", ":", "return", "DatatypeIdImpl", ".", "JSON_DT_TIME", ";", "case", "DatatypeIdValue", ".", "DT_QUANTITY", ":", "return", "DatatypeIdImpl", ".", "JSON_DT_QUANTITY", ";", "case", "DatatypeIdValue", ".", "DT_STRING", ":", "return", "DatatypeIdImpl", ".", "JSON_DT_STRING", ";", "case", "DatatypeIdValue", ".", "DT_MONOLINGUAL_TEXT", ":", "return", "DatatypeIdImpl", ".", "JSON_DT_MONOLINGUAL_TEXT", ";", "case", "DatatypeIdValue", ".", "DT_PROPERTY", ":", "return", "DatatypeIdImpl", ".", "JSON_DT_PROPERTY", ";", "default", ":", "//We apply the reverse algorithm of JacksonDatatypeId::getDatatypeIriFromJsonDatatype", "Matcher", "matcher", "=", "DATATYPE_ID_PATTERN", ".", "matcher", "(", "datatypeIri", ")", ";", "if", "(", "!", "matcher", ".", "matches", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Unknown datatype: \"", "+", "datatypeIri", ")", ";", "}", "StringBuilder", "jsonDatatypeBuilder", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "char", "ch", ":", "StringUtils", ".", "uncapitalize", "(", "matcher", ".", "group", "(", "1", ")", ")", ".", "toCharArray", "(", ")", ")", "{", "if", "(", "Character", ".", "isUpperCase", "(", "ch", ")", ")", "{", "jsonDatatypeBuilder", ".", "append", "(", "'", "'", ")", ".", "append", "(", "Character", ".", "toLowerCase", "(", "ch", ")", ")", ";", "}", "else", "{", "jsonDatatypeBuilder", ".", "append", "(", "ch", ")", ";", "}", "}", "return", "jsonDatatypeBuilder", ".", "toString", "(", ")", ";", "}", "}" ]
Returns the JSON datatype for the property datatype as represented by the given WDTK datatype IRI string. @param datatypeIri the WDTK datatype IRI string; case-sensitive @throws IllegalArgumentException if the given datatype string is not known
[ "Returns", "the", "JSON", "datatype", "for", "the", "property", "datatype", "as", "represented", "by", "the", "given", "WDTK", "datatype", "IRI", "string", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImpl.java#L165-L204
161,317
Wikidata/Wikidata-Toolkit
wdtk-util/src/main/java/org/wikidata/wdtk/util/DirectoryManagerImpl.java
DirectoryManagerImpl.getCompressorInputStream
protected InputStream getCompressorInputStream(InputStream inputStream, CompressionType compressionType) throws IOException { switch (compressionType) { case NONE: return inputStream; case GZIP: return new GZIPInputStream(inputStream); case BZ2: return new BZip2CompressorInputStream(new BufferedInputStream( inputStream)); default: throw new IllegalArgumentException("Unsupported compression type: " + compressionType); } }
java
protected InputStream getCompressorInputStream(InputStream inputStream, CompressionType compressionType) throws IOException { switch (compressionType) { case NONE: return inputStream; case GZIP: return new GZIPInputStream(inputStream); case BZ2: return new BZip2CompressorInputStream(new BufferedInputStream( inputStream)); default: throw new IllegalArgumentException("Unsupported compression type: " + compressionType); } }
[ "protected", "InputStream", "getCompressorInputStream", "(", "InputStream", "inputStream", ",", "CompressionType", "compressionType", ")", "throws", "IOException", "{", "switch", "(", "compressionType", ")", "{", "case", "NONE", ":", "return", "inputStream", ";", "case", "GZIP", ":", "return", "new", "GZIPInputStream", "(", "inputStream", ")", ";", "case", "BZ2", ":", "return", "new", "BZip2CompressorInputStream", "(", "new", "BufferedInputStream", "(", "inputStream", ")", ")", ";", "default", ":", "throw", "new", "IllegalArgumentException", "(", "\"Unsupported compression type: \"", "+", "compressionType", ")", ";", "}", "}" ]
Returns an input stream that applies the required decompression to the given input stream. @param inputStream the input stream with the (possibly compressed) data @param compressionType the kind of compression @return an input stream with decompressed data @throws IOException if there was a problem creating the decompression streams
[ "Returns", "an", "input", "stream", "that", "applies", "the", "required", "decompression", "to", "the", "given", "input", "stream", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-util/src/main/java/org/wikidata/wdtk/util/DirectoryManagerImpl.java#L191-L205
161,318
Wikidata/Wikidata-Toolkit
wdtk-util/src/main/java/org/wikidata/wdtk/util/DirectoryManagerImpl.java
DirectoryManagerImpl.createDirectory
void createDirectory(Path path) throws IOException { if (Files.exists(path) && Files.isDirectory(path)) { return; } if (this.readOnly) { throw new FileNotFoundException( "The requested directory \"" + path.toString() + "\" does not exist and we are in read-only mode, so it cannot be created."); } Files.createDirectory(path); }
java
void createDirectory(Path path) throws IOException { if (Files.exists(path) && Files.isDirectory(path)) { return; } if (this.readOnly) { throw new FileNotFoundException( "The requested directory \"" + path.toString() + "\" does not exist and we are in read-only mode, so it cannot be created."); } Files.createDirectory(path); }
[ "void", "createDirectory", "(", "Path", "path", ")", "throws", "IOException", "{", "if", "(", "Files", ".", "exists", "(", "path", ")", "&&", "Files", ".", "isDirectory", "(", "path", ")", ")", "{", "return", ";", "}", "if", "(", "this", ".", "readOnly", ")", "{", "throw", "new", "FileNotFoundException", "(", "\"The requested directory \\\"\"", "+", "path", ".", "toString", "(", ")", "+", "\"\\\" does not exist and we are in read-only mode, so it cannot be created.\"", ")", ";", "}", "Files", ".", "createDirectory", "(", "path", ")", ";", "}" ]
Creates a directory at the given path if it does not exist yet and if the directory manager was not configured for read-only access. @param path @throws IOException if it was not possible to create a directory at the given path
[ "Creates", "a", "directory", "at", "the", "given", "path", "if", "it", "does", "not", "exist", "yet", "and", "if", "the", "directory", "manager", "was", "not", "configured", "for", "read", "-", "only", "access", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-util/src/main/java/org/wikidata/wdtk/util/DirectoryManagerImpl.java#L230-L243
161,319
Wikidata/Wikidata-Toolkit
wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java
WmfDumpFile.getDumpFilePostfix
public static String getDumpFilePostfix(DumpContentType dumpContentType) { if (WmfDumpFile.POSTFIXES.containsKey(dumpContentType)) { return WmfDumpFile.POSTFIXES.get(dumpContentType); } else { throw new IllegalArgumentException("Unsupported dump type " + dumpContentType); } }
java
public static String getDumpFilePostfix(DumpContentType dumpContentType) { if (WmfDumpFile.POSTFIXES.containsKey(dumpContentType)) { return WmfDumpFile.POSTFIXES.get(dumpContentType); } else { throw new IllegalArgumentException("Unsupported dump type " + dumpContentType); } }
[ "public", "static", "String", "getDumpFilePostfix", "(", "DumpContentType", "dumpContentType", ")", "{", "if", "(", "WmfDumpFile", ".", "POSTFIXES", ".", "containsKey", "(", "dumpContentType", ")", ")", "{", "return", "WmfDumpFile", ".", "POSTFIXES", ".", "get", "(", "dumpContentType", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Unsupported dump type \"", "+", "dumpContentType", ")", ";", "}", "}" ]
Returns the ending used by the Wikimedia-provided dumpfile names of the given type. @param dumpContentType the type of dump @return postfix of the dumpfile name @throws IllegalArgumentException if the given dump file type is not known
[ "Returns", "the", "ending", "used", "by", "the", "Wikimedia", "-", "provided", "dumpfile", "names", "of", "the", "given", "type", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java#L150-L157
161,320
Wikidata/Wikidata-Toolkit
wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java
WmfDumpFile.getDumpFileWebDirectory
public static String getDumpFileWebDirectory( DumpContentType dumpContentType, String projectName) { if (dumpContentType == DumpContentType.JSON) { if ("wikidatawiki".equals(projectName)) { return WmfDumpFile.DUMP_SITE_BASE_URL + WmfDumpFile.WEB_DIRECTORY.get(dumpContentType) + "wikidata" + "/"; } else { throw new RuntimeException( "Wikimedia Foundation uses non-systematic directory names for this type of dump file." + " I don't know where to find dumps of project " + projectName); } } else if (WmfDumpFile.WEB_DIRECTORY.containsKey(dumpContentType)) { return WmfDumpFile.DUMP_SITE_BASE_URL + WmfDumpFile.WEB_DIRECTORY.get(dumpContentType) + projectName + "/"; } else { throw new IllegalArgumentException("Unsupported dump type " + dumpContentType); } }
java
public static String getDumpFileWebDirectory( DumpContentType dumpContentType, String projectName) { if (dumpContentType == DumpContentType.JSON) { if ("wikidatawiki".equals(projectName)) { return WmfDumpFile.DUMP_SITE_BASE_URL + WmfDumpFile.WEB_DIRECTORY.get(dumpContentType) + "wikidata" + "/"; } else { throw new RuntimeException( "Wikimedia Foundation uses non-systematic directory names for this type of dump file." + " I don't know where to find dumps of project " + projectName); } } else if (WmfDumpFile.WEB_DIRECTORY.containsKey(dumpContentType)) { return WmfDumpFile.DUMP_SITE_BASE_URL + WmfDumpFile.WEB_DIRECTORY.get(dumpContentType) + projectName + "/"; } else { throw new IllegalArgumentException("Unsupported dump type " + dumpContentType); } }
[ "public", "static", "String", "getDumpFileWebDirectory", "(", "DumpContentType", "dumpContentType", ",", "String", "projectName", ")", "{", "if", "(", "dumpContentType", "==", "DumpContentType", ".", "JSON", ")", "{", "if", "(", "\"wikidatawiki\"", ".", "equals", "(", "projectName", ")", ")", "{", "return", "WmfDumpFile", ".", "DUMP_SITE_BASE_URL", "+", "WmfDumpFile", ".", "WEB_DIRECTORY", ".", "get", "(", "dumpContentType", ")", "+", "\"wikidata\"", "+", "\"/\"", ";", "}", "else", "{", "throw", "new", "RuntimeException", "(", "\"Wikimedia Foundation uses non-systematic directory names for this type of dump file.\"", "+", "\" I don't know where to find dumps of project \"", "+", "projectName", ")", ";", "}", "}", "else", "if", "(", "WmfDumpFile", ".", "WEB_DIRECTORY", ".", "containsKey", "(", "dumpContentType", ")", ")", "{", "return", "WmfDumpFile", ".", "DUMP_SITE_BASE_URL", "+", "WmfDumpFile", ".", "WEB_DIRECTORY", ".", "get", "(", "dumpContentType", ")", "+", "projectName", "+", "\"/\"", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Unsupported dump type \"", "+", "dumpContentType", ")", ";", "}", "}" ]
Returns the absolute directory on the Web site where dumpfiles of the given type can be found. @param dumpContentType the type of dump @return relative web directory for the current dumpfiles @throws IllegalArgumentException if the given dump file type is not known
[ "Returns", "the", "absolute", "directory", "on", "the", "Web", "site", "where", "dumpfiles", "of", "the", "given", "type", "can", "be", "found", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java#L169-L190
161,321
Wikidata/Wikidata-Toolkit
wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java
WmfDumpFile.getDumpFileCompressionType
public static CompressionType getDumpFileCompressionType(String fileName) { if (fileName.endsWith(".gz")) { return CompressionType.GZIP; } else if (fileName.endsWith(".bz2")) { return CompressionType.BZ2; } else { return CompressionType.NONE; } }
java
public static CompressionType getDumpFileCompressionType(String fileName) { if (fileName.endsWith(".gz")) { return CompressionType.GZIP; } else if (fileName.endsWith(".bz2")) { return CompressionType.BZ2; } else { return CompressionType.NONE; } }
[ "public", "static", "CompressionType", "getDumpFileCompressionType", "(", "String", "fileName", ")", "{", "if", "(", "fileName", ".", "endsWith", "(", "\".gz\"", ")", ")", "{", "return", "CompressionType", ".", "GZIP", ";", "}", "else", "if", "(", "fileName", ".", "endsWith", "(", "\".bz2\"", ")", ")", "{", "return", "CompressionType", ".", "BZ2", ";", "}", "else", "{", "return", "CompressionType", ".", "NONE", ";", "}", "}" ]
Returns the compression type of this kind of dump file using file suffixes @param fileName the name of the file @return compression type @throws IllegalArgumentException if the given dump file type is not known
[ "Returns", "the", "compression", "type", "of", "this", "kind", "of", "dump", "file", "using", "file", "suffixes" ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java#L200-L208
161,322
Wikidata/Wikidata-Toolkit
wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java
WmfDumpFile.getDumpFileDirectoryName
public static String getDumpFileDirectoryName( DumpContentType dumpContentType, String dateStamp) { return dumpContentType.toString().toLowerCase() + "-" + dateStamp; }
java
public static String getDumpFileDirectoryName( DumpContentType dumpContentType, String dateStamp) { return dumpContentType.toString().toLowerCase() + "-" + dateStamp; }
[ "public", "static", "String", "getDumpFileDirectoryName", "(", "DumpContentType", "dumpContentType", ",", "String", "dateStamp", ")", "{", "return", "dumpContentType", ".", "toString", "(", ")", ".", "toLowerCase", "(", ")", "+", "\"-\"", "+", "dateStamp", ";", "}" ]
Returns the name of the directory where the dumpfile of the given type and date should be stored. @param dumpContentType the type of the dump @param dateStamp the date of the dump in format YYYYMMDD @return the local directory name for the dumpfile
[ "Returns", "the", "name", "of", "the", "directory", "where", "the", "dumpfile", "of", "the", "given", "type", "and", "date", "should", "be", "stored", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java#L220-L223
161,323
Wikidata/Wikidata-Toolkit
wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java
WmfDumpFile.getDumpFileName
public static String getDumpFileName(DumpContentType dumpContentType, String projectName, String dateStamp) { if (dumpContentType == DumpContentType.JSON) { return dateStamp + WmfDumpFile.getDumpFilePostfix(dumpContentType); } else { return projectName + "-" + dateStamp + WmfDumpFile.getDumpFilePostfix(dumpContentType); } }
java
public static String getDumpFileName(DumpContentType dumpContentType, String projectName, String dateStamp) { if (dumpContentType == DumpContentType.JSON) { return dateStamp + WmfDumpFile.getDumpFilePostfix(dumpContentType); } else { return projectName + "-" + dateStamp + WmfDumpFile.getDumpFilePostfix(dumpContentType); } }
[ "public", "static", "String", "getDumpFileName", "(", "DumpContentType", "dumpContentType", ",", "String", "projectName", ",", "String", "dateStamp", ")", "{", "if", "(", "dumpContentType", "==", "DumpContentType", ".", "JSON", ")", "{", "return", "dateStamp", "+", "WmfDumpFile", ".", "getDumpFilePostfix", "(", "dumpContentType", ")", ";", "}", "else", "{", "return", "projectName", "+", "\"-\"", "+", "dateStamp", "+", "WmfDumpFile", ".", "getDumpFilePostfix", "(", "dumpContentType", ")", ";", "}", "}" ]
Returns the name under which this dump file. This is the name used online and also locally when downloading the file. @param dumpContentType the type of the dump @param projectName the project name, e.g. "wikidatawiki" @param dateStamp the date of the dump in format YYYYMMDD @return file name string
[ "Returns", "the", "name", "under", "which", "this", "dump", "file", ".", "This", "is", "the", "name", "used", "online", "and", "also", "locally", "when", "downloading", "the", "file", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java#L253-L261
161,324
Wikidata/Wikidata-Toolkit
wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java
WmfDumpFile.isRevisionDumpFile
public static boolean isRevisionDumpFile(DumpContentType dumpContentType) { if (WmfDumpFile.REVISION_DUMP.containsKey(dumpContentType)) { return WmfDumpFile.REVISION_DUMP.get(dumpContentType); } else { throw new IllegalArgumentException("Unsupported dump type " + dumpContentType); } }
java
public static boolean isRevisionDumpFile(DumpContentType dumpContentType) { if (WmfDumpFile.REVISION_DUMP.containsKey(dumpContentType)) { return WmfDumpFile.REVISION_DUMP.get(dumpContentType); } else { throw new IllegalArgumentException("Unsupported dump type " + dumpContentType); } }
[ "public", "static", "boolean", "isRevisionDumpFile", "(", "DumpContentType", "dumpContentType", ")", "{", "if", "(", "WmfDumpFile", ".", "REVISION_DUMP", ".", "containsKey", "(", "dumpContentType", ")", ")", "{", "return", "WmfDumpFile", ".", "REVISION_DUMP", ".", "get", "(", "dumpContentType", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Unsupported dump type \"", "+", "dumpContentType", ")", ";", "}", "}" ]
Returns true if the given dump file type contains page revisions and false if it does not. Dumps that do not contain pages are for auxiliary information such as linked sites. @param dumpContentType the type of dump @return true if the dumpfile contains revisions @throws IllegalArgumentException if the given dump file type is not known
[ "Returns", "true", "if", "the", "given", "dump", "file", "type", "contains", "page", "revisions", "and", "false", "if", "it", "does", "not", ".", "Dumps", "that", "do", "not", "contain", "pages", "are", "for", "auxiliary", "information", "such", "as", "linked", "sites", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/wmf/WmfDumpFile.java#L274-L281
161,325
Wikidata/Wikidata-Toolkit
wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/JsonDumpFileProcessor.java
JsonDumpFileProcessor.processDumpFileContentsRecovery
private void processDumpFileContentsRecovery(InputStream inputStream) throws IOException { JsonDumpFileProcessor.logger .warn("Entering recovery mode to parse rest of file. This might be slightly slower."); BufferedReader br = new BufferedReader(new InputStreamReader( inputStream)); String line = br.readLine(); if (line == null) { // can happen if iterator already has consumed all // the stream return; } if (line.length() >= 100) { line = line.substring(0, 100) + "[...]" + line.substring(line.length() - 50); } JsonDumpFileProcessor.logger.warn("Skipping rest of current line: " + line); line = br.readLine(); while (line != null && line.length() > 1) { try { EntityDocument document; if (line.charAt(line.length() - 1) == ',') { document = documentReader.readValue(line.substring(0, line.length() - 1)); } else { document = documentReader.readValue(line); } handleDocument(document); } catch (JsonProcessingException e) { logJsonProcessingException(e); JsonDumpFileProcessor.logger.error("Problematic line was: " + line.substring(0, Math.min(50, line.length())) + "..."); } line = br.readLine(); } }
java
private void processDumpFileContentsRecovery(InputStream inputStream) throws IOException { JsonDumpFileProcessor.logger .warn("Entering recovery mode to parse rest of file. This might be slightly slower."); BufferedReader br = new BufferedReader(new InputStreamReader( inputStream)); String line = br.readLine(); if (line == null) { // can happen if iterator already has consumed all // the stream return; } if (line.length() >= 100) { line = line.substring(0, 100) + "[...]" + line.substring(line.length() - 50); } JsonDumpFileProcessor.logger.warn("Skipping rest of current line: " + line); line = br.readLine(); while (line != null && line.length() > 1) { try { EntityDocument document; if (line.charAt(line.length() - 1) == ',') { document = documentReader.readValue(line.substring(0, line.length() - 1)); } else { document = documentReader.readValue(line); } handleDocument(document); } catch (JsonProcessingException e) { logJsonProcessingException(e); JsonDumpFileProcessor.logger.error("Problematic line was: " + line.substring(0, Math.min(50, line.length())) + "..."); } line = br.readLine(); } }
[ "private", "void", "processDumpFileContentsRecovery", "(", "InputStream", "inputStream", ")", "throws", "IOException", "{", "JsonDumpFileProcessor", ".", "logger", ".", "warn", "(", "\"Entering recovery mode to parse rest of file. This might be slightly slower.\"", ")", ";", "BufferedReader", "br", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "inputStream", ")", ")", ";", "String", "line", "=", "br", ".", "readLine", "(", ")", ";", "if", "(", "line", "==", "null", ")", "{", "// can happen if iterator already has consumed all", "// the stream", "return", ";", "}", "if", "(", "line", ".", "length", "(", ")", ">=", "100", ")", "{", "line", "=", "line", ".", "substring", "(", "0", ",", "100", ")", "+", "\"[...]\"", "+", "line", ".", "substring", "(", "line", ".", "length", "(", ")", "-", "50", ")", ";", "}", "JsonDumpFileProcessor", ".", "logger", ".", "warn", "(", "\"Skipping rest of current line: \"", "+", "line", ")", ";", "line", "=", "br", ".", "readLine", "(", ")", ";", "while", "(", "line", "!=", "null", "&&", "line", ".", "length", "(", ")", ">", "1", ")", "{", "try", "{", "EntityDocument", "document", ";", "if", "(", "line", ".", "charAt", "(", "line", ".", "length", "(", ")", "-", "1", ")", "==", "'", "'", ")", "{", "document", "=", "documentReader", ".", "readValue", "(", "line", ".", "substring", "(", "0", ",", "line", ".", "length", "(", ")", "-", "1", ")", ")", ";", "}", "else", "{", "document", "=", "documentReader", ".", "readValue", "(", "line", ")", ";", "}", "handleDocument", "(", "document", ")", ";", "}", "catch", "(", "JsonProcessingException", "e", ")", "{", "logJsonProcessingException", "(", "e", ")", ";", "JsonDumpFileProcessor", ".", "logger", ".", "error", "(", "\"Problematic line was: \"", "+", "line", ".", "substring", "(", "0", ",", "Math", ".", "min", "(", "50", ",", "line", ".", "length", "(", ")", ")", ")", "+", "\"...\"", ")", ";", "}", "line", "=", "br", ".", "readLine", "(", ")", ";", "}", "}" ]
Process dump file data from the given input stream. The method can recover from an errors that occurred while processing an input stream, which is assumed to contain the JSON serialization of a list of JSON entities, with each entity serialization in one line. To recover from the previous error, the first line is skipped. @param inputStream the stream to read from @throws IOException if there is a problem reading the stream
[ "Process", "dump", "file", "data", "from", "the", "given", "input", "stream", ".", "The", "method", "can", "recover", "from", "an", "errors", "that", "occurred", "while", "processing", "an", "input", "stream", "which", "is", "assumed", "to", "contain", "the", "JSON", "serialization", "of", "a", "list", "of", "JSON", "entities", "with", "each", "entity", "serialization", "in", "one", "line", ".", "To", "recover", "from", "the", "previous", "error", "the", "first", "line", "is", "skipped", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/JsonDumpFileProcessor.java#L148-L188
161,326
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/JsonSerializer.java
JsonSerializer.reportException
private void reportException(Exception e) { logger.error("Failed to write JSON export: " + e.toString()); throw new RuntimeException(e.toString(), e); }
java
private void reportException(Exception e) { logger.error("Failed to write JSON export: " + e.toString()); throw new RuntimeException(e.toString(), e); }
[ "private", "void", "reportException", "(", "Exception", "e", ")", "{", "logger", ".", "error", "(", "\"Failed to write JSON export: \"", "+", "e", ".", "toString", "(", ")", ")", ";", "throw", "new", "RuntimeException", "(", "e", ".", "toString", "(", ")", ",", "e", ")", ";", "}" ]
Reports a given exception as a RuntimeException, since the interface does not allow us to throw checked exceptions directly. @param e the exception to report @throws RuntimeException in all cases
[ "Reports", "a", "given", "exception", "as", "a", "RuntimeException", "since", "the", "interface", "does", "not", "allow", "us", "to", "throw", "checked", "exceptions", "directly", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/JsonSerializer.java#L140-L143
161,327
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/JsonSerializer.java
JsonSerializer.jacksonObjectToString
protected static String jacksonObjectToString(Object object) { try { return mapper.writeValueAsString(object); } catch (JsonProcessingException e) { logger.error("Failed to serialize JSON data: " + e.toString()); return null; } }
java
protected static String jacksonObjectToString(Object object) { try { return mapper.writeValueAsString(object); } catch (JsonProcessingException e) { logger.error("Failed to serialize JSON data: " + e.toString()); return null; } }
[ "protected", "static", "String", "jacksonObjectToString", "(", "Object", "object", ")", "{", "try", "{", "return", "mapper", ".", "writeValueAsString", "(", "object", ")", ";", "}", "catch", "(", "JsonProcessingException", "e", ")", "{", "logger", ".", "error", "(", "\"Failed to serialize JSON data: \"", "+", "e", ".", "toString", "(", ")", ")", ";", "return", "null", ";", "}", "}" ]
Serializes the given object in JSON and returns the resulting string. In case of errors, null is returned. In particular, this happens if the object is not based on a Jackson-annotated class. An error is logged in this case. @param object object to serialize @return JSON serialization or null
[ "Serializes", "the", "given", "object", "in", "JSON", "and", "returns", "the", "resulting", "string", ".", "In", "case", "of", "errors", "null", "is", "returned", ".", "In", "particular", "this", "happens", "if", "the", "object", "is", "not", "based", "on", "a", "Jackson", "-", "annotated", "class", ".", "An", "error", "is", "logged", "in", "this", "case", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/JsonSerializer.java#L209-L216
161,328
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/ToString.java
ToString.getTimePrecisionString
protected static String getTimePrecisionString(byte precision) { switch (precision) { case TimeValue.PREC_SECOND: return "sec"; case TimeValue.PREC_MINUTE: return "min"; case TimeValue.PREC_HOUR: return "hour"; case TimeValue.PREC_DAY: return "day"; case TimeValue.PREC_MONTH: return "month"; case TimeValue.PREC_YEAR: return "year"; case TimeValue.PREC_DECADE: return "decade"; case TimeValue.PREC_100Y: return "100 years"; case TimeValue.PREC_1KY: return "1000 years"; case TimeValue.PREC_10KY: return "10K years"; case TimeValue.PREC_100KY: return "100K years"; case TimeValue.PREC_1MY: return "1 million years"; case TimeValue.PREC_10MY: return "10 million years"; case TimeValue.PREC_100MY: return "100 million years"; case TimeValue.PREC_1GY: return "1000 million years"; default: return "Unsupported precision " + precision; } }
java
protected static String getTimePrecisionString(byte precision) { switch (precision) { case TimeValue.PREC_SECOND: return "sec"; case TimeValue.PREC_MINUTE: return "min"; case TimeValue.PREC_HOUR: return "hour"; case TimeValue.PREC_DAY: return "day"; case TimeValue.PREC_MONTH: return "month"; case TimeValue.PREC_YEAR: return "year"; case TimeValue.PREC_DECADE: return "decade"; case TimeValue.PREC_100Y: return "100 years"; case TimeValue.PREC_1KY: return "1000 years"; case TimeValue.PREC_10KY: return "10K years"; case TimeValue.PREC_100KY: return "100K years"; case TimeValue.PREC_1MY: return "1 million years"; case TimeValue.PREC_10MY: return "10 million years"; case TimeValue.PREC_100MY: return "100 million years"; case TimeValue.PREC_1GY: return "1000 million years"; default: return "Unsupported precision " + precision; } }
[ "protected", "static", "String", "getTimePrecisionString", "(", "byte", "precision", ")", "{", "switch", "(", "precision", ")", "{", "case", "TimeValue", ".", "PREC_SECOND", ":", "return", "\"sec\"", ";", "case", "TimeValue", ".", "PREC_MINUTE", ":", "return", "\"min\"", ";", "case", "TimeValue", ".", "PREC_HOUR", ":", "return", "\"hour\"", ";", "case", "TimeValue", ".", "PREC_DAY", ":", "return", "\"day\"", ";", "case", "TimeValue", ".", "PREC_MONTH", ":", "return", "\"month\"", ";", "case", "TimeValue", ".", "PREC_YEAR", ":", "return", "\"year\"", ";", "case", "TimeValue", ".", "PREC_DECADE", ":", "return", "\"decade\"", ";", "case", "TimeValue", ".", "PREC_100Y", ":", "return", "\"100 years\"", ";", "case", "TimeValue", ".", "PREC_1KY", ":", "return", "\"1000 years\"", ";", "case", "TimeValue", ".", "PREC_10KY", ":", "return", "\"10K years\"", ";", "case", "TimeValue", ".", "PREC_100KY", ":", "return", "\"100K years\"", ";", "case", "TimeValue", ".", "PREC_1MY", ":", "return", "\"1 million years\"", ";", "case", "TimeValue", ".", "PREC_10MY", ":", "return", "\"10 million years\"", ";", "case", "TimeValue", ".", "PREC_100MY", ":", "return", "\"100 million years\"", ";", "case", "TimeValue", ".", "PREC_1GY", ":", "return", "\"1000 million years\"", ";", "default", ":", "return", "\"Unsupported precision \"", "+", "precision", ";", "}", "}" ]
Returns a human-readable string representation of a reference to a precision that is used for a time value. @param precision the numeric precision @return a string representation of the precision
[ "Returns", "a", "human", "-", "readable", "string", "representation", "of", "a", "reference", "to", "a", "precision", "that", "is", "used", "for", "a", "time", "value", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/ToString.java#L630-L665
161,329
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbEditingAction.java
WbEditingAction.wbSetLabel
public JsonNode wbSetLabel(String id, String site, String title, String newEntity, String language, String value, boolean bot, long baserevid, String summary) throws IOException, MediaWikiApiErrorException { Validate.notNull(language, "Language parameter cannot be null when setting a label"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("language", language); if (value != null) { parameters.put("value", value); } JsonNode response = performAPIAction("wbsetlabel", id, site, title, newEntity, parameters, summary, baserevid, bot); return response; }
java
public JsonNode wbSetLabel(String id, String site, String title, String newEntity, String language, String value, boolean bot, long baserevid, String summary) throws IOException, MediaWikiApiErrorException { Validate.notNull(language, "Language parameter cannot be null when setting a label"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("language", language); if (value != null) { parameters.put("value", value); } JsonNode response = performAPIAction("wbsetlabel", id, site, title, newEntity, parameters, summary, baserevid, bot); return response; }
[ "public", "JsonNode", "wbSetLabel", "(", "String", "id", ",", "String", "site", ",", "String", "title", ",", "String", "newEntity", ",", "String", "language", ",", "String", "value", ",", "boolean", "bot", ",", "long", "baserevid", ",", "String", "summary", ")", "throws", "IOException", ",", "MediaWikiApiErrorException", "{", "Validate", ".", "notNull", "(", "language", ",", "\"Language parameter cannot be null when setting a label\"", ")", ";", "Map", "<", "String", ",", "String", ">", "parameters", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "parameters", ".", "put", "(", "\"language\"", ",", "language", ")", ";", "if", "(", "value", "!=", "null", ")", "{", "parameters", ".", "put", "(", "\"value\"", ",", "value", ")", ";", "}", "JsonNode", "response", "=", "performAPIAction", "(", "\"wbsetlabel\"", ",", "id", ",", "site", ",", "title", ",", "newEntity", ",", "parameters", ",", "summary", ",", "baserevid", ",", "bot", ")", ";", "return", "response", ";", "}" ]
Executes the API action "wbsetlabel" for the given parameters. @param id the id of the entity to be edited; if used, the site and title parameters must be null @param site when selecting an entity by title, the site key for the title, e.g., "enwiki"; if used, title must also be given but id must be null @param title string used to select an entity by title; if used, site must also be given but id must be null @param newEntity used for creating a new entity of a given type; the value indicates the intended entity type; possible values include "item" and "property"; if used, the parameters id, site, and title must be null @param language the language code for the label @param value the value of the label to set. Set it to null to remove the label. @param bot if true, edits will be flagged as "bot edits" provided that the logged in user is in the bot group; for regular users, the flag will just be ignored @param baserevid the revision of the data that the edit refers to or 0 if this should not be submitted; when used, the site will ensure that no edit has happened since this revision to detect edit conflicts; it is recommended to use this whenever in all operations where the outcome depends on the state of the online data @param summary summary for the edit; will be prepended by an automatically generated comment; the length limit of the autocomment together with the summary is 260 characters: everything above that limit will be cut off @return the label as returned by the API @throws IOException if there was an IO problem. such as missing network connection @throws MediaWikiApiErrorException if the API returns an error @throws IOException @throws MediaWikiApiErrorException
[ "Executes", "the", "API", "action", "wbsetlabel", "for", "the", "given", "parameters", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbEditingAction.java#L345-L361
161,330
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbEditingAction.java
WbEditingAction.wbSetAliases
public JsonNode wbSetAliases(String id, String site, String title, String newEntity, String language, List<String> add, List<String> remove, List<String> set, boolean bot, long baserevid, String summary) throws IOException, MediaWikiApiErrorException { Validate.notNull(language, "Language parameter cannot be null when setting aliases"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("language", language); if (set != null) { if (add != null || remove != null) { throw new IllegalArgumentException( "Cannot use parameters \"add\" or \"remove\" when using \"set\" to edit aliases"); } parameters.put("set", ApiConnection.implodeObjects(set)); } if (add != null) { parameters.put("add", ApiConnection.implodeObjects(add)); } if (remove != null) { parameters.put("remove", ApiConnection.implodeObjects(remove)); } JsonNode response = performAPIAction("wbsetaliases", id, site, title, newEntity, parameters, summary, baserevid, bot); return response; }
java
public JsonNode wbSetAliases(String id, String site, String title, String newEntity, String language, List<String> add, List<String> remove, List<String> set, boolean bot, long baserevid, String summary) throws IOException, MediaWikiApiErrorException { Validate.notNull(language, "Language parameter cannot be null when setting aliases"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("language", language); if (set != null) { if (add != null || remove != null) { throw new IllegalArgumentException( "Cannot use parameters \"add\" or \"remove\" when using \"set\" to edit aliases"); } parameters.put("set", ApiConnection.implodeObjects(set)); } if (add != null) { parameters.put("add", ApiConnection.implodeObjects(add)); } if (remove != null) { parameters.put("remove", ApiConnection.implodeObjects(remove)); } JsonNode response = performAPIAction("wbsetaliases", id, site, title, newEntity, parameters, summary, baserevid, bot); return response; }
[ "public", "JsonNode", "wbSetAliases", "(", "String", "id", ",", "String", "site", ",", "String", "title", ",", "String", "newEntity", ",", "String", "language", ",", "List", "<", "String", ">", "add", ",", "List", "<", "String", ">", "remove", ",", "List", "<", "String", ">", "set", ",", "boolean", "bot", ",", "long", "baserevid", ",", "String", "summary", ")", "throws", "IOException", ",", "MediaWikiApiErrorException", "{", "Validate", ".", "notNull", "(", "language", ",", "\"Language parameter cannot be null when setting aliases\"", ")", ";", "Map", "<", "String", ",", "String", ">", "parameters", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "parameters", ".", "put", "(", "\"language\"", ",", "language", ")", ";", "if", "(", "set", "!=", "null", ")", "{", "if", "(", "add", "!=", "null", "||", "remove", "!=", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Cannot use parameters \\\"add\\\" or \\\"remove\\\" when using \\\"set\\\" to edit aliases\"", ")", ";", "}", "parameters", ".", "put", "(", "\"set\"", ",", "ApiConnection", ".", "implodeObjects", "(", "set", ")", ")", ";", "}", "if", "(", "add", "!=", "null", ")", "{", "parameters", ".", "put", "(", "\"add\"", ",", "ApiConnection", ".", "implodeObjects", "(", "add", ")", ")", ";", "}", "if", "(", "remove", "!=", "null", ")", "{", "parameters", ".", "put", "(", "\"remove\"", ",", "ApiConnection", ".", "implodeObjects", "(", "remove", ")", ")", ";", "}", "JsonNode", "response", "=", "performAPIAction", "(", "\"wbsetaliases\"", ",", "id", ",", "site", ",", "title", ",", "newEntity", ",", "parameters", ",", "summary", ",", "baserevid", ",", "bot", ")", ";", "return", "response", ";", "}" ]
Executes the API action "wbsetaliases" for the given parameters. @param id the id of the entity to be edited; if used, the site and title parameters must be null @param site when selecting an entity by title, the site key for the title, e.g., "enwiki"; if used, title must also be given but id must be null @param title string used to select an entity by title; if used, site must also be given but id must be null @param newEntity used for creating a new entity of a given type; the value indicates the intended entity type; possible values include "item" and "property"; if used, the parameters id, site, and title must be null @param language the language code for the label @param add the values of the aliases to add. They will be merged with the existing aliases. This parameter cannot be used in conjunction with "set". @param remove the values of the aliases to remove. Other aliases will be retained. This parameter cannot be used in conjunction with "set". @param set the values of the aliases to set. This will erase any existing aliases in this language and replace them by the given list. @param bot if true, edits will be flagged as "bot edits" provided that the logged in user is in the bot group; for regular users, the flag will just be ignored @param baserevid the revision of the data that the edit refers to or 0 if this should not be submitted; when used, the site will ensure that no edit has happened since this revision to detect edit conflicts; it is recommended to use this whenever in all operations where the outcome depends on the state of the online data @param summary summary for the edit; will be prepended by an automatically generated comment; the length limit of the autocomment together with the summary is 260 characters: everything above that limit will be cut off @return the JSON response from the API @throws IOException if there was an IO problem. such as missing network connection @throws MediaWikiApiErrorException if the API returns an error @throws IOException @throws MediaWikiApiErrorException
[ "Executes", "the", "API", "action", "wbsetaliases", "for", "the", "given", "parameters", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbEditingAction.java#L482-L508
161,331
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbEditingAction.java
WbEditingAction.wbSetClaim
public JsonNode wbSetClaim(String statement, boolean bot, long baserevid, String summary) throws IOException, MediaWikiApiErrorException { Validate.notNull(statement, "Statement parameter cannot be null when adding or changing a statement"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("claim", statement); return performAPIAction("wbsetclaim", null, null, null, null, parameters, summary, baserevid, bot); }
java
public JsonNode wbSetClaim(String statement, boolean bot, long baserevid, String summary) throws IOException, MediaWikiApiErrorException { Validate.notNull(statement, "Statement parameter cannot be null when adding or changing a statement"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("claim", statement); return performAPIAction("wbsetclaim", null, null, null, null, parameters, summary, baserevid, bot); }
[ "public", "JsonNode", "wbSetClaim", "(", "String", "statement", ",", "boolean", "bot", ",", "long", "baserevid", ",", "String", "summary", ")", "throws", "IOException", ",", "MediaWikiApiErrorException", "{", "Validate", ".", "notNull", "(", "statement", ",", "\"Statement parameter cannot be null when adding or changing a statement\"", ")", ";", "Map", "<", "String", ",", "String", ">", "parameters", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "parameters", ".", "put", "(", "\"claim\"", ",", "statement", ")", ";", "return", "performAPIAction", "(", "\"wbsetclaim\"", ",", "null", ",", "null", ",", "null", ",", "null", ",", "parameters", ",", "summary", ",", "baserevid", ",", "bot", ")", ";", "}" ]
Executes the API action "wbsetclaim" for the given parameters. @param statement the JSON serialization of claim to add or delete. @param bot if true, edits will be flagged as "bot edits" provided that the logged in user is in the bot group; for regular users, the flag will just be ignored @param baserevid the revision of the data that the edit refers to or 0 if this should not be submitted; when used, the site will ensure that no edit has happened since this revision to detect edit conflicts; it is recommended to use this whenever in all operations where the outcome depends on the state of the online data @param summary summary for the edit; will be prepended by an automatically generated comment; the length limit of the autocomment together with the summary is 260 characters: everything above that limit will be cut off @return the JSON response from the API @throws IOException if there was an IO problem. such as missing network connection @throws MediaWikiApiErrorException if the API returns an error @throws IOException @throws MediaWikiApiErrorException
[ "Executes", "the", "API", "action", "wbsetclaim", "for", "the", "given", "parameters", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbEditingAction.java#L540-L551
161,332
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbEditingAction.java
WbEditingAction.wbRemoveClaims
public JsonNode wbRemoveClaims(List<String> statementIds, boolean bot, long baserevid, String summary) throws IOException, MediaWikiApiErrorException { Validate.notNull(statementIds, "statementIds parameter cannot be null when deleting statements"); Validate.notEmpty(statementIds, "statement ids to delete must be non-empty when deleting statements"); Validate.isTrue(statementIds.size() <= 50, "At most 50 statements can be deleted at once"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("claim", String.join("|", statementIds)); return performAPIAction("wbremoveclaims", null, null, null, null, parameters, summary, baserevid, bot); }
java
public JsonNode wbRemoveClaims(List<String> statementIds, boolean bot, long baserevid, String summary) throws IOException, MediaWikiApiErrorException { Validate.notNull(statementIds, "statementIds parameter cannot be null when deleting statements"); Validate.notEmpty(statementIds, "statement ids to delete must be non-empty when deleting statements"); Validate.isTrue(statementIds.size() <= 50, "At most 50 statements can be deleted at once"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("claim", String.join("|", statementIds)); return performAPIAction("wbremoveclaims", null, null, null, null, parameters, summary, baserevid, bot); }
[ "public", "JsonNode", "wbRemoveClaims", "(", "List", "<", "String", ">", "statementIds", ",", "boolean", "bot", ",", "long", "baserevid", ",", "String", "summary", ")", "throws", "IOException", ",", "MediaWikiApiErrorException", "{", "Validate", ".", "notNull", "(", "statementIds", ",", "\"statementIds parameter cannot be null when deleting statements\"", ")", ";", "Validate", ".", "notEmpty", "(", "statementIds", ",", "\"statement ids to delete must be non-empty when deleting statements\"", ")", ";", "Validate", ".", "isTrue", "(", "statementIds", ".", "size", "(", ")", "<=", "50", ",", "\"At most 50 statements can be deleted at once\"", ")", ";", "Map", "<", "String", ",", "String", ">", "parameters", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "parameters", ".", "put", "(", "\"claim\"", ",", "String", ".", "join", "(", "\"|\"", ",", "statementIds", ")", ")", ";", "return", "performAPIAction", "(", "\"wbremoveclaims\"", ",", "null", ",", "null", ",", "null", ",", "null", ",", "parameters", ",", "summary", ",", "baserevid", ",", "bot", ")", ";", "}" ]
Executes the API action "wbremoveclaims" for the given parameters. @param statementIds the statement ids to delete @param bot if true, edits will be flagged as "bot edits" provided that the logged in user is in the bot group; for regular users, the flag will just be ignored @param baserevid the revision of the data that the edit refers to or 0 if this should not be submitted; when used, the site will ensure that no edit has happened since this revision to detect edit conflicts; it is recommended to use this whenever in all operations where the outcome depends on the state of the online data @param summary summary for the edit; will be prepended by an automatically generated comment; the length limit of the autocomment together with the summary is 260 characters: everything above that limit will be cut off @return the JSON response from the API @throws IOException if there was an IO problem. such as missing network connection @throws MediaWikiApiErrorException if the API returns an error @throws IOException @throws MediaWikiApiErrorException
[ "Executes", "the", "API", "action", "wbremoveclaims", "for", "the", "given", "parameters", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbEditingAction.java#L583-L597
161,333
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/bots/FixIntegerQuantityPrecisionsBot.java
FixIntegerQuantityPrecisionsBot.fixIntegerPrecisions
protected void fixIntegerPrecisions(ItemIdValue itemIdValue, String propertyId) { String qid = itemIdValue.getId(); try { // Fetch the online version of the item to make sure we edit the // current version: ItemDocument currentItemDocument = (ItemDocument) dataFetcher .getEntityDocument(qid); if (currentItemDocument == null) { System.out.println("*** " + qid + " could not be fetched. Maybe it has been deleted."); return; } // Get the current statements for the property we want to fix: StatementGroup editPropertyStatements = currentItemDocument .findStatementGroup(propertyId); if (editPropertyStatements == null) { System.out.println("*** " + qid + " no longer has any statements for " + propertyId); return; } PropertyIdValue property = Datamodel .makeWikidataPropertyIdValue(propertyId); List<Statement> updateStatements = new ArrayList<>(); for (Statement s : editPropertyStatements) { QuantityValue qv = (QuantityValue) s.getValue(); if (qv != null && isPlusMinusOneValue(qv)) { QuantityValue exactValue = Datamodel.makeQuantityValue( qv.getNumericValue(), qv.getNumericValue(), qv.getNumericValue()); Statement exactStatement = StatementBuilder .forSubjectAndProperty(itemIdValue, property) .withValue(exactValue).withId(s.getStatementId()) .withQualifiers(s.getQualifiers()) .withReferences(s.getReferences()) .withRank(s.getRank()).build(); updateStatements.add(exactStatement); } } if (updateStatements.size() == 0) { System.out.println("*** " + qid + " quantity values for " + propertyId + " already fixed"); return; } logEntityModification(currentItemDocument.getEntityId(), updateStatements, propertyId); dataEditor.updateStatements(currentItemDocument, updateStatements, Collections.<Statement> emptyList(), "Set exact values for [[Property:" + propertyId + "|" + propertyId + "]] integer quantities (Task MB2)"); } catch (MediaWikiApiErrorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
java
protected void fixIntegerPrecisions(ItemIdValue itemIdValue, String propertyId) { String qid = itemIdValue.getId(); try { // Fetch the online version of the item to make sure we edit the // current version: ItemDocument currentItemDocument = (ItemDocument) dataFetcher .getEntityDocument(qid); if (currentItemDocument == null) { System.out.println("*** " + qid + " could not be fetched. Maybe it has been deleted."); return; } // Get the current statements for the property we want to fix: StatementGroup editPropertyStatements = currentItemDocument .findStatementGroup(propertyId); if (editPropertyStatements == null) { System.out.println("*** " + qid + " no longer has any statements for " + propertyId); return; } PropertyIdValue property = Datamodel .makeWikidataPropertyIdValue(propertyId); List<Statement> updateStatements = new ArrayList<>(); for (Statement s : editPropertyStatements) { QuantityValue qv = (QuantityValue) s.getValue(); if (qv != null && isPlusMinusOneValue(qv)) { QuantityValue exactValue = Datamodel.makeQuantityValue( qv.getNumericValue(), qv.getNumericValue(), qv.getNumericValue()); Statement exactStatement = StatementBuilder .forSubjectAndProperty(itemIdValue, property) .withValue(exactValue).withId(s.getStatementId()) .withQualifiers(s.getQualifiers()) .withReferences(s.getReferences()) .withRank(s.getRank()).build(); updateStatements.add(exactStatement); } } if (updateStatements.size() == 0) { System.out.println("*** " + qid + " quantity values for " + propertyId + " already fixed"); return; } logEntityModification(currentItemDocument.getEntityId(), updateStatements, propertyId); dataEditor.updateStatements(currentItemDocument, updateStatements, Collections.<Statement> emptyList(), "Set exact values for [[Property:" + propertyId + "|" + propertyId + "]] integer quantities (Task MB2)"); } catch (MediaWikiApiErrorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
[ "protected", "void", "fixIntegerPrecisions", "(", "ItemIdValue", "itemIdValue", ",", "String", "propertyId", ")", "{", "String", "qid", "=", "itemIdValue", ".", "getId", "(", ")", ";", "try", "{", "// Fetch the online version of the item to make sure we edit the", "// current version:", "ItemDocument", "currentItemDocument", "=", "(", "ItemDocument", ")", "dataFetcher", ".", "getEntityDocument", "(", "qid", ")", ";", "if", "(", "currentItemDocument", "==", "null", ")", "{", "System", ".", "out", ".", "println", "(", "\"*** \"", "+", "qid", "+", "\" could not be fetched. Maybe it has been deleted.\"", ")", ";", "return", ";", "}", "// Get the current statements for the property we want to fix:", "StatementGroup", "editPropertyStatements", "=", "currentItemDocument", ".", "findStatementGroup", "(", "propertyId", ")", ";", "if", "(", "editPropertyStatements", "==", "null", ")", "{", "System", ".", "out", ".", "println", "(", "\"*** \"", "+", "qid", "+", "\" no longer has any statements for \"", "+", "propertyId", ")", ";", "return", ";", "}", "PropertyIdValue", "property", "=", "Datamodel", ".", "makeWikidataPropertyIdValue", "(", "propertyId", ")", ";", "List", "<", "Statement", ">", "updateStatements", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "Statement", "s", ":", "editPropertyStatements", ")", "{", "QuantityValue", "qv", "=", "(", "QuantityValue", ")", "s", ".", "getValue", "(", ")", ";", "if", "(", "qv", "!=", "null", "&&", "isPlusMinusOneValue", "(", "qv", ")", ")", "{", "QuantityValue", "exactValue", "=", "Datamodel", ".", "makeQuantityValue", "(", "qv", ".", "getNumericValue", "(", ")", ",", "qv", ".", "getNumericValue", "(", ")", ",", "qv", ".", "getNumericValue", "(", ")", ")", ";", "Statement", "exactStatement", "=", "StatementBuilder", ".", "forSubjectAndProperty", "(", "itemIdValue", ",", "property", ")", ".", "withValue", "(", "exactValue", ")", ".", "withId", "(", "s", ".", "getStatementId", "(", ")", ")", ".", "withQualifiers", "(", "s", ".", "getQualifiers", "(", ")", ")", ".", "withReferences", "(", "s", ".", "getReferences", "(", ")", ")", ".", "withRank", "(", "s", ".", "getRank", "(", ")", ")", ".", "build", "(", ")", ";", "updateStatements", ".", "add", "(", "exactStatement", ")", ";", "}", "}", "if", "(", "updateStatements", ".", "size", "(", ")", "==", "0", ")", "{", "System", ".", "out", ".", "println", "(", "\"*** \"", "+", "qid", "+", "\" quantity values for \"", "+", "propertyId", "+", "\" already fixed\"", ")", ";", "return", ";", "}", "logEntityModification", "(", "currentItemDocument", ".", "getEntityId", "(", ")", ",", "updateStatements", ",", "propertyId", ")", ";", "dataEditor", ".", "updateStatements", "(", "currentItemDocument", ",", "updateStatements", ",", "Collections", ".", "<", "Statement", ">", "emptyList", "(", ")", ",", "\"Set exact values for [[Property:\"", "+", "propertyId", "+", "\"|\"", "+", "propertyId", "+", "\"]] integer quantities (Task MB2)\"", ")", ";", "}", "catch", "(", "MediaWikiApiErrorException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Fetches the current online data for the given item, and fixes the precision of integer quantities if necessary. @param itemIdValue the id of the document to inspect @param propertyId id of the property to consider
[ "Fetches", "the", "current", "online", "data", "for", "the", "given", "item", "and", "fixes", "the", "precision", "of", "integer", "quantities", "if", "necessary", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/bots/FixIntegerQuantityPrecisionsBot.java#L282-L345
161,334
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java
StatementUpdate.markStatementsForDeletion
protected void markStatementsForDeletion(StatementDocument currentDocument, List<Statement> deleteStatements) { for (Statement statement : deleteStatements) { boolean found = false; for (StatementGroup sg : currentDocument.getStatementGroups()) { if (!sg.getProperty().equals(statement.getMainSnak().getPropertyId())) { continue; } Statement changedStatement = null; for (Statement existingStatement : sg) { if (existingStatement.equals(statement)) { found = true; toDelete.add(statement.getStatementId()); } else if (existingStatement.getStatementId().equals( statement.getStatementId())) { // (we assume all existing statement ids to be nonempty // here) changedStatement = existingStatement; break; } } if (!found) { StringBuilder warning = new StringBuilder(); warning.append("Cannot delete statement (id ") .append(statement.getStatementId()) .append(") since it is not present in data. Statement was:\n") .append(statement); if (changedStatement != null) { warning.append( "\nThe data contains another statement with the same id: maybe it has been edited? Other statement was:\n") .append(changedStatement); } logger.warn(warning.toString()); } } } }
java
protected void markStatementsForDeletion(StatementDocument currentDocument, List<Statement> deleteStatements) { for (Statement statement : deleteStatements) { boolean found = false; for (StatementGroup sg : currentDocument.getStatementGroups()) { if (!sg.getProperty().equals(statement.getMainSnak().getPropertyId())) { continue; } Statement changedStatement = null; for (Statement existingStatement : sg) { if (existingStatement.equals(statement)) { found = true; toDelete.add(statement.getStatementId()); } else if (existingStatement.getStatementId().equals( statement.getStatementId())) { // (we assume all existing statement ids to be nonempty // here) changedStatement = existingStatement; break; } } if (!found) { StringBuilder warning = new StringBuilder(); warning.append("Cannot delete statement (id ") .append(statement.getStatementId()) .append(") since it is not present in data. Statement was:\n") .append(statement); if (changedStatement != null) { warning.append( "\nThe data contains another statement with the same id: maybe it has been edited? Other statement was:\n") .append(changedStatement); } logger.warn(warning.toString()); } } } }
[ "protected", "void", "markStatementsForDeletion", "(", "StatementDocument", "currentDocument", ",", "List", "<", "Statement", ">", "deleteStatements", ")", "{", "for", "(", "Statement", "statement", ":", "deleteStatements", ")", "{", "boolean", "found", "=", "false", ";", "for", "(", "StatementGroup", "sg", ":", "currentDocument", ".", "getStatementGroups", "(", ")", ")", "{", "if", "(", "!", "sg", ".", "getProperty", "(", ")", ".", "equals", "(", "statement", ".", "getMainSnak", "(", ")", ".", "getPropertyId", "(", ")", ")", ")", "{", "continue", ";", "}", "Statement", "changedStatement", "=", "null", ";", "for", "(", "Statement", "existingStatement", ":", "sg", ")", "{", "if", "(", "existingStatement", ".", "equals", "(", "statement", ")", ")", "{", "found", "=", "true", ";", "toDelete", ".", "add", "(", "statement", ".", "getStatementId", "(", ")", ")", ";", "}", "else", "if", "(", "existingStatement", ".", "getStatementId", "(", ")", ".", "equals", "(", "statement", ".", "getStatementId", "(", ")", ")", ")", "{", "// (we assume all existing statement ids to be nonempty", "// here)", "changedStatement", "=", "existingStatement", ";", "break", ";", "}", "}", "if", "(", "!", "found", ")", "{", "StringBuilder", "warning", "=", "new", "StringBuilder", "(", ")", ";", "warning", ".", "append", "(", "\"Cannot delete statement (id \"", ")", ".", "append", "(", "statement", ".", "getStatementId", "(", ")", ")", ".", "append", "(", "\") since it is not present in data. Statement was:\\n\"", ")", ".", "append", "(", "statement", ")", ";", "if", "(", "changedStatement", "!=", "null", ")", "{", "warning", ".", "append", "(", "\"\\nThe data contains another statement with the same id: maybe it has been edited? Other statement was:\\n\"", ")", ".", "append", "(", "changedStatement", ")", ";", "}", "logger", ".", "warn", "(", "warning", ".", "toString", "(", ")", ")", ";", "}", "}", "}", "}" ]
Marks the given list of statements for deletion. It is verified that the current document actually contains the statements before doing so. This check is based on exact statement equality, including qualifier order and statement id. @param currentDocument the document with the current statements @param deleteStatements the list of statements to be deleted
[ "Marks", "the", "given", "list", "of", "statements", "for", "deletion", ".", "It", "is", "verified", "that", "the", "current", "document", "actually", "contains", "the", "statements", "before", "doing", "so", ".", "This", "check", "is", "based", "on", "exact", "statement", "equality", "including", "qualifier", "order", "and", "statement", "id", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java#L307-L346
161,335
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java
StatementUpdate.markStatementsForInsertion
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); } } } } }
java
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); } } } } }
[ "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
[ "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", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java#L361-L376
161,336
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java
StatementUpdate.addStatement
protected void addStatement(Statement statement, boolean isNew) { PropertyIdValue pid = statement.getMainSnak().getPropertyId(); // This code maintains the following properties: // (1) the toKeep structure does not contain two statements with the // same statement id // (2) the toKeep structure does not contain two statements that can // be merged if (this.toKeep.containsKey(pid)) { List<StatementWithUpdate> statements = this.toKeep.get(pid); for (int i = 0; i < statements.size(); i++) { Statement currentStatement = statements.get(i).statement; boolean currentIsNew = statements.get(i).write; if (!"".equals(currentStatement.getStatementId()) && currentStatement.getStatementId().equals( statement.getStatementId())) { // Same, non-empty id: ignore existing statement as if // deleted return; } Statement newStatement = mergeStatements(statement, currentStatement); if (newStatement != null) { boolean writeNewStatement = (isNew || !newStatement .equals(statement)) && (currentIsNew || !newStatement .equals(currentStatement)); // noWrite: (newS == statement && !isNew) // || (newS == cur && !curIsNew) // Write: (newS != statement || isNew ) // && (newS != cur || curIsNew) statements.set(i, new StatementWithUpdate(newStatement, writeNewStatement)); // Impossible with default merge code: // Kept here for future extensions that may choose to not // reuse this id. if (!"".equals(statement.getStatementId()) && !newStatement.getStatementId().equals( statement.getStatementId())) { this.toDelete.add(statement.getStatementId()); } if (!"".equals(currentStatement.getStatementId()) && !newStatement.getStatementId().equals( currentStatement.getStatementId())) { this.toDelete.add(currentStatement.getStatementId()); } return; } } statements.add(new StatementWithUpdate(statement, isNew)); } else { List<StatementWithUpdate> statements = new ArrayList<>(); statements.add(new StatementWithUpdate(statement, isNew)); this.toKeep.put(pid, statements); } }
java
protected void addStatement(Statement statement, boolean isNew) { PropertyIdValue pid = statement.getMainSnak().getPropertyId(); // This code maintains the following properties: // (1) the toKeep structure does not contain two statements with the // same statement id // (2) the toKeep structure does not contain two statements that can // be merged if (this.toKeep.containsKey(pid)) { List<StatementWithUpdate> statements = this.toKeep.get(pid); for (int i = 0; i < statements.size(); i++) { Statement currentStatement = statements.get(i).statement; boolean currentIsNew = statements.get(i).write; if (!"".equals(currentStatement.getStatementId()) && currentStatement.getStatementId().equals( statement.getStatementId())) { // Same, non-empty id: ignore existing statement as if // deleted return; } Statement newStatement = mergeStatements(statement, currentStatement); if (newStatement != null) { boolean writeNewStatement = (isNew || !newStatement .equals(statement)) && (currentIsNew || !newStatement .equals(currentStatement)); // noWrite: (newS == statement && !isNew) // || (newS == cur && !curIsNew) // Write: (newS != statement || isNew ) // && (newS != cur || curIsNew) statements.set(i, new StatementWithUpdate(newStatement, writeNewStatement)); // Impossible with default merge code: // Kept here for future extensions that may choose to not // reuse this id. if (!"".equals(statement.getStatementId()) && !newStatement.getStatementId().equals( statement.getStatementId())) { this.toDelete.add(statement.getStatementId()); } if (!"".equals(currentStatement.getStatementId()) && !newStatement.getStatementId().equals( currentStatement.getStatementId())) { this.toDelete.add(currentStatement.getStatementId()); } return; } } statements.add(new StatementWithUpdate(statement, isNew)); } else { List<StatementWithUpdate> statements = new ArrayList<>(); statements.add(new StatementWithUpdate(statement, isNew)); this.toKeep.put(pid, statements); } }
[ "protected", "void", "addStatement", "(", "Statement", "statement", ",", "boolean", "isNew", ")", "{", "PropertyIdValue", "pid", "=", "statement", ".", "getMainSnak", "(", ")", ".", "getPropertyId", "(", ")", ";", "// This code maintains the following properties:", "// (1) the toKeep structure does not contain two statements with the", "// same statement id", "// (2) the toKeep structure does not contain two statements that can", "// be merged", "if", "(", "this", ".", "toKeep", ".", "containsKey", "(", "pid", ")", ")", "{", "List", "<", "StatementWithUpdate", ">", "statements", "=", "this", ".", "toKeep", ".", "get", "(", "pid", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "statements", ".", "size", "(", ")", ";", "i", "++", ")", "{", "Statement", "currentStatement", "=", "statements", ".", "get", "(", "i", ")", ".", "statement", ";", "boolean", "currentIsNew", "=", "statements", ".", "get", "(", "i", ")", ".", "write", ";", "if", "(", "!", "\"\"", ".", "equals", "(", "currentStatement", ".", "getStatementId", "(", ")", ")", "&&", "currentStatement", ".", "getStatementId", "(", ")", ".", "equals", "(", "statement", ".", "getStatementId", "(", ")", ")", ")", "{", "// Same, non-empty id: ignore existing statement as if", "// deleted", "return", ";", "}", "Statement", "newStatement", "=", "mergeStatements", "(", "statement", ",", "currentStatement", ")", ";", "if", "(", "newStatement", "!=", "null", ")", "{", "boolean", "writeNewStatement", "=", "(", "isNew", "||", "!", "newStatement", ".", "equals", "(", "statement", ")", ")", "&&", "(", "currentIsNew", "||", "!", "newStatement", ".", "equals", "(", "currentStatement", ")", ")", ";", "// noWrite: (newS == statement && !isNew)", "// || (newS == cur && !curIsNew)", "// Write: (newS != statement || isNew )", "// && (newS != cur || curIsNew)", "statements", ".", "set", "(", "i", ",", "new", "StatementWithUpdate", "(", "newStatement", ",", "writeNewStatement", ")", ")", ";", "// Impossible with default merge code:", "// Kept here for future extensions that may choose to not", "// reuse this id.", "if", "(", "!", "\"\"", ".", "equals", "(", "statement", ".", "getStatementId", "(", ")", ")", "&&", "!", "newStatement", ".", "getStatementId", "(", ")", ".", "equals", "(", "statement", ".", "getStatementId", "(", ")", ")", ")", "{", "this", ".", "toDelete", ".", "add", "(", "statement", ".", "getStatementId", "(", ")", ")", ";", "}", "if", "(", "!", "\"\"", ".", "equals", "(", "currentStatement", ".", "getStatementId", "(", ")", ")", "&&", "!", "newStatement", ".", "getStatementId", "(", ")", ".", "equals", "(", "currentStatement", ".", "getStatementId", "(", ")", ")", ")", "{", "this", ".", "toDelete", ".", "add", "(", "currentStatement", ".", "getStatementId", "(", ")", ")", ";", "}", "return", ";", "}", "}", "statements", ".", "add", "(", "new", "StatementWithUpdate", "(", "statement", ",", "isNew", ")", ")", ";", "}", "else", "{", "List", "<", "StatementWithUpdate", ">", "statements", "=", "new", "ArrayList", "<>", "(", ")", ";", "statements", ".", "add", "(", "new", "StatementWithUpdate", "(", "statement", ",", "isNew", ")", ")", ";", "this", ".", "toKeep", ".", "put", "(", "pid", ",", "statements", ")", ";", "}", "}" ]
Adds one statement to the list of statements to be kept, possibly merging it with other statements to be kept if possible. When two existing statements are merged, one of them will be updated and the other will be marked for deletion. @param statement statement to add @param isNew if true, the statement should be marked for writing; if false, the statement already exists in the current data and is only added to remove duplicates and avoid unnecessary writes
[ "Adds", "one", "statement", "to", "the", "list", "of", "statements", "to", "be", "kept", "possibly", "merging", "it", "with", "other", "statements", "to", "be", "kept", "if", "possible", ".", "When", "two", "existing", "statements", "are", "merged", "one", "of", "them", "will", "be", "updated", "and", "the", "other", "will", "be", "marked", "for", "deletion", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java#L391-L451
161,337
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java
StatementUpdate.mergeReferences
protected List<Reference> mergeReferences( List<? extends Reference> references1, List<? extends Reference> references2) { List<Reference> result = new ArrayList<>(); for (Reference reference : references1) { addBestReferenceToList(reference, result); } for (Reference reference : references2) { addBestReferenceToList(reference, result); } return result; }
java
protected List<Reference> mergeReferences( List<? extends Reference> references1, List<? extends Reference> references2) { List<Reference> result = new ArrayList<>(); for (Reference reference : references1) { addBestReferenceToList(reference, result); } for (Reference reference : references2) { addBestReferenceToList(reference, result); } return result; }
[ "protected", "List", "<", "Reference", ">", "mergeReferences", "(", "List", "<", "?", "extends", "Reference", ">", "references1", ",", "List", "<", "?", "extends", "Reference", ">", "references2", ")", "{", "List", "<", "Reference", ">", "result", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "Reference", "reference", ":", "references1", ")", "{", "addBestReferenceToList", "(", "reference", ",", "result", ")", ";", "}", "for", "(", "Reference", "reference", ":", "references2", ")", "{", "addBestReferenceToList", "(", "reference", ",", "result", ")", ";", "}", "return", "result", ";", "}" ]
Merges two lists of references, eliminating duplicates in the process. @param references1 @param references2 @return merged list
[ "Merges", "two", "lists", "of", "references", "eliminating", "duplicates", "in", "the", "process", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java#L503-L514
161,338
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java
StatementUpdate.equivalentClaims
protected boolean equivalentClaims(Claim claim1, Claim claim2) { return claim1.getMainSnak().equals(claim2.getMainSnak()) && isSameSnakSet(claim1.getAllQualifiers(), claim2.getAllQualifiers()); }
java
protected boolean equivalentClaims(Claim claim1, Claim claim2) { return claim1.getMainSnak().equals(claim2.getMainSnak()) && isSameSnakSet(claim1.getAllQualifiers(), claim2.getAllQualifiers()); }
[ "protected", "boolean", "equivalentClaims", "(", "Claim", "claim1", ",", "Claim", "claim2", ")", "{", "return", "claim1", ".", "getMainSnak", "(", ")", ".", "equals", "(", "claim2", ".", "getMainSnak", "(", ")", ")", "&&", "isSameSnakSet", "(", "claim1", ".", "getAllQualifiers", "(", ")", ",", "claim2", ".", "getAllQualifiers", "(", ")", ")", ";", "}" ]
Checks if two claims are equivalent in the sense that they have the same main snak and the same qualifiers, but possibly in a different order. @param claim1 @param claim2 @return true if claims are equivalent
[ "Checks", "if", "two", "claims", "are", "equivalent", "in", "the", "sense", "that", "they", "have", "the", "same", "main", "snak", "and", "the", "same", "qualifiers", "but", "possibly", "in", "a", "different", "order", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java#L535-L539
161,339
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java
StatementUpdate.isSameSnakSet
protected boolean isSameSnakSet(Iterator<Snak> snaks1, Iterator<Snak> snaks2) { ArrayList<Snak> snakList1 = new ArrayList<>(5); while (snaks1.hasNext()) { snakList1.add(snaks1.next()); } int snakCount2 = 0; while (snaks2.hasNext()) { snakCount2++; Snak snak2 = snaks2.next(); boolean found = false; for (int i = 0; i < snakList1.size(); i++) { if (snak2.equals(snakList1.get(i))) { snakList1.set(i, null); found = true; break; } } if (!found) { return false; } } return snakCount2 == snakList1.size(); }
java
protected boolean isSameSnakSet(Iterator<Snak> snaks1, Iterator<Snak> snaks2) { ArrayList<Snak> snakList1 = new ArrayList<>(5); while (snaks1.hasNext()) { snakList1.add(snaks1.next()); } int snakCount2 = 0; while (snaks2.hasNext()) { snakCount2++; Snak snak2 = snaks2.next(); boolean found = false; for (int i = 0; i < snakList1.size(); i++) { if (snak2.equals(snakList1.get(i))) { snakList1.set(i, null); found = true; break; } } if (!found) { return false; } } return snakCount2 == snakList1.size(); }
[ "protected", "boolean", "isSameSnakSet", "(", "Iterator", "<", "Snak", ">", "snaks1", ",", "Iterator", "<", "Snak", ">", "snaks2", ")", "{", "ArrayList", "<", "Snak", ">", "snakList1", "=", "new", "ArrayList", "<>", "(", "5", ")", ";", "while", "(", "snaks1", ".", "hasNext", "(", ")", ")", "{", "snakList1", ".", "add", "(", "snaks1", ".", "next", "(", ")", ")", ";", "}", "int", "snakCount2", "=", "0", ";", "while", "(", "snaks2", ".", "hasNext", "(", ")", ")", "{", "snakCount2", "++", ";", "Snak", "snak2", "=", "snaks2", ".", "next", "(", ")", ";", "boolean", "found", "=", "false", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "snakList1", ".", "size", "(", ")", ";", "i", "++", ")", "{", "if", "(", "snak2", ".", "equals", "(", "snakList1", ".", "get", "(", "i", ")", ")", ")", "{", "snakList1", ".", "set", "(", "i", ",", "null", ")", ";", "found", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "found", ")", "{", "return", "false", ";", "}", "}", "return", "snakCount2", "==", "snakList1", ".", "size", "(", ")", ";", "}" ]
Compares two sets of snaks, given by iterators. The method is optimised for short lists of snaks, as they are typically found in claims and references. @param snaks1 @param snaks2 @return true if the lists are equal
[ "Compares", "two", "sets", "of", "snaks", "given", "by", "iterators", ".", "The", "method", "is", "optimised", "for", "short", "lists", "of", "snaks", "as", "they", "are", "typically", "found", "in", "claims", "and", "references", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java#L550-L574
161,340
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java
StatementUpdate.getRevisionIdFromResponse
protected long getRevisionIdFromResponse(JsonNode response) throws JsonMappingException { if(response == null) { throw new JsonMappingException("API response is null"); } JsonNode entity = null; if(response.has("entity")) { entity = response.path("entity"); } else if(response.has("pageinfo")) { entity = response.path("pageinfo"); } if(entity != null && entity.has("lastrevid")) { return entity.path("lastrevid").asLong(); } throw new JsonMappingException("The last revision id could not be found in API response"); }
java
protected long getRevisionIdFromResponse(JsonNode response) throws JsonMappingException { if(response == null) { throw new JsonMappingException("API response is null"); } JsonNode entity = null; if(response.has("entity")) { entity = response.path("entity"); } else if(response.has("pageinfo")) { entity = response.path("pageinfo"); } if(entity != null && entity.has("lastrevid")) { return entity.path("lastrevid").asLong(); } throw new JsonMappingException("The last revision id could not be found in API response"); }
[ "protected", "long", "getRevisionIdFromResponse", "(", "JsonNode", "response", ")", "throws", "JsonMappingException", "{", "if", "(", "response", "==", "null", ")", "{", "throw", "new", "JsonMappingException", "(", "\"API response is null\"", ")", ";", "}", "JsonNode", "entity", "=", "null", ";", "if", "(", "response", ".", "has", "(", "\"entity\"", ")", ")", "{", "entity", "=", "response", ".", "path", "(", "\"entity\"", ")", ";", "}", "else", "if", "(", "response", ".", "has", "(", "\"pageinfo\"", ")", ")", "{", "entity", "=", "response", ".", "path", "(", "\"pageinfo\"", ")", ";", "}", "if", "(", "entity", "!=", "null", "&&", "entity", ".", "has", "(", "\"lastrevid\"", ")", ")", "{", "return", "entity", ".", "path", "(", "\"lastrevid\"", ")", ".", "asLong", "(", ")", ";", "}", "throw", "new", "JsonMappingException", "(", "\"The last revision id could not be found in API response\"", ")", ";", "}" ]
Extracts the last revision id from the JSON response returned by the API after an edit @param response the response as returned by Mediawiki @return the new revision id of the edited entity @throws JsonMappingException
[ "Extracts", "the", "last", "revision", "id", "from", "the", "JSON", "response", "returned", "by", "the", "API", "after", "an", "edit" ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java#L594-L608
161,341
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java
StatementUpdate.getDatamodelObjectFromResponse
protected <T> T getDatamodelObjectFromResponse(JsonNode response, List<String> path, Class<T> targetClass) throws JsonProcessingException { if(response == null) { throw new JsonMappingException("The API response is null"); } JsonNode currentNode = response; for(String field : path) { if (!currentNode.has(field)) { throw new JsonMappingException("Field '"+field+"' not found in API response."); } currentNode = currentNode.path(field); } return mapper.treeToValue(currentNode, targetClass); }
java
protected <T> T getDatamodelObjectFromResponse(JsonNode response, List<String> path, Class<T> targetClass) throws JsonProcessingException { if(response == null) { throw new JsonMappingException("The API response is null"); } JsonNode currentNode = response; for(String field : path) { if (!currentNode.has(field)) { throw new JsonMappingException("Field '"+field+"' not found in API response."); } currentNode = currentNode.path(field); } return mapper.treeToValue(currentNode, targetClass); }
[ "protected", "<", "T", ">", "T", "getDatamodelObjectFromResponse", "(", "JsonNode", "response", ",", "List", "<", "String", ">", "path", ",", "Class", "<", "T", ">", "targetClass", ")", "throws", "JsonProcessingException", "{", "if", "(", "response", "==", "null", ")", "{", "throw", "new", "JsonMappingException", "(", "\"The API response is null\"", ")", ";", "}", "JsonNode", "currentNode", "=", "response", ";", "for", "(", "String", "field", ":", "path", ")", "{", "if", "(", "!", "currentNode", ".", "has", "(", "field", ")", ")", "{", "throw", "new", "JsonMappingException", "(", "\"Field '\"", "+", "field", "+", "\"' not found in API response.\"", ")", ";", "}", "currentNode", "=", "currentNode", ".", "path", "(", "field", ")", ";", "}", "return", "mapper", ".", "treeToValue", "(", "currentNode", ",", "targetClass", ")", ";", "}" ]
Extracts a particular data model instance from a JSON response returned by MediaWiki. The location is described by a list of successive fields to use, from the root to the target object. @param response the API response as returned by MediaWiki @param path a list of fields from the root to the target object @return the parsed POJO object @throws JsonProcessingException
[ "Extracts", "a", "particular", "data", "model", "instance", "from", "a", "JSON", "response", "returned", "by", "MediaWiki", ".", "The", "location", "is", "described", "by", "a", "list", "of", "successive", "fields", "to", "use", "from", "the", "root", "to", "the", "target", "object", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/StatementUpdate.java#L623-L635
161,342
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EditOnlineDataExample.java
EditOnlineDataExample.findSomeStringProperties
public static void findSomeStringProperties(ApiConnection connection) throws MediaWikiApiErrorException, IOException { WikibaseDataFetcher wbdf = new WikibaseDataFetcher(connection, siteIri); wbdf.getFilter().excludeAllProperties(); wbdf.getFilter().setLanguageFilter(Collections.singleton("en")); ArrayList<PropertyIdValue> stringProperties = new ArrayList<>(); System.out .println("*** Trying to find string properties for the example ... "); int propertyNumber = 1; while (stringProperties.size() < 5) { ArrayList<String> fetchProperties = new ArrayList<>(); for (int i = propertyNumber; i < propertyNumber + 10; i++) { fetchProperties.add("P" + i); } propertyNumber += 10; Map<String, EntityDocument> results = wbdf .getEntityDocuments(fetchProperties); for (EntityDocument ed : results.values()) { PropertyDocument pd = (PropertyDocument) ed; if (DatatypeIdValue.DT_STRING.equals(pd.getDatatype().getIri()) && pd.getLabels().containsKey("en")) { stringProperties.add(pd.getEntityId()); System.out.println("* Found string property " + pd.getEntityId().getId() + " (" + pd.getLabels().get("en") + ")"); } } } stringProperty1 = stringProperties.get(0); stringProperty2 = stringProperties.get(1); stringProperty3 = stringProperties.get(2); stringProperty4 = stringProperties.get(3); stringProperty5 = stringProperties.get(4); System.out.println("*** Done."); }
java
public static void findSomeStringProperties(ApiConnection connection) throws MediaWikiApiErrorException, IOException { WikibaseDataFetcher wbdf = new WikibaseDataFetcher(connection, siteIri); wbdf.getFilter().excludeAllProperties(); wbdf.getFilter().setLanguageFilter(Collections.singleton("en")); ArrayList<PropertyIdValue> stringProperties = new ArrayList<>(); System.out .println("*** Trying to find string properties for the example ... "); int propertyNumber = 1; while (stringProperties.size() < 5) { ArrayList<String> fetchProperties = new ArrayList<>(); for (int i = propertyNumber; i < propertyNumber + 10; i++) { fetchProperties.add("P" + i); } propertyNumber += 10; Map<String, EntityDocument> results = wbdf .getEntityDocuments(fetchProperties); for (EntityDocument ed : results.values()) { PropertyDocument pd = (PropertyDocument) ed; if (DatatypeIdValue.DT_STRING.equals(pd.getDatatype().getIri()) && pd.getLabels().containsKey("en")) { stringProperties.add(pd.getEntityId()); System.out.println("* Found string property " + pd.getEntityId().getId() + " (" + pd.getLabels().get("en") + ")"); } } } stringProperty1 = stringProperties.get(0); stringProperty2 = stringProperties.get(1); stringProperty3 = stringProperties.get(2); stringProperty4 = stringProperties.get(3); stringProperty5 = stringProperties.get(4); System.out.println("*** Done."); }
[ "public", "static", "void", "findSomeStringProperties", "(", "ApiConnection", "connection", ")", "throws", "MediaWikiApiErrorException", ",", "IOException", "{", "WikibaseDataFetcher", "wbdf", "=", "new", "WikibaseDataFetcher", "(", "connection", ",", "siteIri", ")", ";", "wbdf", ".", "getFilter", "(", ")", ".", "excludeAllProperties", "(", ")", ";", "wbdf", ".", "getFilter", "(", ")", ".", "setLanguageFilter", "(", "Collections", ".", "singleton", "(", "\"en\"", ")", ")", ";", "ArrayList", "<", "PropertyIdValue", ">", "stringProperties", "=", "new", "ArrayList", "<>", "(", ")", ";", "System", ".", "out", ".", "println", "(", "\"*** Trying to find string properties for the example ... \"", ")", ";", "int", "propertyNumber", "=", "1", ";", "while", "(", "stringProperties", ".", "size", "(", ")", "<", "5", ")", "{", "ArrayList", "<", "String", ">", "fetchProperties", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "int", "i", "=", "propertyNumber", ";", "i", "<", "propertyNumber", "+", "10", ";", "i", "++", ")", "{", "fetchProperties", ".", "add", "(", "\"P\"", "+", "i", ")", ";", "}", "propertyNumber", "+=", "10", ";", "Map", "<", "String", ",", "EntityDocument", ">", "results", "=", "wbdf", ".", "getEntityDocuments", "(", "fetchProperties", ")", ";", "for", "(", "EntityDocument", "ed", ":", "results", ".", "values", "(", ")", ")", "{", "PropertyDocument", "pd", "=", "(", "PropertyDocument", ")", "ed", ";", "if", "(", "DatatypeIdValue", ".", "DT_STRING", ".", "equals", "(", "pd", ".", "getDatatype", "(", ")", ".", "getIri", "(", ")", ")", "&&", "pd", ".", "getLabels", "(", ")", ".", "containsKey", "(", "\"en\"", ")", ")", "{", "stringProperties", ".", "add", "(", "pd", ".", "getEntityId", "(", ")", ")", ";", "System", ".", "out", ".", "println", "(", "\"* Found string property \"", "+", "pd", ".", "getEntityId", "(", ")", ".", "getId", "(", ")", "+", "\" (\"", "+", "pd", ".", "getLabels", "(", ")", ".", "get", "(", "\"en\"", ")", "+", "\")\"", ")", ";", "}", "}", "}", "stringProperty1", "=", "stringProperties", ".", "get", "(", "0", ")", ";", "stringProperty2", "=", "stringProperties", ".", "get", "(", "1", ")", ";", "stringProperty3", "=", "stringProperties", ".", "get", "(", "2", ")", ";", "stringProperty4", "=", "stringProperties", ".", "get", "(", "3", ")", ";", "stringProperty5", "=", "stringProperties", ".", "get", "(", "4", ")", ";", "System", ".", "out", ".", "println", "(", "\"*** Done.\"", ")", ";", "}" ]
Finds properties of datatype string on test.wikidata.org. Since the test site changes all the time, we cannot hardcode a specific property here. Instead, we just look through all properties starting from P1 to find the first few properties of type string that have an English label. These properties are used for testing in this code. @param connection @throws MediaWikiApiErrorException @throws IOException
[ "Finds", "properties", "of", "datatype", "string", "on", "test", ".", "wikidata", ".", "org", ".", "Since", "the", "test", "site", "changes", "all", "the", "time", "we", "cannot", "hardcode", "a", "specific", "property", "here", ".", "Instead", "we", "just", "look", "through", "all", "properties", "starting", "from", "P1", "to", "find", "the", "first", "few", "properties", "of", "type", "string", "that", "have", "an", "English", "label", ".", "These", "properties", "are", "used", "for", "testing", "in", "this", "code", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EditOnlineDataExample.java#L231-L269
161,343
Wikidata/Wikidata-Toolkit
wdtk-storage/src/main/java/org/wikidata/wdtk/storage/datastructures/FindPositionArray.java
FindPositionArray.findPosition
public long findPosition(long nOccurrence) { updateCount(); if (nOccurrence <= 0) { return RankedBitVector.NOT_FOUND; } int findPos = (int) (nOccurrence / this.blockSize); if (findPos < this.positionArray.length) { long pos0 = this.positionArray[findPos]; long leftOccurrences = nOccurrence - (findPos * this.blockSize); if (leftOccurrences == 0) { return pos0; } for (long index = pos0 + 1; index < this.bitVector.size(); index++) { if (this.bitVector.getBit(index) == this.bit) { leftOccurrences--; } if (leftOccurrences == 0) { return index; } } } return RankedBitVector.NOT_FOUND; }
java
public long findPosition(long nOccurrence) { updateCount(); if (nOccurrence <= 0) { return RankedBitVector.NOT_FOUND; } int findPos = (int) (nOccurrence / this.blockSize); if (findPos < this.positionArray.length) { long pos0 = this.positionArray[findPos]; long leftOccurrences = nOccurrence - (findPos * this.blockSize); if (leftOccurrences == 0) { return pos0; } for (long index = pos0 + 1; index < this.bitVector.size(); index++) { if (this.bitVector.getBit(index) == this.bit) { leftOccurrences--; } if (leftOccurrences == 0) { return index; } } } return RankedBitVector.NOT_FOUND; }
[ "public", "long", "findPosition", "(", "long", "nOccurrence", ")", "{", "updateCount", "(", ")", ";", "if", "(", "nOccurrence", "<=", "0", ")", "{", "return", "RankedBitVector", ".", "NOT_FOUND", ";", "}", "int", "findPos", "=", "(", "int", ")", "(", "nOccurrence", "/", "this", ".", "blockSize", ")", ";", "if", "(", "findPos", "<", "this", ".", "positionArray", ".", "length", ")", "{", "long", "pos0", "=", "this", ".", "positionArray", "[", "findPos", "]", ";", "long", "leftOccurrences", "=", "nOccurrence", "-", "(", "findPos", "*", "this", ".", "blockSize", ")", ";", "if", "(", "leftOccurrences", "==", "0", ")", "{", "return", "pos0", ";", "}", "for", "(", "long", "index", "=", "pos0", "+", "1", ";", "index", "<", "this", ".", "bitVector", ".", "size", "(", ")", ";", "index", "++", ")", "{", "if", "(", "this", ".", "bitVector", ".", "getBit", "(", "index", ")", "==", "this", ".", "bit", ")", "{", "leftOccurrences", "--", ";", "}", "if", "(", "leftOccurrences", "==", "0", ")", "{", "return", "index", ";", "}", "}", "}", "return", "RankedBitVector", ".", "NOT_FOUND", ";", "}" ]
Returns the position for a given number of occurrences or NOT_FOUND if this value is not found. @param nOccurrence number of occurrences @return the position for a given number of occurrences or NOT_FOUND if this value is not found
[ "Returns", "the", "position", "for", "a", "given", "number", "of", "occurrences", "or", "NOT_FOUND", "if", "this", "value", "is", "not", "found", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-storage/src/main/java/org/wikidata/wdtk/storage/datastructures/FindPositionArray.java#L148-L170
161,344
Wikidata/Wikidata-Toolkit
wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/OwlDeclarationBuffer.java
OwlDeclarationBuffer.writeNoValueRestriction
void writeNoValueRestriction(RdfWriter rdfWriter, String propertyUri, String rangeUri, String subject) throws RDFHandlerException { Resource bnodeSome = rdfWriter.getFreshBNode(); rdfWriter.writeTripleValueObject(subject, RdfWriter.RDF_TYPE, RdfWriter.OWL_CLASS); rdfWriter.writeTripleValueObject(subject, RdfWriter.OWL_COMPLEMENT_OF, bnodeSome); rdfWriter.writeTripleValueObject(bnodeSome, RdfWriter.RDF_TYPE, RdfWriter.OWL_RESTRICTION); rdfWriter.writeTripleUriObject(bnodeSome, RdfWriter.OWL_ON_PROPERTY, propertyUri); rdfWriter.writeTripleUriObject(bnodeSome, RdfWriter.OWL_SOME_VALUES_FROM, rangeUri); }
java
void writeNoValueRestriction(RdfWriter rdfWriter, String propertyUri, String rangeUri, String subject) throws RDFHandlerException { Resource bnodeSome = rdfWriter.getFreshBNode(); rdfWriter.writeTripleValueObject(subject, RdfWriter.RDF_TYPE, RdfWriter.OWL_CLASS); rdfWriter.writeTripleValueObject(subject, RdfWriter.OWL_COMPLEMENT_OF, bnodeSome); rdfWriter.writeTripleValueObject(bnodeSome, RdfWriter.RDF_TYPE, RdfWriter.OWL_RESTRICTION); rdfWriter.writeTripleUriObject(bnodeSome, RdfWriter.OWL_ON_PROPERTY, propertyUri); rdfWriter.writeTripleUriObject(bnodeSome, RdfWriter.OWL_SOME_VALUES_FROM, rangeUri); }
[ "void", "writeNoValueRestriction", "(", "RdfWriter", "rdfWriter", ",", "String", "propertyUri", ",", "String", "rangeUri", ",", "String", "subject", ")", "throws", "RDFHandlerException", "{", "Resource", "bnodeSome", "=", "rdfWriter", ".", "getFreshBNode", "(", ")", ";", "rdfWriter", ".", "writeTripleValueObject", "(", "subject", ",", "RdfWriter", ".", "RDF_TYPE", ",", "RdfWriter", ".", "OWL_CLASS", ")", ";", "rdfWriter", ".", "writeTripleValueObject", "(", "subject", ",", "RdfWriter", ".", "OWL_COMPLEMENT_OF", ",", "bnodeSome", ")", ";", "rdfWriter", ".", "writeTripleValueObject", "(", "bnodeSome", ",", "RdfWriter", ".", "RDF_TYPE", ",", "RdfWriter", ".", "OWL_RESTRICTION", ")", ";", "rdfWriter", ".", "writeTripleUriObject", "(", "bnodeSome", ",", "RdfWriter", ".", "OWL_ON_PROPERTY", ",", "propertyUri", ")", ";", "rdfWriter", ".", "writeTripleUriObject", "(", "bnodeSome", ",", "RdfWriter", ".", "OWL_SOME_VALUES_FROM", ",", "rangeUri", ")", ";", "}" ]
Writes no-value restriction. @param rdfWriter the writer to write the restrictions to @param propertyUri URI of the property to which the restriction applies @param rangeUri URI of the class or datatype to which the restriction applies @param subject node representing the restriction @throws RDFHandlerException if there was a problem writing the RDF triples
[ "Writes", "no", "-", "value", "restriction", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/OwlDeclarationBuffer.java#L264-L278
161,345
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/StatementBuilder.java
StatementBuilder.withQualifierValue
public StatementBuilder withQualifierValue(PropertyIdValue propertyIdValue, Value value) { withQualifier(factory.getValueSnak(propertyIdValue, value)); return getThis(); }
java
public StatementBuilder withQualifierValue(PropertyIdValue propertyIdValue, Value value) { withQualifier(factory.getValueSnak(propertyIdValue, value)); return getThis(); }
[ "public", "StatementBuilder", "withQualifierValue", "(", "PropertyIdValue", "propertyIdValue", ",", "Value", "value", ")", "{", "withQualifier", "(", "factory", ".", "getValueSnak", "(", "propertyIdValue", ",", "value", ")", ")", ";", "return", "getThis", "(", ")", ";", "}" ]
Adds a qualifier with the given property and value to the constructed statement. @param propertyIdValue the property of the qualifier @param value the value of the qualifier @return builder object to continue construction
[ "Adds", "a", "qualifier", "with", "the", "given", "property", "and", "value", "to", "the", "constructed", "statement", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/StatementBuilder.java#L153-L157
161,346
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java
EntityStatisticsProcessor.countStatements
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()); } } } } }
java
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()); } } } } }
[ "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", "(", ")", ")", ";", "}", "}", "}", "}", "}" ]
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
[ "Count", "the", "statements", "and", "property", "uses", "of", "an", "item", "or", "property", "document", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java#L178-L200
161,347
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java
EntityStatisticsProcessor.writeFinalResults
private void writeFinalResults() { // Print a final report: printStatus(); // Store property counts in files: writePropertyStatisticsToFile(this.itemStatistics, "item-property-counts.csv"); writePropertyStatisticsToFile(this.propertyStatistics, "property-property-counts.csv"); // Store site link statistics in file: try (PrintStream out = new PrintStream( ExampleHelpers .openExampleFileOuputStream("site-link-counts.csv"))) { out.println("Site key,Site links"); for (Entry<String, Integer> entry : this.siteLinkStatistics .entrySet()) { out.println(entry.getKey() + "," + entry.getValue()); } } catch (IOException e) { e.printStackTrace(); } // Store term statistics in file: writeTermStatisticsToFile(this.itemStatistics, "item-term-counts.csv"); writeTermStatisticsToFile(this.propertyStatistics, "property-term-counts.csv"); }
java
private void writeFinalResults() { // Print a final report: printStatus(); // Store property counts in files: writePropertyStatisticsToFile(this.itemStatistics, "item-property-counts.csv"); writePropertyStatisticsToFile(this.propertyStatistics, "property-property-counts.csv"); // Store site link statistics in file: try (PrintStream out = new PrintStream( ExampleHelpers .openExampleFileOuputStream("site-link-counts.csv"))) { out.println("Site key,Site links"); for (Entry<String, Integer> entry : this.siteLinkStatistics .entrySet()) { out.println(entry.getKey() + "," + entry.getValue()); } } catch (IOException e) { e.printStackTrace(); } // Store term statistics in file: writeTermStatisticsToFile(this.itemStatistics, "item-term-counts.csv"); writeTermStatisticsToFile(this.propertyStatistics, "property-term-counts.csv"); }
[ "private", "void", "writeFinalResults", "(", ")", "{", "// Print a final report:", "printStatus", "(", ")", ";", "// Store property counts in files:", "writePropertyStatisticsToFile", "(", "this", ".", "itemStatistics", ",", "\"item-property-counts.csv\"", ")", ";", "writePropertyStatisticsToFile", "(", "this", ".", "propertyStatistics", ",", "\"property-property-counts.csv\"", ")", ";", "// Store site link statistics in file:", "try", "(", "PrintStream", "out", "=", "new", "PrintStream", "(", "ExampleHelpers", ".", "openExampleFileOuputStream", "(", "\"site-link-counts.csv\"", ")", ")", ")", "{", "out", ".", "println", "(", "\"Site key,Site links\"", ")", ";", "for", "(", "Entry", "<", "String", ",", "Integer", ">", "entry", ":", "this", ".", "siteLinkStatistics", ".", "entrySet", "(", ")", ")", "{", "out", ".", "println", "(", "entry", ".", "getKey", "(", ")", "+", "\",\"", "+", "entry", ".", "getValue", "(", ")", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "// Store term statistics in file:", "writeTermStatisticsToFile", "(", "this", ".", "itemStatistics", ",", "\"item-term-counts.csv\"", ")", ";", "writeTermStatisticsToFile", "(", "this", ".", "propertyStatistics", ",", "\"property-term-counts.csv\"", ")", ";", "}" ]
Prints and stores final result of the processing. This should be called after finishing the processing of a dump. It will print the statistics gathered during processing and it will write a CSV file with usage counts for every property.
[ "Prints", "and", "stores", "final", "result", "of", "the", "processing", ".", "This", "should", "be", "called", "after", "finishing", "the", "processing", "of", "a", "dump", ".", "It", "will", "print", "the", "statistics", "gathered", "during", "processing", "and", "it", "will", "write", "a", "CSV", "file", "with", "usage", "counts", "for", "every", "property", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java#L227-L255
161,348
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java
EntityStatisticsProcessor.writePropertyStatisticsToFile
private void writePropertyStatisticsToFile(UsageStatistics usageStatistics, String fileName) { try (PrintStream out = new PrintStream( ExampleHelpers.openExampleFileOuputStream(fileName))) { out.println("Property id,in statements,in qualifiers,in references,total"); for (Entry<PropertyIdValue, Integer> entry : usageStatistics.propertyCountsMain .entrySet()) { int qCount = usageStatistics.propertyCountsQualifier.get(entry .getKey()); int rCount = usageStatistics.propertyCountsReferences.get(entry .getKey()); int total = entry.getValue() + qCount + rCount; out.println(entry.getKey().getId() + "," + entry.getValue() + "," + qCount + "," + rCount + "," + total); } } catch (IOException e) { e.printStackTrace(); } }
java
private void writePropertyStatisticsToFile(UsageStatistics usageStatistics, String fileName) { try (PrintStream out = new PrintStream( ExampleHelpers.openExampleFileOuputStream(fileName))) { out.println("Property id,in statements,in qualifiers,in references,total"); for (Entry<PropertyIdValue, Integer> entry : usageStatistics.propertyCountsMain .entrySet()) { int qCount = usageStatistics.propertyCountsQualifier.get(entry .getKey()); int rCount = usageStatistics.propertyCountsReferences.get(entry .getKey()); int total = entry.getValue() + qCount + rCount; out.println(entry.getKey().getId() + "," + entry.getValue() + "," + qCount + "," + rCount + "," + total); } } catch (IOException e) { e.printStackTrace(); } }
[ "private", "void", "writePropertyStatisticsToFile", "(", "UsageStatistics", "usageStatistics", ",", "String", "fileName", ")", "{", "try", "(", "PrintStream", "out", "=", "new", "PrintStream", "(", "ExampleHelpers", ".", "openExampleFileOuputStream", "(", "fileName", ")", ")", ")", "{", "out", ".", "println", "(", "\"Property id,in statements,in qualifiers,in references,total\"", ")", ";", "for", "(", "Entry", "<", "PropertyIdValue", ",", "Integer", ">", "entry", ":", "usageStatistics", ".", "propertyCountsMain", ".", "entrySet", "(", ")", ")", "{", "int", "qCount", "=", "usageStatistics", ".", "propertyCountsQualifier", ".", "get", "(", "entry", ".", "getKey", "(", ")", ")", ";", "int", "rCount", "=", "usageStatistics", ".", "propertyCountsReferences", ".", "get", "(", "entry", ".", "getKey", "(", ")", ")", ";", "int", "total", "=", "entry", ".", "getValue", "(", ")", "+", "qCount", "+", "rCount", ";", "out", ".", "println", "(", "entry", ".", "getKey", "(", ")", ".", "getId", "(", ")", "+", "\",\"", "+", "entry", ".", "getValue", "(", ")", "+", "\",\"", "+", "qCount", "+", "\",\"", "+", "rCount", "+", "\",\"", "+", "total", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Stores the gathered usage statistics about property uses to a CSV file. @param usageStatistics the statistics to store @param fileName the name of the file to use
[ "Stores", "the", "gathered", "usage", "statistics", "about", "property", "uses", "to", "a", "CSV", "file", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java#L265-L285
161,349
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java
EntityStatisticsProcessor.writeTermStatisticsToFile
private void writeTermStatisticsToFile(UsageStatistics usageStatistics, String fileName) { // Make sure all keys are present in label count map: for (String key : usageStatistics.aliasCounts.keySet()) { countKey(usageStatistics.labelCounts, key, 0); } for (String key : usageStatistics.descriptionCounts.keySet()) { countKey(usageStatistics.labelCounts, key, 0); } try (PrintStream out = new PrintStream( ExampleHelpers.openExampleFileOuputStream(fileName))) { out.println("Language,Labels,Descriptions,Aliases"); for (Entry<String, Integer> entry : usageStatistics.labelCounts .entrySet()) { countKey(usageStatistics.aliasCounts, entry.getKey(), 0); int aCount = usageStatistics.aliasCounts.get(entry.getKey()); countKey(usageStatistics.descriptionCounts, entry.getKey(), 0); int dCount = usageStatistics.descriptionCounts.get(entry .getKey()); out.println(entry.getKey() + "," + entry.getValue() + "," + dCount + "," + aCount); } } catch (IOException e) { e.printStackTrace(); } }
java
private void writeTermStatisticsToFile(UsageStatistics usageStatistics, String fileName) { // Make sure all keys are present in label count map: for (String key : usageStatistics.aliasCounts.keySet()) { countKey(usageStatistics.labelCounts, key, 0); } for (String key : usageStatistics.descriptionCounts.keySet()) { countKey(usageStatistics.labelCounts, key, 0); } try (PrintStream out = new PrintStream( ExampleHelpers.openExampleFileOuputStream(fileName))) { out.println("Language,Labels,Descriptions,Aliases"); for (Entry<String, Integer> entry : usageStatistics.labelCounts .entrySet()) { countKey(usageStatistics.aliasCounts, entry.getKey(), 0); int aCount = usageStatistics.aliasCounts.get(entry.getKey()); countKey(usageStatistics.descriptionCounts, entry.getKey(), 0); int dCount = usageStatistics.descriptionCounts.get(entry .getKey()); out.println(entry.getKey() + "," + entry.getValue() + "," + dCount + "," + aCount); } } catch (IOException e) { e.printStackTrace(); } }
[ "private", "void", "writeTermStatisticsToFile", "(", "UsageStatistics", "usageStatistics", ",", "String", "fileName", ")", "{", "// Make sure all keys are present in label count map:", "for", "(", "String", "key", ":", "usageStatistics", ".", "aliasCounts", ".", "keySet", "(", ")", ")", "{", "countKey", "(", "usageStatistics", ".", "labelCounts", ",", "key", ",", "0", ")", ";", "}", "for", "(", "String", "key", ":", "usageStatistics", ".", "descriptionCounts", ".", "keySet", "(", ")", ")", "{", "countKey", "(", "usageStatistics", ".", "labelCounts", ",", "key", ",", "0", ")", ";", "}", "try", "(", "PrintStream", "out", "=", "new", "PrintStream", "(", "ExampleHelpers", ".", "openExampleFileOuputStream", "(", "fileName", ")", ")", ")", "{", "out", ".", "println", "(", "\"Language,Labels,Descriptions,Aliases\"", ")", ";", "for", "(", "Entry", "<", "String", ",", "Integer", ">", "entry", ":", "usageStatistics", ".", "labelCounts", ".", "entrySet", "(", ")", ")", "{", "countKey", "(", "usageStatistics", ".", "aliasCounts", ",", "entry", ".", "getKey", "(", ")", ",", "0", ")", ";", "int", "aCount", "=", "usageStatistics", ".", "aliasCounts", ".", "get", "(", "entry", ".", "getKey", "(", ")", ")", ";", "countKey", "(", "usageStatistics", ".", "descriptionCounts", ",", "entry", ".", "getKey", "(", ")", ",", "0", ")", ";", "int", "dCount", "=", "usageStatistics", ".", "descriptionCounts", ".", "get", "(", "entry", ".", "getKey", "(", ")", ")", ";", "out", ".", "println", "(", "entry", ".", "getKey", "(", ")", "+", "\",\"", "+", "entry", ".", "getValue", "(", ")", "+", "\",\"", "+", "dCount", "+", "\",\"", "+", "aCount", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Stores the gathered usage statistics about term uses by language to a CSV file. @param usageStatistics the statistics to store @param fileName the name of the file to use
[ "Stores", "the", "gathered", "usage", "statistics", "about", "term", "uses", "by", "language", "to", "a", "CSV", "file", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java#L296-L324
161,350
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java
EntityStatisticsProcessor.printStatistics
private void printStatistics(UsageStatistics usageStatistics, String entityLabel) { System.out.println("Processed " + usageStatistics.count + " " + entityLabel + ":"); System.out.println(" * Labels: " + usageStatistics.countLabels + ", descriptions: " + usageStatistics.countDescriptions + ", aliases: " + usageStatistics.countAliases); System.out.println(" * Statements: " + usageStatistics.countStatements + ", with references: " + usageStatistics.countReferencedStatements); }
java
private void printStatistics(UsageStatistics usageStatistics, String entityLabel) { System.out.println("Processed " + usageStatistics.count + " " + entityLabel + ":"); System.out.println(" * Labels: " + usageStatistics.countLabels + ", descriptions: " + usageStatistics.countDescriptions + ", aliases: " + usageStatistics.countAliases); System.out.println(" * Statements: " + usageStatistics.countStatements + ", with references: " + usageStatistics.countReferencedStatements); }
[ "private", "void", "printStatistics", "(", "UsageStatistics", "usageStatistics", ",", "String", "entityLabel", ")", "{", "System", ".", "out", ".", "println", "(", "\"Processed \"", "+", "usageStatistics", ".", "count", "+", "\" \"", "+", "entityLabel", "+", "\":\"", ")", ";", "System", ".", "out", ".", "println", "(", "\" * Labels: \"", "+", "usageStatistics", ".", "countLabels", "+", "\", descriptions: \"", "+", "usageStatistics", ".", "countDescriptions", "+", "\", aliases: \"", "+", "usageStatistics", ".", "countAliases", ")", ";", "System", ".", "out", ".", "println", "(", "\" * Statements: \"", "+", "usageStatistics", ".", "countStatements", "+", "\", with references: \"", "+", "usageStatistics", ".", "countReferencedStatements", ")", ";", "}" ]
Prints a report about the statistics stored in the given data object. @param usageStatistics the statistics object to print @param entityLabel the label to use to refer to this kind of entities ("items" or "properties")
[ "Prints", "a", "report", "about", "the", "statistics", "stored", "in", "the", "given", "data", "object", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java#L346-L356
161,351
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java
EntityStatisticsProcessor.countPropertyMain
private void countPropertyMain(UsageStatistics usageStatistics, PropertyIdValue property, int count) { addPropertyCounters(usageStatistics, property); usageStatistics.propertyCountsMain.put(property, usageStatistics.propertyCountsMain.get(property) + count); }
java
private void countPropertyMain(UsageStatistics usageStatistics, PropertyIdValue property, int count) { addPropertyCounters(usageStatistics, property); usageStatistics.propertyCountsMain.put(property, usageStatistics.propertyCountsMain.get(property) + count); }
[ "private", "void", "countPropertyMain", "(", "UsageStatistics", "usageStatistics", ",", "PropertyIdValue", "property", ",", "int", "count", ")", "{", "addPropertyCounters", "(", "usageStatistics", ",", "property", ")", ";", "usageStatistics", ".", "propertyCountsMain", ".", "put", "(", "property", ",", "usageStatistics", ".", "propertyCountsMain", ".", "get", "(", "property", ")", "+", "count", ")", ";", "}" ]
Counts additional occurrences of a property as the main property of statements. @param usageStatistics statistics object where count is stored @param property the property to count @param count the number of times to count the property
[ "Counts", "additional", "occurrences", "of", "a", "property", "as", "the", "main", "property", "of", "statements", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java#L369-L374
161,352
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java
EntityStatisticsProcessor.addPropertyCounters
private void addPropertyCounters(UsageStatistics usageStatistics, PropertyIdValue property) { if (!usageStatistics.propertyCountsMain.containsKey(property)) { usageStatistics.propertyCountsMain.put(property, 0); usageStatistics.propertyCountsQualifier.put(property, 0); usageStatistics.propertyCountsReferences.put(property, 0); } }
java
private void addPropertyCounters(UsageStatistics usageStatistics, PropertyIdValue property) { if (!usageStatistics.propertyCountsMain.containsKey(property)) { usageStatistics.propertyCountsMain.put(property, 0); usageStatistics.propertyCountsQualifier.put(property, 0); usageStatistics.propertyCountsReferences.put(property, 0); } }
[ "private", "void", "addPropertyCounters", "(", "UsageStatistics", "usageStatistics", ",", "PropertyIdValue", "property", ")", "{", "if", "(", "!", "usageStatistics", ".", "propertyCountsMain", ".", "containsKey", "(", "property", ")", ")", "{", "usageStatistics", ".", "propertyCountsMain", ".", "put", "(", "property", ",", "0", ")", ";", "usageStatistics", ".", "propertyCountsQualifier", ".", "put", "(", "property", ",", "0", ")", ";", "usageStatistics", ".", "propertyCountsReferences", ".", "put", "(", "property", ",", "0", ")", ";", "}", "}" ]
Initializes the counters for a property to zero if not done yet. @param usageStatistics statistics object to initialize @param property the property to count
[ "Initializes", "the", "counters", "for", "a", "property", "to", "zero", "if", "not", "done", "yet", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java#L419-L426
161,353
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java
EntityStatisticsProcessor.countKey
private void countKey(Map<String, Integer> map, String key, int count) { if (map.containsKey(key)) { map.put(key, map.get(key) + count); } else { map.put(key, count); } }
java
private void countKey(Map<String, Integer> map, String key, int count) { if (map.containsKey(key)) { map.put(key, map.get(key) + count); } else { map.put(key, count); } }
[ "private", "void", "countKey", "(", "Map", "<", "String", ",", "Integer", ">", "map", ",", "String", "key", ",", "int", "count", ")", "{", "if", "(", "map", ".", "containsKey", "(", "key", ")", ")", "{", "map", ".", "put", "(", "key", ",", "map", ".", "get", "(", "key", ")", "+", "count", ")", ";", "}", "else", "{", "map", ".", "put", "(", "key", ",", "count", ")", ";", "}", "}" ]
Helper method that stores in a hash map how often a certain key occurs. If the key has not been encountered yet, a new entry is created for it in the map. Otherwise the existing value for the key is incremented. @param map the map where the counts are stored @param key the key to be counted @param count value by which the count should be incremented; 1 is the usual case
[ "Helper", "method", "that", "stores", "in", "a", "hash", "map", "how", "often", "a", "certain", "key", "occurs", ".", "If", "the", "key", "has", "not", "been", "encountered", "yet", "a", "new", "entry", "is", "created", "for", "it", "in", "the", "map", ".", "Otherwise", "the", "existing", "value", "for", "the", "key", "is", "incremented", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java#L441-L447
161,354
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java
WorldMapProcessor.addSite
public void addSite(String siteKey) { ValueMap gv = new ValueMap(siteKey); if (!this.valueMaps.contains(gv)) { this.valueMaps.add(gv); } }
java
public void addSite(String siteKey) { ValueMap gv = new ValueMap(siteKey); if (!this.valueMaps.contains(gv)) { this.valueMaps.add(gv); } }
[ "public", "void", "addSite", "(", "String", "siteKey", ")", "{", "ValueMap", "gv", "=", "new", "ValueMap", "(", "siteKey", ")", ";", "if", "(", "!", "this", ".", "valueMaps", ".", "contains", "(", "gv", ")", ")", "{", "this", ".", "valueMaps", ".", "add", "(", "gv", ")", ";", "}", "}" ]
Registers a new site for specific data collection. If null is used as a site key, then all data is collected. @param siteKey the site to collect geo data for
[ "Registers", "a", "new", "site", "for", "specific", "data", "collection", ".", "If", "null", "is", "used", "as", "a", "site", "key", "then", "all", "data", "is", "collected", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java#L179-L184
161,355
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java
WorldMapProcessor.countCoordinateStatement
private void countCoordinateStatement(Statement statement, ItemDocument itemDocument) { Value value = statement.getValue(); if (!(value instanceof GlobeCoordinatesValue)) { return; } GlobeCoordinatesValue coordsValue = (GlobeCoordinatesValue) value; if (!this.globe.equals((coordsValue.getGlobe()))) { return; } int xCoord = (int) (((coordsValue.getLongitude() + 180.0) / 360.0) * this.width) % this.width; int yCoord = (int) (((coordsValue.getLatitude() + 90.0) / 180.0) * this.height) % this.height; if (xCoord < 0 || yCoord < 0 || xCoord >= this.width || yCoord >= this.height) { System.out.println("Dropping out-of-range coordinate: " + coordsValue); return; } countCoordinates(xCoord, yCoord, itemDocument); this.count += 1; if (this.count % 100000 == 0) { reportProgress(); writeImages(); } }
java
private void countCoordinateStatement(Statement statement, ItemDocument itemDocument) { Value value = statement.getValue(); if (!(value instanceof GlobeCoordinatesValue)) { return; } GlobeCoordinatesValue coordsValue = (GlobeCoordinatesValue) value; if (!this.globe.equals((coordsValue.getGlobe()))) { return; } int xCoord = (int) (((coordsValue.getLongitude() + 180.0) / 360.0) * this.width) % this.width; int yCoord = (int) (((coordsValue.getLatitude() + 90.0) / 180.0) * this.height) % this.height; if (xCoord < 0 || yCoord < 0 || xCoord >= this.width || yCoord >= this.height) { System.out.println("Dropping out-of-range coordinate: " + coordsValue); return; } countCoordinates(xCoord, yCoord, itemDocument); this.count += 1; if (this.count % 100000 == 0) { reportProgress(); writeImages(); } }
[ "private", "void", "countCoordinateStatement", "(", "Statement", "statement", ",", "ItemDocument", "itemDocument", ")", "{", "Value", "value", "=", "statement", ".", "getValue", "(", ")", ";", "if", "(", "!", "(", "value", "instanceof", "GlobeCoordinatesValue", ")", ")", "{", "return", ";", "}", "GlobeCoordinatesValue", "coordsValue", "=", "(", "GlobeCoordinatesValue", ")", "value", ";", "if", "(", "!", "this", ".", "globe", ".", "equals", "(", "(", "coordsValue", ".", "getGlobe", "(", ")", ")", ")", ")", "{", "return", ";", "}", "int", "xCoord", "=", "(", "int", ")", "(", "(", "(", "coordsValue", ".", "getLongitude", "(", ")", "+", "180.0", ")", "/", "360.0", ")", "*", "this", ".", "width", ")", "%", "this", ".", "width", ";", "int", "yCoord", "=", "(", "int", ")", "(", "(", "(", "coordsValue", ".", "getLatitude", "(", ")", "+", "90.0", ")", "/", "180.0", ")", "*", "this", ".", "height", ")", "%", "this", ".", "height", ";", "if", "(", "xCoord", "<", "0", "||", "yCoord", "<", "0", "||", "xCoord", ">=", "this", ".", "width", "||", "yCoord", ">=", "this", ".", "height", ")", "{", "System", ".", "out", ".", "println", "(", "\"Dropping out-of-range coordinate: \"", "+", "coordsValue", ")", ";", "return", ";", "}", "countCoordinates", "(", "xCoord", ",", "yCoord", ",", "itemDocument", ")", ";", "this", ".", "count", "+=", "1", ";", "if", "(", "this", ".", "count", "%", "100000", "==", "0", ")", "{", "reportProgress", "(", ")", ";", "writeImages", "(", ")", ";", "}", "}" ]
Counts the coordinates stored in a single statement for the relevant property, if they are actually given and valid. @param statement @param itemDocument
[ "Counts", "the", "coordinates", "stored", "in", "a", "single", "statement", "for", "the", "relevant", "property", "if", "they", "are", "actually", "given", "and", "valid", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java#L216-L247
161,356
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java
WorldMapProcessor.countCoordinates
private void countCoordinates(int xCoord, int yCoord, ItemDocument itemDocument) { for (String siteKey : itemDocument.getSiteLinks().keySet()) { Integer count = this.siteCounts.get(siteKey); if (count == null) { this.siteCounts.put(siteKey, 1); } else { this.siteCounts.put(siteKey, count + 1); } } for (ValueMap vm : this.valueMaps) { vm.countCoordinates(xCoord, yCoord, itemDocument); } }
java
private void countCoordinates(int xCoord, int yCoord, ItemDocument itemDocument) { for (String siteKey : itemDocument.getSiteLinks().keySet()) { Integer count = this.siteCounts.get(siteKey); if (count == null) { this.siteCounts.put(siteKey, 1); } else { this.siteCounts.put(siteKey, count + 1); } } for (ValueMap vm : this.valueMaps) { vm.countCoordinates(xCoord, yCoord, itemDocument); } }
[ "private", "void", "countCoordinates", "(", "int", "xCoord", ",", "int", "yCoord", ",", "ItemDocument", "itemDocument", ")", "{", "for", "(", "String", "siteKey", ":", "itemDocument", ".", "getSiteLinks", "(", ")", ".", "keySet", "(", ")", ")", "{", "Integer", "count", "=", "this", ".", "siteCounts", ".", "get", "(", "siteKey", ")", ";", "if", "(", "count", "==", "null", ")", "{", "this", ".", "siteCounts", ".", "put", "(", "siteKey", ",", "1", ")", ";", "}", "else", "{", "this", ".", "siteCounts", ".", "put", "(", "siteKey", ",", "count", "+", "1", ")", ";", "}", "}", "for", "(", "ValueMap", "vm", ":", "this", ".", "valueMaps", ")", "{", "vm", ".", "countCoordinates", "(", "xCoord", ",", "yCoord", ",", "itemDocument", ")", ";", "}", "}" ]
Counts a single pair of coordinates in all datasets. @param xCoord @param yCoord @param itemDocument
[ "Counts", "a", "single", "pair", "of", "coordinates", "in", "all", "datasets", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java#L256-L271
161,357
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java
WorldMapProcessor.writeImages
private void writeImages() { for (ValueMap gv : this.valueMaps) { gv.writeImage(); } try (PrintStream out = new PrintStream( ExampleHelpers.openExampleFileOuputStream("map-site-count.csv"))) { out.println("Site key,Number of geo items"); out.println("wikidata total," + this.count); for (Entry<String, Integer> entry : this.siteCounts.entrySet()) { out.println(entry.getKey() + "," + entry.getValue()); } } catch (IOException e) { e.printStackTrace(); } }
java
private void writeImages() { for (ValueMap gv : this.valueMaps) { gv.writeImage(); } try (PrintStream out = new PrintStream( ExampleHelpers.openExampleFileOuputStream("map-site-count.csv"))) { out.println("Site key,Number of geo items"); out.println("wikidata total," + this.count); for (Entry<String, Integer> entry : this.siteCounts.entrySet()) { out.println(entry.getKey() + "," + entry.getValue()); } } catch (IOException e) { e.printStackTrace(); } }
[ "private", "void", "writeImages", "(", ")", "{", "for", "(", "ValueMap", "gv", ":", "this", ".", "valueMaps", ")", "{", "gv", ".", "writeImage", "(", ")", ";", "}", "try", "(", "PrintStream", "out", "=", "new", "PrintStream", "(", "ExampleHelpers", ".", "openExampleFileOuputStream", "(", "\"map-site-count.csv\"", ")", ")", ")", "{", "out", ".", "println", "(", "\"Site key,Number of geo items\"", ")", ";", "out", ".", "println", "(", "\"wikidata total,\"", "+", "this", ".", "count", ")", ";", "for", "(", "Entry", "<", "String", ",", "Integer", ">", "entry", ":", "this", ".", "siteCounts", ".", "entrySet", "(", ")", ")", "{", "out", ".", "println", "(", "entry", ".", "getKey", "(", ")", "+", "\",\"", "+", "entry", ".", "getValue", "(", ")", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Writes image files for all data that was collected and the statistics file for all sites.
[ "Writes", "image", "files", "for", "all", "data", "that", "was", "collected", "and", "the", "statistics", "file", "for", "all", "sites", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java#L285-L300
161,358
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java
WorldMapProcessor.getColor
private int getColor(int value) { if (value == 0) { return 0; } double scale = Math.log10(value) / Math.log10(this.topValue); double lengthScale = Math.min(1.0, scale) * (colors.length - 1); int index = 1 + (int) lengthScale; if (index == colors.length) { index--; } double partScale = lengthScale - (index - 1); int r = (int) (colors[index - 1][0] + partScale * (colors[index][0] - colors[index - 1][0])); int g = (int) (colors[index - 1][1] + partScale * (colors[index][1] - colors[index - 1][1])); int b = (int) (colors[index - 1][2] + partScale * (colors[index][2] - colors[index - 1][2])); r = Math.min(255, r); b = Math.min(255, b); g = Math.min(255, g); return (r << 16) | (g << 8) | b; }
java
private int getColor(int value) { if (value == 0) { return 0; } double scale = Math.log10(value) / Math.log10(this.topValue); double lengthScale = Math.min(1.0, scale) * (colors.length - 1); int index = 1 + (int) lengthScale; if (index == colors.length) { index--; } double partScale = lengthScale - (index - 1); int r = (int) (colors[index - 1][0] + partScale * (colors[index][0] - colors[index - 1][0])); int g = (int) (colors[index - 1][1] + partScale * (colors[index][1] - colors[index - 1][1])); int b = (int) (colors[index - 1][2] + partScale * (colors[index][2] - colors[index - 1][2])); r = Math.min(255, r); b = Math.min(255, b); g = Math.min(255, g); return (r << 16) | (g << 8) | b; }
[ "private", "int", "getColor", "(", "int", "value", ")", "{", "if", "(", "value", "==", "0", ")", "{", "return", "0", ";", "}", "double", "scale", "=", "Math", ".", "log10", "(", "value", ")", "/", "Math", ".", "log10", "(", "this", ".", "topValue", ")", ";", "double", "lengthScale", "=", "Math", ".", "min", "(", "1.0", ",", "scale", ")", "*", "(", "colors", ".", "length", "-", "1", ")", ";", "int", "index", "=", "1", "+", "(", "int", ")", "lengthScale", ";", "if", "(", "index", "==", "colors", ".", "length", ")", "{", "index", "--", ";", "}", "double", "partScale", "=", "lengthScale", "-", "(", "index", "-", "1", ")", ";", "int", "r", "=", "(", "int", ")", "(", "colors", "[", "index", "-", "1", "]", "[", "0", "]", "+", "partScale", "*", "(", "colors", "[", "index", "]", "[", "0", "]", "-", "colors", "[", "index", "-", "1", "]", "[", "0", "]", ")", ")", ";", "int", "g", "=", "(", "int", ")", "(", "colors", "[", "index", "-", "1", "]", "[", "1", "]", "+", "partScale", "*", "(", "colors", "[", "index", "]", "[", "1", "]", "-", "colors", "[", "index", "-", "1", "]", "[", "1", "]", ")", ")", ";", "int", "b", "=", "(", "int", ")", "(", "colors", "[", "index", "-", "1", "]", "[", "2", "]", "+", "partScale", "*", "(", "colors", "[", "index", "]", "[", "2", "]", "-", "colors", "[", "index", "-", "1", "]", "[", "2", "]", ")", ")", ";", "r", "=", "Math", ".", "min", "(", "255", ",", "r", ")", ";", "b", "=", "Math", ".", "min", "(", "255", ",", "b", ")", ";", "g", "=", "Math", ".", "min", "(", "255", ",", "g", ")", ";", "return", "(", "r", "<<", "16", ")", "|", "(", "g", "<<", "8", ")", "|", "b", ";", "}" ]
Returns a color for a given absolute number that is to be shown on the map. @param value @return
[ "Returns", "a", "color", "for", "a", "given", "absolute", "number", "that", "is", "to", "be", "shown", "on", "the", "map", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java#L336-L360
161,359
Wikidata/Wikidata-Toolkit
wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/ReferenceBuilder.java
ReferenceBuilder.withPropertyValue
public ReferenceBuilder withPropertyValue(PropertyIdValue propertyIdValue, Value value) { getSnakList(propertyIdValue).add( factory.getValueSnak(propertyIdValue, value)); return getThis(); }
java
public ReferenceBuilder withPropertyValue(PropertyIdValue propertyIdValue, Value value) { getSnakList(propertyIdValue).add( factory.getValueSnak(propertyIdValue, value)); return getThis(); }
[ "public", "ReferenceBuilder", "withPropertyValue", "(", "PropertyIdValue", "propertyIdValue", ",", "Value", "value", ")", "{", "getSnakList", "(", "propertyIdValue", ")", ".", "add", "(", "factory", ".", "getValueSnak", "(", "propertyIdValue", ",", "value", ")", ")", ";", "return", "getThis", "(", ")", ";", "}" ]
Adds the given property and value to the constructed reference. @param propertyIdValue the property to add @param value the value to add @return builder object to continue construction
[ "Adds", "the", "given", "property", "and", "value", "to", "the", "constructed", "reference", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/ReferenceBuilder.java#L70-L75
161,360
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/DumpProcessingOutputAction.java
DumpProcessingOutputAction.close
private static void close(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException ignored) { logger.error("Failed to close output stream: " + ignored.getMessage()); } } }
java
private static void close(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException ignored) { logger.error("Failed to close output stream: " + ignored.getMessage()); } } }
[ "private", "static", "void", "close", "(", "Closeable", "closeable", ")", "{", "if", "(", "closeable", "!=", "null", ")", "{", "try", "{", "closeable", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "ignored", ")", "{", "logger", ".", "error", "(", "\"Failed to close output stream: \"", "+", "ignored", ".", "getMessage", "(", ")", ")", ";", "}", "}", "}" ]
Closes a Closeable and swallows any exceptions that might occur in the process. @param closeable
[ "Closes", "a", "Closeable", "and", "swallows", "any", "exceptions", "that", "might", "occur", "in", "the", "process", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/DumpProcessingOutputAction.java#L347-L356
161,361
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ExampleHelpers.java
ExampleHelpers.configureLogging
public static void configureLogging() { // Create the appender that will write log messages to the console. ConsoleAppender consoleAppender = new ConsoleAppender(); // Define the pattern of log messages. // Insert the string "%c{1}:%L" to also show class name and line. String pattern = "%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n"; consoleAppender.setLayout(new PatternLayout(pattern)); // Change to Level.ERROR for fewer messages: consoleAppender.setThreshold(Level.INFO); consoleAppender.activateOptions(); Logger.getRootLogger().addAppender(consoleAppender); }
java
public static void configureLogging() { // Create the appender that will write log messages to the console. ConsoleAppender consoleAppender = new ConsoleAppender(); // Define the pattern of log messages. // Insert the string "%c{1}:%L" to also show class name and line. String pattern = "%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n"; consoleAppender.setLayout(new PatternLayout(pattern)); // Change to Level.ERROR for fewer messages: consoleAppender.setThreshold(Level.INFO); consoleAppender.activateOptions(); Logger.getRootLogger().addAppender(consoleAppender); }
[ "public", "static", "void", "configureLogging", "(", ")", "{", "// Create the appender that will write log messages to the console.", "ConsoleAppender", "consoleAppender", "=", "new", "ConsoleAppender", "(", ")", ";", "// Define the pattern of log messages.", "// Insert the string \"%c{1}:%L\" to also show class name and line.", "String", "pattern", "=", "\"%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n\"", ";", "consoleAppender", ".", "setLayout", "(", "new", "PatternLayout", "(", "pattern", ")", ")", ";", "// Change to Level.ERROR for fewer messages:", "consoleAppender", ".", "setThreshold", "(", "Level", ".", "INFO", ")", ";", "consoleAppender", ".", "activateOptions", "(", ")", ";", "Logger", ".", "getRootLogger", "(", ")", ".", "addAppender", "(", "consoleAppender", ")", ";", "}" ]
Defines how messages should be logged. This method can be modified to restrict the logging messages that are shown on the console or to change their formatting. See the documentation of Log4J for details on how to do this.
[ "Defines", "how", "messages", "should", "be", "logged", ".", "This", "method", "can", "be", "modified", "to", "restrict", "the", "logging", "messages", "that", "are", "shown", "on", "the", "console", "or", "to", "change", "their", "formatting", ".", "See", "the", "documentation", "of", "Log4J", "for", "details", "on", "how", "to", "do", "this", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ExampleHelpers.java#L97-L109
161,362
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ExampleHelpers.java
ExampleHelpers.processEntitiesFromWikidataDump
public static void processEntitiesFromWikidataDump( EntityDocumentProcessor entityDocumentProcessor) { // Controller object for processing dumps: DumpProcessingController dumpProcessingController = new DumpProcessingController( "wikidatawiki"); dumpProcessingController.setOfflineMode(OFFLINE_MODE); // // Optional: Use another download directory: // dumpProcessingController.setDownloadDirectory(System.getProperty("user.dir")); // Should we process historic revisions or only current ones? boolean onlyCurrentRevisions; switch (DUMP_FILE_MODE) { case ALL_REVS: case ALL_REVS_WITH_DAILIES: onlyCurrentRevisions = false; break; case CURRENT_REVS: case CURRENT_REVS_WITH_DAILIES: case JSON: case JUST_ONE_DAILY_FOR_TEST: default: onlyCurrentRevisions = true; } // Subscribe to the most recent entity documents of type wikibase item: dumpProcessingController.registerEntityDocumentProcessor( entityDocumentProcessor, null, onlyCurrentRevisions); // Also add a timer that reports some basic progress information: EntityTimerProcessor entityTimerProcessor = new EntityTimerProcessor( TIMEOUT_SEC); dumpProcessingController.registerEntityDocumentProcessor( entityTimerProcessor, null, onlyCurrentRevisions); MwDumpFile dumpFile = null; try { // Start processing (may trigger downloads where needed): switch (DUMP_FILE_MODE) { case ALL_REVS: case CURRENT_REVS: dumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.FULL); break; case ALL_REVS_WITH_DAILIES: case CURRENT_REVS_WITH_DAILIES: MwDumpFile fullDumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.FULL); MwDumpFile incrDumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.DAILY); lastDumpFileName = fullDumpFile.getProjectName() + "-" + incrDumpFile.getDateStamp() + "." + fullDumpFile.getDateStamp(); dumpProcessingController.processAllRecentRevisionDumps(); break; case JSON: dumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.JSON); break; case JUST_ONE_DAILY_FOR_TEST: dumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.DAILY); break; default: throw new RuntimeException("Unsupported dump processing type " + DUMP_FILE_MODE); } if (dumpFile != null) { lastDumpFileName = dumpFile.getProjectName() + "-" + dumpFile.getDateStamp(); dumpProcessingController.processDump(dumpFile); } } catch (TimeoutException e) { // The timer caused a time out. Continue and finish normally. } // Print final timer results: entityTimerProcessor.close(); }
java
public static void processEntitiesFromWikidataDump( EntityDocumentProcessor entityDocumentProcessor) { // Controller object for processing dumps: DumpProcessingController dumpProcessingController = new DumpProcessingController( "wikidatawiki"); dumpProcessingController.setOfflineMode(OFFLINE_MODE); // // Optional: Use another download directory: // dumpProcessingController.setDownloadDirectory(System.getProperty("user.dir")); // Should we process historic revisions or only current ones? boolean onlyCurrentRevisions; switch (DUMP_FILE_MODE) { case ALL_REVS: case ALL_REVS_WITH_DAILIES: onlyCurrentRevisions = false; break; case CURRENT_REVS: case CURRENT_REVS_WITH_DAILIES: case JSON: case JUST_ONE_DAILY_FOR_TEST: default: onlyCurrentRevisions = true; } // Subscribe to the most recent entity documents of type wikibase item: dumpProcessingController.registerEntityDocumentProcessor( entityDocumentProcessor, null, onlyCurrentRevisions); // Also add a timer that reports some basic progress information: EntityTimerProcessor entityTimerProcessor = new EntityTimerProcessor( TIMEOUT_SEC); dumpProcessingController.registerEntityDocumentProcessor( entityTimerProcessor, null, onlyCurrentRevisions); MwDumpFile dumpFile = null; try { // Start processing (may trigger downloads where needed): switch (DUMP_FILE_MODE) { case ALL_REVS: case CURRENT_REVS: dumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.FULL); break; case ALL_REVS_WITH_DAILIES: case CURRENT_REVS_WITH_DAILIES: MwDumpFile fullDumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.FULL); MwDumpFile incrDumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.DAILY); lastDumpFileName = fullDumpFile.getProjectName() + "-" + incrDumpFile.getDateStamp() + "." + fullDumpFile.getDateStamp(); dumpProcessingController.processAllRecentRevisionDumps(); break; case JSON: dumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.JSON); break; case JUST_ONE_DAILY_FOR_TEST: dumpFile = dumpProcessingController .getMostRecentDump(DumpContentType.DAILY); break; default: throw new RuntimeException("Unsupported dump processing type " + DUMP_FILE_MODE); } if (dumpFile != null) { lastDumpFileName = dumpFile.getProjectName() + "-" + dumpFile.getDateStamp(); dumpProcessingController.processDump(dumpFile); } } catch (TimeoutException e) { // The timer caused a time out. Continue and finish normally. } // Print final timer results: entityTimerProcessor.close(); }
[ "public", "static", "void", "processEntitiesFromWikidataDump", "(", "EntityDocumentProcessor", "entityDocumentProcessor", ")", "{", "// Controller object for processing dumps:", "DumpProcessingController", "dumpProcessingController", "=", "new", "DumpProcessingController", "(", "\"wikidatawiki\"", ")", ";", "dumpProcessingController", ".", "setOfflineMode", "(", "OFFLINE_MODE", ")", ";", "// // Optional: Use another download directory:", "// dumpProcessingController.setDownloadDirectory(System.getProperty(\"user.dir\"));", "// Should we process historic revisions or only current ones?", "boolean", "onlyCurrentRevisions", ";", "switch", "(", "DUMP_FILE_MODE", ")", "{", "case", "ALL_REVS", ":", "case", "ALL_REVS_WITH_DAILIES", ":", "onlyCurrentRevisions", "=", "false", ";", "break", ";", "case", "CURRENT_REVS", ":", "case", "CURRENT_REVS_WITH_DAILIES", ":", "case", "JSON", ":", "case", "JUST_ONE_DAILY_FOR_TEST", ":", "default", ":", "onlyCurrentRevisions", "=", "true", ";", "}", "// Subscribe to the most recent entity documents of type wikibase item:", "dumpProcessingController", ".", "registerEntityDocumentProcessor", "(", "entityDocumentProcessor", ",", "null", ",", "onlyCurrentRevisions", ")", ";", "// Also add a timer that reports some basic progress information:", "EntityTimerProcessor", "entityTimerProcessor", "=", "new", "EntityTimerProcessor", "(", "TIMEOUT_SEC", ")", ";", "dumpProcessingController", ".", "registerEntityDocumentProcessor", "(", "entityTimerProcessor", ",", "null", ",", "onlyCurrentRevisions", ")", ";", "MwDumpFile", "dumpFile", "=", "null", ";", "try", "{", "// Start processing (may trigger downloads where needed):", "switch", "(", "DUMP_FILE_MODE", ")", "{", "case", "ALL_REVS", ":", "case", "CURRENT_REVS", ":", "dumpFile", "=", "dumpProcessingController", ".", "getMostRecentDump", "(", "DumpContentType", ".", "FULL", ")", ";", "break", ";", "case", "ALL_REVS_WITH_DAILIES", ":", "case", "CURRENT_REVS_WITH_DAILIES", ":", "MwDumpFile", "fullDumpFile", "=", "dumpProcessingController", ".", "getMostRecentDump", "(", "DumpContentType", ".", "FULL", ")", ";", "MwDumpFile", "incrDumpFile", "=", "dumpProcessingController", ".", "getMostRecentDump", "(", "DumpContentType", ".", "DAILY", ")", ";", "lastDumpFileName", "=", "fullDumpFile", ".", "getProjectName", "(", ")", "+", "\"-\"", "+", "incrDumpFile", ".", "getDateStamp", "(", ")", "+", "\".\"", "+", "fullDumpFile", ".", "getDateStamp", "(", ")", ";", "dumpProcessingController", ".", "processAllRecentRevisionDumps", "(", ")", ";", "break", ";", "case", "JSON", ":", "dumpFile", "=", "dumpProcessingController", ".", "getMostRecentDump", "(", "DumpContentType", ".", "JSON", ")", ";", "break", ";", "case", "JUST_ONE_DAILY_FOR_TEST", ":", "dumpFile", "=", "dumpProcessingController", ".", "getMostRecentDump", "(", "DumpContentType", ".", "DAILY", ")", ";", "break", ";", "default", ":", "throw", "new", "RuntimeException", "(", "\"Unsupported dump processing type \"", "+", "DUMP_FILE_MODE", ")", ";", "}", "if", "(", "dumpFile", "!=", "null", ")", "{", "lastDumpFileName", "=", "dumpFile", ".", "getProjectName", "(", ")", "+", "\"-\"", "+", "dumpFile", ".", "getDateStamp", "(", ")", ";", "dumpProcessingController", ".", "processDump", "(", "dumpFile", ")", ";", "}", "}", "catch", "(", "TimeoutException", "e", ")", "{", "// The timer caused a time out. Continue and finish normally.", "}", "// Print final timer results:", "entityTimerProcessor", ".", "close", "(", ")", ";", "}" ]
Processes all entities in a Wikidata dump using the given entity processor. By default, the most recent JSON dump will be used. In offline mode, only the most recent previously downloaded file is considered. @param entityDocumentProcessor the object to use for processing entities in this dump
[ "Processes", "all", "entities", "in", "a", "Wikidata", "dump", "using", "the", "given", "entity", "processor", ".", "By", "default", "the", "most", "recent", "JSON", "dump", "will", "be", "used", ".", "In", "offline", "mode", "only", "the", "most", "recent", "previously", "downloaded", "file", "is", "considered", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ExampleHelpers.java#L119-L199
161,363
Wikidata/Wikidata-Toolkit
wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/values/BufferedValueConverter.java
BufferedValueConverter.addValue
void addValue(V value, Resource resource) { this.valueQueue.add(value); this.valueSubjectQueue.add(resource); }
java
void addValue(V value, Resource resource) { this.valueQueue.add(value); this.valueSubjectQueue.add(resource); }
[ "void", "addValue", "(", "V", "value", ",", "Resource", "resource", ")", "{", "this", ".", "valueQueue", ".", "add", "(", "value", ")", ";", "this", ".", "valueSubjectQueue", ".", "add", "(", "resource", ")", ";", "}" ]
Adds the given value to the list of values that should still be serialized. The given RDF resource will be used as a subject. @param value the value to be serialized @param resource the RDF resource that is used as a subject for serialization
[ "Adds", "the", "given", "value", "to", "the", "list", "of", "values", "that", "should", "still", "be", "serialized", ".", "The", "given", "RDF", "resource", "will", "be", "used", "as", "a", "subject", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/values/BufferedValueConverter.java#L56-L59
161,364
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java
TermStatementUpdate.processAliases
protected void processAliases(List<MonolingualTextValue> addAliases, List<MonolingualTextValue> deleteAliases) { for(MonolingualTextValue val : addAliases) { addAlias(val); } for(MonolingualTextValue val : deleteAliases) { deleteAlias(val); } }
java
protected void processAliases(List<MonolingualTextValue> addAliases, List<MonolingualTextValue> deleteAliases) { for(MonolingualTextValue val : addAliases) { addAlias(val); } for(MonolingualTextValue val : deleteAliases) { deleteAlias(val); } }
[ "protected", "void", "processAliases", "(", "List", "<", "MonolingualTextValue", ">", "addAliases", ",", "List", "<", "MonolingualTextValue", ">", "deleteAliases", ")", "{", "for", "(", "MonolingualTextValue", "val", ":", "addAliases", ")", "{", "addAlias", "(", "val", ")", ";", "}", "for", "(", "MonolingualTextValue", "val", ":", "deleteAliases", ")", "{", "deleteAlias", "(", "val", ")", ";", "}", "}" ]
Processes changes on aliases, updating the planned state of the item. @param addAliases aliases that should be added to the document @param deleteAliases aliases that should be removed from the document
[ "Processes", "changes", "on", "aliases", "updating", "the", "planned", "state", "of", "the", "item", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java#L170-L177
161,365
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java
TermStatementUpdate.deleteAlias
protected void deleteAlias(MonolingualTextValue alias) { String lang = alias.getLanguageCode(); AliasesWithUpdate currentAliases = newAliases.get(lang); if (currentAliases != null) { currentAliases.aliases.remove(alias); currentAliases.deleted.add(alias); currentAliases.write = true; } }
java
protected void deleteAlias(MonolingualTextValue alias) { String lang = alias.getLanguageCode(); AliasesWithUpdate currentAliases = newAliases.get(lang); if (currentAliases != null) { currentAliases.aliases.remove(alias); currentAliases.deleted.add(alias); currentAliases.write = true; } }
[ "protected", "void", "deleteAlias", "(", "MonolingualTextValue", "alias", ")", "{", "String", "lang", "=", "alias", ".", "getLanguageCode", "(", ")", ";", "AliasesWithUpdate", "currentAliases", "=", "newAliases", ".", "get", "(", "lang", ")", ";", "if", "(", "currentAliases", "!=", "null", ")", "{", "currentAliases", ".", "aliases", ".", "remove", "(", "alias", ")", ";", "currentAliases", ".", "deleted", ".", "add", "(", "alias", ")", ";", "currentAliases", ".", "write", "=", "true", ";", "}", "}" ]
Deletes an individual alias @param alias the alias to delete
[ "Deletes", "an", "individual", "alias" ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java#L185-L193
161,366
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java
TermStatementUpdate.addAlias
protected void addAlias(MonolingualTextValue alias) { String lang = alias.getLanguageCode(); AliasesWithUpdate currentAliasesUpdate = newAliases.get(lang); NameWithUpdate currentLabel = newLabels.get(lang); // If there isn't any label for that language, put the alias there if (currentLabel == null) { newLabels.put(lang, new NameWithUpdate(alias, true)); // If the new alias is equal to the current label, skip it } else if (!currentLabel.value.equals(alias)) { if (currentAliasesUpdate == null) { currentAliasesUpdate = new AliasesWithUpdate(new ArrayList<MonolingualTextValue>(), true); } List<MonolingualTextValue> currentAliases = currentAliasesUpdate.aliases; if(!currentAliases.contains(alias)) { currentAliases.add(alias); currentAliasesUpdate.added.add(alias); currentAliasesUpdate.write = true; } newAliases.put(lang, currentAliasesUpdate); } }
java
protected void addAlias(MonolingualTextValue alias) { String lang = alias.getLanguageCode(); AliasesWithUpdate currentAliasesUpdate = newAliases.get(lang); NameWithUpdate currentLabel = newLabels.get(lang); // If there isn't any label for that language, put the alias there if (currentLabel == null) { newLabels.put(lang, new NameWithUpdate(alias, true)); // If the new alias is equal to the current label, skip it } else if (!currentLabel.value.equals(alias)) { if (currentAliasesUpdate == null) { currentAliasesUpdate = new AliasesWithUpdate(new ArrayList<MonolingualTextValue>(), true); } List<MonolingualTextValue> currentAliases = currentAliasesUpdate.aliases; if(!currentAliases.contains(alias)) { currentAliases.add(alias); currentAliasesUpdate.added.add(alias); currentAliasesUpdate.write = true; } newAliases.put(lang, currentAliasesUpdate); } }
[ "protected", "void", "addAlias", "(", "MonolingualTextValue", "alias", ")", "{", "String", "lang", "=", "alias", ".", "getLanguageCode", "(", ")", ";", "AliasesWithUpdate", "currentAliasesUpdate", "=", "newAliases", ".", "get", "(", "lang", ")", ";", "NameWithUpdate", "currentLabel", "=", "newLabels", ".", "get", "(", "lang", ")", ";", "// If there isn't any label for that language, put the alias there", "if", "(", "currentLabel", "==", "null", ")", "{", "newLabels", ".", "put", "(", "lang", ",", "new", "NameWithUpdate", "(", "alias", ",", "true", ")", ")", ";", "// If the new alias is equal to the current label, skip it", "}", "else", "if", "(", "!", "currentLabel", ".", "value", ".", "equals", "(", "alias", ")", ")", "{", "if", "(", "currentAliasesUpdate", "==", "null", ")", "{", "currentAliasesUpdate", "=", "new", "AliasesWithUpdate", "(", "new", "ArrayList", "<", "MonolingualTextValue", ">", "(", ")", ",", "true", ")", ";", "}", "List", "<", "MonolingualTextValue", ">", "currentAliases", "=", "currentAliasesUpdate", ".", "aliases", ";", "if", "(", "!", "currentAliases", ".", "contains", "(", "alias", ")", ")", "{", "currentAliases", ".", "add", "(", "alias", ")", ";", "currentAliasesUpdate", ".", "added", ".", "add", "(", "alias", ")", ";", "currentAliasesUpdate", ".", "write", "=", "true", ";", "}", "newAliases", ".", "put", "(", "lang", ",", "currentAliasesUpdate", ")", ";", "}", "}" ]
Adds an individual alias. It will be merged with the current list of aliases, or added as a label if there is no label for this item in this language yet. @param alias the alias to add
[ "Adds", "an", "individual", "alias", ".", "It", "will", "be", "merged", "with", "the", "current", "list", "of", "aliases", "or", "added", "as", "a", "label", "if", "there", "is", "no", "label", "for", "this", "item", "in", "this", "language", "yet", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java#L203-L224
161,367
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java
TermStatementUpdate.processDescriptions
protected void processDescriptions(List<MonolingualTextValue> descriptions) { for(MonolingualTextValue description : descriptions) { NameWithUpdate currentValue = newDescriptions.get(description.getLanguageCode()); // only mark the description as added if the value we are writing is different from the current one if (currentValue == null || !currentValue.value.equals(description)) { newDescriptions.put(description.getLanguageCode(), new NameWithUpdate(description, true)); } } }
java
protected void processDescriptions(List<MonolingualTextValue> descriptions) { for(MonolingualTextValue description : descriptions) { NameWithUpdate currentValue = newDescriptions.get(description.getLanguageCode()); // only mark the description as added if the value we are writing is different from the current one if (currentValue == null || !currentValue.value.equals(description)) { newDescriptions.put(description.getLanguageCode(), new NameWithUpdate(description, true)); } } }
[ "protected", "void", "processDescriptions", "(", "List", "<", "MonolingualTextValue", ">", "descriptions", ")", "{", "for", "(", "MonolingualTextValue", "description", ":", "descriptions", ")", "{", "NameWithUpdate", "currentValue", "=", "newDescriptions", ".", "get", "(", "description", ".", "getLanguageCode", "(", ")", ")", ";", "// only mark the description as added if the value we are writing is different from the current one", "if", "(", "currentValue", "==", "null", "||", "!", "currentValue", ".", "value", ".", "equals", "(", "description", ")", ")", "{", "newDescriptions", ".", "put", "(", "description", ".", "getLanguageCode", "(", ")", ",", "new", "NameWithUpdate", "(", "description", ",", "true", ")", ")", ";", "}", "}", "}" ]
Adds descriptions to the item. @param descriptions the descriptions to add
[ "Adds", "descriptions", "to", "the", "item", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java#L232-L241
161,368
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java
TermStatementUpdate.processLabels
protected void processLabels(List<MonolingualTextValue> labels) { for(MonolingualTextValue label : labels) { String lang = label.getLanguageCode(); NameWithUpdate currentValue = newLabels.get(lang); if (currentValue == null || !currentValue.value.equals(label)) { newLabels.put(lang, new NameWithUpdate(label, true)); // Delete any alias that matches the new label AliasesWithUpdate currentAliases = newAliases.get(lang); if (currentAliases != null && currentAliases.aliases.contains(label)) { deleteAlias(label); } } } }
java
protected void processLabels(List<MonolingualTextValue> labels) { for(MonolingualTextValue label : labels) { String lang = label.getLanguageCode(); NameWithUpdate currentValue = newLabels.get(lang); if (currentValue == null || !currentValue.value.equals(label)) { newLabels.put(lang, new NameWithUpdate(label, true)); // Delete any alias that matches the new label AliasesWithUpdate currentAliases = newAliases.get(lang); if (currentAliases != null && currentAliases.aliases.contains(label)) { deleteAlias(label); } } } }
[ "protected", "void", "processLabels", "(", "List", "<", "MonolingualTextValue", ">", "labels", ")", "{", "for", "(", "MonolingualTextValue", "label", ":", "labels", ")", "{", "String", "lang", "=", "label", ".", "getLanguageCode", "(", ")", ";", "NameWithUpdate", "currentValue", "=", "newLabels", ".", "get", "(", "lang", ")", ";", "if", "(", "currentValue", "==", "null", "||", "!", "currentValue", ".", "value", ".", "equals", "(", "label", ")", ")", "{", "newLabels", ".", "put", "(", "lang", ",", "new", "NameWithUpdate", "(", "label", ",", "true", ")", ")", ";", "// Delete any alias that matches the new label", "AliasesWithUpdate", "currentAliases", "=", "newAliases", ".", "get", "(", "lang", ")", ";", "if", "(", "currentAliases", "!=", "null", "&&", "currentAliases", ".", "aliases", ".", "contains", "(", "label", ")", ")", "{", "deleteAlias", "(", "label", ")", ";", "}", "}", "}", "}" ]
Adds labels to the item @param labels the labels to add
[ "Adds", "labels", "to", "the", "item" ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java#L249-L265
161,369
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java
TermStatementUpdate.getLabelUpdates
@JsonProperty("labels") @JsonInclude(Include.NON_EMPTY) public Map<String, TermImpl> getLabelUpdates() { return getMonolingualUpdatedValues(newLabels); }
java
@JsonProperty("labels") @JsonInclude(Include.NON_EMPTY) public Map<String, TermImpl> getLabelUpdates() { return getMonolingualUpdatedValues(newLabels); }
[ "@", "JsonProperty", "(", "\"labels\"", ")", "@", "JsonInclude", "(", "Include", ".", "NON_EMPTY", ")", "public", "Map", "<", "String", ",", "TermImpl", ">", "getLabelUpdates", "(", ")", "{", "return", "getMonolingualUpdatedValues", "(", "newLabels", ")", ";", "}" ]
Label accessor provided for JSON serialization only.
[ "Label", "accessor", "provided", "for", "JSON", "serialization", "only", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java#L270-L274
161,370
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java
TermStatementUpdate.getDescriptionUpdates
@JsonProperty("descriptions") @JsonInclude(Include.NON_EMPTY) public Map<String, TermImpl> getDescriptionUpdates() { return getMonolingualUpdatedValues(newDescriptions); }
java
@JsonProperty("descriptions") @JsonInclude(Include.NON_EMPTY) public Map<String, TermImpl> getDescriptionUpdates() { return getMonolingualUpdatedValues(newDescriptions); }
[ "@", "JsonProperty", "(", "\"descriptions\"", ")", "@", "JsonInclude", "(", "Include", ".", "NON_EMPTY", ")", "public", "Map", "<", "String", ",", "TermImpl", ">", "getDescriptionUpdates", "(", ")", "{", "return", "getMonolingualUpdatedValues", "(", "newDescriptions", ")", ";", "}" ]
Description accessor provided for JSON serialization only.
[ "Description", "accessor", "provided", "for", "JSON", "serialization", "only", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java#L279-L283
161,371
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java
TermStatementUpdate.getAliasUpdates
@JsonProperty("aliases") @JsonInclude(Include.NON_EMPTY) public Map<String, List<TermImpl>> getAliasUpdates() { Map<String, List<TermImpl>> updatedValues = new HashMap<>(); for(Map.Entry<String,AliasesWithUpdate> entry : newAliases.entrySet()) { AliasesWithUpdate update = entry.getValue(); if (!update.write) { continue; } List<TermImpl> convertedAliases = new ArrayList<>(); for(MonolingualTextValue alias : update.aliases) { convertedAliases.add(monolingualToJackson(alias)); } updatedValues.put(entry.getKey(), convertedAliases); } return updatedValues; }
java
@JsonProperty("aliases") @JsonInclude(Include.NON_EMPTY) public Map<String, List<TermImpl>> getAliasUpdates() { Map<String, List<TermImpl>> updatedValues = new HashMap<>(); for(Map.Entry<String,AliasesWithUpdate> entry : newAliases.entrySet()) { AliasesWithUpdate update = entry.getValue(); if (!update.write) { continue; } List<TermImpl> convertedAliases = new ArrayList<>(); for(MonolingualTextValue alias : update.aliases) { convertedAliases.add(monolingualToJackson(alias)); } updatedValues.put(entry.getKey(), convertedAliases); } return updatedValues; }
[ "@", "JsonProperty", "(", "\"aliases\"", ")", "@", "JsonInclude", "(", "Include", ".", "NON_EMPTY", ")", "public", "Map", "<", "String", ",", "List", "<", "TermImpl", ">", ">", "getAliasUpdates", "(", ")", "{", "Map", "<", "String", ",", "List", "<", "TermImpl", ">", ">", "updatedValues", "=", "new", "HashMap", "<>", "(", ")", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "AliasesWithUpdate", ">", "entry", ":", "newAliases", ".", "entrySet", "(", ")", ")", "{", "AliasesWithUpdate", "update", "=", "entry", ".", "getValue", "(", ")", ";", "if", "(", "!", "update", ".", "write", ")", "{", "continue", ";", "}", "List", "<", "TermImpl", ">", "convertedAliases", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "MonolingualTextValue", "alias", ":", "update", ".", "aliases", ")", "{", "convertedAliases", ".", "add", "(", "monolingualToJackson", "(", "alias", ")", ")", ";", "}", "updatedValues", ".", "put", "(", "entry", ".", "getKey", "(", ")", ",", "convertedAliases", ")", ";", "}", "return", "updatedValues", ";", "}" ]
Alias accessor provided for JSON serialization only
[ "Alias", "accessor", "provided", "for", "JSON", "serialization", "only" ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java#L288-L305
161,372
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java
TermStatementUpdate.getMonolingualUpdatedValues
protected Map<String, TermImpl> getMonolingualUpdatedValues(Map<String, NameWithUpdate> updates) { Map<String, TermImpl> updatedValues = new HashMap<>(); for(NameWithUpdate update : updates.values()) { if (!update.write) { continue; } updatedValues.put(update.value.getLanguageCode(), monolingualToJackson(update.value)); } return updatedValues; }
java
protected Map<String, TermImpl> getMonolingualUpdatedValues(Map<String, NameWithUpdate> updates) { Map<String, TermImpl> updatedValues = new HashMap<>(); for(NameWithUpdate update : updates.values()) { if (!update.write) { continue; } updatedValues.put(update.value.getLanguageCode(), monolingualToJackson(update.value)); } return updatedValues; }
[ "protected", "Map", "<", "String", ",", "TermImpl", ">", "getMonolingualUpdatedValues", "(", "Map", "<", "String", ",", "NameWithUpdate", ">", "updates", ")", "{", "Map", "<", "String", ",", "TermImpl", ">", "updatedValues", "=", "new", "HashMap", "<>", "(", ")", ";", "for", "(", "NameWithUpdate", "update", ":", "updates", ".", "values", "(", ")", ")", "{", "if", "(", "!", "update", ".", "write", ")", "{", "continue", ";", "}", "updatedValues", ".", "put", "(", "update", ".", "value", ".", "getLanguageCode", "(", ")", ",", "monolingualToJackson", "(", "update", ".", "value", ")", ")", ";", "}", "return", "updatedValues", ";", "}" ]
Helper to format term updates as expected by the Wikibase API @param updates planned updates for the type of term @return map ready to be serialized as JSON by Jackson
[ "Helper", "to", "format", "term", "updates", "as", "expected", "by", "the", "Wikibase", "API" ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/TermStatementUpdate.java#L453-L462
161,373
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/RdfSerializationAction.java
RdfSerializationAction.createRdfSerializer
protected RdfSerializer createRdfSerializer() throws IOException { String outputDestinationFinal; if (this.outputDestination != null) { outputDestinationFinal = this.outputDestination; } else { outputDestinationFinal = "{PROJECT}" + this.taskName + "{DATE}" + ".nt"; } OutputStream exportOutputStream = getOutputStream(this.useStdOut, insertDumpInformation(outputDestinationFinal), this.compressionType); RdfSerializer serializer = new RdfSerializer(RDFFormat.NTRIPLES, exportOutputStream, this.sites, PropertyRegister.getWikidataPropertyRegister()); serializer.setTasks(this.tasks); return serializer; }
java
protected RdfSerializer createRdfSerializer() throws IOException { String outputDestinationFinal; if (this.outputDestination != null) { outputDestinationFinal = this.outputDestination; } else { outputDestinationFinal = "{PROJECT}" + this.taskName + "{DATE}" + ".nt"; } OutputStream exportOutputStream = getOutputStream(this.useStdOut, insertDumpInformation(outputDestinationFinal), this.compressionType); RdfSerializer serializer = new RdfSerializer(RDFFormat.NTRIPLES, exportOutputStream, this.sites, PropertyRegister.getWikidataPropertyRegister()); serializer.setTasks(this.tasks); return serializer; }
[ "protected", "RdfSerializer", "createRdfSerializer", "(", ")", "throws", "IOException", "{", "String", "outputDestinationFinal", ";", "if", "(", "this", ".", "outputDestination", "!=", "null", ")", "{", "outputDestinationFinal", "=", "this", ".", "outputDestination", ";", "}", "else", "{", "outputDestinationFinal", "=", "\"{PROJECT}\"", "+", "this", ".", "taskName", "+", "\"{DATE}\"", "+", "\".nt\"", ";", "}", "OutputStream", "exportOutputStream", "=", "getOutputStream", "(", "this", ".", "useStdOut", ",", "insertDumpInformation", "(", "outputDestinationFinal", ")", ",", "this", ".", "compressionType", ")", ";", "RdfSerializer", "serializer", "=", "new", "RdfSerializer", "(", "RDFFormat", ".", "NTRIPLES", ",", "exportOutputStream", ",", "this", ".", "sites", ",", "PropertyRegister", ".", "getWikidataPropertyRegister", "(", ")", ")", ";", "serializer", ".", "setTasks", "(", "this", ".", "tasks", ")", ";", "return", "serializer", ";", "}" ]
Creates a new RDF serializer based on the current configuration of this object. @return the newly created RDF serializer @throws IOException if there were problems opening the output files
[ "Creates", "a", "new", "RDF", "serializer", "based", "on", "the", "current", "configuration", "of", "this", "object", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/RdfSerializationAction.java#L213-L233
161,374
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/RdfSerializationAction.java
RdfSerializationAction.setTasks
private void setTasks(String tasks) { for (String task : tasks.split(",")) { if (KNOWN_TASKS.containsKey(task)) { this.tasks |= KNOWN_TASKS.get(task); this.taskName += (this.taskName.isEmpty() ? "" : "-") + task; } else { logger.warn("Unsupported RDF serialization task \"" + task + "\". Run without specifying any tasks for help."); } } }
java
private void setTasks(String tasks) { for (String task : tasks.split(",")) { if (KNOWN_TASKS.containsKey(task)) { this.tasks |= KNOWN_TASKS.get(task); this.taskName += (this.taskName.isEmpty() ? "" : "-") + task; } else { logger.warn("Unsupported RDF serialization task \"" + task + "\". Run without specifying any tasks for help."); } } }
[ "private", "void", "setTasks", "(", "String", "tasks", ")", "{", "for", "(", "String", "task", ":", "tasks", ".", "split", "(", "\",\"", ")", ")", "{", "if", "(", "KNOWN_TASKS", ".", "containsKey", "(", "task", ")", ")", "{", "this", ".", "tasks", "|=", "KNOWN_TASKS", ".", "get", "(", "task", ")", ";", "this", ".", "taskName", "+=", "(", "this", ".", "taskName", ".", "isEmpty", "(", ")", "?", "\"\"", ":", "\"-\"", ")", "+", "task", ";", "}", "else", "{", "logger", ".", "warn", "(", "\"Unsupported RDF serialization task \\\"\"", "+", "task", "+", "\"\\\". Run without specifying any tasks for help.\"", ")", ";", "}", "}", "}" ]
Sets the RDF serialization tasks based on the given string value. @param tasks a space-free, comma-separated list of task names
[ "Sets", "the", "RDF", "serialization", "tasks", "based", "on", "the", "given", "string", "value", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/RdfSerializationAction.java#L241-L251
161,375
Wikidata/Wikidata-Toolkit
wdtk-storage/src/main/java/org/wikidata/wdtk/storage/datastructures/BitVectorImpl.java
BitVectorImpl.resizeArray
void resizeArray(int newArraySize) { long[] newArray = new long[newArraySize]; System.arraycopy(this.arrayOfBits, 0, newArray, 0, Math.min(this.arrayOfBits.length, newArraySize)); this.arrayOfBits = newArray; }
java
void resizeArray(int newArraySize) { long[] newArray = new long[newArraySize]; System.arraycopy(this.arrayOfBits, 0, newArray, 0, Math.min(this.arrayOfBits.length, newArraySize)); this.arrayOfBits = newArray; }
[ "void", "resizeArray", "(", "int", "newArraySize", ")", "{", "long", "[", "]", "newArray", "=", "new", "long", "[", "newArraySize", "]", ";", "System", ".", "arraycopy", "(", "this", ".", "arrayOfBits", ",", "0", ",", "newArray", ",", "0", ",", "Math", ".", "min", "(", "this", ".", "arrayOfBits", ".", "length", ",", "newArraySize", ")", ")", ";", "this", ".", "arrayOfBits", "=", "newArray", ";", "}" ]
Resizes the array that represents this bit vector. @param newArraySize new array size
[ "Resizes", "the", "array", "that", "represents", "this", "bit", "vector", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-storage/src/main/java/org/wikidata/wdtk/storage/datastructures/BitVectorImpl.java#L310-L315
161,376
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java
WikibaseDataEditor.updateStatements
public ItemDocument updateStatements(ItemIdValue itemIdValue, List<Statement> addStatements, List<Statement> deleteStatements, String summary) throws MediaWikiApiErrorException, IOException { ItemDocument currentDocument = (ItemDocument) this.wikibaseDataFetcher .getEntityDocument(itemIdValue.getId()); return updateStatements(currentDocument, addStatements, deleteStatements, summary); }
java
public ItemDocument updateStatements(ItemIdValue itemIdValue, List<Statement> addStatements, List<Statement> deleteStatements, String summary) throws MediaWikiApiErrorException, IOException { ItemDocument currentDocument = (ItemDocument) this.wikibaseDataFetcher .getEntityDocument(itemIdValue.getId()); return updateStatements(currentDocument, addStatements, deleteStatements, summary); }
[ "public", "ItemDocument", "updateStatements", "(", "ItemIdValue", "itemIdValue", ",", "List", "<", "Statement", ">", "addStatements", ",", "List", "<", "Statement", ">", "deleteStatements", ",", "String", "summary", ")", "throws", "MediaWikiApiErrorException", ",", "IOException", "{", "ItemDocument", "currentDocument", "=", "(", "ItemDocument", ")", "this", ".", "wikibaseDataFetcher", ".", "getEntityDocument", "(", "itemIdValue", ".", "getId", "(", ")", ")", ";", "return", "updateStatements", "(", "currentDocument", ",", "addStatements", ",", "deleteStatements", ",", "summary", ")", ";", "}" ]
Updates the statements of the item document identified by the given item id. The updates are computed with respect to the current data found online, making sure that no redundant deletions or duplicate insertions happen. The references of duplicate statements will be merged. @param itemIdValue id of the document to be updated @param addStatements the list of statements to be added or updated; statements with empty statement id will be added; statements with non-empty statement id will be updated (if such a statement exists) @param deleteStatements the list of statements to be deleted; statements will only be deleted if they are present in the current document (in exactly the same form, with the same id) @param summary short edit summary @return the updated document @throws MediaWikiApiErrorException if the API returns errors @throws IOException if there are IO problems, such as missing network connection
[ "Updates", "the", "statements", "of", "the", "item", "document", "identified", "by", "the", "given", "item", "id", ".", "The", "updates", "are", "computed", "with", "respect", "to", "the", "current", "data", "found", "online", "making", "sure", "that", "no", "redundant", "deletions", "or", "duplicate", "insertions", "happen", ".", "The", "references", "of", "duplicate", "statements", "will", "be", "merged", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java#L390-L399
161,377
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java
WikibaseDataEditor.updateTermsStatements
public ItemDocument updateTermsStatements(ItemIdValue itemIdValue, List<MonolingualTextValue> addLabels, List<MonolingualTextValue> addDescriptions, List<MonolingualTextValue> addAliases, List<MonolingualTextValue> deleteAliases, List<Statement> addStatements, List<Statement> deleteStatements, String summary) throws MediaWikiApiErrorException, IOException { ItemDocument currentDocument = (ItemDocument) this.wikibaseDataFetcher .getEntityDocument(itemIdValue.getId()); return updateTermsStatements(currentDocument, addLabels, addDescriptions, addAliases, deleteAliases, addStatements, deleteStatements, summary); }
java
public ItemDocument updateTermsStatements(ItemIdValue itemIdValue, List<MonolingualTextValue> addLabels, List<MonolingualTextValue> addDescriptions, List<MonolingualTextValue> addAliases, List<MonolingualTextValue> deleteAliases, List<Statement> addStatements, List<Statement> deleteStatements, String summary) throws MediaWikiApiErrorException, IOException { ItemDocument currentDocument = (ItemDocument) this.wikibaseDataFetcher .getEntityDocument(itemIdValue.getId()); return updateTermsStatements(currentDocument, addLabels, addDescriptions, addAliases, deleteAliases, addStatements, deleteStatements, summary); }
[ "public", "ItemDocument", "updateTermsStatements", "(", "ItemIdValue", "itemIdValue", ",", "List", "<", "MonolingualTextValue", ">", "addLabels", ",", "List", "<", "MonolingualTextValue", ">", "addDescriptions", ",", "List", "<", "MonolingualTextValue", ">", "addAliases", ",", "List", "<", "MonolingualTextValue", ">", "deleteAliases", ",", "List", "<", "Statement", ">", "addStatements", ",", "List", "<", "Statement", ">", "deleteStatements", ",", "String", "summary", ")", "throws", "MediaWikiApiErrorException", ",", "IOException", "{", "ItemDocument", "currentDocument", "=", "(", "ItemDocument", ")", "this", ".", "wikibaseDataFetcher", ".", "getEntityDocument", "(", "itemIdValue", ".", "getId", "(", ")", ")", ";", "return", "updateTermsStatements", "(", "currentDocument", ",", "addLabels", ",", "addDescriptions", ",", "addAliases", ",", "deleteAliases", ",", "addStatements", ",", "deleteStatements", ",", "summary", ")", ";", "}" ]
Updates the terms and statements of the item document identified by the given item id. The updates are computed with respect to the current data found online, making sure that no redundant deletions or duplicate insertions happen. The references of duplicate statements will be merged. The labels and aliases in a given language are kept distinct. @param itemIdValue id of the document to be updated @param addLabels labels to be set on the item. They will overwrite existing values in the same language. @param addDescriptions description to be set on the item. They will overwrite existing values in the same language. @param addAliases aliases to be added. Existing aliases will be kept. @param deleteAliases aliases to be deleted. @param addStatements the list of statements to be added or updated; statements with empty statement id will be added; statements with non-empty statement id will be updated (if such a statement exists) @param deleteStatements the list of statements to be deleted; statements will only be deleted if they are present in the current document (in exactly the same form, with the same id) @param summary short edit summary @return the updated document @throws MediaWikiApiErrorException if the API returns errors @throws IOException if there are any IO errors, such as missing network connection
[ "Updates", "the", "terms", "and", "statements", "of", "the", "item", "document", "identified", "by", "the", "given", "item", "id", ".", "The", "updates", "are", "computed", "with", "respect", "to", "the", "current", "data", "found", "online", "making", "sure", "that", "no", "redundant", "deletions", "or", "duplicate", "insertions", "happen", ".", "The", "references", "of", "duplicate", "statements", "will", "be", "merged", ".", "The", "labels", "and", "aliases", "in", "a", "given", "language", "are", "kept", "distinct", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java#L437-L451
161,378
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java
WikibaseDataEditor.updateTermsStatements
@SuppressWarnings("unchecked") public <T extends TermedStatementDocument> T updateTermsStatements(T currentDocument, List<MonolingualTextValue> addLabels, List<MonolingualTextValue> addDescriptions, List<MonolingualTextValue> addAliases, List<MonolingualTextValue> deleteAliases, List<Statement> addStatements, List<Statement> deleteStatements, String summary) throws MediaWikiApiErrorException, IOException { TermStatementUpdate termStatementUpdate = new TermStatementUpdate( currentDocument, addStatements, deleteStatements, addLabels, addDescriptions, addAliases, deleteAliases); termStatementUpdate.setGuidGenerator(guidGenerator); return (T) termStatementUpdate.performEdit(wbEditingAction, editAsBot, summary); }
java
@SuppressWarnings("unchecked") public <T extends TermedStatementDocument> T updateTermsStatements(T currentDocument, List<MonolingualTextValue> addLabels, List<MonolingualTextValue> addDescriptions, List<MonolingualTextValue> addAliases, List<MonolingualTextValue> deleteAliases, List<Statement> addStatements, List<Statement> deleteStatements, String summary) throws MediaWikiApiErrorException, IOException { TermStatementUpdate termStatementUpdate = new TermStatementUpdate( currentDocument, addStatements, deleteStatements, addLabels, addDescriptions, addAliases, deleteAliases); termStatementUpdate.setGuidGenerator(guidGenerator); return (T) termStatementUpdate.performEdit(wbEditingAction, editAsBot, summary); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "<", "T", "extends", "TermedStatementDocument", ">", "T", "updateTermsStatements", "(", "T", "currentDocument", ",", "List", "<", "MonolingualTextValue", ">", "addLabels", ",", "List", "<", "MonolingualTextValue", ">", "addDescriptions", ",", "List", "<", "MonolingualTextValue", ">", "addAliases", ",", "List", "<", "MonolingualTextValue", ">", "deleteAliases", ",", "List", "<", "Statement", ">", "addStatements", ",", "List", "<", "Statement", ">", "deleteStatements", ",", "String", "summary", ")", "throws", "MediaWikiApiErrorException", ",", "IOException", "{", "TermStatementUpdate", "termStatementUpdate", "=", "new", "TermStatementUpdate", "(", "currentDocument", ",", "addStatements", ",", "deleteStatements", ",", "addLabels", ",", "addDescriptions", ",", "addAliases", ",", "deleteAliases", ")", ";", "termStatementUpdate", ".", "setGuidGenerator", "(", "guidGenerator", ")", ";", "return", "(", "T", ")", "termStatementUpdate", ".", "performEdit", "(", "wbEditingAction", ",", "editAsBot", ",", "summary", ")", ";", "}" ]
Updates the terms and statements of the current document. The updates are computed with respect to the current data in the document, making sure that no redundant deletions or duplicate insertions happen. The references of duplicate statements will be merged. The labels and aliases in a given language are kept distinct. @param currentDocument the document to be updated; needs to have a correct revision id and entity id @param addLabels labels to be set on the item. They will overwrite existing values in the same language. @param addDescriptions description to be set on the item. They will overwrite existing values in the same language. @param addAliases aliases to be added. Existing aliases will be kept. @param deleteAliases aliases to be deleted. @param addStatements the list of statements to be added or updated; statements with empty statement id will be added; statements with non-empty statement id will be updated (if such a statement exists) @param deleteStatements the list of statements to be deleted; statements will only be deleted if they are present in the current document (in exactly the same form, with the same id) @param summary short edit summary @return the updated document @throws MediaWikiApiErrorException if the API returns errors @throws IOException if there are any IO errors, such as missing network connection
[ "Updates", "the", "terms", "and", "statements", "of", "the", "current", "document", ".", "The", "updates", "are", "computed", "with", "respect", "to", "the", "current", "data", "in", "the", "document", "making", "sure", "that", "no", "redundant", "deletions", "or", "duplicate", "insertions", "happen", ".", "The", "references", "of", "duplicate", "statements", "will", "be", "merged", ".", "The", "labels", "and", "aliases", "in", "a", "given", "language", "are", "kept", "distinct", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java#L573-L589
161,379
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java
WikibaseDataEditor.nullEdit
public <T extends StatementDocument> void nullEdit(ItemIdValue itemId) throws IOException, MediaWikiApiErrorException { ItemDocument currentDocument = (ItemDocument) this.wikibaseDataFetcher .getEntityDocument(itemId.getId()); nullEdit(currentDocument); }
java
public <T extends StatementDocument> void nullEdit(ItemIdValue itemId) throws IOException, MediaWikiApiErrorException { ItemDocument currentDocument = (ItemDocument) this.wikibaseDataFetcher .getEntityDocument(itemId.getId()); nullEdit(currentDocument); }
[ "public", "<", "T", "extends", "StatementDocument", ">", "void", "nullEdit", "(", "ItemIdValue", "itemId", ")", "throws", "IOException", ",", "MediaWikiApiErrorException", "{", "ItemDocument", "currentDocument", "=", "(", "ItemDocument", ")", "this", ".", "wikibaseDataFetcher", ".", "getEntityDocument", "(", "itemId", ".", "getId", "(", ")", ")", ";", "nullEdit", "(", "currentDocument", ")", ";", "}" ]
Performs a null edit on an item. This has some effects on Wikibase, such as refreshing the labels of the referred items in the UI. @param itemId the document to perform a null edit on @throws MediaWikiApiErrorException if the API returns errors @throws IOException if there are any IO errors, such as missing network connection
[ "Performs", "a", "null", "edit", "on", "an", "item", ".", "This", "has", "some", "effects", "on", "Wikibase", "such", "as", "refreshing", "the", "labels", "of", "the", "referred", "items", "in", "the", "UI", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java#L602-L608
161,380
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java
WikibaseDataEditor.nullEdit
public <T extends StatementDocument> void nullEdit(PropertyIdValue propertyId) throws IOException, MediaWikiApiErrorException { PropertyDocument currentDocument = (PropertyDocument) this.wikibaseDataFetcher .getEntityDocument(propertyId.getId()); nullEdit(currentDocument); }
java
public <T extends StatementDocument> void nullEdit(PropertyIdValue propertyId) throws IOException, MediaWikiApiErrorException { PropertyDocument currentDocument = (PropertyDocument) this.wikibaseDataFetcher .getEntityDocument(propertyId.getId()); nullEdit(currentDocument); }
[ "public", "<", "T", "extends", "StatementDocument", ">", "void", "nullEdit", "(", "PropertyIdValue", "propertyId", ")", "throws", "IOException", ",", "MediaWikiApiErrorException", "{", "PropertyDocument", "currentDocument", "=", "(", "PropertyDocument", ")", "this", ".", "wikibaseDataFetcher", ".", "getEntityDocument", "(", "propertyId", ".", "getId", "(", ")", ")", ";", "nullEdit", "(", "currentDocument", ")", ";", "}" ]
Performs a null edit on a property. This has some effects on Wikibase, such as refreshing the labels of the referred items in the UI. @param propertyId the document to perform a null edit on @throws MediaWikiApiErrorException if the API returns errors @throws IOException if there are any IO errors, such as missing network connection
[ "Performs", "a", "null", "edit", "on", "a", "property", ".", "This", "has", "some", "effects", "on", "Wikibase", "such", "as", "refreshing", "the", "labels", "of", "the", "referred", "items", "in", "the", "UI", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java#L621-L627
161,381
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java
WikibaseDataEditor.nullEdit
@SuppressWarnings("unchecked") public <T extends StatementDocument> T nullEdit(T currentDocument) throws IOException, MediaWikiApiErrorException { StatementUpdate statementUpdate = new StatementUpdate(currentDocument, Collections.<Statement>emptyList(), Collections.<Statement>emptyList()); statementUpdate.setGuidGenerator(guidGenerator); return (T) this.wbEditingAction.wbEditEntity(currentDocument .getEntityId().getId(), null, null, null, statementUpdate .getJsonUpdateString(), false, this.editAsBot, currentDocument .getRevisionId(), null); }
java
@SuppressWarnings("unchecked") public <T extends StatementDocument> T nullEdit(T currentDocument) throws IOException, MediaWikiApiErrorException { StatementUpdate statementUpdate = new StatementUpdate(currentDocument, Collections.<Statement>emptyList(), Collections.<Statement>emptyList()); statementUpdate.setGuidGenerator(guidGenerator); return (T) this.wbEditingAction.wbEditEntity(currentDocument .getEntityId().getId(), null, null, null, statementUpdate .getJsonUpdateString(), false, this.editAsBot, currentDocument .getRevisionId(), null); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "<", "T", "extends", "StatementDocument", ">", "T", "nullEdit", "(", "T", "currentDocument", ")", "throws", "IOException", ",", "MediaWikiApiErrorException", "{", "StatementUpdate", "statementUpdate", "=", "new", "StatementUpdate", "(", "currentDocument", ",", "Collections", ".", "<", "Statement", ">", "emptyList", "(", ")", ",", "Collections", ".", "<", "Statement", ">", "emptyList", "(", ")", ")", ";", "statementUpdate", ".", "setGuidGenerator", "(", "guidGenerator", ")", ";", "return", "(", "T", ")", "this", ".", "wbEditingAction", ".", "wbEditEntity", "(", "currentDocument", ".", "getEntityId", "(", ")", ".", "getId", "(", ")", ",", "null", ",", "null", ",", "null", ",", "statementUpdate", ".", "getJsonUpdateString", "(", ")", ",", "false", ",", "this", ".", "editAsBot", ",", "currentDocument", ".", "getRevisionId", "(", ")", ",", "null", ")", ";", "}" ]
Performs a null edit on an entity. This has some effects on Wikibase, such as refreshing the labels of the referred items in the UI. @param currentDocument the document to perform a null edit on @throws MediaWikiApiErrorException if the API returns errors @throws IOException if there are any IO errors, such as missing network connection
[ "Performs", "a", "null", "edit", "on", "an", "entity", ".", "This", "has", "some", "effects", "on", "Wikibase", "such", "as", "refreshing", "the", "labels", "of", "the", "referred", "items", "in", "the", "UI", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WikibaseDataEditor.java#L640-L651
161,382
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/JsonSerializationProcessor.java
JsonSerializationProcessor.main
public static void main(String[] args) throws IOException { ExampleHelpers.configureLogging(); JsonSerializationProcessor.printDocumentation(); JsonSerializationProcessor jsonSerializationProcessor = new JsonSerializationProcessor(); ExampleHelpers.processEntitiesFromWikidataDump(jsonSerializationProcessor); jsonSerializationProcessor.close(); }
java
public static void main(String[] args) throws IOException { ExampleHelpers.configureLogging(); JsonSerializationProcessor.printDocumentation(); JsonSerializationProcessor jsonSerializationProcessor = new JsonSerializationProcessor(); ExampleHelpers.processEntitiesFromWikidataDump(jsonSerializationProcessor); jsonSerializationProcessor.close(); }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "throws", "IOException", "{", "ExampleHelpers", ".", "configureLogging", "(", ")", ";", "JsonSerializationProcessor", ".", "printDocumentation", "(", ")", ";", "JsonSerializationProcessor", "jsonSerializationProcessor", "=", "new", "JsonSerializationProcessor", "(", ")", ";", "ExampleHelpers", ".", "processEntitiesFromWikidataDump", "(", "jsonSerializationProcessor", ")", ";", "jsonSerializationProcessor", ".", "close", "(", ")", ";", "}" ]
Runs the example program. @param args @throws IOException if there was a problem in writing the output file
[ "Runs", "the", "example", "program", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/JsonSerializationProcessor.java#L67-L74
161,383
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/JsonSerializationProcessor.java
JsonSerializationProcessor.close
public void close() throws IOException { System.out.println("Serialized " + this.jsonSerializer.getEntityDocumentCount() + " item documents to JSON file " + OUTPUT_FILE_NAME + "."); this.jsonSerializer.close(); }
java
public void close() throws IOException { System.out.println("Serialized " + this.jsonSerializer.getEntityDocumentCount() + " item documents to JSON file " + OUTPUT_FILE_NAME + "."); this.jsonSerializer.close(); }
[ "public", "void", "close", "(", ")", "throws", "IOException", "{", "System", ".", "out", ".", "println", "(", "\"Serialized \"", "+", "this", ".", "jsonSerializer", ".", "getEntityDocumentCount", "(", ")", "+", "\" item documents to JSON file \"", "+", "OUTPUT_FILE_NAME", "+", "\".\"", ")", ";", "this", ".", "jsonSerializer", ".", "close", "(", ")", ";", "}" ]
Closes the output. Should be called after the JSON serialization was finished. @throws IOException if there was a problem closing the output
[ "Closes", "the", "output", ".", "Should", "be", "called", "after", "the", "JSON", "serialization", "was", "finished", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/JsonSerializationProcessor.java#L147-L152
161,384
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/JsonSerializationProcessor.java
JsonSerializationProcessor.includeDocument
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; }
java
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; }
[ "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", ";", "}" ]
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
[ "Returns", "true", "if", "the", "given", "document", "should", "be", "included", "in", "the", "serialization", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/JsonSerializationProcessor.java#L162-L180
161,385
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java
ClientConfiguration.insertDumpInformation
public static String insertDumpInformation(String pattern, String dateStamp, String project) { if (pattern == null) { return null; } else { return pattern.replace("{DATE}", dateStamp).replace("{PROJECT}", project); } }
java
public static String insertDumpInformation(String pattern, String dateStamp, String project) { if (pattern == null) { return null; } else { return pattern.replace("{DATE}", dateStamp).replace("{PROJECT}", project); } }
[ "public", "static", "String", "insertDumpInformation", "(", "String", "pattern", ",", "String", "dateStamp", ",", "String", "project", ")", "{", "if", "(", "pattern", "==", "null", ")", "{", "return", "null", ";", "}", "else", "{", "return", "pattern", ".", "replace", "(", "\"{DATE}\"", ",", "dateStamp", ")", ".", "replace", "(", "\"{PROJECT}\"", ",", "project", ")", ";", "}", "}" ]
Inserts the information about the dateStamp of a dump and the project name into a pattern. @param pattern String with wildcards @param dateStamp @param project @return String with injected information.
[ "Inserts", "the", "information", "about", "the", "dateStamp", "of", "a", "dump", "and", "the", "project", "name", "into", "a", "pattern", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java#L278-L286
161,386
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java
ClientConfiguration.handleArguments
private List<DumpProcessingAction> handleArguments(String[] args) { CommandLine cmd; CommandLineParser parser = new GnuParser(); try { cmd = parser.parse(options, args); } catch (ParseException e) { logger.error("Failed to parse arguments: " + e.getMessage()); return Collections.emptyList(); } // Stop processing if a help text is to be printed: if ((cmd.hasOption(CMD_OPTION_HELP)) || (args.length == 0)) { return Collections.emptyList(); } List<DumpProcessingAction> configuration = new ArrayList<>(); handleGlobalArguments(cmd); if (cmd.hasOption(CMD_OPTION_ACTION)) { DumpProcessingAction action = handleActionArguments(cmd); if (action != null) { configuration.add(action); } } if (cmd.hasOption(CMD_OPTION_CONFIG_FILE)) { try { List<DumpProcessingAction> configFile = readConfigFile(cmd .getOptionValue(CMD_OPTION_CONFIG_FILE)); configuration.addAll(configFile); } catch (IOException e) { logger.error("Failed to read configuration file \"" + cmd.getOptionValue(CMD_OPTION_CONFIG_FILE) + "\": " + e.toString()); } } return configuration; }
java
private List<DumpProcessingAction> handleArguments(String[] args) { CommandLine cmd; CommandLineParser parser = new GnuParser(); try { cmd = parser.parse(options, args); } catch (ParseException e) { logger.error("Failed to parse arguments: " + e.getMessage()); return Collections.emptyList(); } // Stop processing if a help text is to be printed: if ((cmd.hasOption(CMD_OPTION_HELP)) || (args.length == 0)) { return Collections.emptyList(); } List<DumpProcessingAction> configuration = new ArrayList<>(); handleGlobalArguments(cmd); if (cmd.hasOption(CMD_OPTION_ACTION)) { DumpProcessingAction action = handleActionArguments(cmd); if (action != null) { configuration.add(action); } } if (cmd.hasOption(CMD_OPTION_CONFIG_FILE)) { try { List<DumpProcessingAction> configFile = readConfigFile(cmd .getOptionValue(CMD_OPTION_CONFIG_FILE)); configuration.addAll(configFile); } catch (IOException e) { logger.error("Failed to read configuration file \"" + cmd.getOptionValue(CMD_OPTION_CONFIG_FILE) + "\": " + e.toString()); } } return configuration; }
[ "private", "List", "<", "DumpProcessingAction", ">", "handleArguments", "(", "String", "[", "]", "args", ")", "{", "CommandLine", "cmd", ";", "CommandLineParser", "parser", "=", "new", "GnuParser", "(", ")", ";", "try", "{", "cmd", "=", "parser", ".", "parse", "(", "options", ",", "args", ")", ";", "}", "catch", "(", "ParseException", "e", ")", "{", "logger", ".", "error", "(", "\"Failed to parse arguments: \"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "return", "Collections", ".", "emptyList", "(", ")", ";", "}", "// Stop processing if a help text is to be printed:", "if", "(", "(", "cmd", ".", "hasOption", "(", "CMD_OPTION_HELP", ")", ")", "||", "(", "args", ".", "length", "==", "0", ")", ")", "{", "return", "Collections", ".", "emptyList", "(", ")", ";", "}", "List", "<", "DumpProcessingAction", ">", "configuration", "=", "new", "ArrayList", "<>", "(", ")", ";", "handleGlobalArguments", "(", "cmd", ")", ";", "if", "(", "cmd", ".", "hasOption", "(", "CMD_OPTION_ACTION", ")", ")", "{", "DumpProcessingAction", "action", "=", "handleActionArguments", "(", "cmd", ")", ";", "if", "(", "action", "!=", "null", ")", "{", "configuration", ".", "add", "(", "action", ")", ";", "}", "}", "if", "(", "cmd", ".", "hasOption", "(", "CMD_OPTION_CONFIG_FILE", ")", ")", "{", "try", "{", "List", "<", "DumpProcessingAction", ">", "configFile", "=", "readConfigFile", "(", "cmd", ".", "getOptionValue", "(", "CMD_OPTION_CONFIG_FILE", ")", ")", ";", "configuration", ".", "addAll", "(", "configFile", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "logger", ".", "error", "(", "\"Failed to read configuration file \\\"\"", "+", "cmd", ".", "getOptionValue", "(", "CMD_OPTION_CONFIG_FILE", ")", "+", "\"\\\": \"", "+", "e", ".", "toString", "(", ")", ")", ";", "}", "}", "return", "configuration", ";", "}" ]
This function interprets the arguments of the main function. By doing this it will set flags for the dump generation. See in the help text for more specific information about the options. @param args array of arguments from the main function. @return list of {@link DumpProcessingOutputAction}
[ "This", "function", "interprets", "the", "arguments", "of", "the", "main", "function", ".", "By", "doing", "this", "it", "will", "set", "flags", "for", "the", "dump", "generation", ".", "See", "in", "the", "help", "text", "for", "more", "specific", "information", "about", "the", "options", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java#L454-L496
161,387
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java
ClientConfiguration.handleGlobalArguments
private void handleGlobalArguments(CommandLine cmd) { if (cmd.hasOption(CMD_OPTION_DUMP_LOCATION)) { this.dumpDirectoryLocation = cmd .getOptionValue(CMD_OPTION_DUMP_LOCATION); } if (cmd.hasOption(CMD_OPTION_OFFLINE_MODE)) { this.offlineMode = true; } if (cmd.hasOption(CMD_OPTION_QUIET)) { this.quiet = true; } if (cmd.hasOption(CMD_OPTION_CREATE_REPORT)) { this.reportFilename = cmd.getOptionValue(CMD_OPTION_CREATE_REPORT); } if (cmd.hasOption(OPTION_FILTER_LANGUAGES)) { setLanguageFilters(cmd.getOptionValue(OPTION_FILTER_LANGUAGES)); } if (cmd.hasOption(OPTION_FILTER_SITES)) { setSiteFilters(cmd.getOptionValue(OPTION_FILTER_SITES)); } if (cmd.hasOption(OPTION_FILTER_PROPERTIES)) { setPropertyFilters(cmd.getOptionValue(OPTION_FILTER_PROPERTIES)); } if (cmd.hasOption(CMD_OPTION_LOCAL_DUMPFILE)) { this.inputDumpLocation = cmd.getOptionValue(OPTION_LOCAL_DUMPFILE); } }
java
private void handleGlobalArguments(CommandLine cmd) { if (cmd.hasOption(CMD_OPTION_DUMP_LOCATION)) { this.dumpDirectoryLocation = cmd .getOptionValue(CMD_OPTION_DUMP_LOCATION); } if (cmd.hasOption(CMD_OPTION_OFFLINE_MODE)) { this.offlineMode = true; } if (cmd.hasOption(CMD_OPTION_QUIET)) { this.quiet = true; } if (cmd.hasOption(CMD_OPTION_CREATE_REPORT)) { this.reportFilename = cmd.getOptionValue(CMD_OPTION_CREATE_REPORT); } if (cmd.hasOption(OPTION_FILTER_LANGUAGES)) { setLanguageFilters(cmd.getOptionValue(OPTION_FILTER_LANGUAGES)); } if (cmd.hasOption(OPTION_FILTER_SITES)) { setSiteFilters(cmd.getOptionValue(OPTION_FILTER_SITES)); } if (cmd.hasOption(OPTION_FILTER_PROPERTIES)) { setPropertyFilters(cmd.getOptionValue(OPTION_FILTER_PROPERTIES)); } if (cmd.hasOption(CMD_OPTION_LOCAL_DUMPFILE)) { this.inputDumpLocation = cmd.getOptionValue(OPTION_LOCAL_DUMPFILE); } }
[ "private", "void", "handleGlobalArguments", "(", "CommandLine", "cmd", ")", "{", "if", "(", "cmd", ".", "hasOption", "(", "CMD_OPTION_DUMP_LOCATION", ")", ")", "{", "this", ".", "dumpDirectoryLocation", "=", "cmd", ".", "getOptionValue", "(", "CMD_OPTION_DUMP_LOCATION", ")", ";", "}", "if", "(", "cmd", ".", "hasOption", "(", "CMD_OPTION_OFFLINE_MODE", ")", ")", "{", "this", ".", "offlineMode", "=", "true", ";", "}", "if", "(", "cmd", ".", "hasOption", "(", "CMD_OPTION_QUIET", ")", ")", "{", "this", ".", "quiet", "=", "true", ";", "}", "if", "(", "cmd", ".", "hasOption", "(", "CMD_OPTION_CREATE_REPORT", ")", ")", "{", "this", ".", "reportFilename", "=", "cmd", ".", "getOptionValue", "(", "CMD_OPTION_CREATE_REPORT", ")", ";", "}", "if", "(", "cmd", ".", "hasOption", "(", "OPTION_FILTER_LANGUAGES", ")", ")", "{", "setLanguageFilters", "(", "cmd", ".", "getOptionValue", "(", "OPTION_FILTER_LANGUAGES", ")", ")", ";", "}", "if", "(", "cmd", ".", "hasOption", "(", "OPTION_FILTER_SITES", ")", ")", "{", "setSiteFilters", "(", "cmd", ".", "getOptionValue", "(", "OPTION_FILTER_SITES", ")", ")", ";", "}", "if", "(", "cmd", ".", "hasOption", "(", "OPTION_FILTER_PROPERTIES", ")", ")", "{", "setPropertyFilters", "(", "cmd", ".", "getOptionValue", "(", "OPTION_FILTER_PROPERTIES", ")", ")", ";", "}", "if", "(", "cmd", ".", "hasOption", "(", "CMD_OPTION_LOCAL_DUMPFILE", ")", ")", "{", "this", ".", "inputDumpLocation", "=", "cmd", ".", "getOptionValue", "(", "OPTION_LOCAL_DUMPFILE", ")", ";", "}", "}" ]
Analyses the command-line arguments which are relevant for the serialization process in general. It fills out the class arguments with this data. @param cmd {@link CommandLine} objects; contains the command line arguments parsed by a {@link CommandLineParser}
[ "Analyses", "the", "command", "-", "line", "arguments", "which", "are", "relevant", "for", "the", "serialization", "process", "in", "general", ".", "It", "fills", "out", "the", "class", "arguments", "with", "this", "data", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java#L543-L576
161,388
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java
ClientConfiguration.handleGlobalArguments
private void handleGlobalArguments(Section section) { for (String key : section.keySet()) { switch (key) { case OPTION_OFFLINE_MODE: if (section.get(key).toLowerCase().equals("true")) { this.offlineMode = true; } break; case OPTION_QUIET: if (section.get(key).toLowerCase().equals("true")) { this.quiet = true; } break; case OPTION_CREATE_REPORT: this.reportFilename = section.get(key); break; case OPTION_DUMP_LOCATION: this.dumpDirectoryLocation = section.get(key); break; case OPTION_FILTER_LANGUAGES: setLanguageFilters(section.get(key)); break; case OPTION_FILTER_SITES: setSiteFilters(section.get(key)); break; case OPTION_FILTER_PROPERTIES: setPropertyFilters(section.get(key)); break; case OPTION_LOCAL_DUMPFILE: this.inputDumpLocation = section.get(key); break; default: logger.warn("Unrecognized option: " + key); } } }
java
private void handleGlobalArguments(Section section) { for (String key : section.keySet()) { switch (key) { case OPTION_OFFLINE_MODE: if (section.get(key).toLowerCase().equals("true")) { this.offlineMode = true; } break; case OPTION_QUIET: if (section.get(key).toLowerCase().equals("true")) { this.quiet = true; } break; case OPTION_CREATE_REPORT: this.reportFilename = section.get(key); break; case OPTION_DUMP_LOCATION: this.dumpDirectoryLocation = section.get(key); break; case OPTION_FILTER_LANGUAGES: setLanguageFilters(section.get(key)); break; case OPTION_FILTER_SITES: setSiteFilters(section.get(key)); break; case OPTION_FILTER_PROPERTIES: setPropertyFilters(section.get(key)); break; case OPTION_LOCAL_DUMPFILE: this.inputDumpLocation = section.get(key); break; default: logger.warn("Unrecognized option: " + key); } } }
[ "private", "void", "handleGlobalArguments", "(", "Section", "section", ")", "{", "for", "(", "String", "key", ":", "section", ".", "keySet", "(", ")", ")", "{", "switch", "(", "key", ")", "{", "case", "OPTION_OFFLINE_MODE", ":", "if", "(", "section", ".", "get", "(", "key", ")", ".", "toLowerCase", "(", ")", ".", "equals", "(", "\"true\"", ")", ")", "{", "this", ".", "offlineMode", "=", "true", ";", "}", "break", ";", "case", "OPTION_QUIET", ":", "if", "(", "section", ".", "get", "(", "key", ")", ".", "toLowerCase", "(", ")", ".", "equals", "(", "\"true\"", ")", ")", "{", "this", ".", "quiet", "=", "true", ";", "}", "break", ";", "case", "OPTION_CREATE_REPORT", ":", "this", ".", "reportFilename", "=", "section", ".", "get", "(", "key", ")", ";", "break", ";", "case", "OPTION_DUMP_LOCATION", ":", "this", ".", "dumpDirectoryLocation", "=", "section", ".", "get", "(", "key", ")", ";", "break", ";", "case", "OPTION_FILTER_LANGUAGES", ":", "setLanguageFilters", "(", "section", ".", "get", "(", "key", ")", ")", ";", "break", ";", "case", "OPTION_FILTER_SITES", ":", "setSiteFilters", "(", "section", ".", "get", "(", "key", ")", ")", ";", "break", ";", "case", "OPTION_FILTER_PROPERTIES", ":", "setPropertyFilters", "(", "section", ".", "get", "(", "key", ")", ")", ";", "break", ";", "case", "OPTION_LOCAL_DUMPFILE", ":", "this", ".", "inputDumpLocation", "=", "section", ".", "get", "(", "key", ")", ";", "break", ";", "default", ":", "logger", ".", "warn", "(", "\"Unrecognized option: \"", "+", "key", ")", ";", "}", "}", "}" ]
Analyses the content of the general section of an ini configuration file and fills out the class arguments with this data. @param section {@link Section} with name "general"
[ "Analyses", "the", "content", "of", "the", "general", "section", "of", "an", "ini", "configuration", "file", "and", "fills", "out", "the", "class", "arguments", "with", "this", "data", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java#L585-L620
161,389
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java
ClientConfiguration.checkDuplicateStdOutOutput
private void checkDuplicateStdOutOutput(DumpProcessingAction newAction) { if (newAction.useStdOut()) { if (this.quiet) { logger.warn("Multiple actions are using stdout as output destination."); } this.quiet = true; } }
java
private void checkDuplicateStdOutOutput(DumpProcessingAction newAction) { if (newAction.useStdOut()) { if (this.quiet) { logger.warn("Multiple actions are using stdout as output destination."); } this.quiet = true; } }
[ "private", "void", "checkDuplicateStdOutOutput", "(", "DumpProcessingAction", "newAction", ")", "{", "if", "(", "newAction", ".", "useStdOut", "(", ")", ")", "{", "if", "(", "this", ".", "quiet", ")", "{", "logger", ".", "warn", "(", "\"Multiple actions are using stdout as output destination.\"", ")", ";", "}", "this", ".", "quiet", "=", "true", ";", "}", "}" ]
Checks if a newly created action wants to write output to stdout, and logs a warning if other actions are doing the same. @param newAction the new action to be checked
[ "Checks", "if", "a", "newly", "created", "action", "wants", "to", "write", "output", "to", "stdout", "and", "logs", "a", "warning", "if", "other", "actions", "are", "doing", "the", "same", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java#L684-L691
161,390
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java
ClientConfiguration.setLanguageFilters
private void setLanguageFilters(String filters) { this.filterLanguages = new HashSet<>(); if (!"-".equals(filters)) { Collections.addAll(this.filterLanguages, filters.split(",")); } }
java
private void setLanguageFilters(String filters) { this.filterLanguages = new HashSet<>(); if (!"-".equals(filters)) { Collections.addAll(this.filterLanguages, filters.split(",")); } }
[ "private", "void", "setLanguageFilters", "(", "String", "filters", ")", "{", "this", ".", "filterLanguages", "=", "new", "HashSet", "<>", "(", ")", ";", "if", "(", "!", "\"-\"", ".", "equals", "(", "filters", ")", ")", "{", "Collections", ".", "addAll", "(", "this", ".", "filterLanguages", ",", "filters", ".", "split", "(", "\",\"", ")", ")", ";", "}", "}" ]
Sets the set of language filters based on the given string. @param filters comma-separates list of language codes, or "-" to filter all languages
[ "Sets", "the", "set", "of", "language", "filters", "based", "on", "the", "given", "string", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java#L733-L738
161,391
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java
ClientConfiguration.setSiteFilters
private void setSiteFilters(String filters) { this.filterSites = new HashSet<>(); if (!"-".equals(filters)) { Collections.addAll(this.filterSites, filters.split(",")); } }
java
private void setSiteFilters(String filters) { this.filterSites = new HashSet<>(); if (!"-".equals(filters)) { Collections.addAll(this.filterSites, filters.split(",")); } }
[ "private", "void", "setSiteFilters", "(", "String", "filters", ")", "{", "this", ".", "filterSites", "=", "new", "HashSet", "<>", "(", ")", ";", "if", "(", "!", "\"-\"", ".", "equals", "(", "filters", ")", ")", "{", "Collections", ".", "addAll", "(", "this", ".", "filterSites", ",", "filters", ".", "split", "(", "\",\"", ")", ")", ";", "}", "}" ]
Sets the set of site filters based on the given string. @param filters comma-separates list of site keys, or "-" to filter all site links
[ "Sets", "the", "set", "of", "site", "filters", "based", "on", "the", "given", "string", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java#L747-L752
161,392
Wikidata/Wikidata-Toolkit
wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java
ClientConfiguration.setPropertyFilters
private void setPropertyFilters(String filters) { this.filterProperties = new HashSet<>(); if (!"-".equals(filters)) { for (String pid : filters.split(",")) { this.filterProperties.add(Datamodel .makeWikidataPropertyIdValue(pid)); } } }
java
private void setPropertyFilters(String filters) { this.filterProperties = new HashSet<>(); if (!"-".equals(filters)) { for (String pid : filters.split(",")) { this.filterProperties.add(Datamodel .makeWikidataPropertyIdValue(pid)); } } }
[ "private", "void", "setPropertyFilters", "(", "String", "filters", ")", "{", "this", ".", "filterProperties", "=", "new", "HashSet", "<>", "(", ")", ";", "if", "(", "!", "\"-\"", ".", "equals", "(", "filters", ")", ")", "{", "for", "(", "String", "pid", ":", "filters", ".", "split", "(", "\",\"", ")", ")", "{", "this", ".", "filterProperties", ".", "add", "(", "Datamodel", ".", "makeWikidataPropertyIdValue", "(", "pid", ")", ")", ";", "}", "}", "}" ]
Sets the set of property filters based on the given string. @param filters comma-separates list of property ids, or "-" to filter all statements
[ "Sets", "the", "set", "of", "property", "filters", "based", "on", "the", "given", "string", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-client/src/main/java/org/wikidata/wdtk/client/ClientConfiguration.java#L761-L769
161,393
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java
GenderRatioProcessor.writeFinalResults
public void writeFinalResults() { printStatus(); try (PrintStream out = new PrintStream( ExampleHelpers.openExampleFileOuputStream("gender-ratios.csv"))) { out.print("Site key,pages total,pages on humans,pages on humans with gender"); for (EntityIdValue gender : this.genderNamesList) { out.print("," + this.genderNames.get(gender) + " (" + gender.getId() + ")"); } out.println(); List<SiteRecord> siteRecords = new ArrayList<>( this.siteRecords.values()); Collections.sort(siteRecords, new SiteRecordComparator()); for (SiteRecord siteRecord : siteRecords) { out.print(siteRecord.siteKey + "," + siteRecord.pageCount + "," + siteRecord.humanPageCount + "," + siteRecord.humanGenderPageCount); for (EntityIdValue gender : this.genderNamesList) { if (siteRecord.genderCounts.containsKey(gender)) { out.print("," + siteRecord.genderCounts.get(gender)); } else { out.print(",0"); } } out.println(); } } catch (IOException e) { e.printStackTrace(); } }
java
public void writeFinalResults() { printStatus(); try (PrintStream out = new PrintStream( ExampleHelpers.openExampleFileOuputStream("gender-ratios.csv"))) { out.print("Site key,pages total,pages on humans,pages on humans with gender"); for (EntityIdValue gender : this.genderNamesList) { out.print("," + this.genderNames.get(gender) + " (" + gender.getId() + ")"); } out.println(); List<SiteRecord> siteRecords = new ArrayList<>( this.siteRecords.values()); Collections.sort(siteRecords, new SiteRecordComparator()); for (SiteRecord siteRecord : siteRecords) { out.print(siteRecord.siteKey + "," + siteRecord.pageCount + "," + siteRecord.humanPageCount + "," + siteRecord.humanGenderPageCount); for (EntityIdValue gender : this.genderNamesList) { if (siteRecord.genderCounts.containsKey(gender)) { out.print("," + siteRecord.genderCounts.get(gender)); } else { out.print(",0"); } } out.println(); } } catch (IOException e) { e.printStackTrace(); } }
[ "public", "void", "writeFinalResults", "(", ")", "{", "printStatus", "(", ")", ";", "try", "(", "PrintStream", "out", "=", "new", "PrintStream", "(", "ExampleHelpers", ".", "openExampleFileOuputStream", "(", "\"gender-ratios.csv\"", ")", ")", ")", "{", "out", ".", "print", "(", "\"Site key,pages total,pages on humans,pages on humans with gender\"", ")", ";", "for", "(", "EntityIdValue", "gender", ":", "this", ".", "genderNamesList", ")", "{", "out", ".", "print", "(", "\",\"", "+", "this", ".", "genderNames", ".", "get", "(", "gender", ")", "+", "\" (\"", "+", "gender", ".", "getId", "(", ")", "+", "\")\"", ")", ";", "}", "out", ".", "println", "(", ")", ";", "List", "<", "SiteRecord", ">", "siteRecords", "=", "new", "ArrayList", "<>", "(", "this", ".", "siteRecords", ".", "values", "(", ")", ")", ";", "Collections", ".", "sort", "(", "siteRecords", ",", "new", "SiteRecordComparator", "(", ")", ")", ";", "for", "(", "SiteRecord", "siteRecord", ":", "siteRecords", ")", "{", "out", ".", "print", "(", "siteRecord", ".", "siteKey", "+", "\",\"", "+", "siteRecord", ".", "pageCount", "+", "\",\"", "+", "siteRecord", ".", "humanPageCount", "+", "\",\"", "+", "siteRecord", ".", "humanGenderPageCount", ")", ";", "for", "(", "EntityIdValue", "gender", ":", "this", ".", "genderNamesList", ")", "{", "if", "(", "siteRecord", ".", "genderCounts", ".", "containsKey", "(", "gender", ")", ")", "{", "out", ".", "print", "(", "\",\"", "+", "siteRecord", ".", "genderCounts", ".", "get", "(", "gender", ")", ")", ";", "}", "else", "{", "out", ".", "print", "(", "\",0\"", ")", ";", "}", "}", "out", ".", "println", "(", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Writes the results of the processing to a CSV file.
[ "Writes", "the", "results", "of", "the", "processing", "to", "a", "CSV", "file", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java#L249-L282
161,394
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java
GenderRatioProcessor.printDocumentation
public static void printDocumentation() { System.out .println("********************************************************************"); System.out.println("*** Wikidata Toolkit: GenderRatioProcessor"); System.out.println("*** "); System.out .println("*** This program will download and process dumps from Wikidata."); System.out .println("*** It will compute the numbers of articles about humans across"); System.out .println("*** Wikimedia projects, and in particular it will count the articles"); System.out .println("*** for each sex/gender. Results will be stored in a CSV file."); System.out.println("*** See source code for further details."); System.out .println("********************************************************************"); }
java
public static void printDocumentation() { System.out .println("********************************************************************"); System.out.println("*** Wikidata Toolkit: GenderRatioProcessor"); System.out.println("*** "); System.out .println("*** This program will download and process dumps from Wikidata."); System.out .println("*** It will compute the numbers of articles about humans across"); System.out .println("*** Wikimedia projects, and in particular it will count the articles"); System.out .println("*** for each sex/gender. Results will be stored in a CSV file."); System.out.println("*** See source code for further details."); System.out .println("********************************************************************"); }
[ "public", "static", "void", "printDocumentation", "(", ")", "{", "System", ".", "out", ".", "println", "(", "\"********************************************************************\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"*** Wikidata Toolkit: GenderRatioProcessor\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"*** \"", ")", ";", "System", ".", "out", ".", "println", "(", "\"*** This program will download and process dumps from Wikidata.\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"*** It will compute the numbers of articles about humans across\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"*** Wikimedia projects, and in particular it will count the articles\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"*** for each sex/gender. Results will be stored in a CSV file.\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"*** See source code for further details.\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"********************************************************************\"", ")", ";", "}" ]
Prints some basic documentation about this program.
[ "Prints", "some", "basic", "documentation", "about", "this", "program", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java#L287-L303
161,395
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java
GenderRatioProcessor.containsValue
private boolean containsValue(StatementGroup statementGroup, Value value) { for (Statement s : statementGroup) { if (value.equals(s.getValue())) { return true; } } return false; }
java
private boolean containsValue(StatementGroup statementGroup, Value value) { for (Statement s : statementGroup) { if (value.equals(s.getValue())) { return true; } } return false; }
[ "private", "boolean", "containsValue", "(", "StatementGroup", "statementGroup", ",", "Value", "value", ")", "{", "for", "(", "Statement", "s", ":", "statementGroup", ")", "{", "if", "(", "value", ".", "equals", "(", "s", ".", "getValue", "(", ")", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if the given group of statements contains the given value as the value of a main snak of some statement. @param statementGroup the statement group to scan @param value the value to scan for @return true if value was found
[ "Checks", "if", "the", "given", "group", "of", "statements", "contains", "the", "given", "value", "as", "the", "value", "of", "a", "main", "snak", "of", "some", "statement", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java#L397-L405
161,396
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java
GenderRatioProcessor.addNewGenderName
private void addNewGenderName(EntityIdValue entityIdValue, String name) { this.genderNames.put(entityIdValue, name); this.genderNamesList.add(entityIdValue); }
java
private void addNewGenderName(EntityIdValue entityIdValue, String name) { this.genderNames.put(entityIdValue, name); this.genderNamesList.add(entityIdValue); }
[ "private", "void", "addNewGenderName", "(", "EntityIdValue", "entityIdValue", ",", "String", "name", ")", "{", "this", ".", "genderNames", ".", "put", "(", "entityIdValue", ",", "name", ")", ";", "this", ".", "genderNamesList", ".", "add", "(", "entityIdValue", ")", ";", "}" ]
Adds a new gender item and an initial name. @param entityIdValue the item representing the gender @param name the label to use for representing the gender
[ "Adds", "a", "new", "gender", "item", "and", "an", "initial", "name", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java#L415-L418
161,397
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java
GenderRatioProcessor.getSiteRecord
private SiteRecord getSiteRecord(String siteKey) { SiteRecord siteRecord = this.siteRecords.get(siteKey); if (siteRecord == null) { siteRecord = new SiteRecord(siteKey); this.siteRecords.put(siteKey, siteRecord); } return siteRecord; }
java
private SiteRecord getSiteRecord(String siteKey) { SiteRecord siteRecord = this.siteRecords.get(siteKey); if (siteRecord == null) { siteRecord = new SiteRecord(siteKey); this.siteRecords.put(siteKey, siteRecord); } return siteRecord; }
[ "private", "SiteRecord", "getSiteRecord", "(", "String", "siteKey", ")", "{", "SiteRecord", "siteRecord", "=", "this", ".", "siteRecords", ".", "get", "(", "siteKey", ")", ";", "if", "(", "siteRecord", "==", "null", ")", "{", "siteRecord", "=", "new", "SiteRecord", "(", "siteKey", ")", ";", "this", ".", "siteRecords", ".", "put", "(", "siteKey", ",", "siteRecord", ")", ";", "}", "return", "siteRecord", ";", "}" ]
Returns a site record for the site of the given name, creating a new one if it does not exist yet. @param siteKey the key of the site @return the suitable site record
[ "Returns", "a", "site", "record", "for", "the", "site", "of", "the", "given", "name", "creating", "a", "new", "one", "if", "it", "does", "not", "exist", "yet", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java#L428-L435
161,398
Wikidata/Wikidata-Toolkit
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java
GenderRatioProcessor.countGender
private void countGender(EntityIdValue gender, SiteRecord siteRecord) { Integer curValue = siteRecord.genderCounts.get(gender); if (curValue == null) { siteRecord.genderCounts.put(gender, 1); } else { siteRecord.genderCounts.put(gender, curValue + 1); } }
java
private void countGender(EntityIdValue gender, SiteRecord siteRecord) { Integer curValue = siteRecord.genderCounts.get(gender); if (curValue == null) { siteRecord.genderCounts.put(gender, 1); } else { siteRecord.genderCounts.put(gender, curValue + 1); } }
[ "private", "void", "countGender", "(", "EntityIdValue", "gender", ",", "SiteRecord", "siteRecord", ")", "{", "Integer", "curValue", "=", "siteRecord", ".", "genderCounts", ".", "get", "(", "gender", ")", ";", "if", "(", "curValue", "==", "null", ")", "{", "siteRecord", ".", "genderCounts", ".", "put", "(", "gender", ",", "1", ")", ";", "}", "else", "{", "siteRecord", ".", "genderCounts", ".", "put", "(", "gender", ",", "curValue", "+", "1", ")", ";", "}", "}" ]
Counts a single page of the specified gender. If this is the first page of that gender on this site, a suitable key is added to the list of the site's genders. @param gender the gender to count @param siteRecord the site record to count it for
[ "Counts", "a", "single", "page", "of", "the", "specified", "gender", ".", "If", "this", "is", "the", "first", "page", "of", "that", "gender", "on", "this", "site", "a", "suitable", "key", "is", "added", "to", "the", "list", "of", "the", "site", "s", "genders", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java#L447-L454
161,399
Wikidata/Wikidata-Toolkit
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbSearchEntitiesAction.java
WbSearchEntitiesAction.wbSearchEntities
public List<WbSearchEntitiesResult> wbSearchEntities(String search, String language, Boolean strictLanguage, String type, Long limit, Long offset) throws MediaWikiApiErrorException { Map<String, String> parameters = new HashMap<String, String>(); parameters.put(ApiConnection.PARAM_ACTION, "wbsearchentities"); if (search != null) { parameters.put("search", search); } else { throw new IllegalArgumentException( "Search parameter must be specified for this action."); } if (language != null) { parameters.put("language", language); } else { throw new IllegalArgumentException( "Language parameter must be specified for this action."); } if (strictLanguage != null) { parameters.put("strictlanguage", Boolean.toString(strictLanguage)); } if (type != null) { parameters.put("type", type); } if (limit != null) { parameters.put("limit", Long.toString(limit)); } if (offset != null) { parameters.put("continue", Long.toString(offset)); } List<WbSearchEntitiesResult> results = new ArrayList<>(); try { JsonNode root = this.connection.sendJsonRequest("POST", parameters); JsonNode entities = root.path("search"); for (JsonNode entityNode : entities) { try { JacksonWbSearchEntitiesResult ed = mapper.treeToValue(entityNode, JacksonWbSearchEntitiesResult.class); results.add(ed); } catch (JsonProcessingException e) { LOGGER.error("Error when reading JSON for entity " + entityNode.path("id").asText("UNKNOWN") + ": " + e.toString()); } } } catch (IOException e) { LOGGER.error("Could not retrive data: " + e.toString()); } return results; }
java
public List<WbSearchEntitiesResult> wbSearchEntities(String search, String language, Boolean strictLanguage, String type, Long limit, Long offset) throws MediaWikiApiErrorException { Map<String, String> parameters = new HashMap<String, String>(); parameters.put(ApiConnection.PARAM_ACTION, "wbsearchentities"); if (search != null) { parameters.put("search", search); } else { throw new IllegalArgumentException( "Search parameter must be specified for this action."); } if (language != null) { parameters.put("language", language); } else { throw new IllegalArgumentException( "Language parameter must be specified for this action."); } if (strictLanguage != null) { parameters.put("strictlanguage", Boolean.toString(strictLanguage)); } if (type != null) { parameters.put("type", type); } if (limit != null) { parameters.put("limit", Long.toString(limit)); } if (offset != null) { parameters.put("continue", Long.toString(offset)); } List<WbSearchEntitiesResult> results = new ArrayList<>(); try { JsonNode root = this.connection.sendJsonRequest("POST", parameters); JsonNode entities = root.path("search"); for (JsonNode entityNode : entities) { try { JacksonWbSearchEntitiesResult ed = mapper.treeToValue(entityNode, JacksonWbSearchEntitiesResult.class); results.add(ed); } catch (JsonProcessingException e) { LOGGER.error("Error when reading JSON for entity " + entityNode.path("id").asText("UNKNOWN") + ": " + e.toString()); } } } catch (IOException e) { LOGGER.error("Could not retrive data: " + e.toString()); } return results; }
[ "public", "List", "<", "WbSearchEntitiesResult", ">", "wbSearchEntities", "(", "String", "search", ",", "String", "language", ",", "Boolean", "strictLanguage", ",", "String", "type", ",", "Long", "limit", ",", "Long", "offset", ")", "throws", "MediaWikiApiErrorException", "{", "Map", "<", "String", ",", "String", ">", "parameters", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "parameters", ".", "put", "(", "ApiConnection", ".", "PARAM_ACTION", ",", "\"wbsearchentities\"", ")", ";", "if", "(", "search", "!=", "null", ")", "{", "parameters", ".", "put", "(", "\"search\"", ",", "search", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Search parameter must be specified for this action.\"", ")", ";", "}", "if", "(", "language", "!=", "null", ")", "{", "parameters", ".", "put", "(", "\"language\"", ",", "language", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Language parameter must be specified for this action.\"", ")", ";", "}", "if", "(", "strictLanguage", "!=", "null", ")", "{", "parameters", ".", "put", "(", "\"strictlanguage\"", ",", "Boolean", ".", "toString", "(", "strictLanguage", ")", ")", ";", "}", "if", "(", "type", "!=", "null", ")", "{", "parameters", ".", "put", "(", "\"type\"", ",", "type", ")", ";", "}", "if", "(", "limit", "!=", "null", ")", "{", "parameters", ".", "put", "(", "\"limit\"", ",", "Long", ".", "toString", "(", "limit", ")", ")", ";", "}", "if", "(", "offset", "!=", "null", ")", "{", "parameters", ".", "put", "(", "\"continue\"", ",", "Long", ".", "toString", "(", "offset", ")", ")", ";", "}", "List", "<", "WbSearchEntitiesResult", ">", "results", "=", "new", "ArrayList", "<>", "(", ")", ";", "try", "{", "JsonNode", "root", "=", "this", ".", "connection", ".", "sendJsonRequest", "(", "\"POST\"", ",", "parameters", ")", ";", "JsonNode", "entities", "=", "root", ".", "path", "(", "\"search\"", ")", ";", "for", "(", "JsonNode", "entityNode", ":", "entities", ")", "{", "try", "{", "JacksonWbSearchEntitiesResult", "ed", "=", "mapper", ".", "treeToValue", "(", "entityNode", ",", "JacksonWbSearchEntitiesResult", ".", "class", ")", ";", "results", ".", "add", "(", "ed", ")", ";", "}", "catch", "(", "JsonProcessingException", "e", ")", "{", "LOGGER", ".", "error", "(", "\"Error when reading JSON for entity \"", "+", "entityNode", ".", "path", "(", "\"id\"", ")", ".", "asText", "(", "\"UNKNOWN\"", ")", "+", "\": \"", "+", "e", ".", "toString", "(", ")", ")", ";", "}", "}", "}", "catch", "(", "IOException", "e", ")", "{", "LOGGER", ".", "error", "(", "\"Could not retrive data: \"", "+", "e", ".", "toString", "(", ")", ")", ";", "}", "return", "results", ";", "}" ]
Executes the API action "wbsearchentity" for the given parameters. Searches for entities using labels and aliases. Returns a label and description for the entity in the user language if possible. Returns details of the matched term. The matched term text is also present in the aliases key if different from the display label. <p> See the <a href= "https://www.wikidata.org/w/api.php?action=help&modules=wbsearchentity" >online API documentation</a> for further information. <p> @param search (required) search for this text @param language (required) search in this language @param strictLanguage (optional) whether to disable language fallback @param type (optional) search for this type of entity One of the following values: item, property Default: item @param limit (optional) maximal number of results no more than 50 (500 for bots) allowed Default: 7 @param offset (optional) offset where to continue a search Default: 0 this parameter is called "continue" in the API (which is a Java keyword) @return list of matching entities retrieved via the API URL @throws MediaWikiApiErrorException if the API returns an error @throws IllegalArgumentException if the given combination of parameters does not make sense
[ "Executes", "the", "API", "action", "wbsearchentity", "for", "the", "given", "parameters", ".", "Searches", "for", "entities", "using", "labels", "and", "aliases", ".", "Returns", "a", "label", "and", "description", "for", "the", "entity", "in", "the", "user", "language", "if", "possible", ".", "Returns", "details", "of", "the", "matched", "term", ".", "The", "matched", "term", "text", "is", "also", "present", "in", "the", "aliases", "key", "if", "different", "from", "the", "display", "label", "." ]
7732851dda47e1febff406fba27bfec023f4786e
https://github.com/Wikidata/Wikidata-Toolkit/blob/7732851dda47e1febff406fba27bfec023f4786e/wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/WbSearchEntitiesAction.java#L125-L182