我有一个文本,我想提取最经常出现的术语,即使由多个单词组成(即:董事总经理、职位、薪水、Web 开发人员)。
我需要一个库或可安装的可执行文件,而不是 Web 服务。
我遇到了一些需要培训的复杂工具(例如 Topia 的术语提取、MAUI)。我的目的过于复杂,我发现它们很难被我使用。
我只需要一个软件来提取文本中最常见的术语。
谢谢。
我有一个文本,我想提取最经常出现的术语,即使由多个单词组成(即:董事总经理、职位、薪水、Web 开发人员)。
我需要一个库或可安装的可执行文件,而不是 Web 服务。
我遇到了一些需要培训的复杂工具(例如 Topia 的术语提取、MAUI)。我的目的过于复杂,我发现它们很难被我使用。
我只需要一个软件来提取文本中最常见的术语。
谢谢。
你用linux吗?我使用这些 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
}
parse-collocation
要使用的实际功能在哪里。它接受两个可选参数:第一个设置要从结果中跳过的术语的最大重复频率(默认为 0,即考虑所有术语)。第二个参数设置要搜索的最大词条长度。该函数将从标准输入读取文本并将条款逐行打印到标准输出。它需要一个字典文件(在此处/tmp/wordsets-helper-collocations
下载):
使用示例:
$ parse-collocation < some-text
几乎是你想要的。但是,如果您不希望术语与字典匹配,则可以使用这个
$ words < some-text | ngrams 3 4 | sort | uniq -c |sort -nr
ngrams
的第一个参数设置最小术语长度,而它的第二个(可选)参数设置最大术语长度。