{"ok": true, "database": "scotrail", "query_name": "assemble_sentence", "rows": [["Combined sentence:", "I am sorry to announce that the ScotRail service from Bath Spa is delayed due to A wartime bomb near the railway", -1], ["https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0031.mp3", "I am sorry to announce that the", 0], ["https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0032.mp3", "ScotRail", 1], ["https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/1778.mp3", "service from", 2], ["https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0006.mp3", "Bath Spa", 3], ["https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/1750.mp3", "is delayed", 4], ["https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/1528.mp3", "due to", 5], ["https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0946.mp3", "A wartime bomb near the railway", 6]], "truncated": false, "columns": ["mp3", "Transcription", "key"], "query": {"sql": "with phrases as (\n  select\n    key, value\n  from\n    json_each('[\"' || replace(:terms, ',', '\",\"') || '\"]')\n),\nmatches as (select\n  phrases.key,\n  phrases.value,\n  (\n    select File from announcements\n    where announcements.Transcription like '%' || trim(phrases.value) || '%'\n    order by length(announcements.Transcription)\n    limit 1\n  ) as File\nfrom\n  phrases\n),\nresults as (\n  select key, announcements.Transcription, announcements.mp3\n  from announcements join matches on announcements.File = matches.File\n  order by key\n)\nselect\n  'Combined sentence:' as mp3,\n  group_concat(Transcription, ' ') as Transcription,\n  -1 as key\nfrom results\n  union\nselect\n  mp3, Transcription, key\nfrom results\norder by key", "params": {"terms": "i am sorry, scotrail, from, bath spa, is delayed, due to, bomb"}}, "error": null, "private": false, "allow_execute_sql": true, "query_ms": 8.872887999928025, "source": "matteason/scotrail-announcements-june-2022", "source_url": "https://github.com/matteason/scotrail-announcements-june-2022"}