I have the following code, this is to create a graph from Wikipedia index. This code is trying to import Wikipedia graph into a graph.db directory.
// Copyright (c) 2012 Mirko Nasato
//
package org.graphipedia.dataimport.neo4j;
import java.util.HashMap;
import java.util.Map;
import org.neo4j.unsafe.batchinsert.BatchInserter;
import org.neo4j.unsafe.batchinsert.BatchInserters;
public class ImportGraph {
private final BatchInserter inserter;
private final Map<String, Long> inMemoryIndex;
public ImportGraph(String dataDir) {
inserter = BatchInserters.inserter(dataDir);
inserter.createDeferredSchemaIndex(WikiLabel.Page).on("title").create();
inMemoryIndex = new HashMap<String, Long>();
}
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.out.println("USAGE: ImportGraph <input-file> <data-dir>");
System.exit(255);
}
String inputFile = args[0];
String dataDir = args[1];
ImportGraph importer = new ImportGraph(dataDir);
importer.createNodes(inputFile);
importer.createRelationships(inputFile);
importer.finish();
}
public void createNodes(String fileName) throws Exception {
System.out.println("Importing pages...");
NodeCreator nodeCreator = new NodeCreator(inserter, inMemoryIndex);
long startTime = System.currentTimeMillis();
nodeCreator.parse(fileName);
long elapsedSeconds = (System.currentTimeMillis() - startTime) / 1000;
System.out.printf("\n%d pages imported in %d seconds.\n", nodeCreator.getPageCount(), elapsedSeconds);
}
public void createRelationships(String fileName) throws Exception {
System.out.println("Importing links...");
RelationshipCreator relationshipCreator = new RelationshipCreator(inserter, inMemoryIndex);
long startTime = System.currentTimeMillis();
relationshipCreator.parse(fileName);
long elapsedSeconds = (System.currentTimeMillis() - startTime) / 1000;
System.out.printf("\n%d links imported in %d seconds; %d broken links ignored\n",
relationshipCreator.getLinkCount(), elapsedSeconds, relationshipCreator.getBadLinkCount());
}
public void finish() {
inserter.shutdown();
}
}
However, every time I run this code, I am running into the following error.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method inserter(File) in the type BatchInserters is not applicable for the arguments (String)
at org.graphipedia.dataimport.neo4j.ImportGraph.<init>(ImportGraph.java:36)
at org.graphipedia.dataimport.neo4j.ImportGraph.main(ImportGraph.java:48)
Based on this javadoc https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/unsafe/batchinsert/BatchInserters.html
BatchInserters needs a File, not "path/to/dir" string. You will need to create a file object and pass it in.
Code: Add an import at the top.
import java.io.File
Then replace the following line
inserter = BatchInserters.inserter(dataDir);
with this
inserter = BatchInserters.inserter(new File(dataDir));