手动增加本地词典


手动增加本地词典
 
01
#!/bin/sh
02
  
03
 # spelldict.sh -- 使用'aspell'特性以及一些过滤以便
04
 # 允许命令行拼写检查给定的输入文件
05
  
06
 # 不可避免的,你会发现,有些词汇是错误的,但你认为
07
 # 它们是正确的。简单的将它们保存在一个文件中,一次
08
 # 一行,并且确定变量'okaywords'指向这个文件。
09
  
10
 okaywords="$HOME/okaywords"
11
 tempout="/tmp/spell.tmp.$$"
12
 spell="aspell"    # 根据需要修改
13
  
14
 trap "/bin/rm -f $tempout" EXIT
15
  
16
 if [ -z "$1" ]; then
17
     echo "Usage: spell file | URL" >&2
18
     exit 1
19
 elif [ ! -f $okaywords ]; then
20
     echo "No personal dictionary found. Create one and return this command." >&2
21
     echo "Your dictionary file: $okaywords" >&2
22
     exit 1
23
 fi
24
  
25
 for filename
26
 do
27
     $spell -a < $filename | \
28
     grep -v '@(#)' | sed "s/\'//g" | \
29
         awk '{if(length($0) > 15 && length($2) > 2) print $2}' | \
30
     grep -vif $okaywords | \
31
     grep '[[:lower:]]' | grep -v '[[:digit:]]' | sort -u | \
32
     sed 's/^/ /' > $tempout
33
  
34
     if [ -s $tempout ]; then
35
         sed 's/^/${filename}: /' $tempout
36
     fi
37
 done
38
  
39
 exit 0
运行脚本:
这个脚本需要在命令行上提供一个或多个文件名
 
运行结果:
 
01
首先,一个空的个人字典,txt内容摘录自爱丽丝漫游记:
02
$ spelldict ragged.txt
03
ragged.txt:    herrself
04
ragged.txt:    teacups
05
ragged.txt:    Gryphon
06
ragged.txt:    clamour
07
 
08
有两个词拼错了,所以准备用echo命令把它们加到okaywords文件中:
09
 
10
$ echo "Gryphon" >> ~/.okaywords
11
$ echo "teacups" >> ~/.okaywords
12
 
13
扩展了词典文件后的检查结果如下:
14
 
15
$ spelldict ragged.txt
16
ragged.txt:    herrself
17
ragged.txt:    clamour
 

相关内容

    暂无相关文章