Repository: Wikidata/Wikidata-Toolkit
Pull request #701 (2022-07-01 11:09:00)

700: add edtf DatatypeIdValue

Lhaaits: Thanks for the review!

Patch:
diff --git a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImpl.java b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImpl.java
index 499026b4..7131e696 100644
--- a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImpl.java
+++ b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImpl.java
@@ -101,6 +101,11 @@ public class DatatypeIdImpl implements DatatypeIdValue {
 	 * {@link DatatypeIdValue#DT_GEO_SHAPE} in JSON.
 	 */
 	public static final String JSON_DT_GEO_SHAPE = "geo-shape";
+	/**
+	 * String used to refer to the property datatype
+	 * {@link DatatypeIdValue#DT_EDTF} in JSON.
+	 */
+	public static final String JSON_DT_EDTF = "edtf";
 
 	private static final Pattern JSON_DATATYPE_PATTERN = Pattern.compile("^[a-z\\-]+$");
 	private static final Pattern DATATYPE_ID_PATTERN = Pattern.compile("^http://wikiba\\.se/ontology#([a-zA-Z]+)$");
@@ -139,6 +144,8 @@ public class DatatypeIdImpl implements DatatypeIdValue {
 			return DT_STRING;
 		case JSON_DT_MONOLINGUAL_TEXT:
 			return DT_MONOLINGUAL_TEXT;
+		case JSON_DT_EDTF:
+			return DT_EDTF;
 		default:
 			if(!JSON_DATATYPE_PATTERN.matcher(jsonDatatype).matches()) {
 				throw new IllegalArgumentException("Invalid JSON datatype \"" + jsonDatatype + "\"");
@@ -181,6 +188,8 @@ public class DatatypeIdImpl implements DatatypeIdValue {
 				return DatatypeIdImpl.JSON_DT_MONOLINGUAL_TEXT;
 			case DatatypeIdValue.DT_PROPERTY:
 				return DatatypeIdImpl.JSON_DT_PROPERTY;
+			case DatatypeIdValue.DT_EDTF:
+				return DatatypeIdImpl.JSON_DT_EDTF;
 			default:
 				//We apply the reverse algorithm of JacksonDatatypeId::getDatatypeIriFromJsonDatatype
 				Matcher matcher = DATATYPE_ID_PATTERN.matcher(datatypeIri);
diff --git a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/interfaces/DatatypeIdValue.java b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/interfaces/DatatypeIdValue.java
index aa504343..2792dcd0 100644
--- a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/interfaces/DatatypeIdValue.java
+++ b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/interfaces/DatatypeIdValue.java
@@ -97,6 +97,10 @@ public interface DatatypeIdValue {
 	 * IRI of the tabular data datatype in Wikibase.
 	 */
 	String DT_TABULAR_DATA = "http://wikiba.se/ontology#TabularData";
+	/**
+	 * IRI of the extended date time format (EDTF) datatype in Wikibase.
+	 */
+	String DT_EDTF = "http://wikiba.se/ontology#Edtf";
 
 	/**
 	 * Get the IRI of this entity.


Test patch:
diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImplTest.java
index 25393696..65806198 100644
--- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImplTest.java
+++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/DatatypeIdImplTest.java
@@ -224,4 +224,11 @@ public class DatatypeIdImplTest {
 				DatatypeIdImpl.getJsonDatatypeFromDatatypeIri(DatatypeIdImpl.DT_MONOLINGUAL_TEXT),
 				DatatypeIdImpl.JSON_DT_MONOLINGUAL_TEXT);
 	}
+
+	@Test
+	public void testIriForEdtf() {
+		assertEquals(
+				DatatypeIdImpl.getDatatypeIriFromJsonDatatype(DatatypeIdImpl.JSON_DT_EDTF),
+				DatatypeIdValue.DT_EDTF);
+	}
 }