This commit is contained in:
Alessia Bardi 2020-09-07 15:01:00 +02:00
parent 19ebb63d88
commit 38a2ab747e
3 changed files with 532 additions and 2 deletions

View File

@ -1,9 +1,76 @@
package eu.dnetlib.ariadneplus.eu.dnetlib.ariadneplus.reader.json;
package eu.dnetlib.ariadneplus.reader.json;
import eu.dnetlib.ariadneplus.reader.ResourceManager;
import eu.dnetlib.ariadneplus.reader.utils.PropertiesMap;
import net.minidev.json.parser.ParseException;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@Test
public class ParseRDFJsonTest {
ParseRDFJSON parser;
ResourceManager mng;
String spec = getFromClasspath("eu/dnetlib/ariadneplus/reader/json/spec.json");
@Before
public void setup(){
parser = new ParseRDFJSON();
parser.setCatalogEntryCollectionJsonPath("$[*][?(@['https://www.ariadne-infrastructure.eu/property/resourceType'][0]['value']=='Dataset Collection')]");
parser.setCatalogEntryJsonPath("$[*][?(@['https://www.ariadne-infrastructure.eu/property/resourceType'][0]['value']=='provided record')]");
mng = new ResourceManager();
mng.setup("https://www.ariadne-infrastructure.eu/property/resourceType", "eu.dnetlib.ariadneplus.elasticsearch.model.",
"[\"https://www.ariadne-infrastructure.eu/property/resourceType\", \"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\"]",
spec);
}
@Test
public void testParseCollectionJson() throws ParseException {
String collectionJson = getFromClasspath("eu/dnetlib/ariadneplus/reader/json/collection.json");
parser.setCollection(true);
int res = parser.parse(collectionJson);
Assert.assertNotEquals(-1, res);
while(parser.hasNextElement()){
System.out.println(parser.getNextElement());
}
}
@Test
public void testParseEmptyJson() throws ParseException {
String collectionJson = "{}";
parser.setCollection(true);
parser.parse(collectionJson);
int res = parser.parse(collectionJson);
Assert.assertEquals(-1, res);
while(parser.hasNextElement()){
System.out.println(parser.getNextElement());
}
}
@Test
public void testResourceManager() throws ParseException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
String collectionJson = getFromClasspath("eu/dnetlib/ariadneplus/reader/json/collection.json");
parser.setCollection(true);
int res = parser.parse(collectionJson);
Assert.assertNotEquals(-1, res);
mng.manage(parser);
if(mng.hasNext())
System.out.println(mng.next());
}
private String getFromClasspath(String s) {
try {
final ClassPathResource resource = new ClassPathResource(s);
return IOUtils.toString(resource.getInputStream(), "UTF-8");
}catch(IOException e){
return null;
}
}
}

View File

@ -0,0 +1,163 @@
{
"https://ariadne-infrastructure.eu/aocat/Agent/NOTPROVIDED" : {
"https://www.ariadne-infrastructure.eu/property/name" : [
{
"value" : "Not provided",
"type" : "literal",
"datatype" : "http://www.w3.org/2001/XMLSchema#string"
}
]
},
"https://ariadne-infrastructure.eu/aocat/Collection/HNM/8ECF8A71-260D-3372-9BD4-B78E9F32244B" : {
"https://www.ariadne-infrastructure.eu/property/accessRights" : [
{
"value" : "registered access",
"type" : "literal",
"lang" : "en"
},
{
"value" : "researchers",
"type" : "literal",
"lang" : "en"
}
],
"https://www.ariadne-infrastructure.eu/property/archeologicalResourceType" : [
{
"value" : "https://ariadne-infrastructure.eu/aocat/Concept/AO_Subject/Fieldwork",
"type" : "uri"
}
],
"https://www.ariadne-infrastructure.eu/property/contributor" : [
{
"value" : "https://ariadne-infrastructure.eu/aocat/Person/Toldi%2C%20Zolt%C3%A1n%20-%20archaeologist",
"type" : "uri"
}
],
"https://www.ariadne-infrastructure.eu/property/creator" : [
{
"value" : "https://ariadne-infrastructure.eu/aocat/Agent/NOTPROVIDED",
"type" : "uri"
}
],
"https://www.ariadne-infrastructure.eu/property/identifier" : [
{
"value" : "https://ariadne-infrastructure.eu/aocat/Collection/HNM/8ECF8A71-260D-3372-9BD4-B78E9F32244B",
"type" : "uri"
}
],
"https://www.ariadne-infrastructure.eu/property/issued" : [
{
"value" : "2013-03-13",
"type" : "literal",
"datatype" : "http://www.w3.org/2001/XMLSchema#dateTime"
}
],
"https://www.ariadne-infrastructure.eu/property/landingPage" : [
{
"value" : "http://archeodatabase.hnm.hu/en/node/29614",
"type" : "literal",
"datatype" : "http://www.w3.org/2001/XMLSchema#string"
}
],
"https://www.ariadne-infrastructure.eu/property/language" : [
{
"value" : "en",
"type" : "literal",
"datatype" : "http://www.w3.org/2001/XMLSchema#string"
}
],
"https://www.ariadne-infrastructure.eu/property/legalResponsible" : [
{
"value" : "https://ariadne-infrastructure.eu/aocat/Agent/NOTPROVIDED",
"type" : "uri"
}
],
"https://www.ariadne-infrastructure.eu/property/modified" : [
{
"value" : "2013-03-13",
"type" : "literal",
"datatype" : "http://www.w3.org/2001/XMLSchema#dateTime"
}
],
"https://www.ariadne-infrastructure.eu/property/originalId" : [
{
"value" : "84171",
"type" : "literal",
"lang" : "en"
}
],
"https://www.ariadne-infrastructure.eu/property/owner" : [
{
"value" : "https://ariadne-infrastructure.eu/aocat/Agent/NOTPROVIDED",
"type" : "uri"
}
],
"https://www.ariadne-infrastructure.eu/property/publisher" : [
{
"value" : "https://ariadne-infrastructure.eu/aocat/Organisation/HNM",
"type" : "uri"
}
],
"https://www.ariadne-infrastructure.eu/property/resourceType" : [
{
"value" : "Dataset Collection",
"type" : "literal",
"datatype" : "http://www.w3.org/2001/XMLSchema#string"
}
],
"https://www.ariadne-infrastructure.eu/property/spatialRegion" : [
{
"value" : "https://ariadne-infrastructure.eu/aocat/Place/2DEF4AF1-D07E-35E0-AE5F-1E36EB258BD5",
"type" : "uri"
}
],
"https://www.ariadne-infrastructure.eu/property/title" : [
{
"value" : "Darvasi-tábla",
"type" : "literal",
"lang" : "hu"
},
{
"value" : "Nagyhalász, Darvasi-tábla",
"type" : "literal",
"lang" : "hu"
}
]
},
"https://ariadne-infrastructure.eu/aocat/Concept/AO_Subject/Fieldwork" : {
"https://www.ariadne-infrastructure.eu/property/name" : [
{
"value" : "Fieldwork",
"type" : "literal",
"lang" : "en"
}
]
},
"https://ariadne-infrastructure.eu/aocat/Organisation/HNM" : {
"https://www.ariadne-infrastructure.eu/property/name" : [
{
"value" : "HNM",
"type" : "literal",
"lang" : "hu"
}
]
},
"https://ariadne-infrastructure.eu/aocat/Person/Toldi%2C%20Zolt%C3%A1n%20-%20archaeologist" : {
"https://www.ariadne-infrastructure.eu/property/name" : [
{
"value" : "Toldi, Zoltán - archaeologist",
"type" : "literal",
"lang" : "hu"
}
]
},
"https://ariadne-infrastructure.eu/aocat/Place/2DEF4AF1-D07E-35E0-AE5F-1E36EB258BD5" : {
"https://www.ariadne-infrastructure.eu/property/placeName" : [
{
"value" : "Szabolcs-Szatmár-Bereg",
"type" : "literal",
"lang" : "en"
}
]
}
}

View File

@ -0,0 +1,300 @@
{
"AriadneTemporal": {
"class_type": "prototype",
"mappings": {
"https://www.ariadne-infrastructure.eu/property/from": {
"class_field": "From",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/periodName": {
"class_field": "PeriodName",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/until": {
"class_field": "Until",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/uri": {
"class_field": "Uri",
"substring": "no",
"element_type": "java.lang.String"
}
}
},
"AriadneGeoPoint": {
"class_type": "unique",
"mappings": {
"https://www.ariadne-infrastructure.eu/property/lat": {
"class_field": "Lat",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/lon": {
"class_field": "Lon",
"substring": "no",
"element_type": "java.lang.String"
}
}
},
"Spatial": {
"class_type": "prototype",
"mappings":{"https://www.ariadne-infrastructure.eu/property/address": {
"class_field": "Address",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/coordinateSystem": {
"class_field": "CoordinateSystem",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/country": {
"class_field": "Country",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/location": {
"class_field": "Location",
"external_reference": "AriadneGeoPoint",
"substring": "no"
},
"https://www.ariadne-infrastructure.eu/property/lat": {
"class_field": "Lat",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/lon": {
"class_field": "Lon",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/placeName": {
"class_field": "PlaceName",
"substring": "no",
"element_type": "java.lang.String"
}}
},
"ArchaeologicalResourceType": {
"class_type": "unique",
"mappings": {
"https://www.ariadne-infrastructure.eu/property/id": {
"class_field": "Id",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/name": {
"class_field": "Name",
"substring": "no",
"element_type": "java.lang.String"
}
}
},
"AgentInfo": {
"class_type": "prototype",
"mappings": {
"https://www.ariadne-infrastructure.eu/property/name": {
"class_field": "Name",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/type": {
"class_field": "Type",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/email": {
"class_field": "Email",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/phone": {
"class_field": "Phone",
"substring": "no",
"element_type": "java.lang.String"
}
}
},
"NativeSubject": {
"class_type": "prototype",
"mappings": {
"https://www.ariadne-infrastructure.eu/property/prefLabel": {
"class_field": "PrefLabel",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/rdfAbout": {
"class_field": "RdfAbout",
"substring": "yes",
"element_type": "java.lang.String"
}
}
},
"DerivedSubject": {
"class_type": "prototype",
"mappings": {
"https://www.ariadne-infrastructure.eu/property/prefLabel": {
"class_field": "PrefLabel",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/source": {
"class_field": "Source",
"substring": "yes",
"element_type": "java.lang.String"
}
}
},
"AatSubject": {
"class_type": "prototype",
"mappings": {
"https://www.ariadne-infrastructure.eu/property/id": {
"class_field": "Id",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/label": {
"class_field": "Label",
"substring": "yes",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/lang": {
"class_field": "Lang",
"substring": "yes",
"element_type": "java.lang.String"
}
}
},
"AriadneCatalogEntry": {
"class_type": "unique",
"mappings": {
"https://www.ariadne-infrastructure.eu/property/accessPolicy": {
"class_field": "AccessPolicy",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/identifier": {
"class_field": "Identifier",
"substring": "yes",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/publisher": {
"class_field": "Publisher",
"external_reference": "AgentInfo",
"substring": "no"
},
"https://www.ariadne-infrastructure.eu/property/archeologicalResourceType": {
"class_field": "ArchaeologicalResourceType",
"external_reference": "ArchaeologicalResourceType",
"substring": "no"
},
"https://www.ariadne-infrastructure.eu/property/issued": {
"class_field": "Issued",
"element_type": "java.lang.String",
"substring": "no"
},
"https://www.ariadne-infrastructure.eu/property/resourceType": {
"class_field": "ResourceType",
"element_type": "java.lang.String",
"substring": "no"
},
"https://www.ariadne-infrastructure.eu/property/modified": {
"class_field": "Modified",
"element_type": "java.lang.String",
"substring": "no"
},
"https://www.ariadne-infrastructure.eu/property/nativeSubject": {
"class_field": "NativeSubject",
"substring": "no",
"external_reference": "NativeSubject"
},
"https://www.ariadne-infrastructure.eu/property/derivedSubject": {
"class_field": "DerivedSubject",
"substring": "no",
"external_reference": "DerivedSubject"
},
"https://www.ariadne-infrastructure.eu/property/aatSubjects": {
"class_field": "AatSubjects",
"substring": "no",
"external_reference": "AatSubject"
},
"https://www.ariadne-infrastructure.eu/property/spatialRegion": {
"class_field": "Spatial",
"substring": "no",
"external_reference": "Spatial"
},
"https://www.ariadne-infrastructure.eu/property/spatialRegionPoint": {
"class_field": "Spatial",
"substring": "no",
"external_reference": "Spatial"
},
"https://www.ariadne-infrastructure.eu/property/landingPage": {
"class_field": "LandingPage",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/placeName": {
"class_field": "PlaceName",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/title": {
"class_field": "Title",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/accessRights": {
"class_field": "AccessRights",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/description": {
"class_field": "Description",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/creator": {
"class_field": "Creator",
"substring": "no",
"external_reference": "AgentInfo"
},
"https://www.ariadne-infrastructure.eu/property/contributor": {
"class_field": "Contributor",
"substring": "no",
"external_reference": "AgentInfo"
},
"https://www.ariadne-infrastructure.eu/property/legalResponsible": {
"class_field": "LegalResponsible",
"substring": "no",
"external_reference": "AgentInfo"
},
"https://www.ariadne-infrastructure.eu/property/owner": {
"class_field": "Owner",
"substring": "no",
"external_reference": "AgentInfo"
},
"https://www.ariadne-infrastructure.eu/property/originalId": {
"class_field": "OriginalId",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/uri": {
"class_field": "Temporal",
"substring": "no",
"external_reference": "AriadneTemporal"
},
"https://www.ariadne-infrastructure.eu/property/language": {
"class_field": "Language",
"substring": "no",
"element_type": "java.lang.String"
},
"https://www.ariadne-infrastructure.eu/property/partOf": {
"class_field": "UniqueIsPartOf",
"substring": "no",
"element_type": "java.lang.String"
}
}
}
}