WordPress REST APIで非公開の投稿も含めて検索する

背景 WordPress REST APIで非公開の投稿も含めて検索する方法の備忘録です。 以下が参考になりました。 https://wordpress.org/support/topic/wordpress-rest-api-posts-not-showing-other-than-published/ 具体的には、以下のように、引数statusを使い、複数の状態を指定することで、それらを含む記事の一覧を取得できました。 GET /wp-json/wp/v2/posts?status=publish,draft,trash 参考になりましたら幸いです。

2024年5月29日 · 1 分 · Nakamura

Drupalのイベントをトリガーとして、GitHub Actionsを起動する

概要 Drupalのイベントをトリガーとして、GitHub Actionsを起動する方法の備忘録です。 以下のサイトが参考になりました。 https://qiita.com/hmaruyama/items/3d47efde4720d357a39e pipedreamの設定 triggerとcustom_requestを含むワークフローを作成します。 triggerについては、以下を参考にしてください。 https://qiita.com/hmaruyama/items/3d47efde4720d357a39e#pipedream側の設定 custom_requestにおいて、dispatchに関する設定を行います。 https://docs.github.com/ja/rest/repos/repos?apiVersion=2022-11-28#create-a-repository-dispatch-event 以下のような設定を行います。 curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/dispatches \ -d '{"event_type":"webhook"}' Drupalの設定 以下のモジュールをインストールします。 https://www.drupal.org/project/webhooks インストール後、以下のページで設定を行います。 /admin/config/services/webhook GitHub Actionsの設定 以下のようにrepository_dispatchを設定します。これにより、pipedreamからのリクエストに基づき、GitHub Actionsが実行されます。 name: Build and Deploy to Production on: push: branches: - main # Allows external webhook trigger repository_dispatch: types: - webhook permissions: contents: read concurrency: group: "build-and-deploy" cancel-in-progress: true jobs: ... まとめ pipedreamを使用せずに、Drupalのカスタムモジュールを作成することにより、GitHubに通知を送る方法もありそうです。(すでにそのようなモジュールが開発されている可能性が高そうですが、見つけることができませんでした。) ...

2024年5月28日 · 1 分 · Nakamura

YOLOv5モデル(文字領域検出)を使った推論アプリ

概要 以下で文字領域の検出アプリを公開しています。 https://huggingface.co/spaces/nakamura196/yolov5-char 上記アプリが動作しなくなっていたので、以下の記事と同じ手順で修正しました。 なお、本アプリで使用しているモデルの構築にあたっては、「『日本古典籍くずし字データセット』(国文研ほか所蔵/CODH加工) doi:10.20676/00000340」を使用しています。 この修正において、細かい改善も加えたので、紹介します。 gr.JSONの高さ設定 返却結果のJSONデータが大きくなると、結果が見づらいことがありました。 そこで、以下のように、demo.cssを設定することにより、 ... demo = gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples) demo.css = """ .json-holder { height: 300px; overflow: auto; } """ demo.launch() 以下のように、スクロールバーとともに結果を表示できるようになりました。 矩形のみの返却 文字数が多い場合、「Output Image」の画像が見にくいケースがありました。そこで、出力「Output Image with Boxes」を追加しました。 以下のような処理によって実現しています。 def yolo(im): results = model(im) # inference df = results.pandas().xyxy[0].to_json(orient="records") res = json.loads(df) im_with_boxes = results.render()[0] # results.render() returns a list of images # Convert the numpy array back to an image output_image = Image.fromarray(im_with_boxes) draw = ImageDraw.Draw(im) for bb in res: xmin = bb['xmin'] ymin = bb['ymin'] xmax = bb['xmax'] ymax = bb['ymax'] draw.rectangle([xmin, ymin, xmax, ymax], outline="red", width=3) return [ output_image, res, im, ] まとめ 参考になりましたら幸いです。 ...

2024年5月23日 · 1 分 · Nakamura

Drupalで翻訳がないノードの一覧を取得する

概要 Drupalで翻訳がないノードの一覧を取得する機会がありましたので、備忘録です。 方法 色々とやり方があるかと思いますが、今回はjsonapiを使用します。 マスタ言語が日本語(ja)、追加したい翻訳言語を英語(en)とします。 jsonapiによって、例えばcollectionというタクソノミーであれば、以下で取得できます。 https://xxx/jsonapi/taxonomy_term/collection また、以下のように/enを追加することで、翻訳ノードがある場合には、その情報が返却されます。 https://xxx/en/jsonapi/taxonomy_term/collection この時、翻訳ノードがある場合には、attributes/langcodeがenになりますが、翻訳がないノードについては、jaのままとなりました。 { "jsonapi": { "version": "1.0", "meta": { "links": { "self": { "href": "http://jsonapi.org/format/1.0/" } } } }, "data": [ { "type": "taxonomy_term--collection", "id": "1e3d1e6f-5178-4980-96bd-7b045f2cc66e", "links": { "self": { "href": "https://xxx/en/jsonapi/taxonomy_term/collection/1e3d1e6f-5178-4980-96bd-7b045f2cc66e?resourceVersion=id%3A19" } }, "attributes": { "drupal_internal__tid": 19, "drupal_internal__revision_id": 19, "langcode": "en", "revision_created": null, "revision_log_message": null, ... この性質を利用して、指定した言語と異なる言語コードがlangcodeに含まれた場合、その言語に対する翻訳がないノードとして抽出できそうです。 なお、JSON:APIの仕様に基づき、以下のようなpageクエリを使用することで、ページネーションを行うことができます。これを使って、データの一括取得を行います。 https://xxx/en/jsonapi/taxonomy_term/collection?page[offset]=50&page[limit]=50 まとめ 他にも良い方法があるかと思いますが、参考になりましたら幸いです。

2024年5月22日 · 1 分 · Nakamura

mdxでJupyter Labを起動する

概要 mdxでJupyter Labを起動する機会がありましたので、備忘録です。 mdxのセットアップは以下も参考にしてください。 参考 以下の動画がとても参考になりました。 https://youtu.be/-KJwtctadOI?si=xaKajk79b1MxTpJ6 セットアップ サーバ上 pipのインストール sudo apt install python3-pip パスを通す nano ~/.bashrc export PATH="$HOME/.local/bin:$PATH" source ~/.bashrc 以下により、juypter labが起動します。 jupyter-lab ローカル 以下で、ssh接続します。 ssh -N -L 8888:localhost:8888 mdxuser@xxx.yyy.zzz.lll -i ~/.ssh/mdx/id_rsa その上で、サーバ上のコンソールに表示されているアドレスにアクセスします。 http://localhost:8888/lab?token=xxx 結果、以下のように利用できるようになりました。 参考:ファイル転送 以下などで、ローカルからサーバへファイル転送を行う。 scp -i ~/.ssh/mdx/id_rsa /path/to/local/image.jpg username@remote_address:/path/to/remote/directory まとめ 参考になりましたら幸いです。

2024年5月22日 · 1 分 · Nakamura

Hugging Face SpacesとYOLOv5モデル(NDL-DocLデータセットで学習済み)を使った推論アプリの修正

概要 以下の記事でHugging Face Spacesと、以下の記事で紹介したYOLOv5モデル(NDL-DocLデータセットで学習済み)を使った推論アプリを紹介しました。 このアプリが動作しなくなっていたため、動作するように修正しました。 https://huggingface.co/spaces/nakamura196/yolov5-ndl-layout この修正で行なった対応についてメモします。 修正点 修正を加えたapp.pyは以下です。 import gradio as gr from PIL import Image import yolov5 import json model = yolov5.load("nakamura196/yolov5-ndl-layout") def yolo(im): results = model(im) # inference df = results.pandas().xyxy[0].to_json(orient="records") res = json.loads(df) im_with_boxes = results.render()[0] # results.render() returns a list of images # Convert the numpy array back to an image output_image = Image.fromarray(im_with_boxes) return [ output_image, res ] inputs = gr.Image(type='pil', label="Original Image") outputs = [ gr.Image(type="pil", label="Output Image"), gr.JSON() ] title = "YOLOv5 NDL-DocL Datasets" description = "YOLOv5 NDL-DocL Datasets Gradio demo for object detection. Upload an image or click an example image to use." article = "<p style='text-align: center'>YOLOv5 NDL-DocL Datasets is an object detection model trained on the <a href=\"https://github.com/ndl-lab/layout-dataset\">NDL-DocL Datasets</a>.</p>" examples = [ ['『源氏物語』(東京大学総合図書館所蔵).jpg'], ['『源氏物語』(京都大学所蔵).jpg'], ['『平家物語』(国文学研究資料館提供).jpg'] ] demo = gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples) demo.launch(share=False) まず、Gradioのバージョンアップに伴い、gr.inputs.Imageをgr.Imageなどに変更しました。 ...

2024年5月20日 · 1 分 · Nakamura

ultralyticsplus: ValueError: Invalid CUDA 'device=0' requested...への対処

概要 YOLOv8を用いた推論アプリを以下で公開しています。 https://huggingface.co/spaces/nakamura196/yolov8-ndl-layout 当初、以下のエラーが発生しました。 ValueError: Invalid CUDA 'device=0' requested. Use 'device=cpu' or pass valid CUDA device(s) if available, i.e. 'device=0' or 'device=0,1,2,3' for Multi-GPU. torch.cuda.is_available(): False torch.cuda.device_count(): 0 os.environ['CUDA_VISIBLE_DEVICES']: None See https://pytorch.org/get-started/locally/ for up-to-date torch install instructions if no CUDA devices are seen by torch. このエラーがに対して、以下のようにdeviceを追記することで対処できました。 results = model.predict(img, device="cpu") 詳細 以下のライブラリを使用しています。 https://github.com/fcakyon/ultralyticsplus そして、以下のように利用したところ、上記のエラーが発生しました。 from ultralyticsplus import YOLO, render_result # load model model = YOLO("nakamura196/yolov8-ndl-layout") img = 'https://dl.ndl.go.jp/api/iiif/2534020/T0000001/full/full/0/default.jpg' results = model.predict(img) そこで、以下のように引数を追記することで、エラーが解消しました。 results = model.predict(img, device="cpu") 補足 以下のように、ローカルにあるモデルを使用する際には、device="cpu"がなくても、上記のエラーが発生することなく使用できました。 ...

2024年5月20日 · 1 分 · Nakamura

IIIF Curation ListをTEIのfacsimile要素に変換する

概要 IIIF Curation ListをTEIのfacsimile要素に変換するライブラリを作成しました。 https://github.com/nakamura196/iiif-tei さらに、この変換を行うデモページを用意しました。 https://nakamura196.github.io/nuxt3-demo/iiif-tei-demo 使い方の動画は以下です。 https://youtu.be/Y5JlrJbtgz8 参考になりましたら幸いです。

2024年5月17日 · 1 分 · Nakamura

Japan Search利活用スキーマを使ったentity-lookupの試作

概要 以下の記事の続きです。 Japan Searchの利活用スキーマを使って、cwrcのentity-lookupを行うパッケージを試作します。 デモ 以下のページでお試しいただけます。 https://nakamura196.github.io/nuxt3-demo/entity-lookup/ Person, Place, Organizationなどの種別ごとに、JPS, Wikidata, VIAFにentity-lookupを行います。 ライブラリ 以下で公開しています。 https://github.com/nakamura196/jps-entity-lookup cwrcですでに公開されていたリポジトリhttps://github.com/cwrc/wikidata-entity-lookupをベースに、主に以下のファイルをJapan Searchの利活用スキーマに合わせて修正しました。 https://github.com/nakamura196/jps-entity-lookup/blob/main/src/index.js インストール方法 以下が参考になりました。 https://qiita.com/pure-adachi/items/ba82b03dba3ebabc6312 開発中 開発中のライブラリをインストールする場合には、以下のようにインストールしました。 pnpm i /Users/nakamura/xxx/jps-entity-lookup GitHubから GitHubからは以下のようにインストールします。 pnpm i nakamura196/jps-entity-lookup まとめ 参考になりましたら幸いです。

2024年5月17日 · 1 分 · Nakamura

cwrcのwikidata-entity-lookupを試す

概要 以下の記事の続きです。 LEAF-WRITERの特徴として、以下が挙げられています。 the ability to look up and select identifiers for named entity tags (persons, organizations, places, or titles) from the following Linked Open Data authorities: DBPedia, Geonames, Getty, LGPN, VIAF, and Wikidata. この機能は、以下のようなライブラリが使用されています。 https://github.com/cwrc/wikidata-entity-lookup この機能を試しています。 使い方 以下などで、npmパッケージが公開されています。 https://www.npmjs.com/search?q=cwrc 上記のリストにはありませんが、今回は以下を対象にします。 https://www.npmjs.com/package/wikidata-entity-lookup 以下でインストールします。 npm i wikidata-entity-lookup wikidataLookup.findPersonは、以下のように実行することができました。 <script lang="ts" setup> // @ts-ignore import wikidataLookup from "wikidata-entity-lookup"; interface Entity { id: string; name: string; description: string; uri: string; } const query = ref<string>(""); const results = ref<Entity[]>([]); const search = () => { wikidataLookup.findPerson(query.value).then((result: Entity[]) => { results.value = result; }); }; </script> デモ Nuxtでの実装例を用意しました。 ...

2024年5月16日 · 1 分 · Nakamura

CWRC XML Validator APIを試す

概要 TEI/XMLを対象としたエディタの一つとして、LEAF-WRITERがあります。 https://leaf-writer.leaf-vre.org/ 以下のように説明されています。 The XML & RDF online editor of the Linked Editing Academic Framework GitLabのリポジトリは以下です。 https://gitlab.com/calincs/cwrc/leaf-writer/leaf-writer このツールの特徴の一つとして、以下が説明されています。 continuous XML validation このvalidationには以下のAPIが使用されているようでした。 https://validator.services.cwrc.ca/ また、ライブラリは以下のようです。 https://www.npmjs.com/package/@cwrc/leafwriter-validator 今回は、上記のAPIを試してみます。 試す 以下のページが表示されます。 https://validator.services.cwrc.ca/ Try ItのPOSTで以下を試しています。 Schema URL: https://raw.githubusercontent.com/nakamura196/test2021/main/tei_excel.rng Schema Type: RNG_XML Document Content: <?xml version="1.0" encoding="UTF-8"?> <?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?> <?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?> <TEI xmlns="http://www.tei-c.org/ns/1.0"> <teiHeader> <fileDesc> <titleStmt> <title>Title</title> </titleStmt> <publicationStmt> <p>Publication Information</p> </publicationStmt> <sourceDesc> <p>Information about the source</p> </sourceDesc> </fileDesc> </teiHeader> <text> <body> <p> I am <name>Satoru Nakamura</name>. </p> </body> </text> </TEI> 上記は、http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rngをスキーマとする場合にはエラーが生じませんが、使用可能なタグを限定したhttps://raw.githubusercontent.com/nakamura196/test2021/main/tei_excel.rngではエラーが生じるはずです。 ...

2024年5月16日 · 1 分 · Nakamura

RELAX NGとSchematron

概要 oXygen XML EditorでTEI/XMLを作成すると、以下のようなテンプレートが作成されます。 <?xml version="1.0" encoding="UTF-8"?> <?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?> <?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?> <TEI xmlns="http://www.tei-c.org/ns/1.0"> <teiHeader> <fileDesc> <titleStmt> <title>Title</title> </titleStmt> <publicationStmt> <p>Publication Information</p> </publicationStmt> <sourceDesc> <p>Information about the source</p> </sourceDesc> </fileDesc> </teiHeader> <text> <body> <p>Some text here.</p> </body> </text> </TEI> この時、以下の違いが気になりましたので、GPT4への問い合わせ結果を共有します。 <?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?> <?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?> 回答 2行目と3行目の違いは、schematypens属性に指定されている名前空間です。以下に詳細を説明します。 2行目 <?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?> href : http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng type : application/xml schematypens : http://relaxng.org/ns/structure/1.0 この行は、TEI (Text Encoding Initiative) ドキュメントに対して RELAX NG スキーマを指定しています。RELAX NG はXML文書の構造を検証するためのスキーマ言語です。 ...

2024年5月16日 · 1 分 · Nakamura

TEI PublisherのODDの設定例①

概要 TEI PublisherのODDに関する設定方法の備忘録です。 変換先で非表示にする 以下が参考になりました。 https://teipublisher.com/exist/apps/tei-publisher/documentation/odd-customization-other-behaviours behaviour でomit を選択します。 これにより、変換先(上記の例では、latex )でpb要素が非表示になりました。 lbで改行させる latexへの変換に限ったものかもしれませんが、behaviour でparagraph を選択することで、lbタグがあった箇所に、空白行が挿入されるようになりました。

2024年5月15日 · 1 分 · Nakamura

Docker版のTEI Publisherを使用する

概要 Docker版のTEI Publisherを使用する機会があったので、備忘録です。 https://teipublisher.com/exist/apps/tei-publisher-home/index.html TEI Publisherは以下のように説明されています。 TEI Publisher facilitates the integration of the TEI Processing Model into exist-db applications. The TEI Processing Model (PM) extends the TEI ODD specification format with a processing model for documents. That way intended processing for all elements can be expressed within the TEI vocabulary itself. It aims at the XML-savvy editor who is familiar with TEI but is not necessarily a developer. (機械翻訳) TEI Publisherは、TEI Processing Modelをexist-dbアプリケーションに統合することを容易にします。TEI Processing Model(PM)は、ドキュメントの処理モデルを備えたTEI ODD仕様形式を拡張します。これにより、すべての要素の意図された処理をTEI語彙自体内で表現することができます。このモデルは、TEIに精通しているが必ずしも開発者ではないXML熟練のエディターを対象としています。 ...

2024年5月15日 · 1 分 · Nakamura

PythonでXML文字列を整形する

概要 PythonでXML文字列を整形するプログラムの備忘録です。 プログラム1 以下を参考にしました。 https://hawk-tech-blog.com/python-learn-prettyprint-xml/ 不要な空行を削除する処理などを加えています。 from xml.dom import minidom import re def prettify(rough_string): reparsed = minidom.parseString(rough_string) pretty = re.sub(r"[\t ]+\n", "", reparsed.toprettyxml(indent="\t")) # インデント後の不要な改行を削除 pretty = pretty.replace(">\n\n\t<", ">\n\t<") # 不要な空行を削除 pretty = re.sub(r"\n\s*\n", "\n", pretty) # 連続した改行(空白行を含む)を単一の改行に置換 return pretty プログラム2 以下を参考にしました。 https://qiita.com/hrys1152/items/a87b4ca3c74ec4997f66 TEI/XMLを処理する場合には、名前空間の登録をおすすめします。 import xml.etree.ElementTree as ET # 名前空間の登録 ET.register_namespace('', "http://www.tei-c.org/ns/1.0") tree = ET.ElementTree(ET.fromstring(xml_string)) ET.indent(tree, space=' ') tree.write('output.xml', encoding='UTF-8', xml_declaration=True) まとめ 参考になりましたら幸いです。

2024年5月9日 · 1 分 · Nakamura

CMYKカラーの画像から色を反転させないconvertの方法

概要 例えばIIIFを用いた画像配信において、CMYKカラーの画像に対して、ImageMagickで以下のような変換処理を行うと、色が反転するケースがありました。 convert source_image.tif -alpha off -define tiff:tile-geometry=256x256 -compress jpeg 'ptif:output_image.tif' 元画像 (布LAB.で公開されている画像を利用させていただいています。) Image Annotator(神崎正英氏作成)での表示例 これは、Cantaloupe Image ServerやIIPImageなどのイメージサーバ、および、Image AnnotatorやMirador, Universal Viewerなどのビューア側の問題ではなく、作成されるtiled TIFFs画像に問題があるようです。 本記事では、この問題への対応方法について説明します。 背景 同様の不具合は、以下の記事など、いくつかの場所で報告されていました。 https://scrapbox.io/giraffate/ImageMagickでCMYKのJPG画像を合成したら色が反転するバグ 解決策として、今回は以下を参考にしました。 https://www.imagemagick.org/discourse-server/viewtopic.php?t=32585 -colorspace sRGBを追加するようです。 変換 tiled TIFFsを作成するコマンドは以下を参考にします。 https://samvera.github.io/serverless-iiif/docs/source-images#using-imagemagick 具体的には、以下です。 convert source_image.tif -alpha off -define tiff:tile-geometry=256x256 -compress jpeg 'ptif:output_image.tif' 上記をCMYKカラーの画像に対してそのまま実行すると、冒頭で紹介したように、反転した画像が表示されました。 なお、Image ServerにはCantaloupe Image Serverを使用していますが、IIPImageなどでも同様の事象が確認されました。 修正した変換コマンド 以下のように、-colorspace sRGBを追加します。 convert source_image.tif -alpha off -colorspace sRGB -define tiff:tile-geometry=256x256 -compress jpeg 'ptif:output_image.tif' 結果、以下のように、色が反転せずに、Image AnnotatorなどもIIIF対応ビューアでも表示されるようになりました。 参考 画像表示の確認にあたり、MiradorやUniversal Viewerでは、IIIFマニフェストファイルのURLを入力することが一般的ですが、Image Annotatorでは、画像のURIを入力することができます。 ...

2024年5月8日 · 1 分 · Nakamura

RDFストアのトリプル数を数える2: 共起頻度

概要 RDFトリプルに対して、共起頻度を数える機会がありましたので、備忘録です。以下の記事に続き、今回もジャパンサーチのRDFストアを例にします。 例1 以下は、刀剣タイプのインタンスのうち、共通を作成者(schema:creator )を持つトリプルの数をカウントしています。フィルタによって、同一のインスタンスを避け、また重複カウントを避けています。 select (count(*) as ?count) where { ?entity1 a type:刀剣; schema:creator ?value . ?entity2 a type:刀剣; schema:creator ?value . FILTER(?entity1 != ?entity2 && ?entity1 < ?entity2) } https://jpsearch.go.jp/rdf/sparql/easy/?query=select+(count(*)+as+%3Fcount)+where+{ ++%3Fentity1+a+type%3A刀剣%3B +++++++++++++schema%3Acreator+%3Fvalue+. ++%3Fentity2+a+type%3A刀剣%3B +++++++++++++schema%3Acreator+%3Fvalue+. ++FILTER(%3Fentity1+!%3D+%3Fentity2+%26%26+%3Fentity1+<+%3Fentity2) } 例2 具体的なトリプルを表示してみます。 select ?entity1 ?entity2 ?value where { ?entity1 a type:刀剣; schema:creator ?value . ?entity2 a type:刀剣; schema:creator ?value . FILTER(?entity1 != ?entity2 && ?entity1 < ?entity2) } https://jpsearch.go.jp/rdf/sparql/easy/?query=select+%3Fentity1+%3Fentity2+%3Fvalue+where+{ ++%3Fentity1+a+type%3A刀剣%3B +++++++++++++schema%3Acreator+%3Fvalue+. ++%3Fentity2+a+type%3A刀剣%3B +++++++++++++schema%3Acreator+%3Fvalue+. ++FILTER(%3Fentity1+!%3D+%3Fentity2+%26%26+%3Fentity1+<+%3Fentity2) } ...

2024年5月8日 · 1 分 · Nakamura

RDFストアのトリプル数を数える

概要 RDFストアのトリプル数を数える方法について、備忘録です。 今回は、ジャパンサーチのRDFストアを例にします。 https://jpsearch.go.jp/rdf/sparql/easy/ トリプル数 以下でトリプル数をカウントできます。 SELECT (COUNT(*) AS ?NumberOfTriples) WHERE { ?s ?p ?o . } 結果は以下です。 https://jpsearch.go.jp/rdf/sparql/easy/?query=SELECT+(COUNT(*)+AS+%3FNumberOfTriples) WHERE+{ ++%3Fs+%3Fp+%3Fo+. } 本記事の執筆時点(2024年5月6日)において、12億8064万5565トリプルありました。 NumberOfTriples 1280645565 特定のプロパティでどれだけのトリプルが接続されているか 次に、特定のプロパティでどれだけのトリプルが接続されているかをカウントしてみます。以下がクエリ例です。 SELECT ?p (COUNT(*) AS ?count) WHERE { ?s ?p ?o . } GROUP BY ?p ORDER BY DESC(?count) 結果は以下です。 https://jpsearch.go.jp/rdf/sparql/easy/?query=SELECT+%3Fp+(COUNT(*)+AS+%3Fcount) WHERE+{ ++%3Fs+%3Fp+%3Fo+. } GROUP+BY+%3Fp ORDER+BY+DESC(%3Fcount) schema:description で接続されるトリプルが399,447,925件、約4億件あることがわかります。 p count schema:description 399447925 rdf:type 84363276 jps:relationType 72908233 jps:value 72214780 schema:name 57377225 schema:provider 52481873 指定したプロパティを使用して、特定のサブジェクトとオブジェクトのタイプの組み合わせをカウントする 上記の打ち合わせの概要を知るにあたり、?subject と ?object が schema:description プロパティによって結びつけられている場合のサブジェクトタイプとオブジェクトタイプの組み合わせをカウントします。 SELECT ?subjectType ?objectType (COUNT(*) AS ?count) WHERE { ?subject schema:description ?object . ?subject rdf:type ?subjectType . optional {?object rdf:type ?objectType . } } GROUP BY ?subjectType ?objectType ORDER BY DESC(?count) 結果は以下です。 ...

2024年5月6日 · 1 分 · Nakamura

DrupalのSearch APIにおいて、大文字・小文字を無視して検索する

概要 DrupalのSearch APIを用いた検索において、大文字・小文字を無視した検索を行うための備忘録です。 方法 以下にアクセスして、Ignore caseにチェックを入れます。 /admin/config/search/search-api/index/<コンテンツタイプ>/processors さらに画面下部のProcessor settings において、本処理を適用したいフィールドを選択します。以下のように、すべてのフィールドを選択することもできました。 再インデックスを行うことで、上記の設定が反映されます。 まとめ 参考になりましたら幸いです。

2024年5月6日 · 1 分 · Nakamura

TEIGarageを試す

概要 TEIGarageは、以下のように説明されています。 https://github.com/TEIC/TEIGarage/ TEIGarage is a webservice and RESTful service to transform, convert and validate various formats, focussing on the TEI format. TEIGarage is based on the proven OxGarage. (機械翻訳)TEIGarageは、TEIフォーマットを中心にさまざまなフォーマットの変換、変換、検証を行うウェブサービスおよびRESTfulサービスです。TEIGarageは、実績のあるOxGarageに基づいています。 試す 以下のページで試すことができます。 https://teigarage.tei-c.org/ 以下で公開されている「TEI Minimal」のoddファイルを対象にします。このファイルは、Romaのプリセットの一つとしても使用されています。 https://tei-c.org/Vault/P5/current/xml/tei/Exemplars/tei_minimal.odd 上記のファイルをダウンロードします。 そして、TEIGarageのサイトにおいて、「Convert from」に「Compiled TEI ODD」、「Convert to」に「xHTML」を選択して、「ファイルを選択」にダウンロードしたoddファイルをアップロードします。 ダウンロードされたHTMLファイルはブラウザ等で確認することができます。 ちなみに、「Show advanced options」をクリックすると、パラメータのほか、変換に使用するURLが表示されます。 URLはエンコードされているため、デコードすると、以下になります。 https://teigarage.tei-c.org/ege-webservice/Conversions/ODDC:text:xml/TEI:text:xml/xhtml:application:xhtml+xml/conversion?properties=truetrueenfalsedefaulttruetrueenfalsedefault propertiesパラメータの中に、以下のxml記述を確認することができます。 <conversions> <conversion index="0"> <property id="oxgarage.getImages">true</property> <property id="oxgarage.getOnlineImages">true</property> <property id="oxgarage.lang">en</property> <property id="oxgarage.textOnly">false</property> <property id="pl.psnc.dl.ege.tei.profileNames">default</property> </conversion> <conversion index="1"> <property id="oxgarage.getImages">true</property> <property id="oxgarage.getOnlineImages">true</property> <property id="oxgarage.lang">en</property> <property id="oxgarage.textOnly">false</property> <property id="pl.psnc.dl.ege.tei.profileNames">default</property> </conversion> </conversions> Open API 以下にアクセスすると、Open APIに基づき、利用可能なオプション等を確認することができます。 ...

2024年5月5日 · 1 分 · Nakamura