1
|
package eu.dnetlib.parthenos.catalogue;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import eu.dnetlib.parthenos.CRM;
|
6
|
import eu.dnetlib.parthenos.CRMdig;
|
7
|
import eu.dnetlib.parthenos.CRMpe;
|
8
|
import eu.dnetlib.parthenos.rdf.ResourceReader;
|
9
|
import org.apache.commons.io.IOUtils;
|
10
|
import org.apache.jena.ontology.OntModel;
|
11
|
import org.apache.jena.ontology.OntModelSpec;
|
12
|
import org.apache.jena.rdf.model.InfModel;
|
13
|
import org.apache.jena.rdf.model.ModelFactory;
|
14
|
import org.apache.jena.rdf.model.ResIterator;
|
15
|
import org.apache.jena.rdf.model.Resource;
|
16
|
import org.apache.jena.vocabulary.RDF;
|
17
|
import org.junit.Before;
|
18
|
import org.junit.Test;
|
19
|
import org.springframework.core.io.ClassPathResource;
|
20
|
|
21
|
/**
|
22
|
* Created by Alessia Bardi on 11/12/2017.
|
23
|
*
|
24
|
* @author Alessia Bardi
|
25
|
*/
|
26
|
public class CatalogueRegistratorTest {
|
27
|
|
28
|
private CatalogueRegistrator reg;
|
29
|
private ResourceReader reader = new ResourceReader();
|
30
|
|
31
|
private String nakalaService = "eu/dnetlib/parthenos/registry/nakala.rdf";
|
32
|
private String test = "eu/dnetlib/parthenos/registry/test.rdf";
|
33
|
private String noRiot = "eu/dnetlib/parthenos/registry/sampleNoRiot.rdf";
|
34
|
|
35
|
private OntModel baseModel;
|
36
|
|
37
|
@Before
|
38
|
public void setup() {
|
39
|
reg = new CatalogueRegistrator();
|
40
|
reg.setResourceReader(reader);
|
41
|
baseModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
|
42
|
baseModel.read(CRMpe.RDFS_URL);
|
43
|
baseModel.read(CRM.RDFS_URL);
|
44
|
baseModel.read(CRMdig.RDFS_URL);
|
45
|
}
|
46
|
|
47
|
@Test
|
48
|
public void readModel() throws IOException {
|
49
|
String resource = getString(noRiot);
|
50
|
InfModel model = loadBaseModel();
|
51
|
model.read(IOUtils.toInputStream(resource, "UTF-8"), CRMpe.NS);
|
52
|
}
|
53
|
@Test
|
54
|
public void testGetJsonForActivity() throws Exception{
|
55
|
String resource = getString(nakalaService);
|
56
|
InfModel model = loadBaseModel();
|
57
|
model.read(IOUtils.toInputStream(resource, "UTF-8"), CRMpe.NS);
|
58
|
ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
|
59
|
while (subjects.hasNext()) {
|
60
|
Resource subject = subjects.nextResource();
|
61
|
String json = reg.getJsonForActivity(subject, "testCatName");
|
62
|
System.out.println(json);
|
63
|
}
|
64
|
}
|
65
|
|
66
|
@Test
|
67
|
public void testGetJsonForActor() throws Exception{
|
68
|
String resource = getString(test);
|
69
|
InfModel model = loadBaseModel();
|
70
|
model.read(IOUtils.toInputStream(resource, "UTF-8"), CRMpe.NS);
|
71
|
ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E39_Actor);
|
72
|
while (subjects.hasNext()) {
|
73
|
Resource subject = subjects.nextResource();
|
74
|
String json = reg.getJsonForActor(subject, "testActorName");
|
75
|
System.out.println(json);
|
76
|
}
|
77
|
}
|
78
|
|
79
|
|
80
|
private String getString(final String classpath) {
|
81
|
try {
|
82
|
final ClassPathResource resource = new ClassPathResource(classpath);
|
83
|
return IOUtils.toString(resource.getInputStream(), "UTF-8");
|
84
|
}catch(IOException e){
|
85
|
return null;
|
86
|
}
|
87
|
}
|
88
|
|
89
|
protected InfModel loadBaseModel() {
|
90
|
return ModelFactory.createRDFSModel(baseModel);
|
91
|
}
|
92
|
|
93
|
}
|