Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Sentence < Object
- def initialize( words, entry )
- super()
- #
- # Adjust punctuation
- #
- words.gsub!(/(,)(?!")/,'\1 ')
- #words.gsub!(/"(\s*([^"]*?)\s*)"/,'“\1”')
- words.gsub!(/\(\s*([^\)]*?)\s*\)/,'(\1)')
- #
- # Split everything up
- #
- @bits = words.split(/\s+/);
- if @bits == nil
- @bits = []
- end
- @word_count = @bits.length
- #
- # Does it contain the entry?
- #
- @word_index = []
- for i in 0...@word_count
- if /(^|(.*?[^a-z]+))(#{entry})(?![a-z0-9])/i.match(@bits[i])
- @word_index.push(i)
- end
- end
- end
Add Comment
Please, Sign In to add comment