View Single Post
Old 12-26-2010, 07:09 AM   #101
chaley
"chaley", not "charley"
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 7,779
Karma: 2046464
Join Date: Jan 2010
Location: France
Device: Many android devices
Example of use of the new language

As an example and a test of the new language, I have implemented the last recipe in the first post in the new template language. Results are under the spoiler.

In the process I 'improved' the language a bit. The possibility to add comments, the 'program:' keyword, use of '=' for assignment, and the print function will be available in the next release (0.7.36)

Metadata: Put series into the title, using either initials or a shortened form. Strip leading articles from the series name (any) (inspired by Gary_M_Mugford)

Spoiler:
The following program produces the same results as the original recipe, using only one custom column to hold the results of a program that computes the special title value.
Code:
Custom column: 
Name: #special_title
Template: (the following up to but not including the -- END TEMPLATE -- line)
program:
#	compute the equivalent of the composite fields and store them in local variables
stripped = re(field('series'), '^(A|The|An)\s+', '');
shortened = shorten(stripped, 4, '-' ,4);
initials = re(stripped, '[^\w]*(\w?)[^\s]+(\s|$)', '\1');

#	Format the series index. Ends up as empty if there is no series index.
#	Note that leading and trailing spaces will be removed by the formatter,
# 	so we cannot add them here. We will do that in the strcat below.
#	Also note that because we are in 'program' mode, we can freely use
#	curly brackets in strings, something we cannot do in template mode.
s_index = template('{series_index:0>2.0f}');

#	print(stripped, shortened, initials, s_index);

#	Now concatenate all the bits together. The switch picks between 
# 	initials and shortened, depending on whether there is a space
#	in stripped. You can check for more than one space by changing
#	the value in {}. We then add the brackets around s_index if it is
#	not empty. Finally, add the title. As this is the last function in
# 	the program, its value will be returned.
strcat(
    switch(	stripped, 
            '(.+\s+){1}.+', initials, 
            '.', shortened,
            field('series')),
    test(s_index, strcat(' [', s_index, '] '), ''),
    field('title'));
-- END TEMPLATE --

Plugboard expression:
Template:{#special_title}
Destination field: title
It would be possible to do the above with no custom columns by putting the program into the template box of the plugboard. However, to do so, all comments must be removed because the plugboard text box does not support multi-line editing. It is debatable whether the gain of not having the custom column is worth the vast increase in difficulty caused by the program being one giant line.

Last edited by chaley; 01-11-2016 at 07:04 AM.
chaley is offline   Reply With Quote