Class: Poliqarp::Excerpt

Inherits:
Object
  • Object
show all
Defined in:
lib/poliqarpr/excerpt.rb

Overview

Author

Aleksander Pohl

License

MIT License

The excerpt class is used to store single result of the query, i.e. the excerpt of the corpus which contains the words which the corpus was queried for.

The excerpt is divided into groups, which contain segments, which the texts in the corpus were divided for. The first group is the left context, the second – the matched query, and the last – the right context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, client, base_form) ⇒ Excerpt

Returns a new instance of Excerpt.



16
17
18
19
20
21
# File 'lib/poliqarpr/excerpt.rb', line 16

def initialize(index, client, base_form)
  @index = index
  @client = client
  @base_form = base_form
  @short_context = []
end

Instance Attribute Details

#base_formObject (readonly)

Returns the value of attribute base_form.



14
15
16
# File 'lib/poliqarpr/excerpt.rb', line 14

def base_form
  @base_form
end

#indexObject (readonly)

Returns the value of attribute index.



14
15
16
# File 'lib/poliqarpr/excerpt.rb', line 14

def index
  @index
end

#short_contextObject (readonly)

Returns the value of attribute short_context.



14
15
16
# File 'lib/poliqarpr/excerpt.rb', line 14

def short_context
  @short_context
end

Instance Method Details

#<<(value) ⇒ Object

Adds segment group to the excerpt



24
25
26
# File 'lib/poliqarpr/excerpt.rb', line 24

def <<(value)
  @short_context << value
end

#contextObject

Returns the long context of the query.



58
59
60
61
# File 'lib/poliqarpr/excerpt.rb', line 58

def context
  return @context unless @context.nil?
  @context = @client.context(@base_form, @index)
end

#left_contextObject

Returns the segments of the left short context of the match



34
35
36
# File 'lib/poliqarpr/excerpt.rb', line 34

def left_context
  @short_context[0]
end

#matchedObject

Returns the matched segments



29
30
31
# File 'lib/poliqarpr/excerpt.rb', line 29

def matched
  @short_context[1]
end

#right_contextObject

Returns the segments of the right short context of the match



39
40
41
# File 'lib/poliqarpr/excerpt.rb', line 39

def right_context
  @short_context[2]
end

#to_sObject

The string representation of the excerpt is the shord context of the query.



53
54
55
# File 'lib/poliqarpr/excerpt.rb', line 53

def to_s
  @short_context.join("")
end

#wordObject Also known as: inflected_form

Returns the matched query as string



44
45
46
47
# File 'lib/poliqarpr/excerpt.rb', line 44

def word
  #@short_context[0].split(/\s+/)[-1]
  @short_context[1].map{|s| s.to_s}.join("")
end