Handling AttributeError: 'ImageDraw' object has no attribute 'textsize'

When using the following in Python’s Pillow: t f t e o x x n w t t , s i = t z x e I h m = a = g 1 e d 4 F r o a n w t . . t t e r x u t e l t e y n p g e t ( h " ( A l r a i b a e l l , U n f i o c n o t d = e f . o t n t t f ) " , s i z e = t e x t s i z e ) The following error occurred. ...

November 26, 2023 · 2 min · Nakamura

Restarting Virtuoso on EC2 Using Amazon SNS

Overview In the following article, I described how to perform health checks. I also described the command for restarting Virtuoso when it stops in the following article. This time, I will try restarting Virtuoso in conjunction with Amazon SNS notifications. Method To send a command like sudo rm -rf /usr/local/var/lib/virtuoso/db/virtuoso.lck && ... to an EC2 instance, SSM (AWS Systems Manager) configuration was required. IAM Roles and Policies I created a new IAM role and granted the AmazonSSMFullAccess policy. Initially, I had granted the AmazonSSMManagedInstanceCore policy, but the following error occurred when executing the Lambda function described later, and it did not work properly. ...

November 24, 2023 · 13 min · Nakamura

Notes on Extracting Latitude and Longitude from Google Maps Short URLs

Overview I had an opportunity to extract latitude and longitude from a Google Maps short URL like the following. https://goo.gl/maps/aPxUgDJ9KP2FLFkN7 https://goo.gl/maps/aPxUgDJ9KP2FLFkN7 At that time, two sets of latitude and longitude could be obtained, so this is a personal note on the matter. Extraction Method I received the following answer from GPT-4. -– Answer below — It is not possible to directly extract latitude and longitude from a Google Maps short URL (goo.gl/maps/...). However, by expanding this short URL to obtain the original URL, you can extract the latitude and longitude from that URL. ...

August 22, 2023 · 7 min · Nakamura

Batch Registering Data to Omeka Classic IIIF Toolkit

Overview This article explains how to batch register data to the Omeka Classic IIIF Toolkit. For setting up the Omeka Classic IIIF Toolkit, please refer to the following. This is also an enhancement of the following article, making it easier to use by taking Excel data as input. Preparing the Excel File Prepare an Excel file like the following. https://github.com/nakamura196/000_tools/blob/main/data/sample.xlsx Prepare three sheets: “collection,” “item,” and “annotation.” collection manifest_uri https://d1fasenpql7fi9.cloudfront.net/v1/manifest/3437686.json ...

July 20, 2023 · 3 min · Nakamura

Trying Out WikibaseSync

Overview I had the opportunity to try out the following WikibaseSync, so this is a personal note for future reference. https://github.com/the-qa-company/WikibaseSync I learned about this tool from the following paper. https://doi.org/10.11517/jsaisigtwo.2022.SWO-056_04 Installation Install the source code and related libraries. ! c ! g d p e i t W p i c k i l i n o b s n a t e s a e l h S l t y t n - p c r s : r / e / q g u i i t r h e u m b e . n c t o s m . / t t x h t e - q a - c o m p a n y / W i k i b a s e S y n c Creating a Bot Account Access the Wikibase prepared in advance, and click “Bot passwords” from “Special pages”. ...

July 19, 2023 · 6 min · Nakamura

Using the Wikibase API

Overview I had the opportunity to use the Wikibase API from a Python client, so this is a memo of the process. I used the following library. https://wikibase-api.readthedocs.io/en/latest/index.html Installation Install with the following: ! p i p i n s t a l l w i k i b a s e - a p i Read This time, we will work with the following Wikibase instance. ...

July 19, 2023 · 9 min · Nakamura

Trying Dataverse

Overview I had an opportunity to try Dataverse, so here are my notes. I used the following demo environment. https://demo.dataverse.org/ Creating an Account Create an account from Sign Up. Creating a Dataverse Let’s try creating a Dataverse. I created the following Dataverse. https://demo.dataverse.org/dataverse/nakamura196 Creating a Dataset Create a dataset from Add Data. The following is the registration screen. The following is the registration result screen. ...

July 19, 2023 · 7 min · Nakamura

How to Bulk Delete Collections in Omeka Classic

Overview This article introduces one approach for bulk deleting collections in Omeka Classic. In Omeka Classic (Version 3.1.1), there is no GUI for selecting and deleting multiple collections at once. However, this functionality is available for items. Therefore, we will use the API to perform bulk deletion of collections. Obtaining the API Key Follow the instructions below to enable the API and generate an API key: https://omeka.org/classic/docs/Admin/Settings/API_Settings/ Specifically, first access the following page: ...

June 27, 2023 · 3 min · Nakamura

Trying Out bagit-python

bagit is described as follows: bagit is a Python library and command line utility for working with BagIt style packages. I created a Google Colab notebook for trying out this library. https://colab.research.google.com/github/nakamura196/ndl_ocr/blob/main/bagit_python.ipynb I hope this serves as a useful reference for using bagit.

June 20, 2023 · 1 min · Nakamura

Connecting Django with AWS OpenSearch

Overview These are notes on how to connect Django with AWS OpenSearch. The following article was helpful. https://testdriven.io/blog/django-drf-elasticsearch/ However, since the above article targets Elasticsearch, changes corresponding to OpenSearch were needed. Changes Changes for OpenSearch were needed starting from the Elasticsearch Setup section of the article. https://testdriven.io/blog/django-drf-elasticsearch/#elasticsearch-setup Specifically, the following two libraries were required. ( ( e e n n v v ) ) $ $ p p i i p p i i n n s s t t a a l l l l o d p j e a n n s g e o a - r o c p h e - n p s y e a r c h - d s l After that, by replacing django_elasticsearch_dsl with django-opensearch-dsl and elasticsearch_dsl with opensearchpy, I was able to proceed as described in the article. ...

June 19, 2023 · 19 min · Nakamura

Content Registration and Multilingual Support Using Drupal Key Auth

Overview In the following article, I performed content registration using Python with Basic authentication. This time, I tried API Key Authentication, referring to the following article. https://designkojo.com/post-drupal-using-jsonapi-vuejs-front-end API Key Authentication The following module was used. https://www.drupal.org/project/key_auth A “Key authentication” tab appeared on the user edit screen, allowing an API key to be generated. When using the API key, the following program can be used. i e k h } p } r r m n e e a . p d y a y = j o p d l s r o = e ' ' " o " } r o t i r A C a a d e n n ' s c o p d a q ( r t { c n i t u ) e A = e t - = a " " } e q = P p e k " t a s u I { t n e { : y t t e ' ' t y p t s s h k : - " { e r " " } . t t e T : " i t b p s t y ' y : b i o o p } a p k u t d s : ' p e e " t l y " " t / p ' y n e e " v f ( / l : o s " : a o e { i d " : l r n I c ' e : { u m d P a a - " e a p t p - { W " t o a i p a h : " i d o l r a : n d n i t t " t r / c i ' B " , e v a c s e p s n t l l h s d i e u w a e . o " p a i a o a n , t n d r p / f e _ e i v r r t r d + n o . e s o j d m x = m s . M t h a o a P y " e i n p y a n ' i t f d , + h r e n j o i r a s n e s m o " n , e n , d } ' s j / , . s j " o s , n o = n p a a p y i l / o n a o d d ) e / a r t i c l e ' Notes on Multilingual Support As a note, it appears that creating translation data is not supported. ...

June 9, 2023 · 4 min · Nakamura

Trying Wagtail

Overview I tried Wagtail, so here are my notes on issues I encountered. I basically followed this tutorial: https://docs.wagtail.org/en/v5.0.1/getting_started/tutorial.html Search Function When I added a page with a Japanese title of “My First Article” (はじめての記事), the following search did not return any results. http://localhost:8000/admin/pages/search/?q=はじめて On the other hand, the following search did return results. It seems that partial matching for Japanese is not supported by default. http://localhost:8000/admin/pages/search/?q=はじめての記事 Wagtail API The API documentation was found at: ...

June 9, 2023 · 2 min · Nakamura

Customizing Views for Custom Models in Django REST Framework JSON:API (DJA)

Overview Let’s customize the views for the model added in the following article. Sort Let’s add ordering_fields. c l a s s o q s d r u e e U d e r f s e r i e r y a g e i r r i s l e n f e I n e i t t t n g t z _ r e u f _ e o y n r r o f = r b _ t e n V i _ j p r t i e U c e k y u s e l s l c _ r u w d e a t = p n p s s r s ( k e e I s s s E r t = n e e i n ( ( f = l l s t ) M ( o f f r . o " . U ) . n y g d u o s : k o . e e s b e w t o t l e j r a b _ V r e I r N j o i _ c n g o e b e n t f s n c j w a s o . e t e S m . S g : s c e e a e e . t t " l r t g ( ) , l i ( e ) : ( a " t ) ) l e ( i n i # z t d e r = A r y e d _ n d p t e k r d " y , _ h p e N k r o ) e n . e b ) l o g As a result, only user_name became selectable in the “Filters” display. ...

June 5, 2023 · 6 min · Nakamura

Adding Custom Models to Django REST framework JSON:API (DJA)

Overview In the following article, I confirmed the basic operations of Django REST framework JSON:API (DJA). In this article, I will try adding a custom model to DJA. References I will add a UserInfo model, referencing the following article. https://tech-blog.rakus.co.jp/entry/20220329/python Steps Define the Model Add the following: # c l ユ a ー s ザ s u b a c 情 s i g r 報 U e r e e を s r t a 格 e _ h = t 納 r n _ e す I a d m d る n m a o _ f e y d a o e t ( = = l B s = a m m . s o o P m e d d o o M e e s d o l l i e d s s t l e . . i s l C D v . ) h a e D : a t S a r e m t F F a e i i l T e e l i l l I m d d n e ( ( t F v v e i e e g e r r e l b b r d o o F ( s s i v e e e e _ _ l r n n d b a a ( o m m v s e e e e = = r _ ' ' b n ユ 生 o a ー 年 s m ザ 月 e e 名 日 _ = ' ' n ' , ) a 作 m m 成 a e 日 x = 時 _ ' ' l 年 , e 齢 a n ' u g , t t n o h u _ = l n 3 l o 2 = w ) T _ r a u d e d , = u T n r i u q e u ) e = F a l s e ) # # # ユ 生 ー 年 年 ザ 月 齢 名 日 Build the Database Execute the following: ...

June 5, 2023 · 11 min · Nakamura

Trying Django REST Framework JSON:API (DJA)

Overview I had an opportunity to try Django REST framework JSON:API (DJA), so here are my notes. https://django-rest-framework-json-api.readthedocs.io/en/stable/index.html Installation Launch the example app described on the following page. https://django-rest-framework-json-api.readthedocs.io/en/stable/getting-started.html g c p s p d d d i d y o i j j j t t u p a a a d h r n n n c j o c i g g g l a n e n o o o o n 3 s - - - n g e t a a a e o - n a d d d - m v l m m m h r / l i i i t e b n n n t s e i - p t n n U m l r s - v / r i o u : f a g a n / r e c r r d s / a n t e a d e g m v i q t a r i e v u e t v t w a i a e h o t r r u r e e - d b k m s r . - e e f - c j n t _ s o s t t e e m s i x t n . n a t d - t g m i j a x s p n a p t = l g n i e e s g x = o a e - m - x j p s a s l e m o e t p n . t l - s i e a e n . p t g s i t s e / i = t d n e t j g x i a s a n n m g g p s o l - e r . e s s e t t - t f i r n a g m s e w o r k - j s o n - a p i . g i t As a result, the following screens were obtained. ...

June 5, 2023 · 4 min · Nakamura

Creating PDF Files from IIIF Manifest Files

Overview I had the opportunity to create PDF files from IIIF manifest files. As a solution, I found the following repository, but was unable to get it working. https://github.com/jbaiter/pdiiif While the above repository uses JavaScript, this time I created a conversion tool using Python. Usage You can try it from the following notebook. https://colab.research.google.com/github/nakamura196/ndl_ocr/blob/main/iiif2pdf.ipynb During the initial installation, img2pdf is installed, but due to PIL version dependencies, a “RESTART RUNTIME” button will appear. Please click it and then re-run the same cell. ...

May 26, 2023 · 1 min · Nakamura

Prototype of an XML File Validation Tool Using JPCOAR Schema (v1)

I previously wrote the following article, where I tried validating XML files using the JPCOAR schema. This time, based on the verification from the above article, I created a validation tool using Google Colab. You can try it at the following URL. https://colab.research.google.com/github/nakamura196/ndl_ocr/blob/main/JPCOARスキーマ_v1を用いたxmlファイルのバリデーション.ipynb You can validate target files by specifying the URL of a published XML file or by uploading a local file. I hope this serves as a helpful reference when creating XML files using the JPCOAR Schema (v1). ...

April 19, 2023 · 1 min · Nakamura

Bug Fixes and Feature Additions to the NDL Classical Book OCR Tutorial Using Google Colab

Overview I have been creating a tutorial for the NDL “Classical Book” OCR application using Google Colab, as introduced in the following article. This time, the following updates were made. Added terms of use Fixed bugs Added support for IIIF Presentation API v3 manifest file input The updated notebook can be accessed at the same URL as before. https://colab.research.google.com/github/nakamura196/ndl_ocr/blob/main/NDL古典籍OCRの実行例.ipynb Terms of Use Please use the notebook itself under CC0. However, the “NDL Classical Book OCR Application” is released by the National Diet Library under the CC BY 4.0 license, so please include the appropriate credit. Also, please check the terms of use for the materials to which OCR is applied. ...

April 12, 2023 · 1 min · Nakamura

Registering Taxonomies and Adding Them to Content in Drupal Using Python

Overview This is a continuation of the following series. This time, we will register taxonomies and add them to content. Registering Taxonomies A taxonomy called ne_class was created in advance through the GUI. It can be listed at the following URL. /jsonapi/taxonomy_term/ne_class Below is the program for registering a new taxonomy. Please configure host, username, and password as appropriate. p } _ u r r a t r . y y l = j l p s o " } e = r o a d e n d a = f q ( t " u ) = a " " } " { e " t a n h s { : y t e o t p t _ s s { e r " c t . " i n l } p : b a a / o u m s j s " t e s s t t e " " o ( a s : n u x " a r o : " p l n 干 i , o { 瀬 / m " t h y , a e _ x a t o d e n e r o r m m s - y = - _ h n t e e e a _ r d c m e l / r a { s s _ , s t " y a , p u e t } h " = ( u s e r n a m e , p a s s w o r d ) , j s o n = p a y l o a d ) The following result is obtained. ...

April 11, 2023 · 5 min · Nakamura

Updating and Deleting Drupal Content Using Python

Overview In the following article, I described how to create new content. This time, I’ll try updating and deleting existing content. Filtering Items With the following program, you can retrieve registered content. This time, I retrieved content with the title “Pre-update title.” res["data"] is an array. u p h q } i f f f e r r l s a o u t i o i n e e e s s e e l r l d = s n r s t r m t t p ( n w y " _ e k f e o r = r a o = t t r e i r i e e m r = i y s y l _ n q r s e d " t p , t s t u . [ x { l e = e t e j ' = = x e v r r = s s d x " = [ a s t o a " " " : ] l . = f s n t x x " u a ' . ( a x x " a e p ' { g ) ' x x 更 r p & h e ] " " 新 t i e ' o t ) 前 i n n . s ( の c d j t e タ l q ( o } n イ e u f i / d ト " e ' n j p ル r f ( s o " y i f o i . l i n n i t l a t t e t p , e r e i m [ r / h s { s n e ( k ) o a ) e d d : y e e } / r ] { s = i = { t h v e e a m a l _ d u t e e y r } p s ' e , ) } ? a { u f t i h l = t ( e u r s _ e s r t n r a } m ' e , p a s s w o r d ) ) Getting the ID of the Content to Update An ID like 730f844d-b476-4485-8957-c33fccb7f8ac is obtained. ...

April 11, 2023 · 4 min · Nakamura