|
1 现状
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.
This is needed for two different reasons
-
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
-
Sometimes expansion must happen in the document, using variables that could have been (re)defined within the document
We can now define the following normal dynamic variable in the template
tslv2 = $(lnol|${tslv2_0}|${tslv2_1}|${tslv2_2}|${tslv2_3}|${tslv2_4})
and expand it later in the template, using a vmethod expand , which expands recursively until there is no more expansion work to do, e.g.
[* tslv2.expand *]
The expand 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.
The expand vmethod was enriched further so as to become a full equivalent to the tb filter and thus make that filter superfluous.
2 Methods for operations on dynamic variables
Beside the simple expand method, we have a few more vmethods:
- value
-
treat the argument as a variable name and return its value (simplified expansion)
- expand
-
expand the argument as a mlht/maketext (vocabulary building language) expression
- call
-
apply arguments
- fill
-
apply arguments and interpret function calls
- funcall
-
invoke a builtin function of the mlht/maketext language, with
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.
Below are some sample text blocks, based on definitions which illustrate the use of these functions:
template source |
compiled result |
var=‘tit’;var.value |
将动态变量在文书模板中使用 |
‘sut’ FILTER value |
文书与多语字串之间的灰色地带已从双面填充 |
titsut |
${tit}: ${sut} |
titsut.expand |
将动态变量在文书模板中使用: 文书与多语字串之间的灰色地带已从双面填充 |
‘[ title ] ${1}’ FILTER call(tit) |
[ title ] 将动态变量在文书模板中使用 |
‘$(dt|title): ${1}’ FILTER fill(tit, ‘dt=:call:sqbrackets’) |
[ title ]: 将动态变量在文书模板中使用 |
‘23’ FILTER funcall(‘dnumpad’, ‘6’) |
000023 |
3 Document reference functions
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.
template source |
compiled result |
var = ‘perl_a2e_pub’;var.url |
/adv/perl/A2E |
‘perl_a2e_pub’ FILTER url |
/adv/perl/A2E |
dok.predoks.join(‘, ‘) |
adv_pub, adv_pub09, adv_pub0903, adv_pub_int0903, rss090314 |
var = ‘adv_pub0903’;var.subdoks.join(‘, ‘) |
adv_pub_int0903, adv_pub_ont0903 |
var = ‘adv_pub0903’;var.postdoks.join(‘, ‘) |
adv_pub0904 |
dok.lab |
动态 |
dok.lab(‘en’) |
Dynamics |
dok.tit |
将动态变量在文书模板中使用 |
dok.tit(‘de’) |
Einführung dynamischer Variablen in Dokumentvorlagen |
dok.sut |
文书与多语字串之间的灰色地带已从双面填充 |
dok.sut(‘zh’) |
文书与多语字串之间的灰色地带已从双面填充 |
var = ‘a2e’;var.lab |
亚通欧 |
var.lab(‘de’) |
a2e |
var.des |
我们在此用中、日、德、法、意、俄等语文编写、翻译、自动生成我们关心的领域的时事评论及背景分析文章,希望在此过程中开拓出一些使得这种多语文编写工作得以更加轻便地进行的手法以及自由软件。 |
var.des(‘de’) |
Wir schreiben, übersetzen und programmieren hier Texte in Sprachen Asiens und Europas, insbesondere Chinesisch, Japanisch, Deutsch und Englisch über aktuelle Entwicklungen in einigen Zeichensystemen und in den Realitäten, die damit bezeichnet werden. |
var = ‘tit’;var.cit(‘adv_pub’) |
亚通欧多语数据处理 |
‘tit’ FILTER cit(‘adv_pub’) |
亚通欧多语数据处理 |
‘tit’ FILTER cit(‘adv_pub’, ‘de’) |
Automatische Datenverarbeitung |
3.1 Generating meta info about arbitrary documents
Languages can be listed in order of preference, meaningful defaults are chosen.
-
dok: oas_pub
-
url: /oas
-
tit: 亚通欧语言信息事业
-
des: 在德国慕尼黑市中心提供中、日、英、德及其他语种翻译公证件,会场同声传译,信息系统多语化等服务的事务所
-
lab: 翻译
-
meta sut: Chinese, Japanese, German, English et al
-
meta filter sut: Chinese, Japanese, German, English et al
-
dok: eupat
-
url:
-
tit: Patentability and Democracy in Europe
-
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.
-
lab: EU Patent
-
meta sut: How can industrial property be subordinated to modern economic policy?
-
meta filter sut: How can industrial property be subordinated to modern economic policy?
-
dok: apr_pub
-
url:
-
tit: Mimosenschutz verdrängt Meinungsfreiheit
-
des: In Deutschland werden ehrliche Kritiker regelmäßig mit ruinösen Klagen mundtot gemacht. Das im Internet neu erwachte politische Engagement der Bürger wird gedämpft, das produktive Potential der neuen Kommunikationsformen eingeschnürt. Die Einschränkungen der Äußerungsfreiheit sind weit umfassender und repressiver als einer demokratischen Gesellschaft zuträglich sein kann. Deutschland verletzt systematisch Artikel 10 der Europäischen Menschenrechtskonvention. Der Bundestag ist gefordert.
-
lab: Aufruf
-
meta sut: Communication vs Privacy
-
meta filter sut: Communication vs Privacy
3.2 Example: Table of Superordinate Documents of this Node
We see the language default choice algorithm at work here too.
4 CAVEATS
The filter cit , 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.
5 BUGS, LIMITATIONS
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.
6 资源
|