我正在尝试创建一个抽象存储库,用于在Allegro Graph上进行联邦搜索。我能够连接到存储在不同服务器上的存储库。但是,当我尝试使用federate组合它们时,它会抛出一个错误,它无法在第二台服务器上找到repo。有没有办法将存储在不同服务器上的两个存储库合并到一个可以进行联邦搜索的抽象存储库中?
AGServer server = new AGServer(SERVER_URL1, USERNAME1, PASSWORD1);
AGRepository repo1 = server.getRootCatalog().openRepository(REPO1);
AGServer server2 = new AGServer(SERVER_URL2, USERNAME2, PASSWORD2);
AGRepository repo2 = server2.getRootCatalog().openRepository(REPO2);
System.out.println(repo1.getConnection().size());
System.out.println(repo2.getConnection().size());
AGAbstractRepository combinedRepo = server.federate(repo1, repo2);
combinedRepo.initialize();
combinedRepo.getConnection(); //this return an exception
Exception in thread "main" org.openrdf.repository.RepositoryException: org.openrdf.repository.RepositoryException: Repository not found with ID: REPO2
at com.franz.agraph.repository.AGCatalog.openRepository(AGCatalog.java:264)
...
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.openrdf.repository.RepositoryException: Repository not found with ID: REPO2
at com.franz.agraph.repository.AGCatalog.openRepository(AGCatalog.java:260)
... 6 more
TIA
答案 0 :(得分:1)
Sesame框架支持Federation Sail
,您可以使用它将几个Sesame存储库(位于不同的服务器/位置)包装到一个虚拟存储中。您可以尝试使用它而不是使用Allegrograph的定制联合代码(它似乎仅适用于单个服务器上的多个存储库):
// create your AG repositories the same way
AGServer server = new AGServer(SERVER_URL1, USERNAME1, PASSWORD1);
AGRepository repo1 = server.getRootCatalog().openRepository(REPO1);
AGServer server2 = new AGServer(SERVER_URL2, USERNAME2, PASSWORD2);
AGRepository repo2 = server2.getRootCatalog().openRepository(REPO2);
// Use a Sesame Federation to combine them
org.openrdf.sail.federation.Federation federation = new Federation();
federation.addMember(repo1);
federation.addMember(repo2);
federation.setReadOnly(true); // assuming you only use it for query
Repository combinedRepo = new SailRepository(federation);
combinedRepo.initialize();
(ObDisclaimer:上面的代码是从我的头顶写的,我可能忽略了一个必要的配置细节来实现这一点 - 但你希望得到这个要点)
另一种方法是通过SERVICE子句使用SPARQL对联合的支持。这将要求您要查询的每个存储库都可以通过HTTP作为SPARQL端点访问。
答案 1 :(得分:0)
我能够使用Allegro Graph的AGServer创建一个联合存储库。以下是我为那些可能会发现有用的人做的事情:
AGVirtualRepository s = server2.virtualRepository("<http://<ip address>:10035/repositories/repo1> + <http://<ip address>:10035/repositories/repo2>");
AGRepositoryConnection combinedConn = s.getConnection();