use of uk.ac.rothamsted.rdf.neo4j.load.support.CypherIndexer in project rdf2neo by Rothamsted.
the class SimpleCyLoader method load.
/**
* <p>Uses the {@link #getCyNodeLoader()} and {@link #getCyRelationLoader()} to map data from an RDF/TDB
* data source into Cypher entities and load them into a pre-configured Neo4j server.</p>
*
* <p>
* opts [ 0 ] = true, means process Cypher nodes.<br/>
* opts [ 1 ] = true, means process Cypher relations.<br/>
* opts [ 2 ] = true, means process Cypher indices (if {@link #getCypherIndexer()} is defined).<br/>
* </p>
*
* <p>I opts is null, all the three operations above are run in the same sequence.</p>
*
* <p>Nodes are always loaded before relations, indices are created the end of all other operations
* this simplify relation DDL creation commands.</p>
*/
@Override
public void load(String tdbPath, Object... opts) {
try {
RdfDataManager rdfMgr = this.getRdfDataManager();
rdfDataManager.open(tdbPath);
Dataset ds = rdfMgr.getDataSet();
String[] nameStr = { StringUtils.trimToEmpty(this.getName()) };
if (!nameStr[0].isEmpty())
nameStr[0] = "[" + nameStr[0] + "] ";
Txn.executeRead(ds, () -> log.info("{}Sending {} RDF triples to Cypher", nameStr[0], ds.getDefaultModel().size()));
// Nodes
boolean doNodes = opts != null && opts.length > 0 ? (Boolean) opts[0] : true;
if (doNodes)
this.getCyNodeLoader().process(rdfMgr, opts);
// Relations
boolean doRels = opts != null && opts.length > 1 ? (Boolean) opts[1] : true;
if (doRels)
this.getCyRelationLoader().process(rdfMgr, opts);
// User-defined indices
boolean doIdx = opts != null && opts.length > 2 ? (Boolean) opts[2] : true;
if (doIdx) {
CypherIndexer indexer = this.getCypherIndexer();
if (indexer != null)
indexer.index();
}
log.info("{}RDF-Cypher conversion finished", nameStr[0]);
} catch (Exception ex) {
throw new RuntimeException("Error while running the RDF/Cypher loader:" + ex.getMessage(), ex);
}
}
Aggregations