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


Java ItemDocumentBuilder类代码示例

本文整理汇总了Java中org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder的典型用法代码示例。如果您正苦于以下问题:Java ItemDocumentBuilder类的具体用法?Java ItemDocumentBuilder怎么用?Java ItemDocumentBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ItemDocumentBuilder类属于org.wikidata.wdtk.datamodel.helpers包,在下文中一共展示了ItemDocumentBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAddLabel

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Adding a label on an empty item.
 */
@Test
public void testAddLabel() throws JsonProcessingException {
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1).build();
	
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("Apfelstrudel", "de");
	
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.singletonList(label),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList());
	
	// Check model
	
	assertEquals(Collections.singleton("de"), su.getLabelUpdates().keySet());
	assertEquals(label.getText(), su.getLabelUpdates().get("de").getText());
	assertTrue(su.getAliasUpdates().isEmpty());
	assertTrue(su.getDescriptionUpdates().isEmpty());
	
	// Check JSON output
	assertEquals("{\"labels\":{\"de\":{\"language\":\"de\",\"value\":\"Apfelstrudel\"}}}",
			su.getJsonUpdateString());
	assertFalse(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:28,代码来源:TermStatementUpdateTest.java

示例2: testAddAliasWithoutLabel

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * When trying to add an alias for a language that does not have
 * any label yet, add as label instead.
 */
@Test
public void testAddAliasWithoutLabel() {
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1).build();
	
	MonolingualTextValue alias = Datamodel.makeMonolingualTextValue("Apfelstrudel", "de");
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.singletonList(alias),
			Collections.<MonolingualTextValue> emptyList());
	
	
	assertEquals(su.getLabelUpdates().keySet(), Collections.singleton("de"));
	assertEquals(su.getLabelUpdates().get("de").getText(), alias.getText());
	assertTrue(su.getAliasUpdates().isEmpty());
	assertTrue(su.getDescriptionUpdates().isEmpty());
	assertFalse(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:23,代码来源:TermStatementUpdateTest.java

示例3: testAddLabelAndAlias

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Adding a label and an alias at the same time.
 */
@Test
public void testAddLabelAndAlias() throws JsonProcessingException {
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1).build();
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("strudel aux pommes", "fr");
	MonolingualTextValue alias = Datamodel.makeMonolingualTextValue("Apfelstrudel", "fr");
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.singletonList(label),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.singletonList(alias),
			Collections.<MonolingualTextValue> emptyList());
	
	assertEquals(Collections.singleton("fr"), su.getLabelUpdates().keySet());
	assertEquals(label.getText(), su.getLabelUpdates().get("fr").getText());
	assertEquals(Collections.singleton("fr"), su.getAliasUpdates().keySet());
	assertEquals(alias.getText(), su.getAliasUpdates().get("fr").get(0).getText());
	assertTrue(su.getDescriptionUpdates().isEmpty());
	assertFalse(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:22,代码来源:TermStatementUpdateTest.java

示例4: testAliasTwice

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Adding the same alias twice.
 */
@Test
public void testAliasTwice() throws JsonProcessingException {
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("strudel aux pommes", "fr");
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1).withLabel(label).build();
	MonolingualTextValue alias = Datamodel.makeMonolingualTextValue("Apfelstrudel", "fr");
	List<MonolingualTextValue> newAliases = new ArrayList<>();
	newAliases.add(alias);
	newAliases.add(alias);
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList(),
			newAliases,
			Collections.<MonolingualTextValue> emptyList());
	
	assertTrue(su.getLabelUpdates().isEmpty());
	assertEquals(su.getAliasUpdates().size(), 1);
	assertEquals("{\"aliases\":{\"fr\":[{\"language\":\"fr\",\"value\":\"Apfelstrudel\"}]}}",
			su.getJsonUpdateString());
	assertFalse(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:24,代码来源:TermStatementUpdateTest.java

示例5: testAliasMerge

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Adding an alias on an item that has already got one
 */
@Test
public void testAliasMerge() throws JsonProcessingException {
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("strudel aux pommes", "fr");
	MonolingualTextValue alias = Datamodel.makeMonolingualTextValue("Apfelstrudel", "fr");
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1).withLabel(label).withAlias(alias).build();
	

	MonolingualTextValue newAlias = Datamodel.makeMonolingualTextValue("Apfelstrudeln", "fr");
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.singletonList(newAlias),
			Collections.<MonolingualTextValue> emptyList());
	
	assertTrue(su.getLabelUpdates().isEmpty());
	assertEquals(1, su.getAliasUpdates().size());
	assertEquals(2, su.getAliasUpdates().get("fr").size());
	assertEquals("{\"aliases\":{\"fr\":[{\"language\":\"fr\",\"value\":\"Apfelstrudel\"},{\"language\":\"fr\",\"value\":\"Apfelstrudeln\"}]}}",
			su.getJsonUpdateString());
	assertFalse(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:25,代码来源:TermStatementUpdateTest.java

示例6: testAddLabelAsAlias

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Adding an alias identical to the label in the same language does not do anything
 */
@Test
public void testAddLabelAsAlias() {
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("Apfelstrudel", "de");
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1).withLabel(label).build();
	
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.singletonList(label),
			Collections.<MonolingualTextValue> emptyList()
			);
	
	
	assertTrue(su.getLabelUpdates().isEmpty());
	assertTrue(su.getAliasUpdates().isEmpty());
	assertTrue(su.getDescriptionUpdates().isEmpty());
	assertTrue(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:22,代码来源:TermStatementUpdateTest.java

示例7: testAddAliasAsLabel

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Adding a label identical to an alias updates the label and deletes the alias
 */
@Test
public void testAddAliasAsLabel() {
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("strudel aux pommes", "fr");
	MonolingualTextValue alias = Datamodel.makeMonolingualTextValue("Apfelstrudel", "fr");
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1).withLabel(label).withAlias(alias).build();
	
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.singletonList(alias),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList()
			);
	
	assertEquals(Collections.singleton("fr"), su.getAliasUpdates().keySet());
	assertTrue(su.getAliasUpdates().get("fr").isEmpty());
	assertEquals(Collections.singleton("fr"), su.getLabelUpdates().keySet());
	assertEquals(su.getLabelUpdates().get("fr").getText(), alias.getText());
	assertTrue(su.getDescriptionUpdates().isEmpty());
	assertFalse(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:24,代码来源:TermStatementUpdateTest.java

示例8: testDeleteAlias

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Deleting an alias
 */
@Test
public void testDeleteAlias() throws JsonProcessingException {
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("strudel aux pommes", "fr");
	MonolingualTextValue alias = Datamodel.makeMonolingualTextValue("Apfelstrudel", "fr");
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1).withLabel(label).withAlias(alias).build();
	
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.singletonList(alias)
			);
	
	assertTrue(su.getLabelUpdates().isEmpty());
	assertEquals(su.getAliasUpdates().size(), 1);
	assertEquals(su.getAliasUpdates().get("fr").size(), 0);
	assertEquals("{\"aliases\":{\"fr\":[]}}",
			su.getJsonUpdateString());
	assertFalse(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:24,代码来源:TermStatementUpdateTest.java

示例9: testDescription

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Adding a description, for the sake of coverage…
 */
@Test
public void testDescription() throws JsonProcessingException {
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("strudel aux pommes", "fr");
	MonolingualTextValue alias = Datamodel.makeMonolingualTextValue("Apfelstrudel", "fr");
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1).withLabel(label).withAlias(alias).build();

	MonolingualTextValue description = Datamodel.makeMonolingualTextValue("délicieuse pâtisserie aux pommes", "fr");
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.<MonolingualTextValue> emptyList(),
			Collections.singletonList(description),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList());
	
	assertTrue(su.getLabelUpdates().isEmpty());
	assertTrue(su.getAliasUpdates().isEmpty());
	assertEquals(Collections.singleton("fr"), su.getDescriptionUpdates().keySet());
	assertEquals("délicieuse pâtisserie aux pommes", su.getDescriptionUpdates().get("fr").getText());
	assertEquals("{\"descriptions\":{\"fr\":{\"language\":\"fr\",\"value\":\"délicieuse pâtisserie aux pommes\"}}}",
			su.getJsonUpdateString());
	assertFalse(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:25,代码来源:TermStatementUpdateTest.java

示例10: testAddIdenticalDescription

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Adding a description, identical to the current one
 */
@Test
public void testAddIdenticalDescription() {
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("strudel aux pommes", "fr");
	MonolingualTextValue description = Datamodel.makeMonolingualTextValue("délicieuse pâtisserie aux pommes", "fr");
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1)
			.withLabel(label)
			.withDescription(description)
			.build();
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.<MonolingualTextValue> emptyList(),
			Collections.singletonList(description),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList());
	
	assertEquals("{}", su.getJsonUpdateString());
	assertTrue(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:21,代码来源:TermStatementUpdateTest.java

示例11: testAddIdenticalAlias

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
/**
 * Adding an alias, identical to the current one
 */
@Test
public void testAddIdenticalAlias() {
	MonolingualTextValue label = Datamodel.makeMonolingualTextValue("strudel aux pommes", "fr");
	MonolingualTextValue alias = Datamodel.makeMonolingualTextValue("Apfelstrudel", "fr");
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1)
			.withLabel(label)
			.withAlias(alias)
			.build();
	TermStatementUpdate su = makeUpdate(currentDocument,
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.singletonList(alias),
			Collections.<MonolingualTextValue> emptyList());
	
	assertEquals("{}", su.getJsonUpdateString());
	assertTrue(su.isEmptyEdit());
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:21,代码来源:TermStatementUpdateTest.java

示例12: testNoMergeDiffMainSnak

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
@Test
public void testNoMergeDiffMainSnak() {
	Statement s1 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q1).withId("ID-s1").build();
	Statement s2 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q2).build();

	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1)
			.withStatement(s1).build();

	StatementUpdate su = new StatementUpdate(currentDocument,
			Arrays.asList(s2), Collections.<Statement> emptyList());

	assertEquals(0, su.toDelete.size());
	assertEquals(1, su.toKeep.size());
	assertTrue(su.toKeep.containsKey(P1));
	assertEquals(2, su.toKeep.get(P1).size());
	assertEquals(s2, su.toKeep.get(P1).get(0).statement);
	assertTrue(su.toKeep.get(P1).get(0).write);
	assertEquals(s1, su.toKeep.get(P1).get(1).statement);
	assertFalse(su.toKeep.get(P1).get(1).write);
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:23,代码来源:StatementUpdateTest.java

示例13: testNoMergeDiffQualifier

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
@Test
public void testNoMergeDiffQualifier() {
	Statement s1 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q1).withQualifierValue(P3, Q2).withId("ID-s1")
			.build();
	Statement s2 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q1).withQualifierValue(P3, Q3).build();

	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1)
			.withStatement(s1).build();

	StatementUpdate su = new StatementUpdate(currentDocument,
			Arrays.asList(s2), Collections.<Statement> emptyList());

	assertEquals(0, su.toDelete.size());
	assertEquals(1, su.toKeep.size());
	assertTrue(su.toKeep.containsKey(P1));
	assertEquals(2, su.toKeep.get(P1).size());
	assertEquals(s2, su.toKeep.get(P1).get(0).statement);
	assertTrue(su.toKeep.get(P1).get(0).write);
	assertEquals(s1, su.toKeep.get(P1).get(1).statement);
	assertFalse(su.toKeep.get(P1).get(1).write);
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:24,代码来源:StatementUpdateTest.java

示例14: testNoMergeRankConflict

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
@Test
public void testNoMergeRankConflict() {
	Statement s1 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q1).withRank(StatementRank.PREFERRED)
			.withId("ID-s1").build();
	Statement s2 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q1).withRank(StatementRank.DEPRECATED).build();

	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1)
			.withStatement(s1).build();

	StatementUpdate su = new StatementUpdate(currentDocument,
			Arrays.asList(s2), Collections.<Statement> emptyList());

	assertEquals(0, su.toDelete.size());
	assertEquals(1, su.toKeep.size());
	assertTrue(su.toKeep.containsKey(P1));
	assertEquals(2, su.toKeep.get(P1).size());
	assertEquals(s2, su.toKeep.get(P1).get(0).statement);
	assertTrue(su.toKeep.get(P1).get(0).write);
	assertEquals(s1, su.toKeep.get(P1).get(1).statement);
	assertFalse(su.toKeep.get(P1).get(1).write);
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:24,代码来源:StatementUpdateTest.java

示例15: testUpdateStatement

import org.wikidata.wdtk.datamodel.helpers.ItemDocumentBuilder; //导入依赖的package包/类
@Test
public void testUpdateStatement() {

	Statement s1 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q1).withId("ID-s1").build();
	Statement s2 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q2).withId("ID-s1").build();

	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1)
			.withStatement(s1).build();

	StatementUpdate su = new StatementUpdate(currentDocument,
			Arrays.asList(s2), Collections.<Statement> emptyList());

	assertEquals(0, su.toDelete.size());
	assertEquals(1, su.toKeep.size());
	assertTrue(su.toKeep.containsKey(P1));
	assertEquals(1, su.toKeep.get(P1).size());
	assertEquals(s2, su.toKeep.get(P1).get(0).statement);
	assertTrue(su.toKeep.get(P1).get(0).write);
}
 
开发者ID:Wikidata,项目名称:Wikidata-Toolkit,代码行数:22,代码来源:StatementUpdateTest.java


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