liblouis

liblouis はオープンソースの点訳エンジン。

2023年の情報

since 2023-04-19

GPT-4 に解説させつつ liblouis で実際に動作を確認したメモ

middle of a word

midword bb 23

ribbon

⠗⠊⠆⠕⠝

強い短縮形

以下にいくつかの強い短縮形の例を示します。

"and" は ⠯ で表現されます。

"for" は ⠿ で表現されます。

"with" は ⠺ で表現されます。

en-ueb-g2.ctb に例えば下記がある

# and
always and 12346

この行は、「and」という単語の短縮形を定義しています。「and」は、ドット1,2,3,4,6の組み合わせである点字パターン⠯で表現されます。

alwaysキーワードは、単語「and」が表示されるすべてのコンテキストでこの短縮形が使用されることを示します。

Liblouisでen-ueb-g2.ctb翻訳テーブルを使用すると、「and」という単語を含むテキストがこの短縮形を使用して点字に翻訳されます。

always for 123456

単語 "for" が点字パターン⠿で短縮されています。

always with 23456

単語 "with" を点字の短縮形で表現するルールです。ドット2, 3, 4, 5, 6の組み合わせである点字パターン⠺で "with" が表現されます。

input
bread and butter
looking for a solution
I agree with you

output (en-ueb-g2)
⠃⠗⠂⠙ ⠯ ⠃⠥⠞⠞⠻
⠇⠕⠕⠅⠬ ⠿ ⠁ ⠎⠕⠇⠥⠰⠝
⠠⠊ ⠁⠛⠗⠑⠑ ⠾ ⠽

output (en-us-g2)
⠃⠗⠂⠙ ⠯ ⠃⠥⠞⠞⠻
⠇⠕⠕⠅⠬ ⠿⠁ ⠎⠕⠇⠥⠰⠝
⠠⠊ ⠁⠛⠗⠑⠑ ⠾ ⠽

2012年ごろの情報

Linux のアクセシビリティ対応、 NVDADAISY パイプラインなどで使われている。

ライセンスはLesser GPL。

日本語の点訳に対応していない。

NVDA日本語チームによる日本語対応の検討

リンク

Debian 系 Linux には liblouis-bin liblouis-utils などのパッケージがあるようだ。

NVDA は独自に scons でビルドしている。

コマンド

  • lou_translate : コマンドラインのツール。テスト用のツールで、実用的ではないとのこと。

GNOME Orca の情報

Linux Subsystem for Windows

since 2017-08-13

Windows 10 64bit (Version 1703) + Linux Subsystem for Windows で作業。

ただし LSW を作ったのは 1607 のときだったので Ubuntu 14.04 相当。

nvdajp で fork した liblouis を使う。

$ sudo apt-get install -y --force-yes make autoconf automake libtool pkg-config
$ sudo apt-get install -y --force-yes texinfo
$ sudo apt-get install -y --force-yes libyaml-dev
$ git clone git@github.com:nvdajp/liblouis.git
$ cd liblouis/
$ sh autogen.sh
$ ./configure --enable-ucs4
$ make
$ make check
(omitted)

PASS: backtranslate
PASS: backtranslate_noUndefinedDots
PASS: backtranslate_partialTrans
PASS: backtranslate_with_letsign
PASS: capitalization
PASS: capitalized_with_sentance
PASS: capitalized_word
PASS: checkTable
PASS: check_metadata
XFAIL: compbrlAtCursor
PASS: emphclass
XFAIL: en_gb_g1_italics
PASS: findTable
PASS: getTable
PASS: hash_collision
PASS: hyphenate_achena
PASS: hyphenate_alderen
PASS: hyphenate_straightforward
PASS: hyphenate_xxx
PASS: inpos
PASS: inpos_compbrl
PASS: inpos_match_replace
XFAIL: lastworditalafter
PASS: letterDefTest
PASS: logging
PASS: outpos
PASS: pass0_typebuf
PASS: pass1Only
PASS: pass2
PASS: pass2_inpos
XFAIL: present_progressive
PASS: resolve_table
XFAIL: squash_space
PASS: typeform
PASS: typeform_for_emphclass
PASS: uplow_with_unicode
PASS: check_all_tables.pl
PASS: check_endless_loop.pl
PASS: check_included_tables.sh
PASS: multiple_table_path.pl
XFAIL: ueb_test_data.pl
PASS: yaml/ar-ar-g1_harness.yaml
PASS: yaml/ar-fa_harness.yaml
PASS: yaml/back_cont_then_punc.yaml
PASS: yaml/begcaps_endcaps.yaml
PASS: yaml/capsnocont.yaml
PASS: yaml/capsword_for_back.yaml
PASS: yaml/chr-us-g1_harness.yaml
PASS: yaml/before_begmidword.yaml
PASS: yaml/da-dk-g08.yaml
PASS: yaml/da-dk-g16.yaml
PASS: yaml/da-dk-g16-dictionary_harness.yaml
PASS: yaml/da-dk-g16-lit.yaml
PASS: yaml/da-dk-g18-dictionary_harness.yaml
PASS: yaml/da-dk-g18.yaml
PASS: yaml/da-dk-g26.yaml
PASS: yaml/da-dk-g26-dictionary_harness.yaml
PASS: yaml/da-dk-g26-lit.yaml
PASS: yaml/da-dk-g26l.yaml
PASS: yaml/da-dk-g26l-lit.yaml
PASS: yaml/da-dk-g28-dictionary_harness.yaml
PASS: yaml/da-dk-g28.yaml
PASS: yaml/da-dk-g28l.yaml
PASS: yaml/el-backward.yaml
PASS: yaml/el-forward.yaml
PASS: yaml/emphasis-full.yaml
PASS: yaml/emphasis-no-context.yaml
PASS: yaml/en-GB-g2_backward.yaml
PASS: yaml/en-GB-g2_harness.yaml
PASS: yaml/en-gb-g1_harness.yaml
PASS: yaml/en-ueb-02-stand_alone.yaml
PASS: yaml/en-ueb-03-symbols.yaml
PASS: yaml/en-ueb-05-grade_1_mode.yaml
PASS: yaml/en-ueb-06-numeric_mode.yaml
PASS: yaml/en-ueb-08-capitalization.yaml
PASS: yaml/en-ueb-09-typeforms.yaml
PASS: yaml/en-ueb-10-07-contractions.yaml
PASS: yaml/en-ueb-10-13-contractions.yaml
PASS: yaml/en-ueb-g1_backward.yaml
PASS: yaml/en-ueb-g1_harness.yaml
PASS: yaml/en-ueb-g2-dictionary_harness.yaml
PASS: yaml/en-ueb-g2_backward.yaml
PASS: yaml/en-ueb-g2_backward_no_dis.yaml
PASS: yaml/en-ueb-math.yaml
PASS: yaml/en-ueb-symbols_harness.yaml
PASS: yaml/en-us-comp8-ext-back_harness.yaml
PASS: yaml/en-us-comp8-ext-for_harness.yaml
PASS: yaml/en-us-g2-dictionary_harness.yaml
PASS: yaml/en-us-g2-end-emphasis_harness.yaml
PASS: yaml/eo-g1_harness.yaml
PASS: yaml/ethio-g1_harness.yaml
PASS: yaml/example_test.yaml
PASS: yaml/fa-ir-comp8-harness.yaml
PASS: yaml/fa-ir-g1-harness.yaml
PASS: yaml/fi_harness.yaml
PASS: yaml/foo.yaml
PASS: yaml/fr-bfu-comp6.yaml
PASS: yaml/fr-bfu-g2_harness.yaml
PASS: yaml/fr-fr-g1.yaml
PASS: yaml/ga-g1_harness.yaml
PASS: yaml/ga-g2_harness.yaml
PASS: yaml/hr-8dots_harness.yaml
PASS: yaml/hu-hu-comp8_backward.yaml
PASS: yaml/hu-hu-comp8_harness.yaml
PASS: yaml/hu-hu-g1_backward.yaml
PASS: yaml/hu-hu-g1_harness.yaml
PASS: yaml/issue-238.yaml
PASS: yaml/issue-35.yaml
PASS: yaml/iu-ca-g1_harness.yaml
PASS: yaml/ko-2006-g2_harness.yaml
PASS: yaml/ko-g2_harness.yaml
PASS: yaml/letterDefTest_harness.yaml
PASS: yaml/lt_harness.yaml
PASS: yaml/mn-MN_harness.yaml
PASS: yaml/multipass-backward.yaml
PASS: yaml/multipass-forward.yaml
PASS: yaml/multipass.yaml
PASS: yaml/new_emph.yaml
PASS: yaml/nl-NL-g0_harness.yaml
PASS: yaml/nl-g0_harness.yaml
PASS: yaml/no_8dot_harness.yaml
PASS: yaml/no_g1_harness.yaml
PASS: yaml/no_g2_harness.yaml
PASS: yaml/no_harness.yaml
PASS: yaml/nocross_harness.yaml
PASS: yaml/noletsignafter.yaml
PASS: yaml/pl-pl-comp8_harness.yaml
PASS: yaml/sr-g1_harness.yaml
PASS: yaml/syllable.yaml
PASS: yaml/ta-ta-g1_harness.yaml
PASS: yaml/vi-g1_backward.yaml
PASS: yaml/vi-g1_harness.yaml
PASS: yaml/zh-chn.yaml

(omitted)

============================================================================
Testsuite summary for Liblouis 3.2.0
============================================================================
# TOTAL: 133
# PASS:  127
# SKIP:  0
# XFAIL: 6
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

YAML テスト

since 2017-10-29

doc/liblouis.txt の 5.7 lou_checkyaml に書いてある。

特定の YAML を単体でテスト実行するには

$ cd tests
$ make check TESTS=yaml/en-ueb-g1_harness.yaml

lou_checkyaml を正しく動作させるには LOUIS_TABLEPATH を設定する、とのこと。

mac ports

since 2012-07-07

liblouis-2.4.1.tar.gz がリリースされているが port で 2.1.1 がインストールされる。

$ sudo port install liblouis
Password:
--->  Fetching archive for liblouis
--->  Attempting to fetch liblouis-2.1.1_0.darwin_11.x86_64.tbz2 from http://packages.macports.org/liblouis
--->  Attempting to fetch liblouis-2.1.1_0.darwin_11.x86_64.tbz2.rmd160 from http://packages.macports.org/liblouis
--->  Installing liblouis @2.1.1_0
--->  Activating liblouis @2.1.1_0
--->  Cleaning liblouis
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.
$ which lou_translate
/opt/local/bin/lou_translate

liblouisxml

$ sudo port install liblouisxml
$ which xml2brl
/opt/local/bin/xml2brl

Mac OS X Lion

since 2012-07-07

http://code.google.com/p/liblouis/source/checkout

svn checkout http://liblouis.googlecode.com/svn/trunk/ liblouis-read-only

ここからは Mac OS X Lion での作業。

$ cd liblouis-read-only
$ ./autogen.sh 
$ ./configure 
$ make
$ tools/lou_translate --version
lou_translate (liblouis) 2.4.1
Copyright (C) 2009 ViewPlus Technologies, Inc. and JJB Software, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John J. Boyer.

$ tools/lou_translate --help
Usage: lou_translate [OPTION] TABLE
Translate whatever is on standard input and print it on standard
output. It is intended for large-scale testing of the accuracy of
Braille translation and back-translation.

  -h, --help          display this help and exit
  -v, --version       display version information and exit
  -f, --forward       forward translation using the given table
  -b, --backward      backward translation using the given table
                      If neither -f nor -b are specified forward translation
                      is assumed

liblouisxml も落としてみる:

svn checkout http://liblouisxml.googlecode.com/svn/trunk/ liblouisxml-read-only

下記でコンパイルできる:

$ cd liblouisxml-read-only
$ ./autogen.sh 
$ ./configure 
$ make

さきほど svn 版を make install しなかったので、どうやら port で入れた liblouis 2.1.1 が使われたらしい:

$ grep louis Makefile | grep "\-llouis"
BASE_DEPENDENCIES_LIBS = -L/opt/local/lib -llouis -lxml2  
$ ./tools/xml2brl -h
Usage: xml2brl [OPTION] [inputFile] [outputFile]
Translate an xml or a text file into an embosser-ready braille file.
This includes translation into grade two, if desired, mathematical 
codes, etc. It also includes formatting according to a built-in 
style sheet which can be modified by the user.

If inputFile is not specified or '-' input is taken from stdin. If outputFile
is not specified the output is sent to stdout.

  -h, --help          	  display this help and exit
  -v, --version       	  display version information and exit
  -f, --config-file       name a configuration file that specifies
                          how to do the translation
  -b, --backward      	  backward translation
  -r, --reformat      	  reformat a braille file
  -p, --poorly-formatted  translate a poorly formatted file
  -t, --html              html document, not xhtml
  -C, --config-setting    specify particular configuration settings
                          They override any settings that are specified in a
                          config file
  -l, --log-file          write errors to log file instead of stderr

make install

since 2012-11-18

Mac で port と make install を両方やると下記のような状況になる。

/usr/local は make install したバージョン

$ /usr/local/bin/lou_translate --version
/usr/local/bin/lou_translate (liblouis) 2.5.1
Copyright (C) 2012 ViewPlus Technologies, Inc. and JJB Software, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John J. Boyer.

/opt/local は port でいれたバージョン

$ /opt/local/bin/lou_translate --version
/opt/local/bin/lou_translate (liblouis) 2.1.1
Copyright (C) 2009 ViewPlus Technologies, Inc. and JJB Software, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John J. Boyer.

Cygwinでビルド

since 2012-07-08

基本的に cygwin でもビルド方法は同じ。

以下の作業の結果、無事に liblouis の autogen, configure, make ができて、make install にも成功した。

  • svn は Windows バイナリではなく cygwin のコマンドを使う
  • autoconf 系のツール、libtool をちゃんと入れる
$ which lou_translate
/usr/local/bin/lou_translate
$ echo "How are you?" | lou_translate en-us-g2.ctb
,h{ >e y8

cygwin + liblouisxml

configure でエラーになる。

No package 'liblouis' found
No package 'libxml-2.0' found

下記と同じ状況:

pc ファイルはあった:

$ ls /usr/local/lib/
liblouis.a  liblouis.dll.a  liblouis.la  pkgconfig

$ ls /usr/local/lib/pkgconfig/
liblouis.pc

$ cat /usr/local/lib/pkgconfig/liblouis.pc
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
tablesdir=${prefix}/share/liblouis/tables

Name: liblouis
Description: a braille translator and back-translator
Version: 2.4.1
Requires:
Libs: -L${libdir} -llouis
Cflags: -I${includedir}/liblouis

PKG_CONFIG_PATH を設定してみる:

$ export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig

$ pkg-config --cflags liblouis
-I/usr/local/include/liblouis

cygwin パッケージで libxml2 と libxml2-devel を入れた:

$ pkg-config --cflags libxml-2.0
-I/usr/include/libxml2

configure 成功、make, make install できた:

$ which xml2brl
/usr/local/bin/xml2brl

$ xml2brl -h
Usage: xml2brl [OPTION] [inputFile] [outputFile]
Translate an xml or a text file into an embosser-ready braille file.
This includes translation into grade two, if desired, mathematical
codes, etc. It also includes formatting according to a built-in
style sheet which can be modified by the user.

If inputFile is not specified or '-' input is taken from stdin. If outputFile
is not specified the output is sent to stdout.

  -h, --help              display this help and exit
  -v, --version           display version information and exit
  -f, --config-file       name a configuration file that specifies
                          how to do the translation
  -b, --backward          backward translation
  -r, --reformat          reformat a braille file
  -p, --poorly-formatted  translate a poorly formatted file
  -t, --html              html document, not xhtml
  -C, --config-setting    specify particular configuration settings
                          They override any settings that are specified in a
                          config file
  -l, --log-file          write errors to log file instead of stderr

lou_translate

点訳も逆変換もできるテストプログラム。出力は独自の ASCII コードのようだ。

英語の動作

英語1級点字 および 英語2級点字 での動作確認:

$ echo "Welcome to NVDA Japanese team." | ./tools/lou_translate tables/en-us-g1.ctb 
,welcome to ,,nvda ,japanese team4

$ echo "Welcome to NVDA Japanese team." | ./tools/lou_translate tables/en-us-g2.ctb 
,welcome 6,,nvda ,japanese t1m4

$ echo "123456" | ./tools/lou_translate tables/en-us-g1.ctb 
#abcdef

$ echo "This launcher can be downloaded from i.nvda.jp" | ./tools/lou_translate tables/en-us-g1.ctb 
,this launcher can be downloaded from i.nvda.jp

$ echo "This launcher can be downloaded from i.nvda.jp" | ./tools/lou_translate tables/en-us-g2.ctb 
,? laun*} c 2 d{nload$ f i4nvda4jp

文字化けして ? が出ているわけではなさそうだ:

$ echo "This launcher can be downloaded from i.nvda.jp" | ./tools/lou_translate tables/en-us-g2.ctb |od -t x1 -a
0000000    2c  3f  20  6c  61  75  6e  2a  7d  20  63  20  32  20  64  7b
           ,   ?  sp   l   a   u   n   *   }  sp   c  sp   2  sp   d   {
0000020    6e  6c  6f  61  64  24  20  66  20  69  34  6e  76  64  61  34
           n   l   o   a   d   $  sp   f  sp   i   4   n   v   d   a   4
0000040    6a  70  0a                                                    
           j   p  nl                                                    
0000043

ちなみにこの出力形式は8ドット英文字と互換らしい(ようするにNABCCである):

$ echo "ABCDE abc 12345" | ./tools/lou_translate tables/latinLetterDef8Dots.uti 
ABCDE abc                

逆変換してみる:

$ echo ",welcome to ,,nvda ,japanese team4" | ./tools/lou_translate -b tables/en-us-g1.ctb 
Welcome to NVDA Japanese team.

テーブルのファイル名

since 2012-11-19

liblouis-liblouisxml ML での議論:

拡張子 ctb と utb の違いは liblouis では無視される。

  • utb: uncontracted table
  • ctb: contracted table

ただし en-us Grade 1 ファイルは ctb である。すでに en-us-g1.utb という使うべきでない低品質のテーブルがあるから。

日本語対応の検討

since 2012-07-07

nvdajp 2012.2.1jp における点訳テーブルは、事前に Unicode 0x28xx に変換した文字列をそのまま出す処理である。

$ cat tables/nvdajp.ctb 
# nvdajp.ctb
# Japanese braille table by NVDA Japanese Team
include unicode.dis
include braille-patterns.cti

$ echo "⠧⠸⡅⡀⠗⠜⠢⠐" | ./tools/lou_translate tables/nvdajp.ctb 
\x2827\x2838\x2845\x2840\x2817\x281c\x2822\x2810

ちなみに lou_translate は UTF-8 を標準入力から問題なく受け取っている。

かな文字テーブル

とにかく書いてみる:

# nvdajp.ctb
include latinLetterDef6Dots.uti
include digits6Dots.uti
sign あ 1
sign い 12
sign う 14
sign え 124
sign お 24
$ echo "あいうえお abcde 12345" | ./tools/lou_translate tables/nvdajp.ctb
abcfi abcde abcde

定義していないから外字符も数符もちゃんと出ていないが、変換はできる。

アルファベットの点訳に合わせて え (124) を f と お (24) を i と出力するらしい。

英数字

外字符以外は実現できた。

$ echo "123F a A abcABC あいうえお" | ./tools/lou_translate tables/nvdajp.ctb 
#abc6f a 6a abc66abc abcfi

テーブルは以下の内容:

# latinLetterDef6Dots.uti
uplow Aa 1
uplow Bb 12
uplow Cc 14
uplow Dd 145
uplow Ee 15
uplow Ff 124
uplow Gg 1245
uplow Hh 125
uplow Ii 24
uplow Jj 245

sign 6 6
capsign 6
begcaps 6-6

# digits6Dots.uti
digit 0 245
digit 1 1
digit 2 12
digit 3 14
digit 4 145
digit 5 15
digit 6 124
digit 7 1245
digit 8 125
digit 9 24

sign # 3456
numsign 3456

sign あ 1
sign い 12
sign う 14
sign え 124
sign お 24

外国語引用符

本来は grade 2 の実装に使うという letsign, noletsign 命令で外字符っぽいものを作った:

$ echo "123Abcd a A abcABC あaいbうえおか" | ./tools/lou_translate tables/nvdajp.ctb 
#123;,abcd ;a ;,a abc,,abc a;ab;bcfi*

数符 # 外字符 ; 大文字符 , だと思って読むと良さそうにみえるが、「あa」と「い」の間に第1つなぎ符(36)を入れる必要がある。。

テーブルは下記の内容。ukchardefs.cti を入れると「文字が未登録」のエラーが出なくなる。 ここでは大文字符が , になっている。

include ukchardefs.cti

include latinLetterDef6Dots.uti
capsign 6 ,
begcaps 6-6 ,,

letsign 56 ;
noletsign 56 ;

include digits6Dots.uti
numsign 3456 #

sign あ 1
sign い 12
sign う 14
sign え 124
sign お 24
sign か 16

after を使う

after letter replace という命令を使ってアルファベットの直後のカナ文字を置換してみた。

第1つなぎ符(36)をハイフンとする定義は ukchardefs.cti に書かれている。

$ echo "123Abcd a A abcABC いあaいbうえおか" | ./tools/lou_translate tables/nvdajp.ctb 
#123;,abcd ;a ;,a abc,,abc ba;a-b;b-cfi*
# nvdajp.ctb
# Japanese braille table by NVDA Japanese Team

include ukchardefs.cti All character definition opcodes

include latinLetterDef6Dots.uti
capsign 6 ,
begcaps 6-6 ,,

letsign 56 ;
noletsign 56 ;

include digits6Dots.uti
numsign 3456 #

sign あ 1
sign い 12
sign う 14
sign え 124
sign お 24
sign か 16

after letter replace あ -あ
after letter replace い -い
after letter replace う -う
after letter replace え -え
after letter replace お -お
after letter replace か -か

日本語の記号

いろいろ追加してみた:

$ echo "123Abcd a A abcABC いあaいbうえ、 おか。  あ・ いう。  い?  お!" | ./tools/lou_translate tables/nvdajp.ctb
#123;,abcd ;a ;,a abc,,abc ba;a-b;b-cf; i*4  a" bc4  b5  i6

$ echo "あんしん、 でしょー。" | ./tools/lou_translate tables/nvdajp.ctb 
a0|0; "q`|34

ただし、記号のマスあけ(読点と中点のあとで1マス、句点と疑問符と感嘆符のあとで2マス)は自動処理していない。

include ukchardefs.cti

include latinLetterDef6Dots.uti
capsign 6 ,
begcaps 6-6 ,,

letsign 56 ;
noletsign 56 ;

include digits6Dots.uti
numsign 3456 #

sign あ 1
sign い 12
sign う 14
sign え 124
sign お 24
sign か 16

sign し 1256

sign で 5-12345

sign っ 2
sign ん 356

sign ょ 345

always しょ 4-1256

after letter replace あ -あ
after letter replace い -い
after letter replace う -う
after letter replace え -え
after letter replace お -お
after letter replace か -か

sign 。 256
sign 、 56
sign ・ 5
sign ? 26
sign ! 235
sign ー 25

大文字符の問題

アルファベットの大文字が複数あって、直後に小文字が来る場合に日本語は endcaps 符号を使えないのでうまくいかない。

en-us-g1 の場合:

$ echo "ABCabc" | ./tools/lou_translate tables/en-us-g1.ctb 
,,abc,'abc

前述の日本語テーブルの場合:

$ echo "ABCabc" | ./tools/lou_translate tables/nvdajp.ctb
,,abcabc

begcaps を消すとこうなる:

$ echo "ABCabc" | ./tools/lou_translate tables/nvdajp.ctb
,a,b,cabc

そもそもアルファベットだけの場合に外字符または外字引用符を使うという処理が実現できていないという問題もある。

context

ちょっと手強そうに見える context 機能を試してみる。

シンプルなテスト用のテーブルを作る:

$ echo "a b A B abcABCabc ABCabcABC" | ./tools/lou_translate tables/test-context.ctb 
a ;b ;,a ;,b ;abc,,abc,'abc ;,abc,'abc,,abc
include ukchardefs.cti
include latinLetterDef6Dots.uti

class lc abc
class uc ABC
context  %uc[]%lc @6-3
context  %lc[]%uc @6-6

context  "\s"[]%lc @56
context  "\s"[]%uc @56-6

wrapper

MLで質問したら wrapper という拡張モジュールが用意されているが、まだ活用されていないことが分かった。

さっそくパッチを作って動作を確認した。

$ echo "123" | ./tools/lou_translate -w japanese
test
Index: liblouis/wrappers.c
===================================================================
--- liblouis/wrappers.c	(revision 719)
+++ liblouis/wrappers.c	(working copy)
@@ -99,6 +99,8 @@
     case 1:
       return 1;
     case 2:
+      wcscpy(outbuf, L"test");
+      *outlen = 4;
       return 1;
     case 3:
       return 1;
Index: tools/lou_translate.c
===================================================================
--- tools/lou_translate.c	(revision 719)
+++ tools/lou_translate.c	(working copy)
@@ -40,6 +40,7 @@
 
 static int forward_flag = 0;
 static int backward_flag = 0;
+static int wrapper_flag = 0;
 
 static const struct option longopts[] =
 {
@@ -47,6 +48,7 @@
   { "version", no_argument, NULL, 'v' },
   { "forward", no_argument, NULL, 'f' },
   { "backward", no_argument, NULL, 'b' },
+  { "wrapper", no_argument, NULL, 'w' },
   { NULL, 0, NULL, 0 }
 };
 
@@ -67,6 +69,9 @@
   int k;
   int ch = 0;
   int result;
+
+  int mode = 0;
+  if (wrapper_flag) mode = otherTrans;
   while (1)
     {
       translen = BUFSIZE;
@@ -79,10 +84,10 @@
       inlen = extParseChars (charbuf, inbuf);
       if (forward_translation) 
 	  result = lou_translateString (table_name, inbuf, &inlen,
-				      transbuf, &translen, NULL, NULL, 0);
+				      transbuf, &translen, NULL, NULL, mode);
       else 
 	result = lou_backTranslateString (table_name, inbuf, &inlen,
-					  transbuf, &translen, NULL, NULL, 0);
+					  transbuf, &translen, NULL, NULL, mode);
       if (!result)
 	break;
       outputbuf = showString (transbuf, translen);
@@ -110,7 +115,8 @@
   -f, --forward       forward translation using the given table\n\
   -b, --backward      backward translation using the given table\n\
                       If neither -f nor -b are specified forward translation\n\
-                      is assumed\n", stdout);
+                      is assumed\n\
+  -w, --wrapper       enable wrapper mode\n", stdout);
   printf ("\n");
   printf ("\
 Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
@@ -123,7 +129,7 @@
   
   set_program_name (argv[0]);
 
-  while ((optc = getopt_long (argc, argv, "hvfb", longopts, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "hvfbw", longopts, NULL)) != -1)
     switch (optc)
       {
       /* --help and --version exit immediately, per GNU coding standards.  */
@@ -141,6 +147,9 @@
       case 'b':
 	backward_flag = 1;
         break;
+      case 'w':
+	wrapper_flag = 1;
+        break;
       default:
 	fprintf (stderr, "Try `%s --help' for more information.\n",
 		 program_name);

UTDML

上記の wrapper パッチに対して Boyer さんからお返事をいただいた。

いずれ別の仕様でモード設定オプションを付けたい、とのこと。

それから liblouisutdml をテストに使ったらよい、というご教示をいただいた。

http://code.google.com/p/liblouisutdml/

python binding

since 2012-11-18

doc/liblouis.html の section 4 参照。

cygwin にて svn checkout した liblouis を使う:

$ cd python
$ python setup.py install

(omitted)

Writing /usr/lib/python2.6/site-packages/louis-2.5.1-py2.6.egg-info
$ python
>>> from louis import *
>>> translate(['en-us-g1.ctb'], "Aa(b)")
(u',aa7b7', [0, 0, 1, 2, 3, 4], [1, 2, 3, 4, 5], 1)

Mac Python

Mac で Python バインディングをやってみる。

$ which python2.7
/opt/local/bin/python2.7
$ sudo python2.7 setup.py install
Password:
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/louis
copying louis/__init__.py -> build/lib/louis
running install_lib
creating /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/louis
copying build/lib/louis/__init__.py -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/louis
byte-compiling /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/louis/__init__.py to __init__.pyc
running install_egg_info
Writing /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/louis-2.5.1-py2.7.egg-info

$ python2.7
Python 2.7.3 (default, Oct  1 2012, 09:19:49) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.65))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from louis import *
>>> translate(['en-us-g1.ctb'], "Aa(b)")
(u'\U0001002c', [0, 0], [1], 1)

なぜか8桁 Unicode に。。

harness

liblouis/tests/harness に JSON で簡単に書けるテストスイートがある。

nose がないとエラーになる。

さらに liblouis の python バインディングが必要。

$ cd tests
$ python runHarness.py 
The harness tests require nose. Skipping...

cygwin で環境を作る。

$ wget http://peak.telecommunity.com/dist/ez_setup.py
$ python ez_setup.py
$ easy_install nose

Ubuntu 12.10

since 2012-11-25

いろいろ不安なので Linux で自動テストまでやってみたいと思った。

Ubuntu 12.10 desktop i386でまっさらの環境から SVN ソースのコンパイル。

sudo apt-get install subversion autoconf libtool texinfo
sudo apt-get install python-setuptools
sudo easy_install nose
svn checkout http://liblouis.googlecode.com/svn/tags/liblouis_2_5_1 liblouis-2.5.1
cd liblouis-2.5.1
./autogen.sh
./configure 
make
sudo make install
cd python/
sudo python setup.py install
$ python
Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from louis import *
>>> translate(['en-us-g1.ctb'], "Aa(b)")
(u',aa7b7', [0, 0, 1, 2, 3, 4], [1, 2, 3, 4, 5], 1)

これはよさそう。

$ python runHarness.py

結果:

Cannot open table 'hu-hu-g1.ctb'
1 errors found.
unicode.dis,unicode.dis,hu-hu-g1.ctb could not be found or contains errors
(omitted)
Ran 3203 tests, with 768 failures and 2392 errors.
liblouis.txt · 最終更新: 2023/04/19 22:13 by Takuya Nishimoto
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0