-
Notifications
You must be signed in to change notification settings - Fork 4
/
RetrieveGraphModule.java
73 lines (58 loc) · 2.39 KB
/
RetrieveGraphModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cz.cvut.spipes.modules;
import cz.cvut.spipes.constants.KBSS_MODULE;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.engine.ExecutionContextFactory;
import cz.cvut.spipes.impl.GraphChunkedDownload;
import cz.cvut.spipes.modules.annotations.SPipesModule;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SPipesModule(label = "sparql endpoint retrieve graph", comment = "Load namedGraphId from sparql endpoint at endpointUrl.")
public class RetrieveGraphModule extends AnnotatedAbstractModule {
private static final Logger LOG = LoggerFactory.getLogger(RetrieveGraphModule.class);
protected static final String TYPE_URI = KBSS_MODULE.uri + "sparql-endpoint-retrieve-graph";
private static final String TYPE_PREFIX = TYPE_URI + "/";
private static final int DEFAULT_PAGE_SIZE = 10000;
@Parameter(urlPrefix = TYPE_PREFIX, name = "named-graph-id")
private String namedGraphId;
@Parameter(urlPrefix = TYPE_PREFIX, name = "endpoint-url")
private String endpointUrl;
@Parameter(urlPrefix = TYPE_PREFIX, name = "page-size")
private Integer pageSize = DEFAULT_PAGE_SIZE;
public String getNamedGraphId() {
return namedGraphId;
}
public void setNamedGraphId(String namedGraphId) {
this.namedGraphId = namedGraphId;
}
public String getTypeURI() {
return TYPE_URI;
}
public String getEndpointUrl() {
return endpointUrl;
}
public void setEndpointUrl(String endpointUrl) {
this.endpointUrl = endpointUrl;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
@Override
ExecutionContext executeSelf() {
Model outputModel = ModelFactory.createDefaultModel();
GraphChunkedDownload downloader = new GraphChunkedDownload(endpointUrl, namedGraphId, pageSize) {
@Override
protected void processPartialModel(Model partialModel) {
LOG.trace("persisting partial download, {} triples from (<{}>,<{}>)",
partialModel.size(), endpointUrl, namedGraphId);
outputModel.add(partialModel);
}
};
downloader.execute();
return ExecutionContextFactory.createContext(outputModel);
}
}