domnikl/highscore

View on GitHub
docs/params.json

Summary

Maintainability
Test Coverage
{"name":"Highscore","body":"## Features\r\n\r\n* configurable to rank different types of words different (uppercase, long words, etc.)\r\n* rate based on amount (%) of vowels and consonants in a string\r\n* directly get keywords from String objects\r\n* blacklist words via a plain text file, String or an Array of words\r\n* optionally, configure a whitelist and only words from that list will get ranked\r\n* use word stemming (requires the fast-stemmer gem, doesn't work on JRuby platforms!)\r\n* merge together Keywords from multiple sources\r\n* contains a CLI tool that operates on STDIN/OUT and is configurable via parameters\r\n\r\n## Examples\r\n\r\n```ruby\r\ntext = Highscore::Content.new \"foo bar\"\r\ntext.configure do\r\n  set :multiplier, 2\r\n  set :upper_case, 3\r\n  set :long_words, 2\r\n  set :long_words_threshold, 15\r\n  set :vowels, 1                     # => default: 0 = not considered\r\n  set :consonants, 5                 # => default: 0 = not considered\r\n  set :ignore_case, true             # => default: false\r\n  set :word_pattern, /[\\w]+[^\\s0-9]/ # => default: /\\w+/\r\n  set :stemming, true                # => default: false\r\nend\r\n\r\n# get only the top 50 keywords\r\ntext.keywords.top(50).each do |keyword|\r\n  keyword.text   # => keyword text\r\n  keyword.weight # => rank weight (float)\r\nend\r\n\r\n# you could just use a string\r\nkeywords = \"Foo bar baz\".keywords(blacklist) do\r\n  set :multiplier, 10\r\nend\r\n```\r\n\r\nThe result is either a Highscore::Keywords object or an Array (depending on whether it's sorted or not) that you\r\ncan iterate over. Each object in there is a Highscore::Keyword that has methods `text` and `weight`.\r\n\r\n```ruby\r\nkeywords = \"Foo bar is not bar baz\".keywords(Highscore::Blacklist.load(['baz']))\r\n\r\nkeywords.rank.each do |k|\r\n  puts \"#{k.text} #{k.weight}\"\r\nend\r\n\r\n# prints:\r\n# Foo 3.0\r\n# bar 2.0\r\n# not 1.0\r\n```\r\n\r\nHave a look at bin/highscore, you can run highscore on your CLI and feed it with text on STDIN.\r\n\r\n## Using a custom blacklist to ignore keywords\r\n\r\n```ruby\r\n# setting single words\r\nblacklist = Highscore::Blacklist.new\r\nblacklist << 'foo'\r\n\r\n# load a string/array\r\nblacklist = Highscore::Blacklist.load \"a string\"\r\nblacklist = Highscore::Blacklist.load %w{an array}\r\n\r\n# loading from a file (separated by whitespace)\r\nblacklist = Highscore::Blacklist.load_file \"blacklist.txt\"\r\n\r\n# loading the default blacklist (falls back automatically if not explicit given)\r\nblacklist = Highscore::Blacklist.load_default_file\r\n\r\n# inject the blacklist into the content class\r\ncontent = Highscore::Content.new \"a string\", blacklist\r\n```\r\n\r\n## Using a whitelist instead of ranking all words\r\n\r\n```ruby\r\n# construct and inject it just like a blacklist\r\nwhitelist = Highscore::Whitelist.load %w{these are valid keywords}\r\ncontent = Highscore::Content.new \"invalid words\", whitelist\r\n```\r\n\r\n## Install\r\n\r\n* `[sudo] gem install highscore`\r\n\r\nTo use word stemming, you need to have the fast-stemmer gem installed:\r\n\r\n* `[sudo] gem install fast-stemmer`\r\n\r\n## Author\r\n\r\nOriginal author: Dominik Liebler <liebler.dominik@googlemail.com>\r\n\r\n## License\r\n\r\n(The MIT License)\r\n\r\nCopyright (c) 2012 Dominik Liebler\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining\r\na copy of this software and associated documentation files (the\r\n'Software'), to deal in the Software without restriction, including\r\nwithout limitation the rights to use, copy, modify, merge, publish,\r\ndistribute, sublicense, and/or sell copies of the Software, and to\r\npermit persons to whom the Software is furnished to do so, subject to\r\nthe following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be\r\nincluded in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\r\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\r\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n","tagline":"find and rank keywords in text","google":"UA-9816149-12","note":"Don't delete this file! It's used internally to help with page regeneration."}