implement randomly collect sentences from files

This commit is contained in:
konomo 2022-09-18 14:03:08 +00:00
parent a20c845005
commit 40ec084c6a
2 changed files with 26 additions and 4 deletions

View File

@ -8,10 +8,10 @@ made after seeing [https://asteine8.github.io/projects/pronoun-dressing-room/dre
copy it into your gemini directory and make it executable of course
## TODO
* randomly collect sentences from files [opened: 2022-03-14T16:45:30Z]
* [ ] add a lot of sentences
* [ ] make the program select a random selection (like 3 or 4 of them)
* [ ] make that optional
* randomly collect sentences from files [opened: 2022-03-14T16:45:30Z; closed: 2022-09-18T14:02:00Z]
* [X] add a lot of sentences
* [X] make the program select a random selection (like 3 or 4 of them)
* [X] make that optional
* more flexibility [opened: 2022-05-30T14:14:00Z; closed: 2022-05-31T13:13:30Z]
* [X] add another file for pronouns instead of having them hardcoded.
@ -36,3 +36,4 @@ copy it into your gemini directory and make it executable of course
* 2022-09-18: provide link to repository
* 2022-09-18: unhardcode plural grammar
* 2022-09-18: fix orthographic mistakes
* 2022-09-18: implement randomly collect sentences from files

View File

@ -2,6 +2,9 @@
_link="https://tildegit.org/konomo/gem-pd"
readonly _link
_runthru=1 # whether or not a random selection of sentences should be taken
readonly _runthru
_sentences=6 # how many sentences are displayed
if [[ -z "$QUERY_STRING" ]]; then
printf "10 Please enter your name. You may add ; and your preferred pronoun\r\n"
@ -24,6 +27,24 @@ printf "# Pronoun Dressing Room for %s" "$name"
while read sentence; do
sentences+=("${sentence}"); done < sentences
if [[ "${_runthru}" -eq 1 ]]; then
prevs=()
sentarr=()
for (( i = 0; i < ${_sentences}; i++ )); do
while
ran=$(( RANDOM % ${_sentences} + 0))
[[ "${prevs[@]}" =~ "${ran}" ]] # generate new random numbers until it isn't already in array
do true; done
prevs+=(${ran})
sentarr+=("${sentences[${ran}]}")
done
prevs=() # prevs is no longer needed
sentences=() # empty original array
sentences=("${sentarr[@]}")
fi
pr_sub=( $(tail -n +2 pronouns.csv | cut -d ',' -f1) )
pr_obj=( $(tail -n +2 pronouns.csv | cut -d ',' -f2) )
pr_psd=( $(tail -n +2 pronouns.csv | cut -d ',' -f3) )