本文整理汇总了Java中org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue类的典型用法代码示例。如果您正苦于以下问题:Java DatatypeIdValue类的具体用法?Java DatatypeIdValue怎么用?Java DatatypeIdValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatatypeIdValue类属于org.wikidata.wdtk.datamodel.interfaces包,在下文中一共展示了DatatypeIdValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRdfValue
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Override
public Value getRdfValue(EntityIdValue value,
PropertyIdValue propertyIdValue, boolean simple) {
String datatype = this.propertyRegister
.setPropertyTypeFromEntityIdValue(propertyIdValue, value);
switch (datatype) {
case DatatypeIdValue.DT_ITEM:
if (simple) {
this.rdfConversionBuffer.addObjectProperty(propertyIdValue);
return this.rdfWriter.getUri(value.getIri());
} else {
return null; // or blank node
}
case DatatypeIdValue.DT_PROPERTY:
if (simple) {
this.rdfConversionBuffer.addObjectProperty(propertyIdValue);
return this.rdfWriter.getUri(value.getIri());
} else {
return null; // or blank node
}
default:
logIncompatibleValueError(propertyIdValue, datatype, "entity");
return null;
}
}
示例2: getRdfValue
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Override
public Value getRdfValue(MonolingualTextValue value,
PropertyIdValue propertyIdValue, boolean simple) {
String datatype = this.propertyRegister
.setPropertyTypeFromMonolingualTextValue(propertyIdValue, value);
switch (datatype) {
case DatatypeIdValue.DT_MONOLINGUAL_TEXT:
if (simple) {
this.rdfConversionBuffer.addObjectProperty(propertyIdValue);
return RdfConverter.getMonolingualTextValueLiteral(value,
this.rdfWriter);
} else {
return null; // or blank node
}
default:
logIncompatibleValueError(propertyIdValue, datatype, "entity");
return null;
}
}
示例3: getRdfValue
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Override
public Value getRdfValue(GlobeCoordinatesValue value,
PropertyIdValue propertyIdValue, boolean simple) {
String datatype = this.propertyRegister
.setPropertyTypeFromGlobeCoordinatesValue(propertyIdValue,
value);
switch (datatype) {
case DatatypeIdValue.DT_GLOBE_COORDINATES:
if (simple) {
return getSimpleGeoValue(value);
} else {
URI valueUri = this.rdfWriter.getUri(Vocabulary
.getGlobeCoordinatesValueUri(value,
this.propertyRegister.getUriPrefix()));
this.rdfConversionBuffer.addObjectProperty(propertyIdValue);
addValue(value, valueUri);
return valueUri;
}
default:
logIncompatibleValueError(propertyIdValue, datatype,
"globe coordinates");
return null;
}
}
示例4: getRdfValue
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Override
public Value getRdfValue(TimeValue value, PropertyIdValue propertyIdValue,
boolean simple) {
String datatype = this.propertyRegister.setPropertyTypeFromTimeValue(
propertyIdValue, value);
switch (datatype) {
case DatatypeIdValue.DT_TIME:
if (simple) {
this.rdfConversionBuffer.addDatatypeProperty(propertyIdValue);
return TimeValueConverter.getTimeLiteral(value, this.rdfWriter);
} else {
URI valueUri = this.rdfWriter.getUri(Vocabulary
.getTimeValueUri(value,
this.propertyRegister.getUriPrefix()));
this.rdfConversionBuffer.addObjectProperty(propertyIdValue);
addValue(value, valueUri);
return valueUri;
}
default:
logIncompatibleValueError(propertyIdValue, datatype, "time");
return null;
}
}
示例5: testWriteInterPropertyLinks
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Test
public void testWriteInterPropertyLinks() throws RDFHandlerException,
RDFParseException, IOException {
PropertyDocument document = this.dataObjectFactory.getPropertyDocument(
this.dataObjectFactory.getPropertyIdValue("P17",
"http://www.wikidata.org/"), Collections
.<MonolingualTextValue> emptyList(), Collections
.<MonolingualTextValue> emptyList(), Collections
.<MonolingualTextValue> emptyList(), Collections
.<StatementGroup> emptyList(), this.dataObjectFactory
.getDatatypeIdValue(DatatypeIdValue.DT_ITEM), 0);
this.rdfConverter.writeInterPropertyLinks(document);
this.rdfWriter.finish();
Model model = RdfTestHelpers.parseRdf(out.toString());
assertEquals(RdfTestHelpers.parseRdf(RdfTestHelpers
.getResourceFromFile("InterPropertyLinks.rdf")), model);
}
示例6: testSimplePropertyDocumentBuild
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Test
public void testSimplePropertyDocumentBuild() {
MonolingualTextValue mtv = Datamodel.makeMonolingualTextValue("Test",
"de");
PropertyDocument pd1 = Datamodel.makePropertyDocument(
PropertyIdValue.NULL, Collections.singletonList(mtv),
Collections.<MonolingualTextValue> emptyList(),
Collections.<MonolingualTextValue> emptyList(),
Collections.<StatementGroup> emptyList(),
Datamodel.makeDatatypeIdValue(DatatypeIdValue.DT_ITEM));
PropertyDocument pd2 = PropertyDocumentBuilder
.forPropertyIdAndDatatype(PropertyIdValue.NULL,
DatatypeIdValue.DT_ITEM).withLabel(mtv).build();
assertEquals(pd1, pd2);
}
示例7: testModifyingBuild
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Test
public void testModifyingBuild() {
MonolingualTextValue label = Datamodel.makeMonolingualTextValue("color",
"en");
PropertyDocument initial = Datamodel.makePropertyDocument(PropertyIdValue.NULL,
Collections.singletonList(label),
Collections.<MonolingualTextValue>emptyList(),
Collections.<MonolingualTextValue>emptyList(),
Collections.<StatementGroup> emptyList(),
Datamodel.makeDatatypeIdValue(DatatypeIdValue.DT_QUANTITY),
1234);
PropertyDocument copy = PropertyDocumentBuilder.fromPropertyDocument(initial).build();
assertEquals(copy, initial);
MonolingualTextValue alias = Datamodel.makeMonolingualTextValue("tone",
"en");
PropertyDocument withAlias = PropertyDocumentBuilder.fromPropertyDocument(initial).withAlias(alias).build();
assertEquals(withAlias.getAliases().get("en"), Arrays.asList(alias));
}
示例8: testGetPropertyDocument
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Test
public final void testGetPropertyDocument() {
PropertyDocument o1 = Datamodel.makePropertyDocument(
factory.getPropertyIdValue("P42", "foo"),
Collections.<MonolingualTextValue> emptyList(),
Collections.<MonolingualTextValue> emptyList(),
Collections.<MonolingualTextValue> emptyList(),
factory.getDatatypeIdValue(DatatypeIdValue.DT_TIME));
PropertyDocument o2 = factory.getPropertyDocument(
factory.getPropertyIdValue("P42", "foo"),
Collections.<MonolingualTextValue> emptyList(),
Collections.<MonolingualTextValue> emptyList(),
Collections.<MonolingualTextValue> emptyList(),
factory.getDatatypeIdValue(DatatypeIdValue.DT_TIME));
assertEquals(o1, o2);
}
示例9: testPropertyDocumentToJson
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Test
public void testPropertyDocumentToJson() {
PropertyDocument pd = Datamodel.makePropertyDocument(
Datamodel.makeWikidataPropertyIdValue("P1"),
Collections.<MonolingualTextValue> emptyList(),
Collections.<MonolingualTextValue> emptyList(),
Collections.<MonolingualTextValue> emptyList(),
Collections.<StatementGroup> emptyList(),
Datamodel.makeDatatypeIdValue(DatatypeIdValue.DT_ITEM));
String result1 = JsonSerializer.getJsonString(pd);
String result2 = JsonSerializer.getJsonString(datamodelConverter
.copy(pd));
String json = "{\"id\":\"P1\",\"aliases\":{},\"labels\":{},\"descriptions\":{},\"claims\":{},\"type\":\"property\", \"datatype\":\"wikibase-item\"}";
JsonComparator.compareJsonStrings(json, result1);
JsonComparator.compareJsonStrings(json, result2);
}
示例10: testFullDocumentSetup
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Test
public void testFullDocumentSetup() {
JacksonPropertyDocument fullDocument = new JacksonPropertyDocument();
fullDocument.setJsonId(JsonTestData.getTestPropertyId().getId());
fullDocument.setAliases(JsonTestData.getTestAliases());
fullDocument.setDescriptions(JsonTestData.getTestMltvMap());
fullDocument.setLabels(JsonTestData.getTestMltvMap());
fullDocument.setJsonDatatype("quantity");
assertEquals(fullDocument.getAliases(), JsonTestData.getTestAliases());
assertEquals(fullDocument.getDescriptions(),
JsonTestData.getTestMltvMap());
assertEquals(fullDocument.getLabels(), JsonTestData.getTestMltvMap());
assertEquals(fullDocument.getPropertyId(),
JsonTestData.getTestPropertyId());
assertEquals(fullDocument.getEntityId(),
JsonTestData.getTestPropertyId());
assertEquals(fullDocument.getDatatype(),
Datamodel.makeDatatypeIdValue(DatatypeIdValue.DT_QUANTITY));
assertEquals(fullDocument.getPropertyId().getId(),
fullDocument.getJsonId());
}
示例11: testFindStatementDatatypeIdValue
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
@Test
public void testFindStatementDatatypeIdValue() {
DatatypeIdValue v = Datamodel
.makeDatatypeIdValue(DatatypeIdValue.DT_STRING);
Statement s = StatementBuilder.forSubjectAndProperty(q1, p1)
.withValue(v).build();
ItemDocument id = ItemDocumentBuilder.forItemId(q1).withStatement(s)
.build();
assertEquals(v, id.findStatementValue(p1));
assertEquals(v, id.findStatementValue("P1"));
assertEquals(v, id.findStatementDatatypeIdValue(p1));
assertEquals(v, id.findStatementDatatypeIdValue("P1"));
}
示例12: getDatatypeLabel
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
/**
* Returns an English label for a given datatype.
*
* @param datatype
* the datatype to label
* @return the label
*/
private String getDatatypeLabel(DatatypeIdValue datatype) {
if (datatype.getIri() == null) { // TODO should be redundant once the
// JSON parsing works
return "Unknown";
}
switch (datatype.getIri()) {
case DatatypeIdValue.DT_COMMONS_MEDIA:
return "Commons media";
case DatatypeIdValue.DT_GLOBE_COORDINATES:
return "Globe coordinates";
case DatatypeIdValue.DT_ITEM:
return "Item";
case DatatypeIdValue.DT_QUANTITY:
return "Quantity";
case DatatypeIdValue.DT_STRING:
return "String";
case DatatypeIdValue.DT_TIME:
return "Time";
case DatatypeIdValue.DT_URL:
return "URL";
case DatatypeIdValue.DT_PROPERTY:
return "Property";
case DatatypeIdValue.DT_EXTERNAL_ID:
return "External identifier";
case DatatypeIdValue.DT_MATH:
return "Math";
case DatatypeIdValue.DT_MONOLINGUAL_TEXT:
return "Monolingual Text";
default:
throw new RuntimeException("Unknown datatype " + datatype.getIri());
}
}
示例13: findSomeStringProperties
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
/**
* Finds properties of datatype string on test.wikidata.org. Since the test
* site changes all the time, we cannot hardcode a specific property here.
* Instead, we just look through all properties starting from P1 to find the
* first few properties of type string that have an English label. These
* properties are used for testing in this code.
*
* @param connection
* @throws MediaWikiApiErrorException
*/
public static void findSomeStringProperties(ApiConnection connection)
throws MediaWikiApiErrorException {
WikibaseDataFetcher wbdf = new WikibaseDataFetcher(connection, siteIri);
wbdf.getFilter().excludeAllProperties();
wbdf.getFilter().setLanguageFilter(Collections.singleton("en"));
ArrayList<PropertyIdValue> stringProperties = new ArrayList<>();
System.out
.println("*** Trying to find string properties for the example ... ");
int propertyNumber = 1;
while (stringProperties.size() < 5) {
ArrayList<String> fetchProperties = new ArrayList<>();
for (int i = propertyNumber; i < propertyNumber + 10; i++) {
fetchProperties.add("P" + i);
}
propertyNumber += 10;
Map<String, EntityDocument> results = wbdf
.getEntityDocuments(fetchProperties);
for (EntityDocument ed : results.values()) {
PropertyDocument pd = (PropertyDocument) ed;
if (DatatypeIdValue.DT_STRING.equals(pd.getDatatype().getIri())
&& pd.getLabels().containsKey("en")) {
stringProperties.add(pd.getPropertyId());
System.out.println("* Found string property "
+ pd.getEntityId().getId() + " ("
+ pd.getLabels().get("en") + ")");
}
}
}
stringProperty1 = stringProperties.get(0);
stringProperty2 = stringProperties.get(1);
stringProperty3 = stringProperties.get(2);
stringProperty4 = stringProperties.get(3);
stringProperty5 = stringProperties.get(4);
System.out.println("*** Done.");
}
示例14: setPropertyTypeFromEntityIdValue
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
/**
* Returns the IRI of the primitive Type of an Property for
* {@link EntityIdValue} objects.
*
* @param propertyIdValue
* @param value
*/
public String setPropertyTypeFromEntityIdValue(
PropertyIdValue propertyIdValue, EntityIdValue value) {
switch (value.getId().charAt(0)) {
case 'Q':
return DatatypeIdValue.DT_ITEM;
case 'P':
return DatatypeIdValue.DT_PROPERTY;
default:
logger.warn("Could not determine Type of "
+ propertyIdValue.getId()
+ ". It is not a valid EntityDocument Id");
return null;
}
}
示例15: setPropertyTypeFromStringValue
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; //导入依赖的package包/类
/**
* Returns the IRI of the primitive Type of an Property for
* {@link StringValue} objects.
*
* @param propertyIdValue
* @param value
*/
public String setPropertyTypeFromStringValue(
PropertyIdValue propertyIdValue, StringValue value) {
String datatype = getPropertyType(propertyIdValue);
if (datatype == null) {
logger.warn("Could not fetch datatype of "
+ propertyIdValue.getIri() + ". Assuming type "
+ DatatypeIdValue.DT_STRING);
return DatatypeIdValue.DT_STRING; // default type for StringValue
} else {
return datatype;
}
}