Module: Greeb::Core

Defined in:
lib/greeb/core.rb

Overview

Greeb::Core is a simple tool that allows to invoke Greeb::Tokenizer and Greeb::Parser facilities together in a convinient and coherent way.

Constant Summary collapse

HELPERS =

Greeb::Core uses several helpers from Greeb::Parser to perform additional analysis using there heuristic methods.

[:urls, :emails, :abbrevs, :time]

Instance Method Summary collapse

Instance Method Details

#analyze(text, helpers = HELPERS) ⇒ Array<Greeb::Span> Also known as: []

Recognize e-mail addresses in the input text.


19
20
21
22
23
24
25
26
27
# File 'lib/greeb/core.rb', line 19

def analyze(text, helpers = HELPERS)
  Greeb::Tokenizer.tokenize(text).tap do |tokens|
    helpers.each do |helper|
      Greeb::Parser.public_send(helper, text).each do |parsed|
        extract_spans(tokens, parsed)
      end
    end
  end
end

#extract_spans(spans, span) ⇒ Greeb::Span

Extact spans of the specified type from the input spans set.


38
39
40
41
42
43
# File 'lib/greeb/core.rb', line 38

def extract_spans(spans, span)
  from = spans.index { |e| e.from == span.from }
  to = spans.index { |e| e.to == span.to }
  return unless from && to
  spans[from..to] = span
end