Store and reuse questions.
A question file is a small recipe. decide holds the question. true and false say what yes and no mean. threshold sets the band 0.2:0.8. An answer of 0.8 or more is yes, and an answer under 0.2 is no. on picks the title and the album from each record. The request sends only those two fields.
Here a band plays only songs the Beatles wrote. The file asks whether a Beatle wrote a song. decide @original.json runs the recipe on one song.
The numbers come from the bench's songwriter list.
{
"decide": "Did a Beatle write this song?",
"true": "John, Paul, George, or Ringo wrote it.",
"false": "Someone else wrote it. It is a cover.",
"threshold": "0.2:0.8",
"on": ["/title", "/album"]
}Run it
decide prints true for Something and exits 0.printf '%s\n' '{"title":"Something","album":"Abbey Road"}' |
thinkthen decide @original.json
code=$?
echo "exit $code"true exit 0
The lesson
George Harrison wrote Something. The answer is right. The exit code carries the answer too: 0 for yes, 1 for no, and 3 for not sure. The next page puts that code to work in a script.
Write the question once in a file, and every run asks it the same way.
On GitHub: github.com/botassembly/beatles-bench