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.
-
#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.
44 45 46 47 |
# File 'lib/poliqarpr/excerpt.rb', line 44 def context return @context unless @context.nil? @context = @client.context(@base_form, @index) end |
#to_s ⇒ Object
The string representation of the excerpt is the shord context of the query.
39 40 41 |
# File 'lib/poliqarpr/excerpt.rb', line 39 def to_s @short_context.join("") end |
#word ⇒ Object Also known as: inflected_form
Returns the matched query as string
30 31 32 33 |
# File 'lib/poliqarpr/excerpt.rb', line 30 def word #@short_context[0].split(/\s+/)[-1] @short_context[1].to_s end |