类型错误:RepositoryClientConfig 不是构造函数(Ontotext graphdb)

问题描述 投票:0回答:1

我正在使用 node.js 版本 21.7.1 和 graphdb 版本 10.0.6 来查询交互式指南中的“电影”存储库,我将其用作测试。我的问题是我是否会收到一条错误消息(TypeError:RepositoryClientConfig 不是构造函数),但它在文档中声明它是构造函数

下面是代码;

const { ServerClient, ServerClientConfig, RepositoryClientConfig } = require('graphdb').server;
const { RDFMimeType, SparqlJsonResultParser, GetQueryPayload, QueryType } = require('graphdb').http;

const serverConfig = new ServerClientConfig('http://localhost:7200')
  .setTimeout(5000)
  .setHeaders({
    'Accept': RDFMimeType.SPARQL_RESULTS_JSON
  })
  .setKeepAlive(true);

const server = new ServerClient(serverConfig);

const repositoryClientConfig = new RepositoryClientConfig(['http://localhost:7200/movies']);
const repositoryClient = server.getRepository(repositoryClientConfig);
repositoryClient.registerParser(new SparqlJsonResultParser());

const payload = new GetQueryPayload()
  .setQuery('select * where {?s ?p ?o}')
  .setQueryType(QueryType.SELECT)
  .setResponseType(RDFMimeType.SPARQL_RESULTS_JSON)
  .setLimit(100);

repositoryClient.query(payload).then((stream) => {
  stream.on('data', (bindings) => {
    console.log(bindings);
  });
  stream.on('end', () => {
    console.log('Query execution completed');
  });
}).catch((error) => {
  console.error('Error executing query:', error);
});

我收到错误代码

TypeError: RepositoryClientConfig is not a constructor

我使用了“ServerClient”实例的“getRepository”方法,将存储库 ID 作为字符串传递,

代码如下:

const { ServerClient, ServerClientConfig } = require('graphdb').server;
const { RDFMimeType, SparqlJsonResultParser, GetQueryPayload, QueryType } = require('graphdb').http;

const serverConfig = new ServerClientConfig('http://localhost:7200')
  .setTimeout(5000)
  .setHeaders({
    'Accept': RDFMimeType.SPARQL_RESULTS_JSON
  })
  .setKeepAlive(true);

const server = new ServerClient(serverConfig);

const repositoryClient = server.getRepository('movies3', { readOnly: true });
repositoryClient.registerParser(new SparqlJsonResultParser());

const payload = new GetQueryPayload()
  .setQuery('select * where {?s ?p ?o}')
  .setQueryType(QueryType.SELECT)
  .setResponseType(RDFMimeType.SPARQL_RESULTS_JSON)
  .setLimit(100);

repositoryClient.query(payload).then((stream) => {
  stream.on('data', (bindings) => {
    console.log(bindings);
  });
  stream.on('end', () => {
    console.log('Query execution completed');
  });
}).catch((error) => {
  console.error('Error executing query:', error);
});

这是我遇到的错误

Error: RepositoryClientConfig is required parameter!
```

Any help, thank you.
node.js repository rdf graphdb rdfs
1个回答
0
投票

我们假设您在“localhost”和端口“7200”上有一个正在运行的 GDB 实例,该实例至少有一个存储库“movies”。

请注意,您必须配置存储库的方法接受存储库名称数组。

const { ServerClient, ServerClientConfig, RepositoryClientConfig } = require('graphdb').server;

const { RDFMimeType, SparqlJsonResultParser, GetQueryPayload, QueryType } = require('graphdb').http;

 

const serverConfig = new ServerClientConfig('http://localhost:7200')

  .setTimeout(5000)

  .setHeaders({

    'Accept': RDFMimeType.SPARQL_RESULTS_JSON

  })

  .setKeepAlive(true);

 

const server = new ServerClient(serverConfig);

 

const repositoryClientConfig = new RepositoryClientConfig('http://localhost:7200')

                                                    .setEndpoints(['http://localhost:7200/repositories/movies']);

const repositoryClient = await server.getRepository('movies', repositoryClientConfig);

repositoryClient.registerParser(new SparqlJsonResultParser());

 

  const payload = new GetQueryPayload()

  .setQuery('select * where {?s ?p ?o}')

  .setQueryType(QueryType.SELECT)

  .setResponseType(RDFMimeType.SPARQL_RESULTS_JSON)

  .setLimit(100);

 

repositoryClient.query(payload).then((stream) => {

  stream.on('data', (bindings) => {

    console.log(bindings);

 

});

  stream.on('end', () => {

    console.log('Query execution completed');

  });

}).catch((error) => {

  console.error('Error executing query:', error);

});
© www.soinside.com 2019 - 2024. All rights reserved.