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: 5,449
Karma: 831552
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 with all leading spaces removed)
        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. 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', initials, 
                        '.', shortened,
                        field('series')),
                test(s_index, strcat(' [', s_index, '] '), ''),
                field('title'));

    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.
chaley is offline   Reply With Quote