Utilisez-vous linux? J'utilise ces fonctions shell
# copyright by Werner Rudolph <werner (at) artistoex (dot) net>
# copying and distributing of the following source code
# is permitted, as long as this note is preserved.
# ftr CHAR1 CHAR2
# translate delimiter char in frequency list
#
ftr()
{
sed -r 's/^(*[0-9]+)'"$1"'/\1'"$2"'/'
}
# valid-collocations -- find valid collocations in inputstream
# reads records COUNT<SPC>COLLOCATION from inputstream
# writes records with existing collocations to stdout.
valid-collocations()
{
#sort -k 2 -m - "$coll" |uniq -f 1 -D|accumulate
local delimiter="_"
ftr ' ' $delimiter |
join -t $delimiter -o 1.1 0 -1 2 -2 1 - /tmp/wordsets-helper-collocations |
ftr $delimiter ' '
}
# ngrams MAX [MIN]
#
# Generates all n-grams (for each MIN <= n <= MAX, where MIN defaults to 2)
# from inputstream
#
# reads word list, as generated by
#
# $ words < text
#
# from stdin. For each WORD in wordlist, it writes MAX-1 records
#
# COUNT<TAB>WORD<SPC>SUCC_1<SPC>
# COUNT<TAB>WORD<SPC>SUCC_1<SPC>SUCC_2<SPC>
# :
# COUNT<TAB>WORD<SPC>SUCC_1<SPC>SUCC_2<SPC>...<SPC>SUCC_MAX-2
# COUNT<TAB>WORD<SPC>SUCC_1<SPC>SUCC_2<SPC>...<SPC>SUCC_MAX-1
#
# to stdout, where word SUCC follows word WORD, and SUCC_n follows
# SUCC_n-1 in input stream COUNT times.
ngrams()
{
local max=$1
local min=${2:-2};
awk 'FNR > 1 {print old " " $0} {old=$1}' | if (($max - 1 > 1)); then
if (($min <= 2)); then
tee >(ngrams $(($max - 1)) $(($min - 1)));
else
ngrams $(($max - 1)) $(($min - 1));
fi;
else
cat;
fi
}
words() {
grep -Eo '\<([a-zA-Z]'"'"'?){'${1:-3}',}\>'|grep -v "[A-Z]"
}
parse-collocations() {
local freq=${1:-0}
local length=${2:-4}
words | ngrams $length | sort | uniq -c |
awk '$1 > '"$freq"' { print $0; }' |
valid-collocations
}
Où parse-collocation
est la fonction réelle à utiliser. Il accepte deux paramètres facultatifs: Le premier définit la fréquence récurrente maximale des termes à ignorer du résultat (0 par défaut, c'est-à-dire prend en compte tous les termes). Le deuxième paramètre définit la longueur maximale du terme à rechercher. La fonction va lire le texte de stdin et imprimer les termes à stdout ligne par ligne. Il a besoin d'un fichier de dictionnaire à /tmp/wordsets-helper-collocations
(télécharger un here):
Exemple d'utilisation:
$ parse-collocation < some-text
serait à peu près ce que vous voulez. Toutefois, si vous ne voulez pas les termes à être associé à un dictionnaire, vous pouvez utiliser celui-ci
$ words < some-text | ngrams 3 4 | sort | uniq -c |sort -nr
premier paramètre de ngrams
définit la longueur minimale à long terme alors que son deuxième paramètre (facultatif) définit la longueur maximale à long terme .