ruby on rails - Check if a sentence includes any words in an array -


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 |word|     new_score += 0.5 end 

i have splitdescription splits , store description.

i want see if of keywords in splitdescription , each keyword in splitdescription new_score goes 0.5.

im trying code @ moment not work correctly.

you there:

splitdescription.select { |word| keywords.include?(word) } 

since here keywords array lookup single word in.

more robust solution be:

new_score += 0.5 * (splitdescription & keywords).size 

the latter intersect keywords array , splitted description, calculates size of intersection , increase score value divided two.


Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -