我必须解析以柠檬格式提供的RDF数据,一切正常,但我无法访问一个字段,而且这是我需要的最多字段。
所需字段为lvont:nearlySameAs
,我只想取其中一个后续值(它们或多或少都相同)但是如果只有一种方法可以采取它们全部不是一个大问题
这是rdf的一部分:
@prefix lemon: <http://lemon-model.net/lemon#> .
@prefix lvont: <http://lexvo.org/ontology#> .
@prefix wordnet-ontology: <http://wordnet-rdf.princeton.edu/ontology#> .
@prefix mcren: <http://lodserver.iula.upf.edu/id/WordNetLemon/EN/> .
@prefix mcrgl: <http://lodserver.iula.upf.edu/id/WordNetLemon/GL/> .
@prefix mcres: <http://lodserver.iula.upf.edu/id/WordNetLemon/ES/> .
@prefix mcrca: <http://lodserver.iula.upf.edu/id/WordNetLemon/CAT/> .
@prefix mcreu: <http://lodserver.iula.upf.edu/id/WordNetLemon/EU/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix gawnl: <gawn-lemon/> .
<00000003-n> a wordnet-ontology:Synset ;
rdfs:label "aardvark n"@eng ;
rdfs:label "arcán talún"@gle ;
wordnet-ontology:part_of_speech wordnet-ontology:noun .
<arcán_talún-n> a lemon:LexicalEntry ;
lemon:canonicalForm <arcán_talún-n#CanonicalForm> ;
wordnet-ontology:part_of_speech wordnet-ontology:noun .
<arcán_talún-n#CanonicalForm> a lemon:Form ;
lemon:writtenRep "arcán talún"@gle .
<arcán_talún-n> lemon:sense <arcán_talún-n#1-n> .
<00000003-n> lvont:nearlySameAs mcreu:eus-30-02082791-n ,
mcrca:cat-30-02082791-n ,
mcres:spa-30-02082791-n ,
mcrgl:glg-30-02082791-n ,
mcren:eng-30-02082791-n .
<arcán_talún-n#1-n> a lemon:LexicalSense ;
wordnet-ontology:sense_number 1 ;
wordnet-ontology:old_sense_key "aardvark%1:05:00::" ;
lvont:nearlySameAs <http://lexvo.org/id/wordnet/30/noun/aardvark_1_05_00> ;
lemon:reference <00000003-n> .
<00000003-n> wordnet-ontology:synset_member <arcán_talún-n#1-n> .
这是我的疑问:
final String query =
"prefix lemon: <http://lemon-model.net/lemon#> \n" +
"prefix lvont: <http://lexvo.org/ontology#> \n" +
"prefix wordnet-ontology: <http://wordnet-rdf.princeton.edu/ontology#> \n" +
"prefix mcren: <http://lodserver.iula.upf.edu/id/WordNetLemon/EN/> \n" +
"prefix mcrgl: <http://lodserver.iula.upf.edu/id/WordNetLemon/GL/> \n" +
"prefix mcres: <http://lodserver.iula.upf.edu/id/WordNetLemon/ES/> \n" +
"prefix mcrca: <http://lodserver.iula.upf.edu/id/WordNetLemon/CAT/> \n" +
"prefix mcreu: <http://lodserver.iula.upf.edu/id/WordNetLemon/EU/> \n" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
"prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
"prefix gawnl: <gawn-lemon/> \n " +
"\n" +
"select ?lemon ?sense ?nsas where {\n" +
" ?lemon a lemon:Form ;\n" +
" lemon:writtenRep ?sense ;\n" +
" lvont:nearlySameAs ?nsas .\n" +
"}";
;
我可以检索前两个值但是如果我添加第三行,则查询不会产生任何输出。显然,我做错了什么,但我无法弄清楚要改变什么。提前谢谢。
更新查询
final String query =
"prefix lemon: <http://lemon-model.net/lemon#> \n" +
"prefix lvont: <http://lexvo.org/ontology#> \n" +
"prefix wordnet-ontology: <http://wordnet-rdf.princeton.edu/ontology#> \n" +
"prefix mcren: <http://lodserver.iula.upf.edu/id/WordNetLemon/EN/> \n" +
"prefix mcrgl: <http://lodserver.iula.upf.edu/id/WordNetLemon/GL/> \n" +
"prefix mcres: <http://lodserver.iula.upf.edu/id/WordNetLemon/ES/> \n" +
"prefix mcrca: <http://lodserver.iula.upf.edu/id/WordNetLemon/CAT/> \n" +
"prefix mcreu: <http://lodserver.iula.upf.edu/id/WordNetLemon/EU/> \n" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
"prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
"prefix gawnl: <gawn-lemon/> \n " +
"\n" +
"select ?wr ?nsas where {\n" +
" ?le a lemon:LexicalEntry ;\n" +
" lemon:canonicalForm ?cf .\n" +
" ?cf a lemon:Form ;\n" +
" lemon:writtenRep ?wr .\n" +
" ?le lemon:sense ?sense . \n" +
" ?sense a lemon:LexicalSense ; \n" +
" lemon:reference ?ref . \n" +
" ?ref lvont:nearlySameAs ?nsas. \n" +
" FILTER regex(str(?nsas), \"eng\")." +
"}";
使用这最后一个查询,我可以检索整个URI lvont:nearlySameAs mcreu:eus-30-02082791-n...
,现在最后一步应该是添加前缀
@prefix mcren: <http://lodserver.iula.upf.edu/id/WordNetLemon/EN/>
只获取一个值(而不是使用过滤器),但目前我无法知道如何做到这一点。
答案 0 :(得分:2)
您只能查询存在的数据。请再次查看数据,您会看到与查询的前两个三元模式匹配的唯一资源arcán_talún-n#CanonicalForm
?lemon a lemon:Form ;
lemon:writtenRep ?sense .
by the triples
<arcán_talún-n#CanonicalForm> a lemon:Form ;
lemon:writtenRep "arcán talún"@gle .
但是对于此资源,您的数据中没有谓词{{1}}的三元组。因此,数据中没有连接,您的查询模式也不匹配。如果只需要该属性的值,只需编写一个包含与数据匹配的模式的查询。
我不认为这是你想要的,但是
lvont:nearlySameAs
只会返回一个值,但它对我来说看起来并不有用。
SELECT ?nsas WHERE {?s <http://lemon-model.net/lemon#nearlySameAs> ?nsas } LIMIT 1