如何使用 Nodejs 客户端获取 TypeDB 中实体的值?

编程入门 行业动态 更新时间:2024-10-06 19:19:44

<a href=https://www.elefans.com/category/jswz/34/1771452.html style=如何使用 Nodejs 客户端获取 TypeDB 中实体的值?"/>

如何使用 Nodejs 客户端获取 TypeDB 中实体的值?

我尝试在 nodejs 客户端中获取实体属性的实际值,但我只获取字符串 ID。我尝试了许多不同版本的 .getValue() 或 asAttribute 或 getAttribute,但只收到错误消息。如何检索属性的实际值?

这是我的代码

export async function getMarketByTitle(title: string) {
  const database = "know_graph"; // Replace this with the name of your TypeDB database
  const { client, session, transaction } = await openTransaction(database);

  try {
    const query = `
      match
      $m isa market, has title "${title}", has background_information $background_information;
      $m has title $m_title;
      get $m, $m_title, $background_information;
    `;

    const iterator = await transaction.query.match(query);
    let market;
    for await (const answer of iterator) {
      const mConcept = answer.get("m");
      const mTitle = answer.get("m_title");
      const backgroundInformation = answer.get("background_information");
      const checkEntity = mConcept.isEntity();
      const checkAttribute = mTitle.isAttribute();

      market = {
        id: mConcept.toString(),
        title: msTitle.toString(),
        backgroundInformation: backgroundInformation.toString(),
        entity: checkEntity.toString(),
        attribute: checkAttribute.toString
      };

      return market;
    }```
回答如下:

我相信你应该像这样使用

.map
.value

      const mTitle = answer.map.get("m_title").value;
      const backgroundInformation = answer.map.get("background_information").value;

根据https://docs.vaticle/docs/concept-api/thing#retrieve-value-(local)(确保在该页面上将语法切换为javascript)。

更多推荐

如何使用 Nodejs 客户端获取 TypeDB 中实体的值?

本文发布于:2024-05-30 09:57:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770371.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   实体   客户端   Nodejs   TypeDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!