我有以下代码,这是从维基百科索引创建图表。此代码试图将Wikipedia图导入graph.db目录。
// 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();
}
}
但是,每次运行此代码时,我都会遇到以下错误。
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)
答案 0 :(得分:1)
基于这个javadoc https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/unsafe/batchinsert/BatchInserters.html
BatchInserters需要一个File,而不是“path / to / dir”字符串。您需要创建一个文件对象并将其传入。
代码: 在顶部添加导入。
import java.io.File
然后替换以下行
inserter = BatchInserters.inserter(dataDir);
用这个
inserter = BatchInserters.inserter(new File(dataDir));