Class: Nickel::NLP

Inherits:
Object
  • Object
show all
Defined in:
lib/nickel/nlp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, date_time = Time.now) ⇒ NLP

Returns a new instance of NLP


14
15
16
17
18
19
20
# File 'lib/nickel/nlp.rb', line 14

def initialize(query, date_time = Time.now)
  str_time = date_time.strftime('%Y%m%dT%H%M%S')
  validate_input query, str_time
  @query = query.dup
  @input_date = ZDate.new str_time[0..7]   # up to T, note format is already verified
  @input_time = ZTime.new str_time[9..14]  # after T
end

Instance Attribute Details

#construct_finderObject (readonly)

Returns the value of attribute construct_finder


11
12
13
# File 'lib/nickel/nlp.rb', line 11

def construct_finder
  @construct_finder
end

#construct_interpreterObject (readonly)

Returns the value of attribute construct_interpreter


11
12
13
# File 'lib/nickel/nlp.rb', line 11

def construct_interpreter
  @construct_interpreter
end

#input_dateObject (readonly)

Returns the value of attribute input_date


10
11
12
# File 'lib/nickel/nlp.rb', line 10

def input_date
  @input_date
end

#input_timeObject (readonly)

Returns the value of attribute input_time


10
11
12
# File 'lib/nickel/nlp.rb', line 10

def input_time
  @input_time
end

#messageObject (readonly)

Returns the value of attribute message


12
13
14
# File 'lib/nickel/nlp.rb', line 12

def message
  @message
end

#nlp_queryObject (readonly)

Returns the value of attribute nlp_query


10
11
12
# File 'lib/nickel/nlp.rb', line 10

def nlp_query
  @nlp_query
end

#occurrencesObject (readonly)

Returns the value of attribute occurrences


12
13
14
# File 'lib/nickel/nlp.rb', line 12

def occurrences
  @occurrences
end

#queryObject (readonly)

Returns the value of attribute query


10
11
12
# File 'lib/nickel/nlp.rb', line 10

def query
  @query
end

Instance Method Details

#inspectObject


38
39
40
# File 'lib/nickel/nlp.rb', line 38

def inspect
  "message: \"#{message}\", occurrences: #{occurrences.inspect}"
end

#parseObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nickel/nlp.rb', line 22

def parse
  @nlp_query = NLPQuery.new(@query).standardize   # standardizes the query
  @construct_finder = ConstructFinder.new(@nlp_query, @input_date, @input_time)
  @construct_finder.run

  extract_message
  correct_case

  @construct_interpreter = ConstructInterpreter.new(@construct_finder.constructs, @input_date)  # input_date only needed for wrappers
  @construct_interpreter.run

  @occurrences = @construct_interpreter.occurrences.each { |occ| occ.finalize(@input_date) }   # finds start and end dates
  @occurrences.sort_by(&:start_date)
  @occurrences
end