Class: Poliqarp::Excerpt
- Inherits:
-
Object
- Object
- Poliqarp::Excerpt
- 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
-
#base_form ⇒ Object
readonly
Returns the value of attribute base_form.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#short_context ⇒ Object
readonly
Returns the value of attribute short_context.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Adds segment group to the excerpt.
-
#context ⇒ Object
Returns the long context of the query.
-
#initialize(index, client, base_form) ⇒ Excerpt
constructor
A new instance of Excerpt.
-
#left_context ⇒ Object
Returns the segments of the left short context of the match.
-
#matched ⇒ Object
Returns the matched segments.
-
#right_context ⇒ Object
Returns the segments of the right short context of the match.
-
#to_s ⇒ Object
The string representation of the excerpt is the shord context of the query.
-
#word ⇒ Object
(also: #inflected_form)
Returns the matched query as string.
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_form ⇒ Object (readonly)
Returns the value of attribute base_form.
14 15 16 |
# File 'lib/poliqarpr/excerpt.rb', line 14 def base_form @base_form end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
14 15 16 |
# File 'lib/poliqarpr/excerpt.rb', line 14 def index @index end |
#short_context ⇒ Object (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 |
#context ⇒ Object
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_context ⇒ Object
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 |
#matched ⇒ Object
Returns the matched segments
29 30 31 |
# File 'lib/poliqarpr/excerpt.rb', line 29 def matched @short_context[1] end |
#right_context ⇒ Object
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_s ⇒ Object
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 |
#word ⇒ Object 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 |