Code Monkey home page Code Monkey logo

keyword_density's Introduction

KeywordDensity
==============

Simple rails plugin that will count words of more than two characters in a string.
It uses a stop list, which can be supplied by the user. Options exist to give, say,
the top 5 keywords and their relative frequency.

The purpose is to rank content for pushing to a suite of sister sites.

caveats:

Assumes the content is free of tags.

Example Useage:
===============

    # Remove the HTML from content in @page
    @page_no_tags ||= @page.gsub(/\<style.*?\<\/style\>/mi,'').gsub(/\<script.*?\<\/script\>/mi,'').
      gsub(/<\/?[a-z][a-z0-9[:space:]]*[^<>]*>/, '').gsub( /&[^;]+;|[\r\n]/,'').gsub( /[<>]*/, '').strip
    # Create a new object
    density = KeywordDensity.new
    # populate it
    density.get_keyword_density(@page_no_tags)
    # Get the single words that occur more than 4 times
    # More than 14 it's probably some noise
    @keywords_for_cloud = density.words_count.select {|x,y| x.size == 1 && y > 4 && y < 15}
    # take this array, sort it by most frequent first and return the first 5 - this is old code that isn't very good
    @keywords_for_cloud = @keywords_for_cloud.sort { |l,h| h[1] <=> l[1] }[0..5].collect { |x| x[0] }.flatten.join(" ")

keyword_density's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.