Sha256: 1e764a0a58e1df10bad3b17da9c78a77c9fec59c28827d6616fca8be406e4adc

Contents?: true

Size: 637 Bytes

Versions: 1

Compression:

Stored size: 637 Bytes

Contents

# encoding: UTF-8
require 'textquery'

class TextNlp
  class Pattern
        
    def initialize(pattern, options = {})
      options = {:normalize => true}.merge(options)
      if options[:normalize]
        normalize_pattern(pattern) 
        @to_normalize = true
      end
      @text_query = TextQuery.new(pattern, {:ignorecase => options[:normalize]})
    end
      
    def match?(text)
      text.normalize! if @to_normalize
      @text_query.match?(text)
    end
    
    private
    def normalize_pattern(pattern)
      pattern.tr!("éèàçîêô","eeacieo")
      pattern.tr!("!,;?./\\_|[]{}<>:*$%"," ")
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
text_nlp-0.0.3 lib/text_nlp/pattern.rb