简体   繁体   English

在Drupal中查询Sparql

[英]Query Sparql in Drupal

In my website I have articles filled with rdf attributes. 在我的网站上,我的文章充满了rdf属性。 I Can't figure out what's the Sparql query to simply retrieve all the titles of the articles which author is admin. 我无法弄清楚什么是Sparql查询只是检索作者是管理员的文章的所有标题。

在此输入图像描述

I retrieved all the user names by: 我通过以下方式检索了所有用户名:

PREFIX foaf:  <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
    ?person foaf:name ?name .
}

Then I try: 然后我尝试:

PREFIX dc:    <http://purl.org/dc/elements/1.1/>
PREFIX foaf:  <http://xmlns.com/foaf/0.1/>
SELECT ?dc:title
WHERE {
    ?person sioc:has_creator 1 .
}
LIMIT 5

But the result is: 但结果是:

Could not properly handle &quot;PREFIX foaf:  &lt;http://xmlns.co&quot; in ARC2_SPARQLPlusParser

if I remove foaf which is not used I get: 如果我删除未使用的foaf我得到:

Could not properly handle &quot;SELECT ?dc:title  WHERE {     &quot; in ARC2_SPARQLPlusParser.

UPDATE 01 更新01

Sample of data output from the query: 查询输出的数据样本:

select ?s ?p ?o where { ?s ?p ?o } limit 300

Result: 结果:

[...]
{
    "s": {
      "type": "uri",
      "value": "http://drupal.test/users/admin"
    },

    "p": {
      "type": "uri",
      "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
    },

    "o": {
      "type": "uri",
      "value": "http://rdfs.org/sioc/ns#UserAccount"
    }
  },
  {
    "s": {
      "type": "uri",
      "value": "http://drupal.test/users/admin"
    },

    "p": {
      "type": "uri",
      "value": "http://xmlns.com/foaf/0.1/name"
    },

    "o": {
      "type": "literal",
      "value": "admin"
    }
  },
[...]
  {
    "s": {
      "type": "uri",
      "value": "http://drupal.test/content/consectetuer-dignissim-luptatum-tego"
    },

    "p": {
      "type": "uri",
      "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
    },

    "o": {
      "type": "uri",
      "value": "http://xmlns.com/foaf/0.1/Document"
    }
  },
  {
    "s": {
      "type": "uri",
      "value": "http://drupal.test/content/consectetuer-dignissim-luptatum-tego"
    },

    "p": {
      "type": "uri",
      "value": "http://purl.org/rss/1.0/modules/content/encoded"
    },

    "o": {
      "type": "literal",
      "value": "<p>Dignissim luptatum neo te. Damnum decet pala proprius quadrum sagaciter vel. Defui erat qui. Distineo esca macto nisl probo. Humo illum luctus nimis singularis sino sit valde wisi. Consequat eum iaceo paratus velit. Bene dolus esca eu fere mauris pala refero saepius suscipit.<\/p>\n<p>Camur dignissim facilisi genitus huic humo nimis. Ad conventio jumentum pala plaga praemitto premo quibus rusticus. Huic ibidem iriure macto nimis vel. Cui esca euismod sagaciter. Bene eros feugiat genitus jugis pagus quidem sudo valde vicis.<\/p>\n<p>Esca letalis odio tum. Abigo commodo probo quidne singularis. Eros iriure ullamcorper. Antehabeo aptent erat mauris molior oppeto validus verto wisi.<\/p>\n<p>Adipiscing aptent decet mos nostrud similis ullamcorper. Camur commoveo hendrerit jus odio uxor. Decet ea eum illum iriure natu os proprius ratis. Appellatio comis ibidem. Dolore molior neo pertineo. Autem consectetuer hendrerit patria.<\/p>\n<p>Blandit conventio eum te tego. Illum lobortis paratus wisi. Facilisi quibus singularis ulciscor. Illum in lucidus mos torqueo velit. Appellatio bene caecus hendrerit hos qui velit. Praemitto premo vereor. Acsi nulla ratis. Amet commodo consequat defui luctus vereor verto.<\/p>\n<p>Eligo ibidem illum iusto loquor neque oppeto utrum validus. At commodo eligo facilisi hos.<\/p>\n<p>Fere immitto pecus praemitto sino. Damnum hos jus laoreet letalis suscipere. Hos mauris nibh odio paulatim tation tego usitas.<\/p>\n<p>Abluo exputo iaceo volutpat. Abico duis et minim refoveo saluto validus vereor virtus voco. Ex minim vero. Commodo consequat interdico nobis singularis vel wisi. Ea fere hos quis saepius singularis torqueo virtus vulputate. Aliquip consectetuer defui ea ex quidem sudo usitas.<\/p>\n"
    }
  },

UPDATE 02 更新02

Describe the article: 描述文章:

describe 
<http://drupal.test/content/consectetuer-dignissim-luptatum-tego>

Result: 结果:

{
  "http://drupal.test/content/consectetuer-dignissim-luptatum-tego" : {
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : [
      { "value" : "http://xmlns.com/foaf/0.1/Document", "type" : "uri" }
    ],
    "http://purl.org/rss/1.0/modules/content/encoded" : [
      { "value" : "<p>Dignissim luptatum neo te. Damnum decet pala proprius quadrum sagaciter vel. Defui erat qui. Distineo esca macto nisl probo. Humo illum luctus nimis singularis sino sit valde wisi. Consequat eum iaceo paratus velit. Bene dolus esca eu fere mauris pala refero saepius suscipit.</p>\n", "type" : "literal" }
    ],
    "http://purl.org/dc/terms/title" : [
      { "value" : "Consectetuer Dignissim Luptatum Tego", "type" : "literal" }
    ],
    "http://purl.org/dc/terms/date" : [
      { "value" : "2014-06-11T08:22:09-07:00", "type" : "literal", "datatype" : "xsd:dateTime" }
    ],
    "http://purl.org/dc/terms/created" : [
      { "value" : "2014-06-11T08:22:09-07:00", "type" : "literal", "datatype" : "xsd:dateTime" }
    ],
    "http://purl.org/dc/terms/modified" : [
      { "value" : "2014-06-11T08:22:09-07:00", "type" : "literal", "datatype" : "xsd:dateTime" }
    ]
  } 
}

Give me all triples about an article: 给我一篇关于文章的三重奏:

select ?p ?o where { <http://drupal.test/content/consectetuer-dignissim-luptatum-tego> ?p ?o }

Result: 结果:

{
  "head": {
    "vars": [
      "p",
      "o"
    ]
  },
  "results": {
    "bindings": [
      {
        "p": {
          "type": "uri",
          "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
        },

        "o": {
          "type": "uri",
          "value": "http://xmlns.com/foaf/0.1/Document"
        }
      },
      {
        "p": {
          "type": "uri",
          "value": "http://purl.org/rss/1.0/modules/content/encoded"
        },

        "o": {
          "type": "literal",
          "value": "<p>Dignissim luptatum neo te. Damnum decet pala proprius quadrum sagaciter vel. Defui erat qui. Distineo esca macto nisl probo. Humo illum luctus nimis singularis sino sit valde wisi. Consequat eum iaceo paratus velit. Bene dolus esca eu fere mauris pala refero saepius suscipit.<\/p>\n"
        }
      },
      {
        "p": {
          "type": "uri",
          "value": "http://purl.org/dc/terms/title"
        },

        "o": {
          "type": "literal",
          "value": "Consectetuer Dignissim Luptatum Tego"
        }
      },
      {
        "p": {
          "type": "uri",
          "value": "http://purl.org/dc/terms/date"
        },

        "o": {
          "type": "typed-literal",
          "value": "2014-06-11T08:22:09-07:00",
          "datatype": "xsd:dateTime"
        }
      },
      {
        "p": {
          "type": "uri",
          "value": "http://purl.org/dc/terms/created"
        },

        "o": {
          "type": "typed-literal",
          "value": "2014-06-11T08:22:09-07:00",
          "datatype": "xsd:dateTime"
        }
      },
      {
        "p": {
          "type": "uri",
          "value": "http://purl.org/dc/terms/modified"
        },

        "o": {
          "type": "typed-literal",
          "value": "2014-06-11T08:22:09-07:00",
          "datatype": "xsd:dateTime"
        }
      }
    ]
  }
}

This query doesn't make sense: 这个查询没有意义:

SELECT ?dc:title
WHERE {
    ?person sioc:has_creator 1 .
}

I don't think that dc:title can be the name of a variable, and even if it is, you're not using it the query. 我不认为dc:title可以是变量的名称,即使它是,你也不会使用它来查询。 The triple pattern ?person sioc:has_creator 1 is looking for things (which will be bound to the variable ?person that have 1 as the value of the property sioc:has_creator . I can't say for sure, but I doubt that 1 is the creator of many things, unless, as Clive mentions in the comments, the value of sioc:has_creator is the id of the user, rather than some resource representing the user proper. You should start with an exploratory query like 三重模式?person sioc:has_creator 1正在寻找的东西(将被绑定到变量?person具有1作为属性sioc:has_creator的值的sioc:has_creator 。我不能肯定地说,但我怀疑1是许多事情的创造者,除非像Clive在评论中提到的那样, sioc:has_creator的值是用户的id ,而不是代表用户正确的一些资源。你应该从一个探索性的查询开始

select ?s ?p ?o where { ?s ?p ?o } limit 300

to find out what sort of triples you have in your data. 找出你的数据中有三倍的三元组。 Then, based on what you see, you'll have a better idea of what sort of queries you can write against it. 然后,根据您所看到的内容,您将更好地了解可以针对它编写哪种查询。

Without seeing your data, we can't really help you write the query you need, but I expect that to 在没有看到您的数据的情况下,我们无法真正帮助您编写所需的查询,但我希望如此

simply retrieve all the titles of the articles which author is admin. 只需检索作者是管理员的文章的所有标题。

you'll end up doing something like this: 你最终会做这样的事情:

select ?title where {
  ?article dc:title ?title .
  ?article sioc:has_creator ?creator .
  ?creator foaf:name "admin" .
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM