當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。