🐈

wikiextractorでXMLデータの展開中に"global flags not ..."のエラーが発生した場合の対処

に公開

はじめに

Wikipediaの全文のファイルを展開するライブラリとしてwikiextractorがあります。

https://github.com/attardi/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でも挙がっています。

https://github.com/attardi/wikiextractor/issues/336

回避策

wikiextractorは最新のPythonのバージョンに対応していないようなので、他の方が作ってくれた以下のコミットの内容をローカルのファイルにパッチ適用することでエラーを回避して実行できるようになります。

https://github.com/attardi/wikiextractor/commit/ab8988ebfa9e4557411f3d4c0f4ccda139e18875

Discussion