我在玩使用SPARQL来识别事物之间概念重叠的想法。
以电影为例(LinkedMDB数据),如果我有一部电影“黑客帝国”,我的目标是列出与该电影类似的电影,我可能首先做以下工作:
然后使用我在矩阵中标识的东西,我会用这些属性(伪查询)来查询事物。
SELECT movie, genre, director, location, actors
WHERE {
genre is action or sci-fi .
director are the Wachowski brothers .
location is set in a big city .
OPTIONAL( actors were in the matrix . )
}SPARQL中有什么东西允许我检查不同节点之间属性的重叠吗?还是必须像我提议的那样手动完成?
发布于 2014-01-22 17:58:57
匹配某些特定属性
听起来你是在要求某种东西
select ?similarMovie ?genre ?director ?location ?actor where {
values ?movie { <http://.../TheMatrix> }
?genre ^:hasGenre ?movie, ?similarMovie .
?director ^:hasDirectory ?movie, ?similarMovie .
?location ^:hasLocation ?movie, ?similarMovie .
optional { ?actor ^:hasActor ?movie, ?similarMovie .
}它使用反向路径表示法^和对象列表使其比以下短得多:
select ?similarMovie ?genre ?director ?location ?actor where {
values ?movie { <http://.../TheMatrix> }
?movie :hasGenre ?genre .
?movie :hasDirector ?director .
?movie :hasLocation ?location .
?similarMovie :hasGenre ?genre .
?similarMovie :hasDirector ?director .
?similarMovie :hasLocation ?location .
optional {
?movie :hasActor ?actor .
?similarMovie :hasActor ?actor .
}
}例如,使用DBpedia,我们可以获得与“黑客帝国”相同的发行商和摄影师的其他影片:
select ?similar ?cinematographer ?distributor where {
values ?movie { dbpedia:The_Matrix }
?cinematographer ^dbpprop:cinematography ?movie, ?similar .
?distributor ^dbpprop:distributor ?movie, ?similar .
}
limit 10结果都在同一系列中,你可以得到:“矩阵”、“矩阵再定义”、“矩阵革命”、“矩阵”(专营权)和“终极矩阵集”。
匹配至少一些属性
还可以要求至少有一些共同的属性的东西。有多少属性需要有共同之处才能被认为是相似的,这显然是主观的,将取决于特定的数据,并且需要一些实验。例如,我们可以在DBpedia上请求具有至少35个与矩阵相同的属性的电影,并提供如下查询:
select ?similar where {
values ?movie { dbpedia:The_Matrix }
?similar ?p ?o ; a dbpedia-owl:Film .
?movie ?p ?o .
}
group by ?similar ?movie
having count(?p) > 35这给出了13部电影(包括“黑客帝国”和特许经营中的其他电影):
使用这种方法,您甚至可以使用公共属性的数量作为相似性的度量。例如:
select ?similar (count(?p) as ?similarity) where {
values ?movie { dbpedia:The_Matrix }
?similar ?p ?o ; a dbpedia-owl:Film .
?movie ?p ?o .
}
group by ?similar ?movie
having count(?p) > 35
order by desc(?similarity)The Matrix 206
The Matrix Revolutions 63
The Matrix Reloaded 60
The Matrix (franchise) 55
Demolition Man (film) 41
Speed Racer (film) 40
V for Vendetta (film) 38
The Invasion (film) 38
The Postman (film) 36
Executive Decision 36
Freejack 36
Exit Wounds 36
Outbreak (film) 36发布于 2019-10-27 13:24:23
使用DBpedia中的新前缀,约书亚·泰勒的答案是:
select ?similar (count(?p) as ?similarity) where {
values ?movie { dbr:The_Matrix }
?similar ?p ?o ; a dbo:Film .
?movie ?p ?o .
}
group by ?similar ?movie
having (count(?p) > 35)
order by desc(?similarity)https://stackoverflow.com/questions/21290186
复制相似问题