我正在从网络加载一个RDF rump作为InputStream,它包含120到1500三元组。平均而言,清除上下文大约需要半秒钟,而添加三元组需要大约74秒才能获得120个三元组。 RDFXML序列化的物理文件大小介于6KB和195KB之间。
InputStream input = ...
try (RepositoryConnection conn = db.getConnection()) {
try {
conn.clear(context);
conn.add(input, "", RDFFormat.RDFXML, context);
} catch (Exception e) {
e.printStackTrace();
}
}
存储库初始化如下:
RemoteRepositoryManager manager = new RemoteRepositoryManager(serverUrl);
manager.initialize();
db = manager.getRepository("repo");
答案 0 :(得分:3)
您可以尝试以下方法:
Repository repo = new SailRepository(new MemoryStore());
-Xmx
为您的Java应用提供足够的内存
conn.clear(context);
的目的是什么。根据我的理解it will remove all triples in the context?从我的位置开始,它持续大约5分钟,从wikidata加载10,000,000三倍的2.7G rdf转储到内存中的回购(我使用export MAVEN_OPTS=-Xmx7000m
进行maven测试)。这使得每秒约33333个三倍 - 如果我计算得对;-)。
@Test
public void variant3() throws MalformedURLException, IOException {
Repository repo = new SailRepository(new MemoryStore());
repo.initialize();
IRI context = repo.getValueFactory().createIRI("info/mycontext:context1");
RDFFormat format = RDFFormat.NTRIPLES;
System.out.println("Load zip file of format " + format);
try (InputStream in = new URL(
"https://tools.wmflabs.org/wikidata-exports/rdf/exports/20160801/wikidata-terms.nt.gz")
.openConnection().getInputStream();
NotifyingRepositoryConnectionWrapper con = new NotifyingRepositoryConnectionWrapper(repo,
repo.getConnection());) {
RepositoryConnectionListenerAdapter myListener = new RepositoryConnectionListenerAdapter() {
private long count = 0;
@Override
public void add(RepositoryConnection arg0, Resource arg1, IRI arg2, Value arg3, Resource... arg4) {
count++;
if (count % 100000 == 0)
System.out.println("Add statement number " + count + "\n" + arg1 + " " + arg2 + " " + arg3);
}
};
con.addRepositoryConnectionListener(myListener);
con.add(in, "", format,context);
} catch (Exception e) {
throw new RuntimeException(e);
}
}