When I see some of my command use keywords as arguments, I realized I might be able to make a word search command as part of error message.
I’m not using remove_duplicates command here as that is bugged, so I had to write my own.
#@cli rep_rm_dup
#@cli : Remove duplicates images
rep_rm_dup:
e[^-1] "Remove duplicates images in selected list of image$?."
p=0
do {
q,not_removed={$p+1},1
do {
if [w#$p,h#$p,d#$p,s#$p]!=[w#$q,h#$q,d#$q,s#$q]
q+=1
continue
fi
+neq[$p,$q]
if !iM#-1
rm[$q,-1]
not_removed=0
else
rm[-1]
fi
q+=1
} while $q<$!
if $not_removed
p+=1
fi
} while $p<($!-1)
#@cli rep_sug_arg: inp,arg0,arg1,...
#@cli : Suggest arguments given input.
#@cli : Returns 1 if any match. Returns 0 if no close match is found. Returns suggestion when close matches are found.
rep_sug_arg:
# Set up variables
$=vars
input1,input2:=$!+[0,1]
# Input as image
('$vars1')
p=2
# Word to search from as images
repeat $#-1 {
('${vars$p}')
p+=1
}
# Remove Duplicates
rep_rm_dup[$input2--1]
# Initialize variable to loop toward words and to put in score
words_to_search={$!-$input2}
eval "
const p=$input1;
q=$input2;
base_stats=[w#p,h#p,d#p,s#p];
found=0;
repeat($words_to_search,
if(same(base_stats,[w#q,h#q,d#q,s#q]),
if(same(crop(#p),crop(#q,0,0,0,0,w#p,h#p,d#p,s#p)),
found=1;
break();
);
);
++q;
);
found;
"
if ${}
rm[$input1--1]
u 1
return
fi
# Hold image indices and score
$words_to_search,1,1,2,[x,0]
# Scores per images
repeat w {
set[-1] ${-_$0_score[$input1,$input2]},$>,0,0,1
input2+=1
}
# Collect suggested matches with score<=2
100%
eval. >begin(p=0;);F=i[#-2,w+x];F==1||F==2?i[#-1,p++]=i[#-2,x];I;end(set('\{\}',p);)
rm..
if !${}
rm[$input1--1]
u 0
return
fi
K={crop(#-1,0,${})}
l[{$input1+1}--1] {
k[$K]
foreach {
suggest.=$sep\"{t}\"
sep=,
}
rm
}
# Output result into status
rm.
u $suggest
_rep_sug_arg_score:
check $!==2
{[whd#0,whd#1]+1},1,1,!y?x:!x?y
{[w,h]-1},1,1,>"
X=x+1;
Y=y+1;
cost=!(i[#0,X-1]==i[#1,Y-1]);
i(#2,X,Y)=min(i(#2,X-1,Y)+1,i(#2,X,Y-1)+1,i(#2,X-1,Y-1)+cost);
i;
"
u {i[#-2,whd#-2-1]} rm[-2,-1]
Example of use:
C:\Windows\System32>gmic e ${rep_sug_arg\ automobble,automobile,autocars,automobit,automatic}
[gmic]./ Start G'MIC interpreter (v.3.7.0).
"automobile"
[gmic]./ End G'MIC interpreter.
C:\Windows\System32>gmic e ${rep_sug_arg\ hel,hell,hello,help,yell,bike}
[gmic]./ Start G'MIC interpreter (v.3.7.0).
"hell","hello","help","yell"
[gmic]./ End G'MIC interpreter.