Skip to content

Instantly share code, notes, and snippets.

@kkxlkkxllb
Last active December 14, 2015 04:19
Show Gist options
  • Select an option

  • Save kkxlkkxllb/5027248 to your computer and use it in GitHub Desktop.

Select an option

Save kkxlkkxllb/5027248 to your computer and use it in GitHub Desktop.
content = "Meet Mr. Jon. Jon is a computer programmer and lives in Connecticut. Jon is tall. Shouldn't take web 2.0 as two sentences. And this is a new sentence. "
words = {}
content.gsub!(/(Mr)\.|(Mrs)\./,"\\1{dot}").split(/\. |\? |\! /).each_with_index do |sentences, index|
puts "\n#{index}: #{sentences}"
sentences.split(/ +/).each do |word|
word=word.gsub(/{dot}/,"\.").downcase
puts word
words[word]=words[word]||[0,[]]
words[word][0]+=1
words[word][1]<<index
end
end
@kkxlkkxllb
Copy link
Author

require 'scalpel'
class String
  def geo
        sentences = Scalpel.cut self
        sentences.collect{|x| x.scan(/[[:upper:]]\S+\s/)}.flatten.uniq.map{|x| x.strip!}
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment