1 | !!POUNDBANG!! |
---|
2 | # |
---|
3 | # $Id: tryaffix.X,v 1.1.1.2 2007-02-01 19:50:19 ghudson Exp $ |
---|
4 | # |
---|
5 | # Copyright 1987-1989, 1992, 1993, 1999, 2001, 2005, Geoff Kuenning, |
---|
6 | # Claremont, CA |
---|
7 | # All rights reserved. |
---|
8 | # |
---|
9 | # Redistribution and use in source and binary forms, with or without |
---|
10 | # modification, are permitted provided that the following conditions |
---|
11 | # are met: |
---|
12 | # |
---|
13 | # 1. Redistributions of source code must retain the above copyright |
---|
14 | # notice, this list of conditions and the following disclaimer. |
---|
15 | # 2. Redistributions in binary form must reproduce the above copyright |
---|
16 | # notice, this list of conditions and the following disclaimer in the |
---|
17 | # documentation and/or other materials provided with the distribution. |
---|
18 | # 3. All modifications to the source code must be clearly marked as |
---|
19 | # such. Binary redistributions based on modified source code |
---|
20 | # must be clearly marked as modified versions in the documentation |
---|
21 | # and/or other materials provided with the distribution. |
---|
22 | # 4. The code that causes the 'ispell -v' command to display a prominent |
---|
23 | # link to the official ispell Web site may not be removed. |
---|
24 | # 5. The name of Geoff Kuenning may not be used to endorse or promote |
---|
25 | # products derived from this software without specific prior |
---|
26 | # written permission. |
---|
27 | # |
---|
28 | # THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND |
---|
29 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
30 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
31 | # ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE |
---|
32 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
33 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
34 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
35 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
36 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
37 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
38 | # SUCH DAMAGE. |
---|
39 | # |
---|
40 | # Try out affixes to see if they produce valid roots |
---|
41 | # |
---|
42 | # Usage: |
---|
43 | # |
---|
44 | # tryaffix [-p | -s] [-c] dict-file affix[+addition] ... |
---|
45 | # |
---|
46 | # The -p and -s flags specify whether prefixes or suffixes |
---|
47 | # are being tried; if neither is specified, suffixes are assumed. |
---|
48 | # |
---|
49 | # If the -c flag is given, statistics on the various affixes are given: |
---|
50 | # a count of words it potentially applies to, and an estimate of the |
---|
51 | # number of dictionary bytes the flag would save. The estimate will |
---|
52 | # be high if the flag generates words that are currently generated |
---|
53 | # by other flags. |
---|
54 | # |
---|
55 | # The dictionary file, dict-file, must already be expanded and sorted, |
---|
56 | # and things will work best if uppercase has been folded to lower with |
---|
57 | # 'tr'. |
---|
58 | # |
---|
59 | # The "affixes" are things to be stripped from the dictionary |
---|
60 | # file to produce trial roots: for English, "con" and "ing" |
---|
61 | # are examples. The "additions" are letters that would have |
---|
62 | # been stripped off the root before adding the affix. For |
---|
63 | # example, the affix "ing" strips "e" for words ending in "e" |
---|
64 | # (as in "like --> liking") so we might run: |
---|
65 | # |
---|
66 | # tryaffix ing ing+e |
---|
67 | # |
---|
68 | # to cover both cases. |
---|
69 | # |
---|
70 | # $Log: not supported by cvs2svn $ |
---|
71 | # Revision 1.13 2005/04/27 01:18:35 geoff |
---|
72 | # Fix a typo in a comment. Work around idiotic POSIX incompatibilities |
---|
73 | # in sort. Add secure temp-file handling. |
---|
74 | # |
---|
75 | # Revision 1.12 2005/04/14 14:40:13 geoff |
---|
76 | # Use /tmp as the default temp directory |
---|
77 | # |
---|
78 | # Revision 1.11 2005/04/14 14:38:23 geoff |
---|
79 | # Update license. Protect against modernized (i.e., incompatible) and |
---|
80 | # internationalized sort commands. |
---|
81 | # |
---|
82 | # Revision 1.10 2001/09/06 00:30:29 geoff |
---|
83 | # Changes from Eli Zaretskii to support DJGPP compilation. |
---|
84 | # |
---|
85 | # Revision 1.9 2001/07/25 21:51:47 geoff |
---|
86 | # Minor license update. |
---|
87 | # |
---|
88 | # Revision 1.8 2001/07/23 20:24:04 geoff |
---|
89 | # Update the copyright and the license. |
---|
90 | # |
---|
91 | # Revision 1.7 1999/01/07 01:57:48 geoff |
---|
92 | # Update the copyright. |
---|
93 | # |
---|
94 | # Revision 1.6 1994/01/25 07:12:18 geoff |
---|
95 | # Get rid of all old RCS log lines in preparation for the 3.1 release. |
---|
96 | # |
---|
97 | # |
---|
98 | |
---|
99 | USAGE='tryaffix [-p | -s] [-c] dict-file affix[+addition] ...' |
---|
100 | counts=no |
---|
101 | pre= |
---|
102 | suf='$' |
---|
103 | while : |
---|
104 | do |
---|
105 | case "$1" in |
---|
106 | -p) |
---|
107 | pre='^' |
---|
108 | suf= |
---|
109 | ;; |
---|
110 | -s) |
---|
111 | pre= |
---|
112 | suf='$' |
---|
113 | ;; |
---|
114 | -c) |
---|
115 | counts=yes |
---|
116 | ;; |
---|
117 | -*) |
---|
118 | echo "$USAGE" 1>&2 |
---|
119 | exit 1 |
---|
120 | ;; |
---|
121 | *) |
---|
122 | break |
---|
123 | ;; |
---|
124 | esac |
---|
125 | shift |
---|
126 | done |
---|
127 | dict="$1" |
---|
128 | shift |
---|
129 | if [ ! -r "$dict" ] |
---|
130 | then |
---|
131 | echo "Can't read $dict" 1>&2 |
---|
132 | echo "$USAGE" 1>&2 |
---|
133 | exit 1 |
---|
134 | elif [ $# -eq 0 ] |
---|
135 | then |
---|
136 | echo "$USAGE" 1>&2 |
---|
137 | exit 1 |
---|
138 | fi |
---|
139 | while [ $# -ne 0 ] |
---|
140 | do |
---|
141 | case "$1" in |
---|
142 | *+*) |
---|
143 | affix=`expr "$1" : '\(.*\)+'` |
---|
144 | addition=`expr "$1" : '.*+\(.*\)'` |
---|
145 | sedscript="s/$pre$affix$suf/$addition/p" |
---|
146 | ;; |
---|
147 | *) |
---|
148 | sedscript="s/$pre$1$suf//p" |
---|
149 | ;; |
---|
150 | esac |
---|
151 | if [ "$counts" = no ] |
---|
152 | then |
---|
153 | echo ===== "$1" ===== |
---|
154 | sed -n -e "$sedscript" "$dict" | comm -12 - "$dict" |
---|
155 | else |
---|
156 | echo "$1" \ |
---|
157 | `sed -n -e "$sedscript" "$dict" | comm -12 - "$dict" | wc -lc` |
---|
158 | fi |
---|
159 | shift |
---|
160 | done |
---|