【问题标题】:Freebase MQL filter where value != null?Freebase MQL 过滤器在哪里 value != null?
【发布时间】:2009-03-24 17:30:58
【问题描述】:

我正在尝试编写一个过滤掉空值的 MQL 查询。

我现在的查询(可以使用MQL Query Editor 执行):

[
  {
    "/common/topic/image" : [
      {
        "id" : null
      }
    ],
    "article" : [
      {
        "content" : null
      }
    ],
    "name" : "bill gates",
    "type" : "/common/topic"
  }
]

我得到的结果:

[
  {
    "/common/topic/image" : [
      {
        "id" : "/guid/9202a8c04000641f8000000004fb4c01"
      },
      {
        "id" : "/wikipedia/images/commons_id/4486276"
      }
    ],
    "article" : [
      {
        "content" : null
      },
      {
        "content" : "/guid/9202a8c04000641f800000000903535d"
      }
    ],
    "name" : "Bill Gates",
    "type" : "/common/topic"
  }
]

我试图弄清楚如何在查询时过滤掉“内容”:“文章”数组中的空匹配。我查看了 MQL 文档,但没有找到明确的方法。

【问题讨论】:

    标签: freebase mql


    【解决方案1】:

    要过滤掉没有分配任何内容的文章,您必须扩展内容 id 属性并将可选指令设置为 false。

    [
      {
        "/common/topic/image" : [
          {
            "id" : null
          }
        ],
        "article" : [
          {
            "content" : {
              "id" : null,
              "optional" : false
            }
          }
        ],
        "name" : "bill gates",
        "type" : "/common/topic"
      }
    ]
    

    这将为您提供以下结果:

    [
      {
        "/common/topic/image" : [
          {
            "id" : "/guid/9202a8c04000641f8000000004fb4c01"
          },
          {
            "id" : "/wikipedia/images/commons_id/4486276"
          }
        ],
        "article" : [
          {
            "content" : {
              "id" : "/guid/9202a8c04000641f800000000903535d"
            }
          }
        ],
        "name" : "Bill Gates",
        "type" : "/common/topic"
      }
    ]
    

    有关使用可选指令的更多信息,请参阅文档here

    【讨论】:

    • 您是谁以及您如何对 MQL 了解这么多? ;)
    • 哈哈,我只是 Freebase 社区的一员,已经在 MQL 中研究了一年左右。我很高兴能够帮助人们学习技巧,并希望让更多的开发人员使用 Freebase 数据构建应用程序。
    • 当我将可选标志切换为 false 时,它​​告诉我:“查询太难了。”
    猜你喜欢
    • 1970-01-01
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多