这个RDF.rb查询有什么问题?

时间:2022-01-09 15:40:19

I'm learning rdf via the RDF.rb ruby library. I am able to load the following turtle file into a graph:

我正在通过RDF.rb ruby​​库学习rdf。我能够将以下龟文件加载到图表中:

# filename: ex002.ttl

@prefix ab: <http://learningsparql.com/ns/addressbook#> .

ab:richard ab:homeTel "(229) 276-5135" . 
ab:richard ab:email   "richard49@hotmail.com" . 

ab:cindy ab:homeTel "(245) 646-5488" . 
ab:cindy ab:email   "cindym@gmail.com" . 

ab:craig ab:homeTel "(194) 966-1505" . 
ab:craig ab:email   "craigellis@yahoo.com" . 
ab:craig ab:email   "c.ellis@usairwaysgroup.com" . 

But when I try to extract all triples with a #homeTel, using a query, I get no results at all. I am not sure if I have a basic misunderstanding of how the the query should work, or if I have a misunderstanding of how RDF.rb works, because I'm new to it all!

但是当我尝试使用#homeTel提取所有三元组时,使用查询,我根本得不到任何结果。我不确定我是否对查询应该如何工作有一个基本的误解,或者我是否对RDF.rb如何工作有误解,因为我对这一切都是新手!

Here is the ruby code:

这是ruby代码:

require 'rdf'
require 'rdf/ntriples'
require 'rdf/raptor'

graph = RDF::Graph.load("../data/ex002.ttl")

query = RDF::Query.new do
    pattern [:person, RDF::URI("http://learningsparql.com/ns/addressbook/#homeTel"), :o]
end

response = query.execute(graph)

puts "response: #{response.to_s}" # gives me an empty result

I've tried various alternative ways of representing the predicate, including a plain string with full uri, and "ab:homeTel, and an RDF::Vocabulary. If I just put ':p' in place of the predicate above it does return results so I know the graph is loaded ok.

我已经尝试了各种表示谓词的替代方法,包括带有完整uri的普通字符串,以及“ab:homeTel和RDF :: Vocabulary。如果我只是将':p'代替上面的谓词,它确实返回结果所以我知道图表加载好了。

I hope someone can help. Thanks in advance!

我希望有人能帮帮忙。提前致谢!

1 个解决方案

#1


0  

The prefix in the data is

数据中的前缀是

@prefix ab: <http://learningsparql.com/ns/addressbook#> .

that means that ab:homeTel is the IRI

这意味着ab:homeTel是IRI

http://learningsparql.com/ns/addressbook#homeTel

However, in your query, you're using a different IRI:

但是,在您的查询中,您使用的是其他IRI:

RDF::URI("http://learningsparql.com/ns/addressbook/#homeTel")
#                                                 ^
#                                                 |
#                                       get rid of this slash

#1


0  

The prefix in the data is

数据中的前缀是

@prefix ab: <http://learningsparql.com/ns/addressbook#> .

that means that ab:homeTel is the IRI

这意味着ab:homeTel是IRI

http://learningsparql.com/ns/addressbook#homeTel

However, in your query, you're using a different IRI:

但是,在您的查询中,您使用的是其他IRI:

RDF::URI("http://learningsparql.com/ns/addressbook/#homeTel")
#                                                 ^
#                                                 |
#                                       get rid of this slash