1

我一直在尝试使用 RDF4J 在远程 GraphDB 服务器上创建一个新的存储库,但我遇到了问题。

这运行,但似乎不正确

HTTPRepositoryConfig implConfig = new HTTPRepositoryConfig(address);
RepositoryConfig repoConfig = new RepositoryConfig("test", "test", implConfig);
Model m = new

但是,根据我从工作台中的“编辑存储库”获得的信息,结果看起来不正确。除了 id 和 title 之外,所有值都是空的。

这失败了

我试图从我在工作台上创建的现有存储库中复制设置,但失败了:

org.eclipse.rdf4j.repository.config.RepositoryConfigException: 
                         Unsupported repository type: owlim:MonitorRepository

该尝试的代码受到此处找到的代码的启发。除了配置文件基于现有的 repo,如上所述。我还尝试配置示例中提供的文件,但也失败了:

org.eclipse.rdf4j.repository.config.RepositoryConfigException: 
       Unsupported Sail type: graphdb:FreeSail

有人有任何提示吗?

更新 正如 Henriette Harmse 正确指出的那样,我应该提供我的代码,而不是简单地链接到它。这样我可能会发现我根本没有完成完整的副本,而是更改了她在回答中指出的重要的第一部分。完整代码如下:

String address = "serveradr";
RemoteRepositoryManager repositoryManager = new RemoteRepositoryManager( address);
repositoryManager.initialize();

// Instantiate a repository graph model
TreeModel graph = new TreeModel();
InputStream config = Rdf4jHelper.class.getResourceAsStream("/repoconf2.ttl");
RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
rdfParser.setRDFHandler(new StatementCollector(graph));
rdfParser.parse(config, RepositoryConfigSchema.NAMESPACE);
config.close();

// Retrieve the repository node as a resource
Resource repositoryNode = graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY).subjects().iterator().next();

// Create a repository configuration object and add it to the repositoryManager
RepositoryConfig repositoryConfig = RepositoryConfig.create(graph, repositoryNode);

它在最后一行失败。

已回答@HenrietteHarmse在下面的答案中给出了正确的方法。该错误是由于缺少依赖项引起的。我应该使用 graphdb-free-runtime,而不是直接使用 RDF4J。

4

2 回答 2

1

这里有很多问题:

(1)RepositoryManager repositoryManager = new LocalRepositoryManager(new File("."));将在运行 Java 应用程序的地方创建一个存储库。

(2) 仅当 GraphDB 未运行时,更改为new LocalRepositoryManager(new File("$GraphDBInstall/data/repositories"))将导致在 GraphDB 的控制下创建存储库(假设您有一个本地 GraphDB 实例)。如果您在运行程序后启动 GraphDB,您将能够在 GraphDB 工作台中看到存储库。

(3)你需要做的是获取远程GraphDB的repository manager,可以用RepositoryManager repositoryManager = RepositoryProvider.getRepositoryManager("http://IPAddressOfGraphDB:7200");.

(4) 在您指定配置的方式中,您会导致 RDF 图配置丢失。指定它的正确方法是:

RepositoryConfig repositoryConfig = RepositoryConfig.create(graph, repositoryNode);
repositoryManager.addRepositoryConfig(repositoryConfig);

(5) 一个小问题GraphUtil.getUniqueSubject(...)已被弃用,您可以使用以下内容:

Model model = graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY);
Iterator<Statement> iterator = model.iterator(); 
if (!iterator.hasNext()) 
   throw new RuntimeException("Oops, no <http://www.openrdf.org/config/repository#> subject found!");
Statement statement = iterator.next();
Resource repositoryNode =  statement.getSubject();

编辑20180408:

(5)或者您可以使用评论中建议的@JeenBroekstra 的紧凑选项:

Models.subject(
    graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY))
    .orElseThrow(() -> new RuntimeException("Oops, no <http://www.openrdf.org/config/repository#> subject found!")); 

编辑20180409:

为方便起见,我在此处添加了完整的代码示例。

编辑20180410:

所以实际的罪魁祸首原来是不正确的pom.xml。正确的版本如下:

<dependency>
  <groupId>com.ontotext.graphdb</groupId>
  <artifactId>graphdb-free-runtime</artifactId>
  <version>8.4.1</version>
</dependency>
于 2018-04-07T13:32:17.897 回答
0

我相信我只是遇到了同样的问题。我使用 GraphDB Free 中的示例代码将 RDF4J 作为远程服务运行,并遇到了与您相同的异常(不支持的 Sail 类型:graphdb:FreeSail)。Henriette Harmse 的回答没有直接解决这个问题,但应该遵循那里给出的建议以避免以后遇到问题。此外,基于对 RDF4J 代码的查看,您的pom.xml文件中需要以下依赖项(假设 GraphDB 8.5):

<dependency>
    <groupId>com.ontotext.graphdb</groupId>
    <artifactId>graphdb-free-runtime</artifactId>
    <version>8.5.0</version>
</dependency>

这似乎是因为 META-INF 正在进行某种服务加载,坦率地说我并不熟悉。也许有人可以在评论中提供更多细节。说明中似乎也没有添加此依赖项的要求,因此如果这对您有用,请告诉我。遵循我们所做的相同步骤的其他人也应该能够解决这个问题。

于 2018-04-10T06:44:55.090 回答