曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 3197|回复: 0
打印 上一主题 下一主题

aspell -- 交互式拼写检查工具

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34397
跳转到指定楼层
楼主
发表于 2012-3-26 14:05:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在许多的用户文本编辑软件中经常会看到它们已经集成了单词拼写检查功能,如 Microsoft Office Word,以及各种电子邮件客户端等。

在 Linux 里,也有一个实用的,且基于命令行的拼写检查工具 -- aspell ,它亦能提供交互式的拼写检查,更改,保存等功能。

一般情况下,你所用的发行版也许没有默认安装该工具。如果使用的是 Debian 或者 Ubuntu 这样的发行版,那么安装命令为:
#apt-get install aspell
如果使用的是 Fedora 这样的发行版,可以:
# yum install aspell


下面是个测试文件,里面写了几个单词,有对的也有错的:
# cat tmp.txt
hello
linus
world
shell groad www net
unix and linux go spellings
下面使用 aspell 来检查该文件,运行命令如下:
# aspell check tmp.txt
这时会看到一个交互式界面如下:

在上图中,程序对人命 linus 的拼写建议通过数字和字母的顺序列出来,比如你按下 1 键,那么相应的文本就会修改成 Linus ,修改所有的错误后,可以按下 x 键保存退出;如果按下 b 键则会中断修改操作。

在默认情况下,aspell 自带的检查辞典可能不够用,我们可以搜索安装更多,比如在 Debian 或 Ubuntu 下:
# apt-cache search aspell
aspell-de-alt - German dictionary for aspell (old spelling)
aspell-lt - aspell dictionary for Lithuanian (LT)
aspell-uk - Ukrainian dictionary for GNU Aspell
aspell-et - Estonian dictionary for Aspell
ilohamail - Light weight yet full featured multilingual web-based IMAP/POP3 client
aspell-gl-minimos - Aspell dictionary for Galician (minimos)
aspell-de - German dictionary for aspell
aspell-ca - Catalan dictionary for aspell
aspell-fo - The Faroese dictionary for aspell
aspell-bg - Bulgarian dictionary for aspell
... ...

下面是个测试脚本:
[Bash shell] 纯文本查看 复制代码
#!/bin/bash

word=$1

output=`echo \"$word\" | aspell list`

if [ -z $output ]; then
    echo $word is a dictionary word;
else
    echo $word is not a dictionary word;
fi

运行输出:
# ./aspell.sh groad
groad is not a dictionary word
# ./aspell.sh hello
hello is a dictionary word
在上面的脚本中,使用了 aspell 命令的 list 选项,该选项表示如果所检查到的单词如果在词典中,那么它不会输出任何内容,此时变量 output 为空,所以在 if 里测试时也正是使用了 -z 选项来判断 output 是否为空,若为空那么表示该单词在辞典中,否则不在词典中,此时只会简单的输出拼写错误的单词。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-6-18 21:46 , Processed in 0.089065 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表