微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 heracles.ts

如何解决使用 heracles.ts

我正在寻找使用 hydra:classhydra:collection/hydra:member 对象属性的指导,这些属性来自自定义 Hydra 端点的响应,该端点通过 TypeScript Heracles.ts 中的引用客户端请求.

例如,考虑来自我的服务器的以下 JSON-LD 响应:

{
  "context": {...},"member": [
    {
      "@id": "example:2bfd5353-6842-48f7-9f8c-111474f57dfb","@type": "schema:person","label": "Person 1"
    },{
      "@id": "example:108d8384-a55a-4b21-8511-654fb3830d5f","label": "Person 2"
    },],}

我可以得到这个响应并使用以下代码循环它就好了:

const data = await Client.getResource(
  "http://example.com/api/persons"
);
for (const person of data.members) {
  const iri = person.iri;
  const label = person.label; // How can I do this?
}

我不知道如何从响应中提取iritype 之外的属性。 Hydra 存储库中的文档和用例只讨论了诸如 对象做某事(例如在 Use Case Draft 4 中)之类的事情,而没有展示如何去做。我也无法在 repo 中的测试和其他源代码中找到具体示例。

非常感谢任何帮助。

最好的, 丹尼尔

解决方法

我在 Heracles GitHub 存储库上提出了同样的问题,并得到了 answer 需要手动实现除 Hydra 元数据之外的内容的访问器,类似于:

const data = await Client.getResource(
  "http://localhost:4000/persons"
);
const graph = await jsonld.expand(await data.json());
for (const person of data.members) {
  const personResource = graph["@graph"].find(_ => _["@id"] === person.iri);
  const label = personResource["http://some.uri/vocab#label][0]["@value"];
}

来源:GitHub 上的外星人 mcl

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。