本文整理汇总了Java中org.wikidata.wdtk.datamodel.interfaces.ItemIdValue类的典型用法代码示例。如果您正苦于以下问题:Java ItemIdValue类的具体用法?Java ItemIdValue怎么用?Java ItemIdValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ItemIdValue类属于org.wikidata.wdtk.datamodel.interfaces包,在下文中一共展示了ItemIdValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getItemIdValueOfStatement
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的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;
}
开发者ID:heindorf,项目名称:cikm16-wdvd-feature-extraction,代码行数:22,代码来源:ItemDocumentDbItem.java
示例2: getAllSuperClasses
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
private Set<ItemIdValue> getAllSuperClasses(ItemIdValue itemId) {
Set<ItemIdValue> superClasses = new HashSet<>();
superClasses.add(itemId);
Stack<ItemIdValue> toGet = new Stack<>();
toGet.add(itemId);
while (!toGet.empty()) {
for (ItemIdValue superClass : typeHierarchy.getSuperClasses(toGet.pop())) {
if (!superClasses.contains(superClass)) {
superClasses.add(superClass);
toGet.add(superClass);
}
}
}
return superClasses;
}
开发者ID:askplatypus,项目名称:platypus-kb-lucene,代码行数:18,代码来源:TypeMapper.java
示例3: includeDocument
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的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
示例4: processGDMResourceNode
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
private ItemIdValue processGDMResourceNode(final ResourceNode resourceNode) {
final String resourceURI = resourceNode.getUri();
return gdmResourceURIWikidataItemMap.computeIfAbsent(resourceURI, resourceURI1 -> {
try {
final List<MonolingualTextValue> labels = generateLabels(resourceURI);
final List<MonolingualTextValue> descriptions = generateLabels(resourceURI);
final List<MonolingualTextValue> aliases = new ArrayList<>();
final List<StatementGroup> statementGroups = new ArrayList<>();
final Map<String, SiteLink> siteLinkMap = new HashMap<>();
// note: list of descriptions cannot be null
// note: list of aliases cannot be null
// note: list of statement groups cannot be null
final ItemDocument wikidataItem = Datamodel.makeItemDocument(null, labels, descriptions, aliases, statementGroups, siteLinkMap);
return createWikidataItem(resourceURI1, wikidataItem);
} catch (final WikidataImporterException e) {
throw WikidataImporterError.wrap(e);
}
});
}
开发者ID:dswarm,项目名称:wikidata-d-swarm-importer,代码行数:27,代码来源:WikidataDswarmImporter.java
示例5: testUriPatternStatement
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的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")));
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:24,代码来源:RdfConverterTest.java
示例6: testFreebaseStatement
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的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")));
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:23,代码来源:RdfConverterTest.java
示例7: testDisableEditing
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Test
public void testDisableEditing() throws IOException,
MediaWikiApiErrorException {
WikibaseDataEditor wde = new WikibaseDataEditor(this.con,
Datamodel.SITE_WIKIDATA);
wde.disableEditing();
assertEquals(0, wde.getRemainingEdits());
ItemDocument itemDocument = ItemDocumentBuilder.forItemId(
ItemIdValue.NULL).build();
ItemDocument result = wde
.createItemDocument(itemDocument, "My summary");
assertEquals(null, result);
assertEquals(0, wde.getRemainingEdits());
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:18,代码来源:WikibaseDataEditorTest.java
示例8: testCreateItemBadToken
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Test(expected = TokenErrorException.class)
public void testCreateItemBadToken() throws IOException,
MediaWikiApiErrorException {
WikibaseDataEditor wde = new WikibaseDataEditor(this.con,
Datamodel.SITE_WIKIDATA);
ItemDocument itemDocument = ItemDocumentBuilder.forItemId(
ItemIdValue.NULL).build();
Map<String, String> params = new HashMap<String, String>();
params.put("action", "wbeditentity");
params.put("summary", "My summary");
params.put("new", "item");
params.put("token", "42307b93c79b0cb558d2dfb4c3c92e0955e06041+\\");
params.put("format", "json");
params.put("maxlag", "5");
String data = JsonSerializer.getJsonString(itemDocument);
params.put("data", data);
this.con.setWebResourceFromPath(params, this.getClass(),
"/error-badtoken.json", CompressionType.NONE);
wde.createItemDocument(itemDocument, "My summary");
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:24,代码来源:WikibaseDataEditorTest.java
示例9: testCreateItemBadEntityDocumentJson
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Test(expected = IOException.class)
public void testCreateItemBadEntityDocumentJson() throws IOException,
MediaWikiApiErrorException {
// Test what happens if the API returns JSON without an actual entity
// document, but with a respective key pointing to an empty object
WikibaseDataEditor wde = new WikibaseDataEditor(this.con,
Datamodel.SITE_WIKIDATA);
ItemDocument itemDocument = ItemDocumentBuilder.forItemId(
ItemIdValue.NULL).build();
String expectedResult = "{\"entity\":" + "{}" + ",\"success\":1}";
Map<String, String> params = new HashMap<String, String>();
params.put("action", "wbeditentity");
params.put("summary", "My summary");
params.put("new", "item");
params.put("token", "42307b93c79b0cb558d2dfb4c3c92e0955e06041+\\");
params.put("format", "json");
params.put("maxlag", "5");
String data = JsonSerializer.getJsonString(itemDocument);
params.put("data", data);
con.setWebResource(params, expectedResult);
wde.createItemDocument(itemDocument, "My summary");
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:26,代码来源:WikibaseDataEditorTest.java
示例10: testCreateItemMissingEntityDocumentJson
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Test(expected = IOException.class)
public void testCreateItemMissingEntityDocumentJson() throws IOException,
MediaWikiApiErrorException {
WikibaseDataEditor wde = new WikibaseDataEditor(this.con,
Datamodel.SITE_WIKIDATA);
ItemDocument itemDocument = ItemDocumentBuilder.forItemId(
ItemIdValue.NULL).build();
String expectedResult = "{\"success\":1}";
Map<String, String> params = new HashMap<String, String>();
params.put("action", "wbeditentity");
params.put("summary", "My summary");
params.put("new", "item");
params.put("token", "42307b93c79b0cb558d2dfb4c3c92e0955e06041+\\");
params.put("format", "json");
params.put("maxlag", "5");
String data = JsonSerializer.getJsonString(itemDocument);
params.put("data", data);
con.setWebResource(params, expectedResult);
wde.createItemDocument(itemDocument, "My summary");
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:24,代码来源:WikibaseDataEditorTest.java
示例11: testComplexStatement
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的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);
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:23,代码来源:StatementBuilderTest.java
示例12: testQualifierList
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的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);
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:23,代码来源:StatementBuilderTest.java
示例13: testReferenceList
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的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);
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:26,代码来源:StatementBuilderTest.java
示例14: testComplexReference
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的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);
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:17,代码来源:ReferenceBuilderTest.java
示例15: testStatementToJson
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Test
public void testStatementToJson() {
Statement s = Datamodel
.makeStatement(
Datamodel.makeClaim(
ItemIdValue.NULL,
Datamodel.makeNoValueSnak(Datamodel
.makeWikidataPropertyIdValue(JsonTestData.TEST_PROPERTY_ID)),
Collections.<SnakGroup> emptyList()),
Collections.<Reference> emptyList(),
StatementRank.NORMAL, JsonTestData.TEST_STATEMENT_ID);
String result1 = JsonSerializer.getJsonString(s);
String result2 = JsonSerializer.getJsonString(datamodelConverter
.copy(s));
JsonComparator.compareJsonStrings(JsonTestData.JSON_NOVALUE_STATEMENT,
result1);
JsonComparator.compareJsonStrings(JsonTestData.JSON_NOVALUE_STATEMENT,
result2);
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:22,代码来源:JsonSerializerTest.java
示例16: statementGroupsUseSameSubject
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void statementGroupsUseSameSubject() {
ItemIdValue iid2 = new ItemIdValueImpl("Q23", "http://example.org/");
Claim c2 = new ClaimImpl(iid2, new SomeValueSnakImpl(
new PropertyIdValueImpl("P42", "http://wikibase.org/entity/")),
Collections.<SnakGroup> emptyList());
Statement s2 = new StatementImpl(c2,
Collections.<Reference> emptyList(), StatementRank.NORMAL,
"MyId");
StatementGroup sg2 = new StatementGroupImpl(
Collections.singletonList(s2));
List<StatementGroup> statementGroups2 = new ArrayList<StatementGroup>();
statementGroups2.add(statementGroups.get(0));
statementGroups2.add(sg2);
new ItemDocumentImpl(iid,
Collections.<MonolingualTextValue> emptyList(),
Collections.<MonolingualTextValue> emptyList(),
Collections.<MonolingualTextValue> emptyList(),
statementGroups2, sitelinks, 1234);
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:23,代码来源:ItemDocumentImplTest.java
示例17: mapMainValue
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Override
default Stream<Claim> mapMainValue(Value value) throws InvalidWikibaseValueException {
if (!(value instanceof ItemIdValue)) {
throw new InvalidWikibaseValueException(value + " should be a ItemIdValue");
}
return mapMainItemIdValue((ItemIdValue) value);
}
开发者ID:askplatypus,项目名称:platypus-kb-lucene,代码行数:8,代码来源:StatementMainItemIdValueMapper.java
示例18: testStatementComplexValue
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Test
public void testStatementComplexValue() throws RDFHandlerException,
RDFParseException, IOException {
GlobeCoordinatesValue value = Datamodel.makeGlobeCoordinatesValue(51,
13, GlobeCoordinatesValue.PREC_DEGREE,
GlobeCoordinatesValue.GLOBE_EARTH);
Statement statement = StatementBuilder
.forSubjectAndProperty(ItemIdValue.NULL, PropertyIdValue.NULL)
.withValue(value).build();
this.rdfConverter.writeStatement(statement);
this.rdfWriter.finish();
Model model = RdfTestHelpers.parseRdf(this.out.toString());
assertEquals(model, RdfTestHelpers.parseRdf(RdfTestHelpers
.getResourceFromFile("StatementCplx.rdf")));
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:16,代码来源:RdfConverterTest.java
示例19: testSetRemainingEdits
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Test
public void testSetRemainingEdits() throws IOException,
MediaWikiApiErrorException {
WikibaseDataEditor wde = new WikibaseDataEditor(this.con,
Datamodel.SITE_WIKIDATA);
wde.setRemainingEdits(1);
ItemDocument itemDocument = ItemDocumentBuilder.forItemId(
ItemIdValue.NULL).build();
ItemDocument expectedResultDocument = ItemDocumentBuilder
.forItemId(Datamodel.makeWikidataItemIdValue("Q1234"))
.withRevisionId(1234).build();
String resultData = JsonSerializer
.getJsonString(expectedResultDocument);
String expectedResult = "{\"entity\":" + resultData + ",\"success\":1}";
Map<String, String> params = new HashMap<String, String>();
params.put("action", "wbeditentity");
params.put("summary", "My summary");
params.put("new", "item");
params.put("token", "42307b93c79b0cb558d2dfb4c3c92e0955e06041+\\");
params.put("format", "json");
params.put("maxlag", "5");
String data = JsonSerializer.getJsonString(itemDocument);
params.put("data", data);
con.setWebResource(params, expectedResult);
assertEquals(1, wde.getRemainingEdits());
ItemDocument result = wde
.createItemDocument(itemDocument, "My summary");
assertEquals(expectedResultDocument, result);
assertEquals(0, wde.getRemainingEdits());
result = wde.createItemDocument(itemDocument, "My summary");
assertEquals(null, result);
assertEquals(0, wde.getRemainingEdits());
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:37,代码来源:WikibaseDataEditorTest.java
示例20: testCreateItem
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; //导入依赖的package包/类
@Test
public void testCreateItem() throws IOException, MediaWikiApiErrorException {
WikibaseDataEditor wde = new WikibaseDataEditor(this.con,
Datamodel.SITE_WIKIDATA);
ItemDocument itemDocument = ItemDocumentBuilder.forItemId(
ItemIdValue.NULL).build();
ItemDocument expectedResultDocument = ItemDocumentBuilder
.forItemId(Datamodel.makeWikidataItemIdValue("Q1234"))
.withRevisionId(1234).build();
String resultData = JsonSerializer
.getJsonString(expectedResultDocument);
String expectedResult = "{\"entity\":" + resultData + ",\"success\":1}";
Map<String, String> params = new HashMap<String, String>();
params.put("action", "wbeditentity");
params.put("summary", "My summary");
params.put("new", "item");
params.put("token", "42307b93c79b0cb558d2dfb4c3c92e0955e06041+\\");
params.put("format", "json");
params.put("maxlag", "5");
String data = JsonSerializer.getJsonString(itemDocument);
params.put("data", data);
con.setWebResource(params, expectedResult);
ItemDocument result = wde
.createItemDocument(itemDocument, "My summary");
assertEquals(expectedResultDocument, result);
assertEquals(-1, wde.getRemainingEdits());
}
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:32,代码来源:WikibaseDataEditorTest.java
注:本文中的org.wikidata.wdtk.datamodel.interfaces.ItemIdValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论