<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
    "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<!-- ** deplate dbk-article template          -->
<!--                                          -->
<!-- by phm at a2e de                         -->
<article lang="en">
<articleinfo>
    <pubdate>2009-03-07</pubdate>
    <title>Introducing dynamic variables into document templates</title>
    <subtitle>Accomodating a grey area between vocabulary and templates</subtitle>
    <author></author>
    <abstract>abstract Currently the document templates of the A2E multilingual hypertext system only process variables that have been fully rendered into strings and stored in DBM database files before template processing began.   While it is desirable to treat variables in this way for sake of speed, it is not always adequate.  There is a large gray area of vocabulary expansion that we want to happen outside of DBM files, using the latest values as they were set in the tempate itself.</abstract>
</articleinfo>
    <sect1 xreflabel="1" id="hd001" label="1">
        <title xreflabel="1" id="hd001_title">Situation</title>
        <anchor id="int" /><anchor id="file000" /><anchor id="file001" />
        <para>We needed a possibility to store unexpanded variables and expand them later only during document processing, even though this meant giving up a virtuous guiding principle of our document processing system.</para>
        <para>This is needed for two different reasons</para>
        <orderedlist>
            <listitem>
                <para>It does not make sense to store big expanded text chunks in the dbm database and in fact the SDBM_File package does not allow this at all, setting a severe limit of 1K</para>
            </listitem>
            <listitem>
                <para>Sometimes expansion must happen in the document, using variables that could have been (re)defined within the document</para>
            </listitem>
        </orderedlist>
        <para>We can now define the following normal dynamic variable in the template</para>
        <blockquote>
            <para>tslv2 = $(lnol|${tslv2_0}|${tslv2_1}|${tslv2_2}|${tslv2_3}|${tslv2_4})</para>
        </blockquote>
        <para>and expand it later in the template, using a vmethod <literal>expand</literal>, which expands recursively until there is no more expansion work to do, e.g.</para>
<screen>
<![CDATA[[* tslv2.expand *]]]>
</screen>
        <para>The <literal>expand</literal> vmethod does not even need to know which variables are dynamic.  It is up to the document template creator to decide whether the variable in question might need expansion.</para>
        <para>The <literal>expand</literal> vmethod was enriched further so as to become a full equivalent to the <ulink url="/adv/perl/A2E/Template/Plugin/Textbau.pm.html">tb filter</ulink> and thus make that filter superfluous.</para>
    </sect1>
    <sect1 xreflabel="2" id="hd002" label="2">
        <title xreflabel="2" id="hd002_title">Methods for operations on dynamic variables</title>
        <anchor id="mlht" />
        <para>Beside the simple <literal>expand</literal> method, we have a few more vmethods:</para>
        <variablelist>
            <varlistentry>
                <term>value</term>
                <listitem>
                <para>treat the argument as a variable name and return its value (simplified expansion)</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>expand</term>
                <listitem>
                <para>expand the argument as a mlht/maketext (vocabulary building language) expression</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>call</term>
                <listitem>
                <para>apply arguments</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>fill</term>
                <listitem>
                <para>apply arguments and interpret function calls</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>funcall</term>
                <listitem>
                <para>invoke a builtin function of the mlht/maketext language, with </para>
                </listitem>
            </varlistentry>
        </variablelist>
        <para>All of these vmethods are also available as filters.  A filter is slightly bulkier to use and to program, but has the advantage that it can be used not only on a variable but also directly on a string value.</para>
        <para>Below are some sample text blocks, based on <ulink url="@lng.dynaarbs090307.txt">definitions</ulink> which illustrate the use of these functions:</para>
        <informaltable frame="topbot">
            <tgroup cols="2">
            <colspec colname="c0" />
            <colspec colname="c1" />
            <thead>
                <row>
                    <entry>
                        <para>template source</para>
                    </entry>
                    <entry>
                        <para>compiled result</para>
                    </entry>
                </row>
            </thead>
            <tbody>
                <row>
                    <entry>
                        <para>var=‘tit’;var.value</para>
                    </entry>
                    <entry>
                        <para>Introducing dynamic variables into document templates</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>‘sut’ FILTER value</para>
                    </entry>
                    <entry>
                        <para>Accomodating a grey area between vocabulary and templates</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>titsut</para>
                    </entry>
                    <entry>
                        <para>${tit}: ${sut}</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>titsut.expand</para>
                    </entry>
                    <entry>
                        <para>Introducing dynamic variables into document templates: Accomodating a grey area between vocabulary and templates</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>‘[ title ] ${1}’ FILTER call(tit)</para>
                    </entry>
                    <entry>
                        <para>[ title ] Introducing dynamic variables into document templates</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>‘$(dt|title): ${1}’ FILTER fill(tit, ‘dt=:call:sqbrackets’)</para>
                    </entry>
                    <entry>
                        <para>[ title ]: Introducing dynamic variables into document templates</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>‘23’ FILTER funcall(‘dnumpad’, ‘6’)</para>
                    </entry>
                    <entry>
                        <para>００００２３</para>
                    </entry>
                </row>
            </tbody>
            </tgroup>
        </informaltable>
        <informaltable frame="topbot">
            <tgroup cols="1">
            <colspec colname="c0" />
            </tgroup>
        </informaltable>
    </sect1>
    <sect1 xreflabel="3" id="hd003" label="3">
        <title xreflabel="3" id="hd003_title">Document reference functions</title>
        <anchor id="dokfs" />
        <para>We have moreover added some functions that allow us to retrieve properties and text chunks from other documents.  We have used these to replace our menu generation system so that the menu is now entirely written using the Template toolkit.</para>
        <informaltable frame="topbot">
            <tgroup cols="2">
            <colspec colname="c0" />
            <colspec colname="c1" />
            <thead>
                <row>
                    <entry>
                        <para>template source</para>
                    </entry>
                    <entry>
                        <para>compiled result</para>
                    </entry>
                </row>
            </thead>
            <tbody>
                <row>
                    <entry>
                        <para>var = ‘perl_a2e_pub’;var.url</para>
                    </entry>
                    <entry>
                        <para>/adv/perl/A2E</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>‘perl_a2e_pub’ FILTER url</para>
                    </entry>
                    <entry>
                        <para>/adv/perl/A2E</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>dok.predoks.join(‘, ‘)</para>
                    </entry>
                    <entry>
                        <para>adv_pub, adv_pub09, adv_pub0903, adv_pub_int0903, rss090314</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>var = ‘adv_pub0903’;var.subdoks.join(‘, ‘)</para>
                    </entry>
                    <entry>
                        <para>adv_pub_int0903, adv_pub_ont0903</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>var = ‘adv_pub0903’;var.postdoks.join(‘, ‘)</para>
                    </entry>
                    <entry>
                        <para>adv_pub0904</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>dok.lab</para>
                    </entry>
                    <entry>
                        <para>Dynamics</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>dok.lab(‘en’)</para>
                    </entry>
                    <entry>
                        <para>Dynamics</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>dok.tit</para>
                    </entry>
                    <entry>
                        <para>Introducing dynamic variables into document templates</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>dok.tit(‘de’)</para>
                    </entry>
                    <entry>
                        <para>Einführung dynamischer Variablen in Dokumentvorlagen</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>dok.sut</para>
                    </entry>
                    <entry>
                        <para>Accomodating a grey area between vocabulary and templates</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>dok.sut(‘zh’)</para>
                    </entry>
                    <entry>
                        <para>文書與多語字串之間的灰色地带已從雙面填充</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>var = ‘a2e’;var.lab</para>
                    </entry>
                    <entry>
                        <para>a2e</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>var.lab(‘zh’)</para>
                    </entry>
                    <entry>
                        <para>亞通歐</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>var.des</para>
                    </entry>
                    <entry>
                        <para>We write, translate and program texts in languages of Asia and Europe, especially Chinese, Japanese, German and English, regarding current developments in semiotic systems and the realities to which they refer.</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>var.des(‘zh’)</para>
                    </entry>
                    <entry>
                        <para>我們在此用中、日、德、法、意、俄等語文編寫、翻譯、自動生成我們關心的領域的時事評論及背景分析文章，希望在此過程中開拓出一些使得這種多語文編寫工作得以更加輕便地進行的手法以及自由軟件。</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>var = ‘tit’;var.cit(‘adv_pub’)</para>
                    </entry>
                    <entry>
                        <para>ADP Advances at A2E</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>‘tit’ FILTER cit(‘adv_pub’)</para>
                    </entry>
                    <entry>
                        <para>ADP Advances at A2E</para>
                    </entry>
                </row>
                <row>
                    <entry>
                        <para>‘tit’ FILTER cit(‘adv_pub’, ‘zh’)</para>
                    </entry>
                    <entry>
                        <para>亞通歐多語數據處理</para>
                    </entry>
                </row>
            </tbody>
            </tgroup>
        </informaltable>
        <informaltable frame="topbot">
            <tgroup cols="1">
            <colspec colname="c0" />
            </tgroup>
        </informaltable>
        
        <sect2 xreflabel="3001" id="hd003001" label="1">
            <title xreflabel="3001" id="hd003001_title">Generating meta info about arbitrary documents</title>
            <anchor id="meta" />
            <para>Languages can be listed in order of preference, meaningful defaults are chosen.</para>
            <orderedlist>
                <listitem>
                    <para>dok: oas_pub</para>
                    <itemizedlist>
                        <listitem>
                            <para>url: /oas</para>
                        </listitem>
                        <listitem>
                            <para>tit: A2E Language Services</para>
                        </listitem>
                        <listitem>
                            <para>des: Authoritative and sophisticated translating, interpreting and multilingual computing services, involving languages of Asia and Europe, by an experienced team of geeks, operating from an office in the center of Munich.</para>
                        </listitem>
                        <listitem>
                            <para>lab: Services</para>
                        </listitem>
                        <listitem>
                            <para>meta sut: Chinese, Japanese, German, English et al</para>
                        </listitem>
                        <listitem>
                            <para>meta filter sut: Chinese, Japanese, German, English et al</para>
                        </listitem>
                    </itemizedlist>
                </listitem>
                <listitem>
                    <para>dok: eupat</para>
                    <itemizedlist>
                        <listitem>
                            <para>url: </para>
                        </listitem>
                        <listitem>
                            <para>tit: Patentability and Democracy in Europe</para>
                        </listitem>
                        <listitem>
                            <para>des: The European Patent Organisation (EPO) is continuing to grant thousands of monopolies on “computer-implemented” algorithms and business methods every year, against the letter and spirit of the written law, and is now, for the third time, pushing for European legislation that would impose this practise on reticent national courts.   Patent interests in combination with inter-governmental lawmaking have formed a caricature of “innovation policy” and thereby are helping us to see clearly what is going wrong in Europe today and what the alternatives are.</para>
                        </listitem>
                        <listitem>
                            <para>lab: EU Patent</para>
                        </listitem>
                        <listitem>
                            <para>meta sut: How can industrial property be subordinated to modern economic policy?</para>
                        </listitem>
                        <listitem>
                            <para>meta filter sut: How can industrial property be subordinated to modern economic policy?</para>
                        </listitem>
                    </itemizedlist>
                </listitem>
                <listitem>
                    <para>dok: apr_pub</para>
                    <itemizedlist>
                        <listitem>
                            <para>url: </para>
                        </listitem>
                        <listitem>
                            <para>tit: Freedom of Speech</para>
                        </listitem>
                        <listitem>
                            <para>des: Personality Rights, Privacy Rights and Copyright are being emphasised by courts at least here in Germany in a way that is detrimental to the Communication Society of the digital age</para>
                        </listitem>
                        <listitem>
                            <para>lab: Appeal</para>
                        </listitem>
                        <listitem>
                            <para>meta sut: Communication vs Privacy</para>
                        </listitem>
                        <listitem>
                            <para>meta filter sut: Communication vs Privacy</para>
                        </listitem>
                    </itemizedlist>
                </listitem>
            </orderedlist>
        </sect2>
        <sect2 xreflabel="3002" id="hd003002" label="2">
            <title xreflabel="3002" id="hd003002_title">Example: Table of Superordinate Documents of this Node</title>
            <anchor id="predoks" />
            <para>We see the language default choice algorithm at work here too.</para>
            <table xreflabel="3.1" id="tab003001" frame="topbot">
                <title>predoks</title>
                <tgroup cols="1">
                <colspec colname="c0" colwidth="100mm" align="left" />
                <tbody>
                    <row>
                        <entry>
                            <para><inlinemediaobject>
                                <imageobject>
                                    <imagedata fileref="/img/icons/text.png" width="20" />
                                </imageobject>
                            </inlinemediaobject> <ulink url="/adv">ADP: ADP Advances at A2E</ulink>: Not a Field of Technology: Automated Data Processing (ADP) on Asian and European texts —- tools, methods and support services.</para>
                        </entry>
                    </row>
                    <row>
                        <entry>
                            <para><inlinemediaobject>
                                <imageobject>
                                    <imagedata fileref="/img/icons/text.png" width="20" />
                                </imageobject>
                            </inlinemediaobject> <ulink url="/adv/09">2009: Datenverarbeitung 2009</ulink>: Notizen des Jahres: Erfahrungen beim Simultandolmetschen von Chinesisch, Japanisch, Englisch und Deutsch, Übersetzungen, Programmierung vielsprachiger Dokumentation und was das Jahr sonst noch brachte.</para>
                        </entry>
                    </row>
                    <row>
                        <entry>
                            <para><inlinemediaobject>
                                <imageobject>
                                    <imagedata fileref="/img/icons/text.png" width="20" />
                                </imageobject>
                            </inlinemediaobject> <ulink url="/adv/09/03">03: Thema</ulink>: Begriff und Anwendung: Hier sammeln und destillieren wir unsere Erkenntnisse zum Thema .</para>
                        </entry>
                    </row>
                    <row>
                        <entry>
                            <para><inlinemediaobject>
                                <imageobject>
                                    <imagedata fileref="/img/icons/text.png" width="20" />
                                </imageobject>
                            </inlinemediaobject> <ulink url="/adv/09/03/int">Was War: Data Processing im March 2009</ulink>: Verlauf des Monats: Was diesen Monat im Bereich Data Processing passierte.</para>
                        </entry>
                    </row>
                    <row>
                        <entry>
                            <para><inlinemediaobject>
                                <imageobject>
                                    <imagedata fileref="/img/icons/text.png" width="20" />
                                </imageobject>
                            </inlinemediaobject> <ulink url="/adv/09/03/rss14">Nachrichten: Einrichtung von RSS-Nachrichtenkanälen in A2E MLHT</ulink>: Wie wir die rechte Spalte jeder Webseite mit passenden Meldungen anreichern: Mittels mehr oder weniger detaillierter Angaben in der Konfigurationsdatei des Multilingualen Hypertextsystems (MLHT) und in Vokabulardateien können wir eine detaillierte Kontrolle über die Zusammensetzung der Nachrichtenkanäle ausüben oder uns mit einigermaßen sinnvollen Voreinstellungen zufrieden geben.</para>
                        </entry>
                    </row>
                </tbody>
                </tgroup>
            </table>
        </sect2>
    </sect1>
    <sect1 xreflabel="4" id="hd004" label="4">
        <title xreflabel="4" id="hd004_title">CAVEATS</title>
        <anchor id="cav" />
        <para>The filter <literal>cit</literal>, by loading the whole vocabulary of a quoted document into memory side by side with that of the current document, provides a great mechanism for commenting a source document.  This vocabulary includes the whole vocabulary of superior files and template used by that file.  Use with care, i.e. only for real quotations, on one or two source documents that you may want to comment on, not for substituting the proper vocabulary building mechanisms.  Otherwise our system could quickly lose its compactness and speed.</para>
    </sect1>
    <sect1 xreflabel="5" id="hd005" label="5">
        <title xreflabel="5" id="hd005_title">BUGS, LIMITATIONS</title>
        <anchor id="bug" />
        <para>Variables defined in the document do not thereby become available to the vmethods/filters.  The vmethods (e.g. call, fill, funcall) are aware only of the definitions made in the vocabulary file.  In the above examples, the verb ‘sqbrackets’ must be defined in the vocabulary file.</para>
    </sect1>
    <sect1 xreflabel="6" id="hd006" label="6">
        <title xreflabel="6" id="hd006_title">Resources</title>
        <anchor id="ah" />
        <itemizedlist>
            <listitem>
                <para><ulink url="/adv/perl/A2E">A2E Perl libraries</ulink></para>
            </listitem>
            <listitem>
                <para><ulink url="http://docs.huihoo.com/template-toolkit/Modules/Template/Manual/VMethods.html">perldoc Template::Manual:VMethods</ulink></para>
            </listitem>
            <listitem>
                <para><ulink url="http://docs.huihoo.com/template-toolkit/Modules/Template/Context.html">perldoc Template::Context</ulink></para>
            </listitem>
            <listitem>
                <para><ulink url="http://docs.huihoo.com/template-toolkit/Modules/Template/Filters.html">perldoc Template::Filters</ulink></para>
            </listitem>
            <listitem>
                <para><ulink url="/adv/tmpl/a2e/jpat/multemp/deplate_tmpl.txt">tmpl</ulink></para>
            </listitem>
            <listitem>
                <para><ulink url="/adv/prg/bin/nav_tmpl_repl.pl">nav_tmpl_repl</ulink>: script for conversion from old to new menu source format</para>
            </listitem>
            <listitem>
                <para><ulink url="/sig/oas/09/03/adv/jpat">Textbausteine für Patentübersetzungen</ulink></para>
            </listitem>
            <listitem>
                <para><ulink url="@dok.od_jpat0903.txt">Document Source</ulink></para>
            </listitem>
            <listitem>
                <para><ulink url="@lng.od_jpat0903.en.txt">Language-dependent text elements</ulink></para>
            </listitem>
        </itemizedlist>
    </sect1>
</article>

<!-- Local Variables: -->
<!-- coding: utf-8 -->
<!-- srcfile: /adv/mktdir/tmpl/multemp/a2e_dba_tmpl.txt -->
<!-- mode: xml -->
<!-- End: -->

