0

A には RDF ファイルがあり、特定の作成者の説明を選択する選択 SPARQL クエリを作成したいと考えています。以下のようなクエリを試しましたが、成功しませんでした。私は SPARQL を初めて使用するので、誰か助けていただければ幸いです…</p>

私の試み:

String query = "PREFIX schema: <"+Constants.SCHEMA+"> \n" + 
               "SELECT ?description \n" +
               "WHERE { \n" +
                   "?review a schema:Review; \n" +
                   "schema:author \"Judson C.\"; \n" +
               "}"; 

RDF ファイルは次のようになります。

<rdf:Description rdf:nodeID="A3">
    <schema:ratingValue>5.0</schema:ratingValue>
    <rdf:type rdf:resource="http://schema.org/Rating" />
</rdf:Description>
<rdf:Description rdf:nodeID="A4">
    < schema:reviewRating rdf:nodeID="A5"/>
    <schema:description>OMG Love this place!! But glad I don't have to
        stand in line for an hour like back in the day to get my fix!</schema:description>
    <schema:datePublished>2013-05-18</schema:datePublished>
    <schema:author>Judson C.</schema:author>
    <rdf:type rdf:resource="http://schema.org/Review" />
</rdf:Description>
<rdf:Description rdf:nodeID="A6">
    <schema:reviewRating rdf:nodeID="A7" />
    <schema:description>If you're ever wondering of where to stuff your
        face with a good ol' sandwich, you'll definitely have to pop in at
        Ike's Place. Not only are the different sandwiches uniquely named,
        they're also uniquely flavor profiled. A wonderful experience
        indeed!Sandwiches I've personally ordered are the Love Triangle,
        Nacho girl, and the Al Bundy. For all you people out there who loved
        the tv show, Married with Children, I think you could appreciate the
        sentiment of having a sammie named after the 'No Ma'am enthusiast. I
        know I did. Ahhh... *tucks hand under pant waistband*All kidding
        aside, these sandwiches are pretty legit. You go to the counter and
        order whichever sandwich sounds appealing and they can either add
        chips or a drink to your meal. Simple. They have a wide range of
        sandwiches that are made to please any meat lover, vegetarian, or
        vegan palate alike. The huge variety is an A+ in my book. They can
        even individualize and customize your sandwich to your liking. This
        means that even the pickiest of eaters are welcome!So if you're
        interested in a fun place to enjoy a good sandwich, most definitely
        give 'em a try!</schema:description>
    <schema:datePublished>2013-04-30</schema:datePublished>
    <schema:author>Ann S.</schema:author>
    <rdf:type rdf:resource="http://schema.org/Review" />
</rdf:Description>
4

2 に答える 2

2

簡潔な答え

簡単に言えば、クエリが構文的に適切に形成されておらず、探しているものが返されないということです。.クエリは、セミコロン ( ) ではなくピリオド ( )でトリプル パターンを終了する必要があります;。固定クエリは次のようになります。

PREFIX schema: <http://schema.org/>
SELECT ?description
WHERE {
  ?review a schema:Review ;
          schema:author "Judson C." .
}

ただし、これはクエリで使用されないSELECT変数?descriptionであるため、常に空です。おそらくSELECT ?review、パターンに追加するか、パターンに追加しますschema:description ?description

長い答え

これが機能することを示すもう少し詳細が続きます。あなたが提供した RDF は整形式ではないため、それに対してテストするのは困難です。私はあなたが提供したものを取り、それをN3として書き、次のようにしました. (RDF/XML も回答の最後にあります。)

@prefix schema: <http://schema.org/> .

[]
  a schema:Rating ;
  schema:ratingValue "5.0" .

[]
  a schema:Review ;
  schema:reviewRating [] ;
  schema:description "OMG Love this place!!  But glad I don't have to stand in line for an hour like back in the day to get my fix!" ;
  schema:datePublished "2013-05-18" ;
  schema:author "Judson C." .

[]
 a schema:Review ;
 schema:reviewRating [] ;
 schema:description "If you're ever wondering of where to stuff your face with a good ol' sandwich, you'll definitely have to pop in at Ike's Place. Not only are the different sandwiches uniquely named, they're also uniquely flavor profiled. A wonderful experience indeed!Sandwiches I've personally ordered are the Love Triangle, Nacho girl, and the Al Bundy. For all you people out there who loved the tv show, Married with Children, I think you could appreciate the sentiment of having a sammie named after the 'No Ma'am enthusiast. I know I did. Ahhh... *tucks hand under pant waistband*All kidding aside, these sandwiches are pretty legit. You go to the counter and order whichever sandwich sounds appealing and they can either add chips or a drink to your meal. Simple. They have a wide range of sandwiches that are made to please any meat lover, vegetarian, or vegan palate alike. The huge variety is an A+ in my book. They can even individualize and customize your sandwich to your liking. This means that even the pickiest of eaters are welcome!So if you're interested in a fun place to enjoy a good sandwich, most definitely give 'em a try!" ;
 schema:datePublished "2013-04-30" ;
 schema:author "Ann S." .

前述のように、クエリにはいくつかの構文エラーがあります。トリプル パターンは.ではなく で終わる必要があり、次の;ようにする必要があります。

PREFIX schema: <http://schema.org/>
SELECT ?description
WHERE {
  ?review a schema:Review ;
          schema:author "Judson C." .
}

?descriptionただし、クエリで使用されていないため、これは有用なものを返しません。Jena の ARQ を使用して (およびクエリを schema.query として記述)、1 つの行 (パターンが一致したため) を出力しますが、バインドされていない変数を使用します。

$ /usr/local/lib/apache-jena-2.10.0/bin/arq \
  --query schema.query \
  --data schema.n3
---------------
| description |
===============
|             |
---------------

バインドするクエリは次の?descriptionとおりです。

PREFIX schema: <http://schema.org/>
SELECT ?description
WHERE {
  ?review a schema:Review ;
          schema:author "Judson C." ;
          schema:description ?description .
}

予想どおり、いくつかの有用な結果が得られます。

$ /usr/local/lib/apache-jena-2.10.0/bin/arq \
  --query schema2.query \
  --data schema.n3
-------------------------------------------------------------------------------------------------------------------
| description                                                                                                     |
===================================================================================================================
| "OMG Love this place!!  But glad I don't have to stand in line for an hour like back in the day to get my fix!" |
-------------------------------------------------------------------------------------------------------------------

RDF/XML 付録

手元にあるデータの RDF/XML シリアル化は次のとおりです。

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:schema="http://schema.org/">
  <schema:Review>
    <schema:reviewRating rdf:parseType="Resource">
    </schema:reviewRating>
    <schema:description>If you're ever wondering of where to stuff your face with a good ol' sandwich, you'll definitely have to pop in at Ike's Place. Not only are the different sandwiches uniquely named, they're also uniquely flavor profiled. A wonderful experience indeed!Sandwiches I've personally ordered are the Love Triangle, Nacho girl, and the Al Bundy. For all you people out there who loved the tv show, Married with Children, I think you could appreciate the sentiment of having a sammie named after the 'No Ma'am enthusiast. I know I did. Ahhh... *tucks hand under pant waistband*All kidding aside, these sandwiches are pretty legit. You go to the counter and order whichever sandwich sounds appealing and they can either add chips or a drink to your meal. Simple. They have a wide range of sandwiches that are made to please any meat lover, vegetarian, or vegan palate alike. The huge variety is an A+ in my book. They can even individualize and customize your sandwich to your liking. This means that even the pickiest of eaters are welcome!So if you're interested in a fun place to enjoy a good sandwich, most definitely give 'em a try!</schema:description>
    <schema:datePublished>2013-04-30</schema:datePublished>
    <schema:author>Ann S.</schema:author>
  </schema:Review>
  <schema:Review>
    <schema:reviewRating rdf:parseType="Resource">
    </schema:reviewRating>
    <schema:description>OMG Love this place!!  But glad I don't have to stand in line for an hour like back in the day to get my fix!</schema:description>
    <schema:datePublished>2013-05-18</schema:datePublished>
    <schema:author>Judson C.</schema:author>
  </schema:Review>
  <schema:Rating>
    <schema:ratingValue>5.0</schema:ratingValue>
  </schema:Rating>
</rdf:RDF>
于 2013-05-23T17:53:07.417 に答える
0

質問は本当にJavaではなくSPARQLにあると思います。

書いているかどうか試しましたか:

?review schema:author "Judson C."^^xsd:string

また:

?review schema:author ?author:
FILTER(str(?author)=="Judson C.")
于 2013-05-23T16:43:33.297 に答える