質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

632閲覧

求められている章よりも深い章・節を求めたい(深い層まで求めたい) SPARQL/Wikidata/

takumiohashi012

総合スコア4

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/10/15 15:16

目的:現在のコードで求められている章よりも深い章・節を求めたい(深い層まで求めたい)

現在Wikidata Query Service内以下のコードで聖書(マタイによる福音書)に関する作品の画像を求めています。
画像を求めるに当たっての過程で
1新約聖書(マタイによる福音)のすべての章を求める 
2その章のうち描かれた実体・もの(エピソード)を求める
3それを描いた画像を求める
という順番で進めています。
最終目標である画像の結果を求めることはできていますが、
以下の結果にあるようにこのコードでは最初の変数mat_partには章のみが反映されています。

私は現在、その作品がどの1.章と2.節で記載されているかまでを求めることを目標としています。

____________________________________________
コード:
SELECT ?mat_part ?mat_ob ?mat_sec ?mat_img #変数
?mat_partLabel ?mat_obLabel ?mat_secLabel ?mat_imgLabel #1行目3つの変数のラベルを表示するための変数
WHERE
{
wd:Q392302 wdt:P527 ?mat_part.
//主:マタイによる福音書(Q392392) 述:この主題の一部(P527) 目:mat_part
?mat_part wdt:P180 ?mat_ob.
//主:mat_part       述:描かれた実体(P180)  目:mat_ob
?mat_ob wdt:P18 ?mat_img.
//主:mat_ob        述:画像(P18)       目:mat_img

SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } #ラベル出力用の処理
}

____________________________________________
結果:
mat_part wd:Q6789861
mat_ob wd:Q1267621
mat_img commons:Scarsellino - Driving of the merchants from the temple - Google Art Project.jpg 
mat_partLabel マタイによる福音書 第21章
mat_obLabel Cleansing of the Temple
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Scarsellino%20-%20Driving%20of%20the%20merchants%20from%20the%20temple%20-%20Google%20Art%20Project.jpg
____________________________________________
mat_part wd:Q6789938
mat_ob wd:Q4015942
mat_img commons:Ghirlandaio, Domenico - Calling of the Apostles - 1481.jpg
mat_partLabel マタイによる福音書 第4章
mat_obLabel calling of the disciples
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Ghirlandaio%2C%20Domenico%20-%20Calling%20of%20the%20Apostles%20-%201481.jpg
____________________________________________
mat_part  wd:Q6790067
mat_ob wd:Q4015942
mat_img commons:Ghirlandaio, Domenico - Calling of the Apostles - 1481.jpg
mat_partLabel マタイによる福音書 第9章
mat_obLabel calling of the disciples
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Ghirlandaio%2C%20Domenico%20-%20Calling%20of%20the%20Apostles%20-%201481.jpg
____________________________________________
mat_part wd:Q6790067
mat_ob wd:Q5022191
mat_img commons:Bernardo Strozzi - Calling of St Matthew.jpg
mat_partLabel マタイによる福音書 第9章
mat_obLabel Calling of Matthew
mat_imgLabel
http://commons.wikimedia.org/wiki/Special:FilePath/Bernardo%20Strozzi%20-%20Calling%20of%20St%20Matthew.jpg
____________________________________________
mat_part wd:Q6789819
mat_ob  wd:Q56857972
mat_img  commons:Degollación de San Juan Bautista, Juan Martínez Montañés.jpg
mat_partLabel マタイによる福音書 第14章
mat_obLabel beheading of John the Baptist
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Degollaci%C3%B3n%20de%20San%20Juan%20Bautista%2C%20Juan%20Mart%C3%ADnez%20Monta%C3%B1%C3%A9s.jpg

__________________________________________
理想的な実行結果
mat_part wd:Q6789819
mat_ob  wd:Q56857972
mat_img  commons:Degollación de San Juan Bautista, Juan Martínez Montañés.jpg
mat_partLabel マタイによる福音書 第14章 23~28
mat_obLabel beheading of John the Baptist
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Degollaci%C3%B3n%20de%20San%20Juan%20Bautista%2C%20Juan%20Mart%C3%ADnez%20Monta%C3%B1%C3%A9s.jpg

文章に至らない点もあるとは思いますが、コメント等ですぐに対応させていただきます。
よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

その作品がどの1.章と2.節で記載されているか

ここで「作品」と書かれているのは、「エピソード」のことでしょうか。
もしかしたら「画像」のつもりで書かれたのかもしれませんが、画像自体は聖書に記載されていません。その画像が題材としているエピソードが聖書に記載されています。ですから聖書の章節番号を属性として持つのは画像ではなくエピソードです。

クエリで表示された個別のエピソードの、それぞれのWikiDataページを確認していただけたらわかりますが、聖書の章番号はすべてのエピソードがデータとして持っていますが、節番号に関してはデータとして持っているエピソードと、持っていないエピソードがあります。
WikiDataはボランティアベースで運営されていますので、誰かが入力していないデータは、ないです。ないものは取得できません。

(ちなみにWikiDataの「マタイによる福音書第9章」と「マタイによる福音書第4章」の項目は、いずれも題材として "calling of the disciples" を持つとされていますが、当の "calling of the disciples" のページには、章節番号としてマタイによる福音書第4章第18-22節しか記載されていません。これは「マタイによる福音書第9章」のデータが間違っているのか、"calling of the disciples" にデータが入力されていないだけのか、データだけからは分かりません。ボランティアベースなのでこのようなことも起こります。)

以上のような前置きをした上でになりますが、クエリは以下のようになります。

sparql

1SELECT 2?mat_part ?mat_sec ?mat_ob ?book_part ?mat_img 3?mat_partLabel ?mat_secLabel ?mat_obLabel ?mat_imgLabel 4WHERE 5{ 6wd:Q392302 wdt:P527 ?mat_part. 7?mat_part wdt:P180 ?mat_ob. 8OPTIONAL { 9 ?mat_ob p:P361 ?stmt_of_p361. 10 ?stmt_of_p361 ps:P361 ?mat_part. 11 ?stmt_of_p361 pq:P958 ?mat_sec. 12 ?mat_part wdt:P361 wd:Q392302. 13 } 14?mat_ob wdt:P18 ?mat_img. 15 16SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 17}

以下が実行結果です。実行結果を確認していただけたらわかる通り、各エピソードのWikiDataページに聖書の節番号をデータとして持っている場合しか、節番号は抽出されていません。


mat_part wd:Q6789861
mat_sec 12-17
mat_ob wd:Q1267621
mat_img commons:Scarsellino - Driving of the merchants from the temple - Google Art Project.jpg
mat_partLabel マタイによる福音書 第21章
mat_secLabel 12-17
mat_obLabel Cleansing of the Temple
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Scarsellino%20-%20Driving%20of%20the%20merchants%20from%20the%20temple%20-%20Google%20Art%20Project.jpg


mat_part wd:Q6789938
mat_sec 18-22
mat_ob wd:Q4015942
mat_img commons:Ghirlandaio, Domenico - Calling of the Apostles - 1481.jpg
mat_partLabel マタイによる福音書 第4章
mat_secLabel 18-22
mat_obLabel calling of the disciples
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Ghirlandaio%2C%20Domenico%20-%20Calling%20of%20the%20Apostles%20-%201481.jpg


mat_part wd:Q6790067
mat_ob wd:Q4015942
mat_img commons:Ghirlandaio, Domenico - Calling of the Apostles - 1481.jpg
mat_partLabel マタイによる福音書 第9章
mat_obLabel calling of the disciples
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Ghirlandaio%2C%20Domenico%20-%20Calling%20of%20the%20Apostles%20-%201481.jpg


mat_part wd:Q6790067
mat_ob wd:Q5022191
mat_img commons:Bernardo Strozzi - Calling of St Matthew.jpg
mat_partLabel マタイによる福音書 第9章
mat_obLabel Calling of Matthew
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Bernardo%20Strozzi%20-%20Calling%20of%20St%20Matthew.jpg


mat_part wd:Q6789819
mat_ob wd:Q56857972
mat_img commons:Degollación de San Juan Bautista, Juan Martínez Montañés.jpg
mat_partLabel マタイによる福音書 第14章
mat_obLabel beheading of John the Baptist
mat_imgLabel http://commons.wikimedia.org/wiki/Special:FilePath/Degollaci%C3%B3n%20de%20San%20Juan%20Bautista%2C%20Juan%20Mart%C3%ADnez%20Monta%C3%B1%C3%A9s.jpg

投稿2021/10/16 04:16

etherbeg

総合スコア1195

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takumiohashi012

2021/10/17 07:45

ご丁寧な回答ありがとうございます。 私の考えが誤っていた点も含めご指摘いただき、大変勉強になりました。 また実行結果も私が求めていたものであり、過程も参考にさせていただきます。 様々な角度からのご意見いただきありがとうございます。
guest

0

Wikidata Query Serviceも聖書(のデータ構造)についても無知ですが
depicts (P180)からsection, verse, paragraph, or clause (P958)mat_secとして抽出してみました。

SQL

1SELECT ?mat_part ?mat_ob ?mat_sec ?mat_img #変数 2?mat_partLabel ?mat_obLabel ?mat_secLabel ?mat_imgLabel #1行目3つの変数のラベルを表示するための変数 3WHERE 4{ 5wd:Q392302 wdt:P527 ?mat_part. 6# 主:マタイによる福音書(Q392392) 述:この主題の一部(P527) 目:mat_part 7 8?mat_part wdt:P180 ?mat_ob. 9# 主:mat_part       述:描かれた実体(P180)  目:mat_ob 10 11?mat_obj wdt:P958 ?mat_sec. 12# 主:mat_obj       述:verse(P958)  目:mat_sec 13 14?mat_ob wdt:P18 ?mat_img. 15# 主:mat_ob        述:画像(P18)       目:mat_img 16 17SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } #ラベル出力用の処理 18}

上記の結果ですが、コレジャナイ感があります。

私は現在、その作品がどの1.章と2.節で記載されているかまでを求めることを目標としています。

というのが最終目的であれば
質問で提示された元のクエリで画像の一覧を得たうえで、さらにそれらの各画像において

  • 画像の説明(といったメタ情報)を得る。
  • 画像の説明から章と節を得る。

といった2段階のクエリを組まないといけないような気がします。

投稿2021/10/16 01:54

編集2021/10/16 02:51
can110

総合スコア38266

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

etherbeg

2021/10/16 02:45

?mat_obj wdt:P1661 ?mat_sec. とあるところは ?mat_obj wdt:P958 ?mat_sec. の間違いではないでしょうか。
can110

2021/10/16 02:52

ご指摘ありがとうございます。間違っていましたので修正しました。
takumiohashi012

2021/10/17 07:53

ご回答いただきありがとうございます。 画像の一覧を得てから、次にその作品の情報を扱い求めていくという過程がものすごく勉強になりました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問