Abbreviations, easy: Difference between revisions

Added 11l
(Added 11l)
Line 84:
{{Template:Strings}}
<br><br>
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>V command_table_text =
|‘Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput
Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO
MErge MODify MOve MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT
READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT
RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up’
 
V user_words = ‘riG rePEAT copies put mo rest types fup. 6 poweRin’
 
F find_abbreviations_length(command_table_text)
‘ find the minimal abbreviation length for each word by counting capital letters.
a word that does not have capital letters gets it's full length as the minimum.
[String = Int] command_table
L(word) command_table_text.split((‘ ’, "\n"), group_delimiters' 1B)
V abbr_len = sum(word.filter(c -> c.is_uppercase()).map(c -> 1))
I abbr_len == 0
abbr_len = word.len
command_table[word] = abbr_len
R command_table
 
F find_abbreviations(command_table)
‘ for each command insert all possible abbreviations’
[String = String] abbreviations
L(command, min_abbr_len) command_table
L(l) min_abbr_len .. command.len
V abbr = command[0 .< l].lowercase()
abbreviations[abbr] = command.uppercase()
R abbreviations
 
F parse_user_string(user_string, abbreviations)
V user_words = user_string.split(‘ ’, group_delimiters' 1B).map(word -> word.lowercase())
V commands = user_words.map(user_word -> @abbreviations.get(user_word, ‘*error*’))
R commands.join(‘ ’)
 
V command_table = find_abbreviations_length(command_table_text)
V abbreviations_table = find_abbreviations(command_table)
 
V full_words = parse_user_string(user_words, abbreviations_table)
 
print(‘user words: ’user_words)
print(‘full words: ’full_words)</lang>
 
{{out}}
<pre>
user words: riG rePEAT copies put mo rest types fup. 6 poweRin
full words: RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT
</pre>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 534 ⟶ 588:
pi@debian-buster-64:~/asm64/rosetta/asm9 $
</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
1,480

edits