jena 查询 RDF turtle,我有一个前缀,后面跟着其他前缀

jena query RDF turtle, I have a prefix followed by other prefixes

我必须解析以柠檬格式给出的 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/> 

只获取一个值(而不是使用过滤器),但目前我不知道该怎么做。

您只能查询存在的数据。请再次查看数据,您会看到唯一与查询的前两个三元组模式匹配的资源 arcán_talún-n#CanonicalForm

?lemon a lemon:Form ;
       lemon:writtenRep ?sense .

三元组

<arcán_talún-n#CanonicalForm> a lemon:Form ;
    lemon:writtenRep "arcán talún"@gle .

但是对于此资源,您的数据中没有带有谓词 lvont:nearlySameAs 的三元组。因此,数据中没有连接,您的查询模式不匹配。如果您只想要 属性 的值,只需编写一个包含匹配数据的模式的查询。

我不认为这是你想要的,但是

SELECT ?nsas WHERE {?s <http://lemon-model.net/lemon#nearlySameAs> ?nsas } LIMIT 1

只是 return 一个值,但它对我来说似乎没有用。

更新:从某种意义上说,一个更复杂和关联的查询将是

PREFIX lemon: <http://lemon-model.net/lemon#>
PREFIX lvont: <http://lexvo.org/ontology#>

SELECT ?lemon ?sense ?nsas WHERE {
  ?lemon a lemon:Form ;
         lemon:writtenRep ?sense .
  ?sense lemon:reference ?ref .
  ?ref lvont:nearlySameAs ?nsas .
} LIMIT 1