Add serialization tests for Wikidata schema
This commit is contained in:
parent
a609d3786d
commit
497505eef1
@ -0,0 +1 @@
|
||||
{"itemDocuments":[{"subject":{"type":"wbitemvariable","columnName":"name"},"statementGroups":[{"property":{"datatype":"wikibase-item","pid":"P39","label":"position held","type":"wbpropconstant"},"statements":[{"value":{"type":"wbitemconstant","qid":"Q30461","label":"president"},"qualifiers":[{"prop":{"datatype":"wikibase-item","pid":"P642","label":"of","type":"wbpropconstant"},"value":{"label":"History of Medicine Society","type":"wbitemconstant","qid":"Q37461404"}},{"prop":{"datatype":"time","pid":"P580","label":"start date","type":"wbpropconstant"},"value":{"type":"wbdatevariable","columnName":"start"}},{"prop":{"datatype":"time","pid":"P582","label":"end date","type":"wbpropconstant"},"value":{"type":"wbdatevariable","columnName":"end"}}],"references":[{"snaks":[{"prop":{"datatype":"wikibase-item","pid":"P248","label":"stated in","type":"wbpropconstant"},"value":{"label":"The History of The Royal Society of Medicine","type":"wbitemconstant","qid":"Q42036099"}},{"prop":{"datatype":"string","pid":"P304","label":"page","type":"wbpropconstant"},"value":{"type":"wbstringconstant","value":"330-333"}}]}]}]}],"nameDescs":[]},{"subject":{"label":"History of Medicine Society","type":"wbitemconstant","qid":"Q37461404"},"statementGroups":[{"property":{"datatype":"wikibase-item","pid":"P488","label":"chairperson","type":"wbpropconstant"},"statements":[{"value":{"type":"wbitemvariable","columnName":"name"},"qualifiers":[{"prop":{"datatype":"time","pid":"P580","label":"start date","type":"wbpropconstant"},"value":{"type":"wbdatevariable","columnName":"start"}},{"prop":{"datatype":"time","pid":"P582","label":"end date","type":"wbpropconstant"},"value":{"type":"wbdatevariable","columnName":"end"}}],"references":[{"snaks":[{"prop":{"datatype":"wikibase-item","pid":"P248","label":"stated in","type":"wbpropconstant"},"value":{"label":"The History of The Royal Society of Medicine","type":"wbitemconstant","qid":"Q42036099"}},{"prop":{"datatype":"string","pid":"P304","label":"page","type":"wbpropconstant"},"value":{"type":"wbstringconstant","value":"330-333"}}]}]}]}],"nameDescs":[]}],"wikibasePrefix":"http://www.wikidata.org/entity/"}
|
1
extensions/wikidata/tests/data/schema/roarmap.json
Normal file
1
extensions/wikidata/tests/data/schema/roarmap.json
Normal file
@ -0,0 +1 @@
|
||||
{"itemDocuments":[{"type":"wbitemdocument","subject":{"type":"wbitemvariable","columnName":"oapolicy_name"},"nameDescs":[{"type":"wbnamedescexpr","name_type":"LABEL","value":{"type":"wbmonolingualexpr","language":{"type":"wblanguageconstant","id":"en","label":"en"},"value":{"type":"wbstringvariable","columnName":"oapolicy_name"}}}],"statementGroups":[{"type":"wbstatementgroupexpr","property":{"type":"wbpropconstant","pid":"P4203","label":"ROARMAP ID","datatype":"external-id"},"statements":[{"type":"wbstatementexpr","value":{"type":"wbstringvariable","columnName":"roarmap_id"},"qualifiers":[],"references":[]}]},{"type":"wbstatementgroupexpr","property":{"type":"wbpropconstant","pid":"P1891","label":"signatory","datatype":"wikibase-item"},"statements":[{"type":"wbstatementexpr","value":{"type":"wbitemvariable","columnName":"eprint - title"},"qualifiers":[],"references":[{"type":"wbreferences","snaks":[{"prop":{"type":"wbpropconstant","pid":"P4203","label":"ROARMAP ID","datatype":"external-id"},"value":{"type":"wbstringvariable","columnName":"roarmap_id"}},{"prop":{"type":"wbpropconstant","pid":"P813","label":"retrieved","datatype":"time"},"value":{"type":"wbdateconstant","value":"2017-09-18"}}]}]}]},{"type":"wbstatementgroupexpr","property":{"type":"wbpropconstant","pid":"P571","label":"inception","datatype":"time"},"statements":[{"type":"wbstatementexpr","value":{"type":"wbdatevariable","columnName":"eprint - policy_adoption"},"qualifiers":[],"references":[{"type":"wbreferences","snaks":[{"prop":{"type":"wbpropconstant","pid":"P4203","label":"ROARMAP ID","datatype":"external-id"},"value":{"type":"wbstringvariable","columnName":"roarmap_id"}},{"prop":{"type":"wbpropconstant","pid":"P813","label":"retrieved","datatype":"time"},"value":{"type":"wbdateconstant","value":"2017-09-18"}}]}]}]},{"type":"wbstatementgroupexpr","property":{"type":"wbpropconstant","pid":"P31","label":"instance of","datatype":"wikibase-item"},"statements":[{"type":"wbstatementexpr","value":{"type":"wbitemconstant","qid":"Q2000006","label":"open access policy"},"qualifiers":[],"references":[{"type":"wbreferences","snaks":[{"prop":{"type":"wbpropconstant","pid":"P4203","label":"ROARMAP ID","datatype":"external-id"},"value":{"type":"wbstringvariable","columnName":"roarmap_id"}},{"prop":{"type":"wbpropconstant","pid":"P813","label":"retrieved","datatype":"time"},"value":{"type":"wbdateconstant","value":"2017-09-18"}}]}]}]},{"type":"wbstatementgroupexpr","property":{"type":"wbpropconstant","pid":"P953","label":"full work available at","datatype":"url"},"statements":[{"type":"wbstatementexpr","value":{"type":"wbstringvariable","columnName":"first_policy_url"},"qualifiers":[],"references":[{"type":"wbreferences","snaks":[{"prop":{"type":"wbpropconstant","pid":"P4203","label":"ROARMAP ID","datatype":"external-id"},"value":{"type":"wbstringvariable","columnName":"roarmap_id"}},{"prop":{"type":"wbpropconstant","pid":"P813","label":"retrieved","datatype":"time"},"value":{"type":"wbdateconstant","value":"2017-09-18"}}]}]}]}]}]}
|
@ -0,0 +1,32 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
public class SchemaSerializationTest {
|
||||
|
||||
static JSONObject jsonFromFile(String filename) throws IOException, JSONException {
|
||||
byte[] contents = Files.readAllBytes(Paths.get(filename));
|
||||
String decoded = new String(contents, "utf-8");
|
||||
return ParsingUtilities.evaluateJsonStringToObject(decoded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializeHistoryOfMedicine() throws JSONException, IOException {
|
||||
JSONObject serialized = jsonFromFile("data/schema/history_of_medicine.json");
|
||||
WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializeROARMAP() throws JSONException, IOException {
|
||||
JSONObject serialized = jsonFromFile("data/schema/roarmap.json");
|
||||
WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user