#4181
roku
メンバー

追加させていただきます。

=====================================
名前: 単語の出現回数を数えるマクロ
版: 1.0
用途: 英数字とアンダースコアで構成される単語の
出現回数を数えます。
コメント: プログラムのトークンの出現回数を数えて、
極端に出現回数が少ないものを打ち間違いと見なし、
出現回数が多いものの中に近い単語があれば
それを正解として修正する、ということを目標に、
第一歩として作ったのですが、なかなか難しいです。
acos が cos に修正されては困るのです。
その後あまり使う機会がありません。
=====================================

/* word counter */
FIND_WORD = “[_a-zA-Z][_a-zA-Z0-9]*”;
FIND_FLAG = eeFindNext | eeFindReplaceCase | eeFindReplaceOnlyWord
| eeFindReplaceRegExp | eeFindAround;
dic = new ActiveXObject(“Scripting.Dictionary”);

Window.Redraw = false;
word = GetNextWord();
StorePosition();

do{
RegisterWord(word);
word = GetNextWord();
}while(!IsOriginalPosition());

PrintWords();
Window.Redraw = true;
dic = null;

function StorePosition(){
originalBottomX = document.selection.GetBottomPointX(eePosLogical);
originalBottomY = document.selection.GetBottomPointY(eePosLogical);
}

function GetNextWord(){
document.selection.WordRight();
document.selection.Find(FIND_WORD, FIND_FLAG);
document.HighlightFind = false;

return document.selection.Text;
}

function IsOriginalPosition(){
bottomX = document.selection.GetBottomPointX(eePosLogical);
bottomY = document.selection.GetBottomPointY(eePosLogical);

if (bottomX == originalBottomX && bottomY == originalBottomY)
return true;
else
return false;
}

function RegisterWord(word){
if(dic.Exists(word)){
n = dic.Item(word);
dic.Item(word) = n + 1;
} else {
dic.Add(word, 1);
}
}

function PrintWords(){
editor.NewFile();
newDoc = editor.ActiveDocument;

total = 0;
words = dic.Keys().toArray().sort();
//words = words.sort(SortByCount);
for(i in words) {
n = dic.Item(words);
newDoc.selection.Text = words
+ “, ” + n + “n”;
total += n;
}
newDoc.selection.Text = “——————–n”;
newDoc.selection.Text = “total ” + total + ” words.n”;
}

function SortByCount(a, b){
i = dic.Item(a);
j = dic.Item(b);

if (i > j) return -1;
else if (i b) return 1;
else if (a < b) return -1;
else return 0;
}