Graph 使用SPARQL计算自定义直方图度量以了解图形结构
我想分析一个图的结构,我想尝试的一个特殊查询是在一个图中提取主题类型-边缘类型-对象类型的不同组合 这是我之前几个问题的后续: 例如:如果有一个边类型(属性/谓词类型)为的语义图Graph 使用SPARQL计算自定义直方图度量以了解图形结构,graph,rdf,sparql,Graph,Rdf,Sparql,我想分析一个图的结构,我想尝试的一个特殊查询是在一个图中提取主题类型-边缘类型-对象类型的不同组合 这是我之前几个问题的后续: 例如:如果有一个边类型(属性/谓词类型)为的语义图 IsCapitalOf IsCityOf 人口 等等等等等等 如果节点类型如下所示: 城市 国家 河流 山脉 等 那么我应该得到: 城市->IsCapitalOf->国家4元组 城市->城市->国家21元组 河流->伊斯帕托夫->国家3 河流->穿越->城市11 等等 注意:对象字段中没有文字,因为我需要单位子图模
<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> .
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
rdf:type。
假设您有如下数据:
@前缀:。
:城市a:城市。
:城市2 a:城市。
:国家a:国家。
当前位置国家2答:国家。
:国家。
例如:河流。
河流。
例如:河流。
:City1:isCapitalOf:Country1。
:River1:isPartOf:Country1,:Country2。
:River2:isPartOf:Country2,:Country3。
:河流1:穿过:城市1,:城市2。
:河流2:通过:城市2。
然后这个查询会给你想要的结果,我想:
前缀:
选择?类型1?p?类型2(计数(不同*)作为?计数),其中{
[a?类型1;?p[a?类型2]]
}
按类型1分组?按类型2分组
----------------------------------------------
|类型1 | p |类型2 |计数|
==============================================
|:河流通过城市3|
|:城市:首都:国家1|
|:河流|:伊斯帕托夫|:国家| 4|
----------------------------------------------
如果您对[…]
空白节点语法不太熟悉,可以查看扩展的表单:
选择类型1?p?类型2(计数(不同*)作为计数)
哪里
{ub0:rdf:type?type1。
_:b0?p_u1;b1。
_:b1 rdf:类型?类型2
}
按类型1分组?按类型2分组
但是,这只捕获具有类型的内容。如果您想包含没有rdf:type
s的内容,您应该这样做
选择?类型1?p?类型2(计数(不同*)作为?计数){
?x?p?y
可选{x a?类型1}
可选的{y a?type2}
}
按类型1分组?按类型2分组
假设您有如下数据:
@前缀:。
:城市a:城市。
:城市2 a:城市。
:国家a:国家。
当前位置国家2答:国家。
:国家。
例如:河流。
河流。
例如:河流。
:City1:isCapitalOf:Country1。
:River1:isPartOf:Country1,:Country2。
:River2:isPartOf:Country2,:Country3。
:河流1:穿过:城市1,:城市2。
:河流2:通过:城市2。
然后这个查询会给你想要的结果,我想:
前缀:
选择?类型1?p?类型2(计数(不同*)作为?计数),其中{
[a?类型1;?p[a?类型2]]
}
按类型1分组?按类型2分组
----------------------------------------------
|类型1 | p |类型2 |计数|
==============================================
|:河流通过城市3|
|:城市:首都:国家1|
|:河流|:伊斯帕托夫|:国家| 4|
----------------------------------------------
如果您对[…]
空白节点语法不太熟悉,可以查看扩展的表单:
选择类型1?p?类型2(计数(不同*)作为计数)
哪里
{ub0:rdf:type?type1。
_:b0?p_u1;b1。
_:b1 rdf:类型?类型2
}
按类型1分组?按类型2分组
但是,这只捕获具有类型的内容。如果您想包含没有rdf:type
s的内容,您应该这样做
选择?类型1?p?类型2(计数(不同*)作为?计数){
?x?p?y
可选{x a?类型1}
可选的{y a?type2}
}
按类型1分组?按类型2分组
该数据不构成非常有趣的直方图;没有(非rdf:type)属性。是的……我想。对不起。我将构造一个更有意义的示例数据。现在必须停止工作。您的查询工作并回答了我的问题!该数据不构成非常有趣的直方图;没有(非rdf:type)属性。是的…我想。对不起。我将构造一个更有意义的示例数据。现在必须停止工作。您的查询工作,并回答了我的问题!