我正在查询this endpoint以使用其同义词来吸引分类单元,我希望最终结果是一个包含分类单元URI及其名称以及同义词的JSON文件:
{
TAXON_URI: [TAXON_NAME, TAXON_SYN1, .....],
...
}
我使用的查询:
PREFIX ns0: <http://aims.fao.org/aos/agrontology#>
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#>
SELECT ?taxon_name_uri ?taxon_name ?taxon_synonym
WHERE{
# select only 'Taxonomic terms for plants' !!
?taxon_name_uri ns0:hasTermType "Taxonomic terms for plants".
?taxon_name_uri ns0:hasSynonym ?taxon_synonym_uri.
?taxon_name_uri skosxl:literalForm ?taxon_name.
?taxon_synonym_uri skosxl:literalForm ?taxon_synonym.
FILTER (lang(?taxon_synonym) = 'en' || lang(?taxon_synonym) = 'fr')
}
ORDER BY ?taxon_name_uri
LIMIT 100
结果似乎合乎逻辑,但这并不是我想要的,这是一个说明我的问题的示例:
taxon_name_uri taxon_name taxon_synonym
------------------------------------------------------------------------
agrovoc:/xl_en_1299492690497 "Plantago ovata" "Plantago minima"
agrovoc:/xl_en_1299492690497 "Plantago ovata" "Plantago gooddingii"
agrovoc:/xl_en_1299492690497 "Plantago ovata" "Plantago brunnea"
agrovoc:/xl_en_1299492690497 "Plantago ovata" "Plantago fastigiata"
agrovoc:/xl_en_1299492690497 "Plantago ovata" "Plantago insularis"
agrovoc:/xl_en_1299492691630 "Plantago brunnea" "Plantago ovata"
agrovoc:/xl_en_1299492691706 "Plantago fastigiata" "Plantago ovata"
agrovoc:/xl_en_1299492691791 "Plantago gooddingii" "Plantago ovata"
agrovoc:/xl_en_1299492691878 "Plantago insularis" "Plantago ovata"
agrovoc:/xl_en_1299492691969 "Plantago minima" "Plantago ovata"
这是我根据上面的结果得到的JSON:
{
"http://aims.fao.org/aos/agrovoc/xl_en_1299492690497": [
"Plantago ovata",
"Plantago minima",
"Plantago gooddingii",
"Plantago brunnea",
"Plantago fastigiata",
"Plantago insularis"
],
"http://aims.fao.org/aos/agrovoc/xl_en_1299492691630": [
"Plantago brunnea",
"Plantago ovata"
],
"http://aims.fao.org/aos/agrovoc/xl_en_1299492691706": [
"Plantago fastigiata",
"Plantago ovata"
],
"http://aims.fao.org/aos/agrovoc/xl_en_1299492691791": [
"Plantago gooddingii",
"Plantago ovata"
],
"http://aims.fao.org/aos/agrovoc/xl_en_1299492691878": [
"Plantago insularis",
"Plantago ovata"
],
"http://aims.fao.org/aos/agrovoc/xl_en_1299492691969": [
"Plantago minima",
"Plantago ovata"
]
}
我在这里有很多重复项,我只对SPARQL查询结果的前5行感兴趣,其中taxon_name
是Plantago ovata
,基于这种想法,JSON如下所示:
{
"http://aims.fao.org/aos/agrovoc/xl_en_1299492690497": [
"Plantago ovata",
"Plantago minima",
"Plantago gooddingii",
"Plantago brunnea",
"Plantago fastigiata",
"Plantago insularis"
]
}
有办法吗?