私はxqueryの初心者です。簡単な説明を手伝っていただければ幸いです。BaseX 7.0.1 を使用しています。
次のような Dictionary.xml ファイルがあります。
<doc>
<entry>
<vedette>je</vedette>
<variante>je</variante>
<variante>j'</variante>
<partiedudiscours>pronom</partiedudiscours>
</entry>
</doc>
そして、注釈を付けたいテキストを含む別の malone_fr.xml ファイルがあります。これは次のようになります。
<doc>
L’Opportunité
Par : Walter Malone (1866-1915)
Ils ont mal conclu ceux qui disent que je ne reviendrai plus
Quand une fois j’ai frappé à ta porte et ne t’ai pas rencontré,
</doc>
そのため、dictionary.xml の < variante > 部分のコンテンツをテキストと比較し、テキストを < partieddiscours > のコンテンツでマークアップしたいと思います。これまでのところ、私はこのコードでそれを行うことができました:
let $comp := data(for $j in tokenize(for $i in db:open('malone_fr')/doc return $i,"\n")
return tokenize($j," "))
for $aa in $comp
return
for $lemme in db:open('dictionnaire')/doc/entry
return
let $oldName :=$aa
return
if ($oldName= $lemme/variante)
then
let $newName := element {$lemme/partiedudiscours} {$aa}
return
for $bb in $comp
return
if ($bb=$oldName)
then $newName
else ($bb)
else ()
それは私に次の結果を与えます: [最初の反復]
L’Opportunité Par : Walter Malone (1866-1915) Ils<verbe>ont</verbe> mal conclu ceux qui disent que je ne reviendrai plus
[2 回目の反復]
L’Opportunité Par : Walter Malone (1866-1915) <pronom>Ils</pronom>ont mal conclu ceux qui disent que je ne reviendrai plus
ご覧のとおり、反復による単語ごとの結果のみが表示されますが、テキスト全体に次のような注釈が付けられた結果が必要です。
L’Opportunité Par : Walter Malone (1866-1915) <pronom>Ils</pronom><verbe>ont</verbe> <adverbe>mal</adverbe> <verb>conclu</verb>
それを行うために for ループを処理する方法がわかりません。
前もって感謝します。