1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package org.bgbm.biovel.drf.store;
|
11
|
|
12
|
import java.io.File;
|
13
|
|
14
|
import org.openrdf.repository.sail.SailRepository;
|
15
|
import org.openrdf.sail.Sail;
|
16
|
import org.openrdf.sail.SailException;
|
17
|
|
18
|
import com.tinkerpop.blueprints.Graph;
|
19
|
import com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph;
|
20
|
import com.tinkerpop.blueprints.oupls.sail.GraphSail;
|
21
|
import com.tinkerpop.blueprints.oupls.sail.SailLoader;
|
22
|
import com.tinkerpop.gremlin.java.GremlinPipeline;
|
23
|
|
24
|
/**
|
25
|
* @author a.kohlbecker
|
26
|
* @date Oct 19, 2015
|
27
|
*
|
28
|
*/
|
29
|
public class Neo4jStore extends Store{
|
30
|
|
31
|
private Neo4jGraph graph;
|
32
|
private Sail sail;
|
33
|
private SailRepository sailRepo;
|
34
|
|
35
|
/**
|
36
|
* @throws Exception
|
37
|
*/
|
38
|
public Neo4jStore() throws Exception {
|
39
|
super();
|
40
|
}
|
41
|
|
42
|
|
43
|
/**
|
44
|
* {@inheritDoc}
|
45
|
* @throws SailException
|
46
|
*/
|
47
|
@Override
|
48
|
protected void initStoreEngine() throws Exception {
|
49
|
|
50
|
graph = new Neo4jGraph(storeLocation.toString());
|
51
|
sail = new GraphSail<Neo4jGraph>(graph);
|
52
|
sail.initialize();
|
53
|
sailRepo = new SailRepository(sail);
|
54
|
|
55
|
// logger.info("Using Neo4jGraph store at " + storeLocation.toString());
|
56
|
// logger.info("Neo4jGraph has " + sizeInfo());
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* {@inheritDoc}
|
61
|
*/
|
62
|
@Override
|
63
|
protected void stopStoreEngine() throws Exception {
|
64
|
sailRepo.shutDown();
|
65
|
sail.shutDown(); // should be none by the above command already
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* @throws Exception
|
70
|
*
|
71
|
*/
|
72
|
@Override
|
73
|
protected void load(File rdfFile) throws Exception {
|
74
|
|
75
|
SailLoader loader = new SailLoader(sail);
|
76
|
// loader.setBufferSize(100000); // TODO optimize?
|
77
|
logger.info("loading RDF/XML into Neo4jGraph store");
|
78
|
loader.load(rdfFile);
|
79
|
logger.info("loading RDF/XML done");
|
80
|
logger.info("Neo4jGraph has " + sizeInfo());
|
81
|
|
82
|
logger.info("rdf loaded into Neo4jGraph store at " + storeLocation);
|
83
|
}
|
84
|
|
85
|
|
86
|
private long countEdges() {
|
87
|
GremlinPipeline<Neo4jGraph, Object> pipe = new GremlinPipeline<Neo4jGraph, Object>();
|
88
|
return pipe.start(graph).E().count();
|
89
|
}
|
90
|
|
91
|
private long countVertexes() {
|
92
|
GremlinPipeline<Neo4jGraph, Object> pipe = new GremlinPipeline<Neo4jGraph, Object>();
|
93
|
return pipe.start(graph).V().count();
|
94
|
}
|
95
|
|
96
|
public String sizeInfo() {
|
97
|
return countEdges() + " edges, " + countVertexes() + " vertexes";
|
98
|
}
|
99
|
|
100
|
|
101
|
/**
|
102
|
* {@inheritDoc}
|
103
|
*/
|
104
|
@Override
|
105
|
protected String storeName() {
|
106
|
return "neo4j";
|
107
|
}
|
108
|
|
109
|
public Graph graph() {
|
110
|
return graph;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* @return the sailRepo
|
115
|
*/
|
116
|
public SailRepository getSailRepo() {
|
117
|
return sailRepo;
|
118
|
}
|
119
|
|
120
|
|
121
|
}
|