本文整理汇总了Java中org.wikidata.wdtk.datamodel.interfaces.Snak类的典型用法代码示例。如果您正苦于以下问题:Java Snak类的具体用法?Java Snak怎么用?Java Snak使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Snak类属于org.wikidata.wdtk.datamodel.interfaces包,在下文中一共展示了Snak类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculate
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
@Override
public FeatureIntegerValue calculate(Revision revision) {
int result = 0;
ItemDocument itemDocument = revision.getItemDocument();
if (itemDocument != null) {
Iterator<Statement> statements = itemDocument.getAllStatements();
while (statements.hasNext()) {
Statement statement = statements.next();
Iterator<Snak> qualifiers =
statement.getClaim().getAllQualifiers();
while (qualifiers.hasNext()) {
qualifiers.next();
result += 1;
}
}
}
return new FeatureIntegerValue(result);
}
示例2: getNumberOfIdentifiersChanged
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
private int getNumberOfIdentifiersChanged(ItemDiff itemDiff) {
List<Pair<Statement, Statement>> changedClaims = itemDiff.getChangedClaims();
int counter = 0;
for (Pair<Statement, Statement> changedClaim: changedClaims) {
Statement oldClaim = changedClaim.getLeft();
Snak snak = oldClaim.getClaim().getMainSnak();
if (snak instanceof ValueSnak) {
if (((ValueSnak) snak).getValue() instanceof StringValue) {
counter++;
}
}
}
return counter;
}
示例3: getItemIdValueOfStatement
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
private static Integer getItemIdValueOfStatement(Statement statement) {
Integer result = null;
Claim claim = statement.getClaim();
Snak snak = claim.getMainSnak();
if (snak instanceof ValueSnak) {
ValueSnak valueSnak = (ValueSnak) snak;
ItemIdValue value = (ItemIdValue) valueSnak.getValue();
String idStr = value.getId();
if (idStr != null && idStr.length() > 0) {
if (!idStr.startsWith("Q")) {
throw new RuntimeException("Item should start with Q");
}
result = Integer.parseInt(idStr.substring(1));
}
}
return result;
}
示例4: getSourceMap
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
private Map<Object, Snak> getSourceMap(Iterator<Statement> statements) {
HashMap<Object, Snak> map = new HashMap<Object, Snak>();
while (statements.hasNext()) {
Statement statement = statements.next();
List<? extends Reference> references = statement.getReferences();
for (Reference reference: references) {
Iterator<Snak> snaks = reference.getAllSnaks();
while (snaks.hasNext()) {
Snak snak = snaks.next();
map.put(snak.hashCode(), snak);
}
}
}
return map;
}
示例5: processGDMQualifiedAttributes
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
private Optional<List<Snak>> processGDMQualifiedAttributes(final Statement statement) {
final List<Snak> snakList = new ArrayList<>();
final Optional<Snak> optionalConfidence = processGDMQualifiedAttribute(CONFIDENCE_QUALIFIED_ATTRIBUTE_IDENTIFIER, statement.getConfidence());
final Optional<Snak> optionalEvidence = processGDMQualifiedAttribute(EVIDENCE_QUALIFIED_ATTRIBUTE_IDENTIFIER, statement.getEvidence());
final Optional<Snak> optionalOrder = processGDMQualifiedAttribute(ORDER_QUALIFIED_ATTRIBUTE_IDENTIFIER, statement.getOrder());
// D:SWARM statement uuid
final Optional<Snak> optionalUUID = processGDMQualifiedAttribute(STATEMENT_UUID_QUALIFIED_ATTRIBUTE_IDENTIFIER, statement.getUUID());
addToSnakList(optionalConfidence, snakList);
addToSnakList(optionalEvidence, snakList);
addToSnakList(optionalOrder, snakList);
addToSnakList(optionalUUID, snakList);
if (snakList.isEmpty()) {
return Optional.empty();
}
return Optional.of(snakList);
}
示例6: testUriPatternStatement
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
@Test
public void testUriPatternStatement() throws RDFHandlerException,
RDFParseException, IOException {
ItemIdValue subject = Datamodel.makeItemIdValue("Q100",
Datamodel.SITE_WIKIDATA);
PropertyIdValue propertyId = Datamodel
.makeWikidataPropertyIdValue("P434");
StringValue value = Datamodel
.makeStringValue("d735497b-25f9-4503-8fb5-f50150730c18");
Snak mainSnak = Datamodel.makeValueSnak(propertyId, value);
Claim claim = Datamodel.makeClaim(subject, mainSnak,
Collections.<SnakGroup> emptyList());
Statement statement = Datamodel.makeStatement(claim,
Collections.<Reference> emptyList(), StatementRank.NORMAL,
"stmtid");
this.rdfConverter.writeStatement(statement);
this.rdfWriter.finish();
Model model = RdfTestHelpers.parseRdf(this.out.toString());
assertEquals(model, RdfTestHelpers.parseRdf(RdfTestHelpers
.getResourceFromFile("StatementMusicBrainz.rdf")));
}
示例7: testFreebaseStatement
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
@Test
public void testFreebaseStatement() throws RDFHandlerException,
RDFParseException, IOException {
ItemIdValue subject = Datamodel.makeItemIdValue("Q100",
Datamodel.SITE_WIKIDATA);
PropertyIdValue propertyId = Datamodel
.makeWikidataPropertyIdValue("P646");
StringValue value = Datamodel.makeStringValue("/m/0j9kvph");
Snak mainSnak = Datamodel.makeValueSnak(propertyId, value);
Claim claim = Datamodel.makeClaim(subject, mainSnak,
Collections.<SnakGroup> emptyList());
Statement statement = Datamodel.makeStatement(claim,
Collections.<Reference> emptyList(), StatementRank.NORMAL,
"stmtid");
this.rdfConverter.writeStatement(statement);
this.rdfWriter.finish();
Model model = RdfTestHelpers.parseRdf(this.out.toString());
assertEquals(model, RdfTestHelpers.parseRdf(RdfTestHelpers
.getResourceFromFile("StatementFreebase.rdf")));
}
示例8: isSameSnakSet
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
/**
* 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
*/
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();
}
示例9: deepCopySnak
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
/**
* Copies a {@link Snak}, creating deep copies of all subobjects.
*
* @param snak
* object to copy
* @return the copied object
*/
private Snak deepCopySnak(Snak snak) {
if (snak instanceof ValueSnak) {
return this.dataObjectFactory.getValueSnak(
copy(snak.getPropertyId()),
copyValue(snak.getValue()));
} else if (snak instanceof NoValueSnak) {
return this.dataObjectFactory.getNoValueSnak(copy(snak
.getPropertyId()));
} else if (snak instanceof SomeValueSnak) {
return this.dataObjectFactory.getSomeValueSnak(copy(snak
.getPropertyId()));
} else {
throw new IllegalArgumentException(
"I don't know how to copy snaks of type " + snak.getClass());
}
}
示例10: SnakGroupImpl
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
/**
* Constructor.
*
* @param snaks
* a non-empty list of snaks that use the same property
*/
SnakGroupImpl(List<? extends Snak> snaks) {
Validate.notNull(snaks, "List of statements cannot be null");
Validate.notEmpty(snaks, "List of statements cannot be empty");
PropertyIdValue property = snaks.get(0).getPropertyId();
for (Snak s : snaks) {
if (!property.equals(s.getPropertyId())) {
throw new IllegalArgumentException(
"All snaks in a snak group must use the same property");
}
}
this.snaks = snaks;
}
示例11: testComplexStatement
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
@Test
public void testComplexStatement() {
ItemIdValue i = ItemIdValue.NULL;
PropertyIdValue p = PropertyIdValue.NULL;
Snak q1 = Datamodel.makeSomeValueSnak(p);
Snak q2 = Datamodel.makeNoValueSnak(p);
Snak q3 = Datamodel.makeValueSnak(p, i);
SnakGroup sg = Datamodel.makeSnakGroup(Arrays.asList(q1, q2, q3));
Reference r = Datamodel.makeReference(Collections.singletonList(sg));
Statement stmt1 = Datamodel.makeStatement(Datamodel.makeClaim(i,
Datamodel.makeValueSnak(p, i), Collections.singletonList(sg)),
Collections.singletonList(r), StatementRank.PREFERRED, "id");
Statement stmt2 = StatementBuilder.forSubjectAndProperty(i, p)
.withRank(StatementRank.PREFERRED).withValue(i)
.withQualifierSomeValue(p).withQualifierNoValue(p)
.withQualifierValue(p, i).withId("id").withReference(r).build();
assertEquals(stmt1, stmt2);
}
示例12: testQualifierList
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
@Test
public void testQualifierList() {
ItemIdValue i = ItemIdValue.NULL;
PropertyIdValue p = PropertyIdValue.NULL;
Snak q1 = Datamodel.makeSomeValueSnak(p);
Snak q2 = Datamodel.makeNoValueSnak(p);
Snak q3 = Datamodel.makeValueSnak(p, i);
SnakGroup sg = Datamodel.makeSnakGroup(Arrays.asList(q1, q2, q3));
Reference r = Datamodel.makeReference(Collections.singletonList(sg));
Statement stmt1 = Datamodel.makeStatement(Datamodel.makeClaim(i,
Datamodel.makeValueSnak(p, i), Collections.singletonList(sg)),
Collections.singletonList(r), StatementRank.PREFERRED, "id");
Statement stmt2 = StatementBuilder.forSubjectAndProperty(i, p)
.withRank(StatementRank.PREFERRED).withValue(i)
.withQualifiers(stmt1.getClaim().getQualifiers()).withId("id")
.withReference(r).build();
assertEquals(stmt1, stmt2);
}
示例13: testReferenceList
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
@Test
public void testReferenceList() {
ItemIdValue i = ItemIdValue.NULL;
PropertyIdValue p = PropertyIdValue.NULL;
Reference r1 = ReferenceBuilder.newInstance().withSomeValue(p).build();
Reference r2 = ReferenceBuilder.newInstance().withPropertyValue(p, i)
.build();
Snak q1 = Datamodel.makeSomeValueSnak(p);
Snak q2 = Datamodel.makeNoValueSnak(p);
Snak q3 = Datamodel.makeValueSnak(p, i);
SnakGroup sg = Datamodel.makeSnakGroup(Arrays.asList(q1, q2, q3));
Statement stmt1 = Datamodel.makeStatement(Datamodel.makeClaim(i,
Datamodel.makeValueSnak(p, i), Collections.singletonList(sg)),
Arrays.asList(r1, r2), StatementRank.PREFERRED, "id");
Statement stmt2 = StatementBuilder.forSubjectAndProperty(i, p)
.withRank(StatementRank.PREFERRED).withValue(i)
.withQualifierSomeValue(p).withQualifierNoValue(p)
.withQualifierValue(p, i).withId("id")
.withReferences(Arrays.asList(r1, r2)).build();
assertEquals(stmt1, stmt2);
}
示例14: testComplexReference
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
@Test
public void testComplexReference() {
ItemIdValue i = ItemIdValue.NULL;
PropertyIdValue p = PropertyIdValue.NULL;
Snak q1 = Datamodel.makeSomeValueSnak(p);
Snak q2 = Datamodel.makeNoValueSnak(p);
Snak q3 = Datamodel.makeValueSnak(p, i);
SnakGroup sg = Datamodel.makeSnakGroup(Arrays.asList(q1, q2, q3));
Reference r1 = Datamodel.makeReference(Collections.singletonList(sg));
Reference r2 = ReferenceBuilder.newInstance().withSomeValue(p)
.withNoValue(p).withPropertyValue(p, i).build();
assertEquals(r1, r2);
}
示例15: equalityBasedOnContent
import org.wikidata.wdtk.datamodel.interfaces.Snak; //导入依赖的package包/类
@Test
public void equalityBasedOnContent() {
Claim cDiffSubject, cDiffMainSnak, cDiffQualifiers;
EntityIdValue subject2 = new ItemIdValueImpl("Q43",
"http://wikidata.org/entity/");
PropertyIdValue property = new PropertyIdValueImpl(
"P43", "http://wikidata.org/entity/");
ValueSnak mainSnak2 = new ValueSnakImpl(property, subject2);
cDiffSubject = new ClaimImpl(subject2, mainSnak,
Collections.<SnakGroup> emptyList());
cDiffMainSnak = new ClaimImpl(subject, mainSnak2,
Collections.<SnakGroup> emptyList());
cDiffQualifiers = new ClaimImpl(subject, mainSnak,
Collections.<SnakGroup> singletonList(new SnakGroupImpl(
Collections.<Snak> singletonList(mainSnak))));
assertEquals(c1, c1);
assertEquals(c1, c2);
assertThat(c1, not(equalTo(cDiffSubject)));
assertThat(c1, not(equalTo(cDiffMainSnak)));
assertThat(c1, not(equalTo(cDiffQualifiers)));
assertThat(c1, not(equalTo(null)));
assertFalse(c1.equals(this));
}