Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何清理和改进关键字列表?_Ruby_Api_Keyword - Fatal编程技术网

Ruby 如何清理和改进关键字列表?

Ruby 如何清理和改进关键字列表?,ruby,api,keyword,Ruby,Api,Keyword,在使用关键字API获取流行关键字和短语之后,我还得到了很多带有太多额外单词的“肮脏”术语(“the”、“a”等) 我还想在搜索词中隔离名称 是否有一个Ruby库来清理关键字列表?这样的算法存在吗?你说的是“stopwords”,它是演讲稿,如“the”和“a”,加上经常遇到的毫无价值的单词 存在停止词列表;如果我没记错的话,它有一个,在Ruby或模块中可能有一个,但实际上它们很容易自己生成。而且,你可能需要这样做,因为垃圾词因特定主题而异 最简单的方法是使用几个示例文档运行一个初步过程,将文本拆

在使用关键字API获取流行关键字和短语之后,我还得到了很多带有太多额外单词的“肮脏”术语(“the”、“a”等)

我还想在搜索词中隔离名称

是否有一个Ruby库来清理关键字列表?这样的算法存在吗?

你说的是“stopwords”,它是演讲稿,如“the”和“a”,加上经常遇到的毫无价值的单词

存在停止词列表;如果我没记错的话,它有一个,在Ruby或模块中可能有一个,但实际上它们很容易自己生成。而且,你可能需要这样做,因为垃圾词因特定主题而异

最简单的方法是使用几个示例文档运行一个初步过程,将文本拆分为单词,然后循环它们,每增加一个计数器。当你写完的时候,寻找那些两到四个字母长的单词,它们的数量要多得不成比例。这些都是很好的停止语候选词

然后,run遍历目标文档,像以前一样分割文本,边运行边计算出现次数。您可以忽略停止字列表中的字,而不将其添加到哈希中,或者处理所有内容,然后删除停止字

text = <<EOT
You have reached this web page by typing "example.com", "example.net","example.org"
or "example.edu" into your web browser.

These domain names are reserved for use in documentation and are not available
for registration. See RFC 2606, Section 3.
EOT

# do this against several documents to build a stopword list. Tweak as necessary to fine-tune the words.
stopwords = text.downcase.split(/\W+/).inject(Hash.new(0)) { |h,w| h[w] += 1; h }.select{ |n,v| n.length < 5 }

print "Stopwords => ", stopwords.keys.sort.join(', '), "\n"

# >> Stopwords => 2606, 3, and, are, by, com, edu, for, have, in, into, net, not, or, org, page, rfc, see, this, use, web, you, your
text=>Stopwords=>2606,3和,是,由,com,edu,for,have,in,into,net,not,or,org,page,rfc,see,this,use,web,you,your
然后,您可以进行一些关键字收集:

text = <<EOT
You have reached this web page by typing "example.com", "example.net","example.org"
or "example.edu" into your web browser.

These domain names are reserved for use in documentation and are not available
for registration. See RFC 2606, Section 3.
EOT

stopwords = %w[2606 3 and are by com edu for have in into net not or org page rfc see this use web you your]

keywords = text.downcase.split(/\W+/).inject(Hash.new(0)) { |h,w| h[w] += 1; h }
stopwords.each { |s| keywords.delete(s) }

# output in order of most often seen to least often seen.
keywords.keys.sort{ |a,b| keywords[b] <=> keywords[a] }.each { |k| puts "#{k} => #{keywords[k]}"}
# >> example => 4
# >> names => 1
# >> reached => 1
# >> browser => 1
# >> these => 1
# >> domain => 1
# >> typing => 1
# >> reserved => 1
# >> documentation => 1
# >> available => 1
# >> registration => 1
# >> section => 1
text=>example=>4
#>>名称=>1
#>>达到=>1
#>>浏览器=>1
#>>这些=>1
#>>域=>1
#>>键入=>1
#>>保留=>1
#>>文档=>1
#>>可用=>1
#>>注册=>1
#>>部分=>1
缩小单词列表后,您可以通过WordNet运行候选词,查找同义词、同音词、单词关系、带复数等。如果您要对大量文本执行此操作,您需要将停止词保存在数据库中,以便不断对其进行微调。同样的道理也适用于你的关键词,因为你可以从这些关键词开始判断语调和其他语义上的优点。

你说的是“stopwords”,它是演讲稿,如“The”和“a”,加上经常遇到的毫无价值的词

存在停止词列表;如果我没记错的话,它有一个,在Ruby或模块中可能有一个,但实际上它们很容易自己生成。而且,你可能需要这样做,因为垃圾词因特定主题而异

最简单的方法是使用几个示例文档运行一个初步过程,将文本拆分为单词,然后循环它们,每增加一个计数器。当你写完的时候,寻找那些两到四个字母长的单词,它们的数量要多得不成比例。这些都是很好的停止语候选词

然后,run遍历目标文档,像以前一样分割文本,边运行边计算出现次数。您可以忽略停止字列表中的字,而不将其添加到哈希中,或者处理所有内容,然后删除停止字

text = <<EOT
You have reached this web page by typing "example.com", "example.net","example.org"
or "example.edu" into your web browser.

These domain names are reserved for use in documentation and are not available
for registration. See RFC 2606, Section 3.
EOT

# do this against several documents to build a stopword list. Tweak as necessary to fine-tune the words.
stopwords = text.downcase.split(/\W+/).inject(Hash.new(0)) { |h,w| h[w] += 1; h }.select{ |n,v| n.length < 5 }

print "Stopwords => ", stopwords.keys.sort.join(', '), "\n"

# >> Stopwords => 2606, 3, and, are, by, com, edu, for, have, in, into, net, not, or, org, page, rfc, see, this, use, web, you, your
text=>Stopwords=>2606,3和,是,由,com,edu,for,have,in,into,net,not,or,org,page,rfc,see,this,use,web,you,your
然后,您可以进行一些关键字收集:

text = <<EOT
You have reached this web page by typing "example.com", "example.net","example.org"
or "example.edu" into your web browser.

These domain names are reserved for use in documentation and are not available
for registration. See RFC 2606, Section 3.
EOT

stopwords = %w[2606 3 and are by com edu for have in into net not or org page rfc see this use web you your]

keywords = text.downcase.split(/\W+/).inject(Hash.new(0)) { |h,w| h[w] += 1; h }
stopwords.each { |s| keywords.delete(s) }

# output in order of most often seen to least often seen.
keywords.keys.sort{ |a,b| keywords[b] <=> keywords[a] }.each { |k| puts "#{k} => #{keywords[k]}"}
# >> example => 4
# >> names => 1
# >> reached => 1
# >> browser => 1
# >> these => 1
# >> domain => 1
# >> typing => 1
# >> reserved => 1
# >> documentation => 1
# >> available => 1
# >> registration => 1
# >> section => 1
text=>example=>4
#>>名称=>1
#>>达到=>1
#>>浏览器=>1
#>>这些=>1
#>>域=>1
#>>键入=>1
#>>保留=>1
#>>文档=>1
#>>可用=>1
#>>注册=>1
#>>部分=>1

缩小单词列表后,您可以通过WordNet运行候选词,查找同义词、同音词、单词关系、带复数等。如果您要对大量文本执行此操作,您需要将停止词保存在数据库中,以便不断对其进行微调。同样的道理也适用于你的关键词,因为你可以从这些关键词开始判断语调和其他语义的优点。

顺便说一句,我决定走这条路:

bad_words = ["the", "a", "for", "on"] #etc etc
# Strip non alpha chars, and split into a temp array, then cut out the bad words
tmp_str = str.gsub(/[^A-Za-z0-9\s]/, "").split - bad_words
str = tmp_str.join(" ")

顺便说一句,我决定走这条路线:

bad_words = ["the", "a", "for", "on"] #etc etc
# Strip non alpha chars, and split into a temp array, then cut out the bad words
tmp_str = str.gsub(/[^A-Za-z0-9\s]/, "").split - bad_words
str = tmp_str.join(" ")

我在你的标签列表中添加了
ruby
,但我还是不明白你在问什么。你在说什么关键字API?从哪里提取关键字/短语?你说的搜索词是什么?我用的是AlchemyAPI,一种关键字提取方法。哎呀,太快按回车键了。例如,如果您转到该URL并输入,您将返回标记。但是标签中有很多不必要的词,比如“on”或其他过于泛化的词。我想清理它们,因为我需要通过另一个API运行这些标记。我将
ruby
添加到了您的标记列表中。但我仍然不知道您在问什么。你在说什么关键字API?从哪里提取关键字/短语?你说的搜索词是什么?我用的是AlchemyAPI,一种关键字提取方法。哎呀,太快按回车键了。例如,如果您转到该URL并输入,您将返回标记。但是标签中有很多不必要的词,比如“on”或其他过于泛化的词。我想清理它们,因为我需要通过另一个API运行这些标记。仅供参考,一个好的停止词列表:我的建议是编写一些代码来构建停止词列表。手动操作会错过很多,因为我们的眼睛不善于查看列表和挑选小细节。代码是迂腐的,不会错过它们。。。假设您正确地编写了代码。如果你查看该链接中提到的长列表,你会发现它缺少完整和缩写的月份名称(2个和3个字母),以及周日的2个和3个字母缩写。我还经常添加诸如“百万”、“百”、度量值和非强标识符的单词。仅供参考,一个好的停止词列表:我的建议是编写一些代码来构建停止词