本文整理汇总了Java中org.wikidata.wdtk.datamodel.interfaces.ItemDocument.getStatementGroups方法的典型用法代码示例。如果您正苦于以下问题:Java ItemDocument.getStatementGroups方法的具体用法?Java ItemDocument.getStatementGroups怎么用?Java ItemDocument.getStatementGroups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wikidata.wdtk.datamodel.interfaces.ItemDocument
的用法示例。
在下文中一共展示了ItemDocument.getStatementGroups方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculate
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; //导入方法依赖的package包/类
@Override
public FeatureBooleanValue calculate(Revision revision) {
ItemDocument itemDocument = revision.getItemDocument();
boolean hasDateOfBirth = false;
boolean hasDateOfDeath = false;
if (itemDocument != null) {
List<StatementGroup> statementGroups =
itemDocument.getStatementGroups();
for (StatementGroup statementGroup: statementGroups) {
String property = statementGroup.getProperty().getId();
if (property.equals("P569")) {
hasDateOfBirth = true;
}
if (property.equals("P570")) {
hasDateOfDeath = true;
}
}
}
boolean result = hasDateOfBirth && !hasDateOfDeath;
return new FeatureBooleanValue(result);
}
示例2: includeDocument
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; //导入方法依赖的package包/类
/**
* Returns true if the given document should be included in the
* serialization.
*
* @param itemDocument
* the document to check
* @return true if the document should be serialized
*/
private boolean includeDocument(ItemDocument itemDocument) {
for (StatementGroup sg : itemDocument.getStatementGroups()) {
// "P19" is "place of birth" on Wikidata
if (!"P19".equals(sg.getProperty().getId())) {
continue;
}
for (Statement s : sg.getStatements()) {
if (s.getClaim().getMainSnak() instanceof ValueSnak) {
Value v = ((ValueSnak) s.getClaim().getMainSnak())
.getValue();
// "Q1731" is "Dresden" on Wikidata
if (v instanceof ItemIdValue
&& "Q1731".equals(((ItemIdValue) v).getId())) {
return true;
}
}
}
}
return false;
}
示例3: countCooccurringProperties
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; //导入方法依赖的package包/类
private void countCooccurringProperties(ItemDocument itemDocument,
UsageRecord usageRecord, PropertyIdValue thisPropertyIdValue) {
for (StatementGroup sg : itemDocument.getStatementGroups()) {
if (!sg.getProperty().equals(thisPropertyIdValue)) {
if (!usageRecord.propertyCoCounts.containsKey(sg.getProperty())) {
usageRecord.propertyCoCounts.put(sg.getProperty(), 1);
} else {
usageRecord.propertyCoCounts
.put(sg.getProperty(), usageRecord.propertyCoCounts
.get(sg.getProperty()) + 1);
}
}
}
}
示例4: processItemDocument
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; //导入方法依赖的package包/类
@Override
public void processItemDocument(ItemDocument itemDocument) {
for (StatementGroup sg : itemDocument.getStatementGroups()) {
if (COORD_PROPERTY.equals(sg.getProperty().getId())) {
for (Statement s : sg.getStatements()) {
countCoordinateStatement(s, itemDocument);
}
}
}
}
示例5: writeInstanceOfStatements
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; //导入方法依赖的package包/类
void writeInstanceOfStatements(Resource subject, ItemDocument itemDocument) {
for (StatementGroup statementGroup : itemDocument.getStatementGroups()) {
if (!"P31".equals(statementGroup.getProperty().getId())) {
continue;
}
for (Statement statement : statementGroup.getStatements()) {
if (statement.getClaim().getMainSnak() instanceof ValueSnak
&& statement.getClaim().getQualifiers().size() == 0) {
ValueSnak mainSnak = (ValueSnak) statement.getClaim()
.getMainSnak();
Value value = this.valueRdfConverter
.getRdfValue(mainSnak.getValue(),
mainSnak.getPropertyId(), true);
if (value == null) {
logger.error("Could not serialize instance of snak: missing value (Snak: "
+ mainSnak.toString() + ")");
continue;
}
try {
this.rdfWriter.writeTripleValueObject(subject,
RdfWriter.RDF_TYPE, value);
} catch (RDFHandlerException e) {
throw new RuntimeException(e.toString(), e);
}
}
}
}
}
示例6: processItemDocument
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; //导入方法依赖的package包/类
@Override
public void processItemDocument(ItemDocument itemDocument) {
this.countItems++;
if (itemDocument.getStatementGroups().size() > 0) {
this.countPropertyItems++;
}
ClassRecord classRecord = null;
if (TOP_LEVEL_CLASSES.contains(itemDocument.getItemId().getId())
|| this.classRecords.containsKey(itemDocument.getItemId())) {
classRecord = getClassRecord(itemDocument.getItemId());
}
for (StatementGroup sg : itemDocument.getStatementGroups()) {
PropertyRecord propertyRecord = getPropertyRecord(sg.getProperty());
propertyRecord.itemCount++;
propertyRecord.statementCount = propertyRecord.statementCount
+ sg.getStatements().size();
boolean isInstanceOf = "P31".equals(sg.getProperty().getId());
boolean isSubclassOf = "P279".equals(sg.getProperty().getId());
if (isSubclassOf && classRecord == null) {
classRecord = getClassRecord(itemDocument.getItemId());
}
for (Statement s : sg.getStatements()) {
// Count uses of properties in qualifiers
for (SnakGroup q : s.getClaim().getQualifiers()) {
countPropertyQualifier(q.getProperty(), q.getSnaks().size());
}
// Count statements with qualifiers
if (s.getClaim().getQualifiers().size() > 0) {
propertyRecord.statementWithQualifierCount++;
}
// Count uses of properties in references
for (Reference r : s.getReferences()) {
for (SnakGroup snakGroup : r.getSnakGroups()) {
countPropertyReference(snakGroup.getProperty(),
snakGroup.getSnaks().size());
}
}
// Process value of instance of/subclass of:
if ((isInstanceOf || isSubclassOf)
&& s.getClaim().getMainSnak() instanceof ValueSnak) {
Value value = ((ValueSnak) s.getClaim().getMainSnak())
.getValue();
if (value instanceof EntityIdValue) {
ClassRecord otherClassRecord = getClassRecord((EntityIdValue) value);
if (isInstanceOf) {
otherClassRecord.itemCount++;
countCooccurringProperties(itemDocument,
otherClassRecord, null);
} else {
otherClassRecord.subclassCount++;
classRecord.superClasses.add((EntityIdValue) value);
}
}
}
}
countCooccurringProperties(itemDocument, propertyRecord,
sg.getProperty());
}
if (classRecord != null) {
this.countClasses++;
classRecord.itemDocument = converter.copy(itemDocument);
}
// print a report once in a while:
if (this.countItems % 100000 == 0) {
printReport();
}
// if (this.countItems % 100000 == 0) {
// writePropertyData();
// writeClassData();
// }
}
示例7: printImage
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; //导入方法依赖的package包/类
/**
* Prints the URL of a thumbnail for the given item document to the output,
* or a default image if no image is given for the item.
*
* @param out
* the output to write to
* @param itemDocument
* the document that may provide the image information
*/
private void printImage(PrintStream out, ItemDocument itemDocument) {
String imageFile = null;
if (itemDocument != null) {
for (StatementGroup sg : itemDocument.getStatementGroups()) {
boolean isImage = "P18".equals(sg.getProperty().getId());
if (!isImage) {
continue;
}
for (Statement s : sg.getStatements()) {
if (s.getClaim().getMainSnak() instanceof ValueSnak) {
Value value = ((ValueSnak) s.getClaim().getMainSnak())
.getValue();
if (value instanceof StringValue) {
imageFile = ((StringValue) value).getString();
break;
}
}
}
if (imageFile != null) {
break;
}
}
}
if (imageFile == null) {
out.print(",\"http://commons.wikimedia.org/w/thumb.php?f=MA_Route_blank.svg&w=50\"");
} else {
try {
String imageFileEncoded;
imageFileEncoded = URLEncoder.encode(
imageFile.replace(" ", "_"), "utf-8");
// Keep special title symbols unescaped:
imageFileEncoded = imageFileEncoded.replace("%3A", ":")
.replace("%2F", "/");
out.print(","
+ csvStringEscape("http://commons.wikimedia.org/w/thumb.php?f="
+ imageFileEncoded) + "&w=50");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(
"Your JRE does not support UTF-8 encoding. Srsly?!", e);
}
}
}
示例8: writeSubclassOfStatements
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; //导入方法依赖的package包/类
void writeSubclassOfStatements(Resource subject, ItemDocument itemDocument) {
for (StatementGroup statementGroup : itemDocument.getStatementGroups()) {
boolean isSubClassOf = "P279".equals(statementGroup.getProperty()
.getId());
boolean isInstanceOf = "P31".equals(statementGroup.getProperty()
.getId());
if (!isInstanceOf && !isSubClassOf) {
continue;
}
for (Statement statement : statementGroup.getStatements()) {
if (statement.getClaim().getMainSnak() instanceof ValueSnak) {
ValueSnak mainSnak = (ValueSnak) statement.getClaim()
.getMainSnak();
if (isSubClassOf) {
this.owlDeclarationBuffer.addClass(itemDocument
.getEntityId());
}
if (mainSnak.getValue() instanceof EntityIdValue) {
this.owlDeclarationBuffer
.addClass((EntityIdValue) mainSnak.getValue());
}
if (statement.getClaim().getQualifiers().size() == 0
&& isSubClassOf) {
Value value = this.valueRdfConverter.getRdfValue(
mainSnak.getValue(), mainSnak.getPropertyId(),
true);
if (value == null) {
logger.error("Could not serialize subclass of snak: missing value (Snak: "
+ mainSnak.toString() + ")");
continue;
}
try {
this.rdfWriter.writeTripleValueObject(subject,
RdfWriter.RDFS_SUBCLASS_OF, value);
} catch (RDFHandlerException e) {
throw new RuntimeException(e.toString(), e);
}
}
}
}
}
}