通过RepositoryManager创建的存储库的行为与通过工作台创建的repo不同



我使用以下代码创建芝麻原生java存储:

创建本地java存储:

  // create a configuration for the SAIL stack
  boolean persist = true;
  String indexes = "spoc,posc,cspo";
  SailImplConfig backendConfig = new NativeStoreConfig(indexes);
  // stack an inferencer config on top of our backend-config
  backendConfig = new ForwardChainingRDFSInferencerConfig(backendConfig);
  // create a configuration for the repository implementation
  RepositoryImplConfig repositoryTypeSpec = new SailRepositoryConfig(backendConfig);
  RepositoryConfig repConfig = new RepositoryConfig(repositoryId, repositoryTypeSpec);
  repConfig.setTitle(repositoryId);
  manager.addRepositoryConfig(repConfig);
  Repository repository = manager.getRepository(repositoryId);

创建内存存储:

  // create a configuration for the SAIL stack
  boolean persist = true;
  SailImplConfig backendConfig = new MemoryStoreConfig(persist);
  // stack an inferencer config on top of our backend-config
  backendConfig = new ForwardChainingRDFSInferencerConfig(backendConfig);
  // create a configuration for the repository implementation
  RepositoryImplConfig repositoryTypeSpec = new SailRepositoryConfig(backendConfig);
  RepositoryConfig repConfig = new RepositoryConfig(repositoryId, repositoryTypeSpec);
  repConfig.setTitle(repositoryId);
  manager.addRepositoryConfig(repConfig);
  Repository repository = manager.getRepository(repositoryId);

当我将数据存储在这个repo中并进行查询时,结果与使用workbench创建的存储库返回的结果不同。我的结果集中有重复/多个条目。

内存中存储的行为相同。

我还观察到,我的三元组属于一个空白上下文,而在通过工作台创建的存储库中则不是这样。

我上面的代码出了什么问题?

据我所见,您的代码没有任何问题。如果从工作台创建的存储行为不同,这很可能意味着它配置了不同的SAIL堆栈。

差异最有可能的候选者是这个位:

// stack an inferencer config on top of our backend-config
backendConfig = new ForwardChainingRDFSInferencerConfig(backendConfig);

您已在此处顶部配置了一个推理机来配置您的存储库。如果通过工作台创建的存储库没有使用推理器,那么在相同的查询上会得到不同的结果(有时包括明显的重复结果)。

如果你认为这是一个问题,你可以用两种方法来解决。一个是(当然)不要在上面创建推理器来创建存储库。另一种是禁用特定查询的推理。在工作台中,您可以通过禁用查询屏幕中的"包含推断语句"复选框来完成此操作。通过编程,您可以在准备好的查询对象上使用Query.setIncludeInferred(false)来实现这一点。有关详细信息,请参阅javadoc。

最新更新