我想分析图的结构,我想尝试的一个特定查询是在图中提取主题类型的不同组合 - 边类型 - 对象类型。
这是我之前几个问题的后续跟进:
如何使用 SPARQL 查询生成适合特定节点类型 or/and 边缘类型的所有三元组?
如何使用 SPARQL 查询列出和计算图数据中不同类型的节点和边缘实体?
例如:如果存在边缘 types(property/predicate 类型的语义图)
-
IsCapitalOf
-
IsCityOf
-
有人口等等
如果节点类型如下:
-
城市
-
国家
-
里弗斯
-
山等
然后我应该得到:
-
City-> IsCapitalOf-> Country 4 元组
-
City-> IsCityOf-> Country 21 元组
-
河 - > IsPartOf->国家 3
-
River-> PassesThrough-> City 11
等等...
注意:对象字段中没有文字,因为我希望单位子图模式拟合(subjecttype edgetype objecttype)
总结一下:我认为我接近这个的方式是:
a)在图中计算不同的主题类型 b)在图中计算不同的边类型 c)在图中计算不同的对象类型(在之前的问题中已经回答了 a/b/c)
现在 d)生成所有可能的 combinations(of 主题类型 - >边缘类型 - >对象 type(NO 文字)并对这些模式进行计数(如直方图)
希望这个问题能够得到很好的表达
编辑:添加样本数据[5]这是 yago 数据集,可以公开获取
<Alabama> rdf:type <wordnet_country_108544813> .
<Abraham_Lincoln> rdf:type <wordnet_president_110467179> .
<Aristotle> rdf:type <wordnet_writer_110794014> .
<Academy_Award_for_Best_Art_Direction> rdf:type <wordnet_award_106696483> .
<Academy_Award> rdf:type <wordnet_award_106696483> .
<Actrius> rdf:type <wordnet_movie_106613686> .
<Animalia_(book)> rdf:type <wordnet_book_106410904> .
<Ayn_Rand> rdf:type <wordnet_novelist_110363573> .
<Allan_Dwan> rdf:type <wikicategory_American_film_directors> .
<Algeria> rdf:type <wordnet_country_108544813> .
<Andre_Agassi> rdf:type <wordnet_player_110439851> .
<Austro-Asiatic_languages> rdf:type <wordnet_language_106282651> .
<Afroasiatic_languages> rdf:type <wordnet_language_106282651> .
<Andorra> rdf:type <wordnet_country_108544813> .
<Animal_Farm> rdf:type <wordnet_novelette_106368962> .
<Alaska> rdf:type <wordnet_country_108544813> .
<Aldous_Huxley> rdf:type <wordnet_writer_110794014> .
<Andrei_Tarkovsky> rdf:type <wordnet_film_maker_110088390> .
1 回答
假设你有这样的数据:
然后,这个查询为您提供了您想要的实物结果,我认为:
如果您对
[ … ]
空白节点语法不太满意,则可能有助于查看扩展形式:但是,这只能捕获具有类型的东西。如果你想要包含那些没有
rdf:type
的东西,你可以这样做