Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
160
Task/Textonyms/AWK/textonyms.awk
Normal file
160
Task/Textonyms/AWK/textonyms.awk
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
#!/usr/bin/env -S gawk -E
|
||||
|
||||
BEGIN { # user's configuration area
|
||||
|
||||
KEYMAP="2 abc 3 def 4 ghi 5 jkl 6 mno 7 pqrs 8 tuv 9 wxyz"
|
||||
FNAME="/usr/share/dict/american-english" # 0.5 MB; 102775 words;
|
||||
|
||||
#KEYMAP="2 αβγά 3 δεζέ 4 ηθιήίϊΐ 5 κλμ 6 νξοό 7 πρσς 8 τυφύϋΰ 9 χψωώ"
|
||||
#FNAME="/usr/share/dict/greek" # 19.5MB; 828808 words;
|
||||
|
||||
# where generated data will be written,
|
||||
# or comment out a line if you don’t need it.
|
||||
EXPORT_TXN="/tmp/textonyms"
|
||||
EXPORT_ALL="/tmp/phonewords"
|
||||
EXPORT_BAD="/tmp/invalidwords" #also the line ‘BUFF_ERRW = BUFF_...’
|
||||
}
|
||||
BEGIN { # main
|
||||
delete ARGV; ARGC=1 # do not accept command line arguments
|
||||
delete XEK # reserve id for use only as a hash table
|
||||
delete TXN # reserve id ...
|
||||
AZ="" # generated Alphabet
|
||||
EE=0 # invalid word Counter
|
||||
KK=0 # valid word Counter
|
||||
TT=0 # textonym groups in the table TXN
|
||||
BUFF_ERRW="" # invalid word buffer
|
||||
TOTAL=1 # enum
|
||||
COUNT=2 # enum
|
||||
|
||||
STDERR="/dev/stderr"
|
||||
OLD_RS=RS
|
||||
OLD_FS=FS
|
||||
processFile()
|
||||
generateReport()
|
||||
userQuery()
|
||||
}
|
||||
function processFile( ii,jj,nn,errW,ss,aKey,aGroup,qqq){
|
||||
$0=KEYMAP
|
||||
AZ=" "
|
||||
for (ii=1; ii<=NF; ii=ii+2) {
|
||||
aKey=$ii; aGroup=$(ii+1)
|
||||
nn=split(aGroup, qqq, //)
|
||||
for (jj=1; jj<=nn; jj++) {ss=qqq[jj]; XEK[ss]=aKey; AZ = AZ ss " " }
|
||||
}
|
||||
AZ = AZ " "
|
||||
######################
|
||||
RS="^$" #
|
||||
FS="[\n\t ]+" #
|
||||
######################
|
||||
if ((getline <FNAME) <= 0) {
|
||||
printf "unexpected EOF or error: ‘%s’ %s\n",FNAME,ERRNO >STDERR
|
||||
exit 1
|
||||
} else printf "total words in the file ‘%s’: %s\n", FNAME,NF
|
||||
|
||||
for (ii=1; ii<=NF; ii++) {
|
||||
errW=0
|
||||
ss=tolower($ii)
|
||||
nn=split(ss, qqq, //)
|
||||
nmb=""
|
||||
for (jj=1; jj<=nn; jj++) {
|
||||
lchr=qqq[jj]
|
||||
if (index(AZ," "lchr" ")>0) { nmb = nmb XEK[lchr] }
|
||||
else {
|
||||
EE++
|
||||
errW=1
|
||||
BUFF_ERRW = BUFF_ERRW $ii "\n"
|
||||
break
|
||||
}
|
||||
}
|
||||
if (errW) { continue }
|
||||
T9=TXN[nmb][TOTAL]
|
||||
if (index(T9" "," "ss" ")==0) {
|
||||
TXN[nmb][TOTAL] = T9 " " ss
|
||||
TXN[nmb][COUNT]++
|
||||
}
|
||||
KK++
|
||||
}
|
||||
}
|
||||
function generateReport( elm){
|
||||
for (elm in TXN) { if (TXN[elm][COUNT]>1) { TT++ } }
|
||||
printf "valid words: %9s\n", KK
|
||||
printf "invalid words: %9s\n", EE
|
||||
printf "table indices for valid words: %9s\n", length(TXN)
|
||||
printf "textonym groups in the table: %9s\n", TT
|
||||
exportData()
|
||||
close(EXPORT_BAD); close(EXPORT_TXN); close(EXPORT_ALL)
|
||||
}
|
||||
function exportData( elm){
|
||||
if (EXPORT_BAD != "") print BUFF_ERRW >EXPORT_BAD
|
||||
|
||||
if (EXPORT_TXN != "" && EXPORT_ALL != "") {
|
||||
printf "%s\n",
|
||||
"number-of-textonyms\tword's-length\tkeys\tlist-of-textonyms" >EXPORT_ALL
|
||||
printf "%s\n",
|
||||
"number-of-textonyms\tword's-length\tkeys\tlist-of-textonyms" >EXPORT_TXN
|
||||
for (elm in TXN) {
|
||||
printf "%s\t%s\t%s\t%s\n",
|
||||
TXN[elm][COUNT], length(elm), elm, TXN[elm][TOTAL] >EXPORT_ALL
|
||||
if (TXN[elm][COUNT]>1) {
|
||||
printf "%s\t%s\t%s\t%s\n",
|
||||
TXN[elm][COUNT], length(elm), elm, TXN[elm][TOTAL] >EXPORT_TXN
|
||||
}
|
||||
}
|
||||
return ## return ## return ## return ##
|
||||
} else if (EXPORT_ALL != "") {
|
||||
printf "%s\n",
|
||||
"number-of-textonyms\tword's-length\tkeys\tlist-of-textonyms" >EXPORT_ALL
|
||||
for (elm in TXN) {
|
||||
printf "%s\t%s\t%s\t%s\n",
|
||||
TXN[elm][COUNT], length(elm), elm, TXN[elm][TOTAL] >EXPORT_ALL
|
||||
}
|
||||
}
|
||||
else if (EXPORT_TXN != "") {
|
||||
printf "%s\n",
|
||||
"number-of-textonyms\tword's-length\tkeys\tlist-of-textonyms" >EXPORT_TXN
|
||||
for (elm in TXN) {
|
||||
if (TXN[elm][COUNT]>1) {
|
||||
printf "%s\t%s\t%s\t%s\n",
|
||||
TXN[elm][COUNT], length(elm), elm, TXN[elm][TOTAL] >EXPORT_TXN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function userQuery( userasks,ss,ss1,nn,key,words){
|
||||
printf "txn>> "
|
||||
RS=OLD_RS
|
||||
FS=OLD_FS
|
||||
while ((getline ) > 0) {
|
||||
userasks=$1
|
||||
if (NF==0){ printf "txn>> ", ""; continue }
|
||||
else if (userasks ~ /^-e|--ex|--exit$/) { exit }
|
||||
else if (userasks ~ /^[0-9]+$/) {
|
||||
nn=TXN[userasks][COUNT]+0
|
||||
words=TXN[userasks][TOTAL]
|
||||
if (nn == 0) { printf "%s -> %s\n", userasks,"no matching words" }
|
||||
else { printf "%s -> (%s) %s\n", userasks,nn,words }
|
||||
}
|
||||
else {
|
||||
ss=tolower(userasks)
|
||||
if ((key=keySeq_orElse_zero(ss))>0) {
|
||||
ss1=(index((TXN[key][TOTAL]" ") , " "ss" ")>0) ?
|
||||
", and the word is in" : ", but the word is not in"
|
||||
printf "%s -> %s; the key is%s in the table%s\n", ss,key,
|
||||
((key in TXN) ?"":" not"),ss1
|
||||
}
|
||||
else {
|
||||
printf "%s -> not a valid word for the alphabet:\n%s\n", userasks,AZ
|
||||
}
|
||||
}
|
||||
printf "txn>> "
|
||||
}
|
||||
printf "\n"
|
||||
}
|
||||
function keySeq_orElse_zero(aWord, qqq,lchr,nn,jj,buf){
|
||||
nn=split(aWord, qqq, //)
|
||||
for (jj=1; jj<=nn; jj++) {
|
||||
lchr=qqq[jj]
|
||||
if (index(AZ," "lchr" ")>0) { buf = buf XEK[lchr] } else { return 0 }
|
||||
}
|
||||
return buf
|
||||
}
|
||||
124
Task/Textonyms/AppleScript/textonyms-1.applescript
Normal file
124
Task/Textonyms/AppleScript/textonyms-1.applescript
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
use AppleScript version "2.3.1" -- OS X 10.9 (Mavericks) or later.
|
||||
-- https://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Straightforward
|
||||
use sorter : script "Quicksort"
|
||||
use scripting additions
|
||||
|
||||
on textonyms(posixPath, query)
|
||||
set digits to "23456789"
|
||||
set keys to {"", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}
|
||||
set {mv, LF} to {missing value, linefeed}
|
||||
-- Check input.
|
||||
try
|
||||
set reporting to (query's class is not text)
|
||||
if (not reporting) then
|
||||
repeat with chr in query
|
||||
if (chr is not in digits) then error "Invalid digit input"
|
||||
end repeat
|
||||
set digitCount to (count query)
|
||||
end if
|
||||
script o
|
||||
property |words| : (do shell script ("cat " & posixPath))'s paragraphs
|
||||
property combos : mv
|
||||
end script
|
||||
on error errMsg
|
||||
display alert "Textonyms handler: parameter error" message ¬
|
||||
errMsg as critical buttons {"Stop"} default button 1
|
||||
error number -128
|
||||
end try
|
||||
|
||||
ignoring case
|
||||
-- Lose obvious no-hope words.
|
||||
set alphabet to join(keys's rest, "")
|
||||
repeat with i from 1 to (count o's |words|)
|
||||
set wrd to o's |words|'s item i
|
||||
if ((reporting) or (wrd's length = digitCount)) then
|
||||
repeat with chr in wrd
|
||||
if (chr is not in alphabet) then
|
||||
set o's |words|'s item i to mv
|
||||
exit repeat
|
||||
end if
|
||||
end repeat
|
||||
else
|
||||
set o's |words|'s item i to mv
|
||||
end if
|
||||
end repeat
|
||||
set o's |words| to o's |words|'s every text
|
||||
set wordCount to (count o's |words|)
|
||||
|
||||
-- Derive digit combinations from the rest.
|
||||
set txt to join(o's |words|, LF)
|
||||
repeat with d in digits
|
||||
set d to d's contents
|
||||
repeat with letter in keys's item d
|
||||
set txt to replaceText(txt, letter's contents, d)
|
||||
end repeat
|
||||
end repeat
|
||||
set o's combos to txt's paragraphs
|
||||
end ignoring
|
||||
|
||||
-- Return the appropriate result
|
||||
considering case -- Case insensitivity not needed with digits.
|
||||
if (reporting) then
|
||||
tell sorter to sort(o's combos, 1, wordCount)
|
||||
set {previousCombo, comboCount, textonymCount, counting} to ¬
|
||||
{"", wordCount, 0, true}
|
||||
repeat with i from 1 to wordCount
|
||||
set thisCombo to o's combos's item i
|
||||
if (thisCombo = previousCombo) then
|
||||
set comboCount to comboCount - 1
|
||||
if (counting) then
|
||||
set textonymCount to textonymCount + 1
|
||||
set counting to false
|
||||
end if
|
||||
else
|
||||
set previousCombo to thisCombo
|
||||
set counting to true
|
||||
end if
|
||||
end repeat
|
||||
set output to (wordCount as text) & " words in '" & ¬
|
||||
(do shell script ("basename " & posixPath)) & ¬
|
||||
"' can be represented by the digit key mapping." & ¬
|
||||
(LF & comboCount & " digit combinations are required to represent them.") & ¬
|
||||
(LF & textonymCount & " of the digit combinations represent Textonyms.")
|
||||
else
|
||||
set output to {}
|
||||
repeat with i from 1 to wordCount
|
||||
if (o's combos's item i = query) then set output's end to o's |words|'s item i
|
||||
end repeat
|
||||
if ((count output) = 1) then set output to {}
|
||||
end if
|
||||
end considering
|
||||
|
||||
return output
|
||||
end textonyms
|
||||
|
||||
on join(lst, delim)
|
||||
set astid to AppleScript's text item delimiters
|
||||
set AppleScript's text item delimiters to delim
|
||||
set txt to lst as text
|
||||
set AppleScript's text item delimiters to astid
|
||||
return txt
|
||||
end join
|
||||
|
||||
on replaceText(mainText, searchText, replacementText)
|
||||
set astid to AppleScript's text item delimiters
|
||||
set AppleScript's text item delimiters to searchText
|
||||
set textItems to mainText's text items
|
||||
set AppleScript's text item delimiters to replacementText
|
||||
set mainText to textItems as text
|
||||
set AppleScript's text item delimiters to astid
|
||||
return mainText
|
||||
end replaceText
|
||||
|
||||
on task()
|
||||
set posixPath to "~/Desktop/www.rosettacode.org/unixdict.txt"
|
||||
set report to textonyms(posixPath, missing value)
|
||||
set output to {report, "", "Examples:"}
|
||||
repeat with digitCombo in {"729", "723353", "25287876746242"}
|
||||
set foundWords to textonyms(posixPath, digitCombo's contents)
|
||||
set output's end to digitCombo & " --> {" & join(foundWords, ", ") & "}"
|
||||
end repeat
|
||||
return join(output, linefeed)
|
||||
end task
|
||||
|
||||
task()
|
||||
8
Task/Textonyms/AppleScript/textonyms-2.applescript
Normal file
8
Task/Textonyms/AppleScript/textonyms-2.applescript
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
"24978 words in 'unixdict.txt' can be represented by the digit key mapping.
|
||||
22903 digit combinations are required to represent them.
|
||||
1473 of the digit combinations represent Textonyms.
|
||||
|
||||
Examples:
|
||||
729 --> {paw, pax, pay, paz, raw, ray, saw, sax, say}
|
||||
723353 --> {paddle, raffle, saddle}
|
||||
25287876746242 --> {claustrophobia, claustrophobic}"
|
||||
99
Task/Textonyms/AppleScript/textonyms-3.applescript
Normal file
99
Task/Textonyms/AppleScript/textonyms-3.applescript
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
|
||||
use framework "Foundation"
|
||||
use scripting additions
|
||||
|
||||
on textonyms(posixPath, query)
|
||||
set digits to "23456789"
|
||||
set keys to {"", "[abc]", "[def]", "[ghi]", "[jkl]", "[mno]", "[pqrs]", "[tuv]", "[wxyz]"}
|
||||
set {mv, LF} to {missing value, linefeed}
|
||||
-- Check input.
|
||||
try
|
||||
set reporting to (query's class is not text)
|
||||
if (not reporting) then
|
||||
repeat with chr in query
|
||||
if (chr is not in digits) then error "Invalid digit input"
|
||||
end repeat
|
||||
set digitCount to (count query)
|
||||
end if
|
||||
set || to current application
|
||||
set pathStr to (||'s NSString's stringWithString:(posixPath))'s ¬
|
||||
stringByExpandingTildeInPath()
|
||||
set {txt, err} to ||'s NSMutableString's stringWithContentsOfFile:(pathStr) ¬
|
||||
usedEncoding:(mv) |error|:(reference)
|
||||
if (err ≠ mv) then error (err's localizedDescription() as text)
|
||||
on error errMsg
|
||||
display alert "Textonyms handler: parameter error" message ¬
|
||||
errMsg as critical buttons {"Stop"} default button 1
|
||||
error number -128
|
||||
end try
|
||||
|
||||
-- Lose obvious no-hope words.
|
||||
set regex to ||'s NSRegularExpressionSearch
|
||||
txt's replaceOccurrencesOfString:("\\R") withString:(LF) ¬
|
||||
options:(regex) range:({0, txt's |length|()})
|
||||
set |words| to txt's componentsSeparatedByString:(LF)
|
||||
if ((reporting) or (digitCount > 9)) then
|
||||
set predFormat to "(self MATCHES '(?i)[a-z]++')"
|
||||
else
|
||||
set predFormat to "(self MATCHES '(?i)[a-z]{" & digitCount & "}+')"
|
||||
end if
|
||||
set predicate to ||'s NSPredicate's predicateWithFormat:(predFormat)
|
||||
set |words| to |words|'s filteredArrayUsingPredicate:(predicate)
|
||||
set wordCount to |words|'s |count|()
|
||||
|
||||
-- Derive digit combinations from the rest.
|
||||
set txt to (|words|'s componentsJoinedByString:(LF))'s mutableCopy()
|
||||
set range to {0, txt's |length|()}
|
||||
repeat with d in digits
|
||||
(txt's replaceOccurrencesOfString:("(?i)" & keys's item d) withString:(d) ¬
|
||||
options:(regex) range:(range))
|
||||
end repeat
|
||||
set combos to txt's componentsSeparatedByString:(LF)
|
||||
|
||||
-- Return the appropriate result.
|
||||
if (reporting) then
|
||||
set comboSet to ||'s NSSet's setWithArray:(combos)
|
||||
set comboCount to comboSet's |count|()
|
||||
set textonymSet to ||'s NSCountedSet's alloc()'s initWithArray:(combos)
|
||||
textonymSet's minusSet:(comboSet)
|
||||
set textonymCount to textonymSet's |count|()
|
||||
set output to (wordCount as text) & " words in '" & ¬
|
||||
(pathStr's lastPathComponent()) & ¬
|
||||
"' can be represented by the digit key mapping." & ¬
|
||||
(LF & comboCount & " digit combinations are required to represent them.") & ¬
|
||||
(LF & textonymCount & " of the digit combinations represent Textonyms.")
|
||||
else
|
||||
set output to {}
|
||||
set range to {0, wordCount}
|
||||
set i to combos's indexOfObject:(query) inRange:(range)
|
||||
repeat until (i > wordCount)
|
||||
set output's end to (|words|'s objectAtIndex:(i)) as text
|
||||
set range to {i + 1, wordCount - (i + 1)}
|
||||
set i to combos's indexOfObject:(query) inRange:(range)
|
||||
end repeat
|
||||
if ((count output) = 1) then set output to {}
|
||||
end if
|
||||
|
||||
return output
|
||||
end textonyms
|
||||
|
||||
on join(lst, delim)
|
||||
set astid to AppleScript's text item delimiters
|
||||
set AppleScript's text item delimiters to delim
|
||||
set txt to lst as text
|
||||
set AppleScript's text item delimiters to astid
|
||||
return txt
|
||||
end join
|
||||
|
||||
on task()
|
||||
set posixPath to "~/Desktop/www.rosettacode.org/unixdict.txt"
|
||||
set report to textonyms(posixPath, missing value)
|
||||
set output to {report, "", "Examples:"}
|
||||
repeat with digitCombo in {"729", "723353", "25287876746242"}
|
||||
set foundWords to textonyms(posixPath, digitCombo's contents)
|
||||
set output's end to digitCombo & " --> {" & join(foundWords, ", ") & "}"
|
||||
end repeat
|
||||
return join(output, linefeed)
|
||||
end task
|
||||
|
||||
task()
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import "io" for File
|
||||
import "/str" for Char, Str
|
||||
import "/sort" for Sort
|
||||
import "/fmt" for Fmt
|
||||
import "./str" for Char, Str
|
||||
import "./sort" for Sort
|
||||
import "./fmt" for Fmt
|
||||
|
||||
var wordList = "unixdict.txt"
|
||||
var DIGITS = "22233344455566677778889999"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue