1
0
Fork 0

Return positions

This commit is contained in:
Alex Kotov 2023-02-20 13:37:38 +04:00
parent 9c11d7b6f6
commit 6dc6f4435d
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 9 additions and 7 deletions

16
main.rb
View File

@ -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