Return positions
This commit is contained in:
parent
9c11d7b6f6
commit
6dc6f4435d
16
main.rb
16
main.rb
|
@ -168,18 +168,16 @@ public
|
|||
end.freeze
|
||||
end
|
||||
|
||||
##
|
||||
# @return [Array<Array(String, String, Array<Integer>)>]
|
||||
#
|
||||
def examples(word_id)
|
||||
word_id = Integer word_id
|
||||
|
||||
result = @db_conn.exec_params(
|
||||
@db_conn.exec_params(
|
||||
(
|
||||
<<~SQL
|
||||
SELECT
|
||||
array_agg(foo.value ORDER BY foo.language_id DESC)::text[]
|
||||
AS values,
|
||||
array_agg(word_forms.len) AS lens,
|
||||
array_agg(word_form_example_texts.pos) AS positions
|
||||
FROM example_texts foo
|
||||
LEFT JOIN word_form_example_texts
|
||||
|
@ -217,8 +215,12 @@ public
|
|||
SQL
|
||||
),
|
||||
[word_id],
|
||||
).map { |row| [*row['values'], row['positions'].compact.freeze] }
|
||||
|
||||
result.map { |pair| pair.map(&:freeze).freeze }.freeze
|
||||
).map do |row|
|
||||
{
|
||||
values: row['values'].map(&:freeze).freeze,
|
||||
length: row['lens'].compact.first,
|
||||
positions: row['positions'].compact.freeze,
|
||||
}.freeze
|
||||
end.freeze
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue