🐈
wikiextractorでXMLデータの展開中に"global flags not ..."のエラーが発生した場合の対処
はじめに
Wikipediaの全文のファイルを展開するライブラリとしてwikiextractorがあります。
WikipediaからファイルをダウンロードしてXMLデータを展開する場合は次のように使用します。
$ wget https://dumps.wikimedia.org/jawiki/latest/jawiki-latest-pages-articles.xml.bz2
$ pip install wikiextractor
$ python -m wikiextractor.WikiExtractor jawiki-latest-pages-articles.xml.bz2
このツールをコードPython 3.12.2の環境で利用すると以下のエラーが発生しました。
raise source.error('global flags not at the start '
re.error: global flags not at the start of the expression at position 99 (line 2, column 50)
同様の問題はライブラリのissueでも挙がっています。
回避策
wikiextractorは最新のPythonのバージョンに対応していないようなので、他の方が作ってくれた以下のコミットの内容をローカルのファイルにパッチ適用することでエラーを回避して実行できるようになります。
Discussion