检查一个句子是否包含数组中的任何单词

时间:2016-06-28 09:52:21

标签: ruby-on-rails ruby ruby-on-rails-4

splitDescription = work.workdescription.downcase.split(' ')

keywords = ['teamwork', 'developed', 'enhanced', 'transformed', 'achieved','grew', 'introduced', 'project', 'awarded',
             'planned','supervised','created','designed','discovered','evaluated','promoted','represented','completed',
             'devised','liaised','controlled','researched','organised','achieved','managed','analysed','assessed','conducted',
             'solved','responsible for','responsibilities']

splitDescription.select {|word| word.include?(keywords)}.each do |word|
    new_score += 0.5
end

我有splitDescription分割并存储说明。

我想看看splitDescription中是否有任何关键字,keyword splitDescriptionnew_score的每个 TextView bt = new TextView(getContext()); 上升了0.5。

我现在正在尝试此代码,但它无法正常工作。

1 个答案:

答案 0 :(得分:7)

你快到了:

A, B & C

因为此处splitDescription.select { |word| keywords.include?(word) } 是一个用于查找单个keywords的数组。

更强大的解决方案是:

word

后者将与new_score += 0.5 * (splitDescription & keywords).size 数组和分裂描述相交,计算交点的大小,并将得分除以此值。

相关问题