Class: NLPBackpack::Chunker::RegexChunker
- Inherits:
-
Object
- Object
- NLPBackpack::Chunker::RegexChunker
- Defined in:
- lib/nlp_backpack/chunker/regex_chunker.rb
Instance Method Summary collapse
-
#initialize(pattern) ⇒ RegexChunker
constructor
A new instance of RegexChunker.
-
#match(pos_array) ⇒ Object
Extract all matches.
Constructor Details
#initialize(pattern) ⇒ RegexChunker
Returns a new instance of RegexChunker.
15 16 17 18 19 20 21 22 23 |
# File 'lib/nlp_backpack/chunker/regex_chunker.rb', line 15 def initialize(pattern) @pattern = prepare_pattern(pattern) @cached_pattern = @pattern.clone @cached_pattern.freeze @matched_patterns = [] @potential_pattern = [] end |
Instance Method Details
#match(pos_array) ⇒ Object
Extract all matches
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nlp_backpack/chunker/regex_chunker.rb', line 26 def match(pos_array) next_pattern(:start) pos_array.each do |word| begin pos = word[1] if pos.match(@current_pattern.tag) @potential_pattern << word[0] next_pattern(:matched) else next_pattern(:no_match) end rescue Retry retry end end pop_potential_pattern! @matched_patterns.map {|pattern| pattern.join(" ") } end |