当前位置: 首页>>代码示例>>Java>>正文


Java ItemDocument.getStatementGroups方法代码示例

本文整理汇总了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);
}
 
开发者ID:heindorf,项目名称:cikm16-wdvd-feature-extraction,代码行数:27,代码来源:IsLivingPerson.java

示例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;
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit-Examples,代码行数:29,代码来源:JsonSerializationProcessor.java

示例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);
			}
		}
	}
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit-Examples,代码行数:15,代码来源:ClassPropertyUsageAnalyzer.java

示例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);
			}
		}
	}

}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit-Examples,代码行数:13,代码来源:WorldMapProcessor.java

示例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);
				}
			}
		}
	}
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:31,代码来源:RdfConverter.java

示例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();
	// }
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit-Examples,代码行数:80,代码来源:ClassPropertyUsageAnalyzer.java

示例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);
		}
	}
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit-Examples,代码行数:54,代码来源:ClassPropertyUsageAnalyzer.java

示例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);
					}
				}
			}
		}
	}
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:46,代码来源:RdfConverter.java


注:本文中的org.wikidata.wdtk.datamodel.interfaces.ItemDocument.getStatementGroups方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。