在DBpedia上使用EasyRdf的Person的SPARQL查询 [英] SPARQL query of Person using EasyRdf on DBpedia
问题描述
我想从DBpedia SPARQL API获得有关人员的所有信息。
第一个问题是,请求花费了太长时间。
其次,我没有得到有关我要找的人的任何信息。
我不知道我在做什么错吗?
I want to get all information about a Person from the DBpedia SPARQL API. First problem is, the request took too long time. Second, I don't get back any information about the person I looked for. I don't know what I am doing wrong?
我的代码:
require_once "EasyRdf.php";
require_once "html_tag_helpers.php";
// Setup some additional prefixes for DBpedia
EasyRdf_Namespace::set('category', 'http://dbpedia.org/resource/Category:');
EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
EasyRdf_Namespace::set('dbp', 'http://dbpedia.org/property/');
$sparql = new EasyRdf_Sparql_Client('http://dbpedia.org/sparql');
$result = $sparql->query(
'SELECT *
WHERE {
?person foaf:name ?name.
?person foaf:name ?name.
FILTER(regex(?person,"John Lennon"))
}
'
);
echo "<pre>";
print_r($result);
我的结果:
EasyRdf_Sparql_Result Object
(
[type:EasyRdf_Sparql_Result:private] => bindings
[boolean:EasyRdf_Sparql_Result:private] =>
[ordered:EasyRdf_Sparql_Result:private] =>
[distinct:EasyRdf_Sparql_Result:private] =>
[fields:EasyRdf_Sparql_Result:private] => Array
(
[0] => person
[1] => name
)
[storage:ArrayIterator:private] => Array
(
)
)
推荐答案
您不会获得类似以下结果的结果:
You're not going to get results with something like:
regex(?person,"John Lennon"
因为?person 的值是一个URI,而不是字符串,并且URI不包含空格。可以查询具有真实姓名的个人(不要忘记语言标签),如:
since the value of ?person is a URI, not a string, and URIs don't contain spaces. Instead, you could query for individuals with the actual name (don't forget the language tag), as in:
select * where {
?resource foaf:name "John Lennon"@en
}
我想获取所有信息
如果要获取有关某个人的所有财产价值,则可以用以下内容扩展查询:
If you want to get all the property values about a person, you could extend the query with something like:
select ?subject ?property ?object {
?resource foaf:name "John Lennon"@en ;
?property ?object .
}
当然,这只会检索人是的数据三元组的主题,但您也可能会关心该人也是三元组的对象的事物,在这种情况下,您可能会追求:
Of course, that will only retrieve data where the person is the subject of the triples, but you might also care about things where the person is the object of a triple too, in which case you might go for:
describe ?person where {
?person foaf:name "John Lennon"@en
}
describe 查询是依赖于实现的,但是获取资源作为主题或对象的所有三元组很普遍。
The results of describe queries are implementation dependent, but it's pretty common to get all the triples of which the resource is the subject or object.
这篇关于在DBpedia上使用EasyRdf的Person的SPARQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!