Difference between revisions of "How to create a XHTML word list with a Toolbox export process"
(→Explanation of the code) |
(→Notes) |
||
Line 18: | Line 18: | ||
* However it is possible to open it in a spreadsheet program as well and thus add additional data; the file may be later merged back to the Toolbox database it came from. | * However it is possible to open it in a spreadsheet program as well and thus add additional data; the file may be later merged back to the Toolbox database it came from. | ||
+ | |||
+ | ==The complete code== | ||
<pre> | <pre> | ||
Line 279: | Line 281: | ||
endfile | endfile | ||
</pre> | </pre> | ||
− | |||
== Explantation of the consistent changes table == | == Explantation of the consistent changes table == |
Revision as of 07:57, 11 October 2012
The Toolbox program offers the feature to define various export processes.
The definition of an export process consists of
- a selection of fields
- a selection of records
- an optional transformation step written in the 'consistent changes' (cc) scripting language.
The cc scripting language is a domain specific language (DSL, more information).
Below there is a script for a "cct" (consistent changes table) to produce a word list in XHTML based on a Toolbox lexicon.
To use it copy and past the code into a text file (e.g. done with 'notepad') and then set up an export process. The description how to do it is in the comment.
Contents
Notes
- A line starting the letter 'c' indicates a comment.
- An XHTML file is primarily meant to be displayed in a web browser
- However it is possible to open it in a spreadsheet program as well and thus add additional data; the file may be later merged back to the Toolbox database it came from.
The complete code
C ======================================================================== C file name: genWordListInXHTMLtable.cct C based on: aswGenHTML.cct C C C converts a part of Toolbox lexicon database c c to an HTML table c c c Fields: c \lx (lexeme) c \hm (homonym number) c \ps (part of speech) c \ge (gloss English) c c to XHTML-Code c c c c c c Instructions: c put this file into the settings folder, the one within the Toolbox project folder. c c c To run the program the first time c choose "File export" c Choose "Add a new export process" c Choose "Standard Format" radio button c give a process name, e.g. WordListTableInHTML c and add this file as the changes table c c export the database file c c For subsequent execution do c choose "File export" c choose the process 'WordListTableInHTML' c c c c c Tamale, 4th October 2012 / Hannes Hirzel c c c Acknowledgement: c Karen Buseman reviewed the code and c provided suggestions to shorten it considerably. c c c c ------------------------------------------------------------------------------------------------------------------------------ c c http://opensource.org/licenses/mit-license.php c c c The MIT License (MIT) c c c c Copyright (c) 2012 Hannes Hirzel c c Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated c documentation files (the "Software"), to deal in the Software without restriction, including without limitation c the rights c to use, c copy, c modify, c merge, c publish, c distribute, c sublicense, c and/or sell copies of the Software, c c and to permit persons to whom the Software is furnished to do so, c c subject to the following conditions: c c The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. c c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c MERCHANTABILITY, c FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE c FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, c WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN c CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c c c ================================ =========================================================================================== c ---------------------------------------------------------- c write out complete HTML header including style information c ---------------------------------------------------------- begin > '<?xml version="1.0" encoding="UTF-8"?>' nl '<html xmlns="http://www.w3.org/1999/xhtml">' nl '<header>' nl '<script language="JavaScript" type="text/javascript">' nl ' function test(file, titleString)' nl ' {' nl " //" nl ' }' nl '</script>' nl ' ' nl '<link href="theStyleSheet.css" rel="stylesheet" type="text/css" />' nl ' ' nl ' ' nl '<!-- additional styles --> ' nl '<!-- delete the examples and replace them with what you want --> ' nl '<style type="text/css">' nl "td.LexiconEntry {padding-bottom: 2px; color: black; font-size: 14; " nl ' padding-left: 10px; padding-right: 10px; background-color="#C0FFCC";}' nl nl "td.note {padding-bottom: 2px; color: black; font-size: 11;" nl 'padding-left: 10px; padding-right: 10px; background-color="#A0FFA0";}' nl nl '</style>' nl '</header>' nl ' ' nl ' ' nl "<body>" nl '<h2>' 'Nkonya lexicon data' '</h2>' nl '<table>' nl c ------------------------------------------------------------- c define output procedures c c c The output procedure will be called for each entry. c It produces one HTML table row. c Currently the row has two cells. c ------------------------------------------------------------- define(output_LexiconEntry) > if(lxFlag) begin "<tr>" c tr = table row; HTML table row mark '<td class="LexiconEntry">' out(lx) "</td>" nl '<td class="hm">' out(hm) '</td>' nl '<td class="ps">' out(ps) '</ td>' nl '<td class="ge">' out(ge) '</t d>' nl '<td class="sd">' nl out(sd) "</t d>" nl "</tr>" c end HTML table row nl nl c two new line commands do(clear_stores) c call procedure 'clear_Flags' defined below. end c if(lxFlag) define(clear_stores) > store(lx) endstore store(hm) endstore store(ps) endstore store(ge) endstore store(sd) endstore c --------------------------------------------------------------------------------------- nl > "" c eliminate new lines '\lx ' > endstore c stop storing and output previous entry if(lxFlag) c only output if lx has been encountered before, do(output_LexiconEntry) c i.e. if we are not at the very first record end if c then store new entry store(lx) c 'lx ' is name of data store set(lxFlag) c set lxFlag so for that all subsequent occurenences of lx c there will be output. '\hm ' > store(hm) c hm (homonym number) data store '\ps ' > store(ps) c ps (part of speech) data store '\ge ' > store(ge) c ge (gloss English) data store '\' > store(away) c eliminate all other fields by storing them c in another store called 'away' which we will not use. c ============================================================================================================ c c Treatment of last record and output of final HTML code c c ============================================================================================================ endfile > endstore do(output_LexiconEntry) c output last entry. "</table>" nl c end of table "</body>" nl "</html>" endfile
Explantation of the consistent changes table
The code has four parts
- a comment section which describes the table
- a
begin
section which is executed once before the processing of the input file. - a main section (not labeled) which contains the processing rules.
- an
endfile
section which is executed after all the characters of the input file have been consumed.
Initial comment section
C ======================================================================== C file name: genWordListInXHTMLtable.cct C based on: aswGenHTML.cct C C C converts a part of Toolbox lexicon database c c to an HTML table c c c Fields: c \lx (lexeme) c \hm (homonym number) c \ps (part of speech) c \ge (gloss English) c c to XHTML-Code c c c c c c Instructions: c put this file into the settings folder, the one within the Toolbox project folder. c c c To run the program the first time c choose "File export" c Choose "Add a new export process" c Choose "Standard Format" radio button c give a process name, e.g. WordListTableInHTML c and add this file as the changes table c c export the database file c c For subsequent execution do c choose "File export" c choose the process 'WordListTableInHTML' c c c c c Tamale, 4th October 2012 / Hannes Hirzel c c c Acknowledgement: c Karen Buseman reviewed the code and c provided suggestions to shorten it considerably. c c c c ------------------------------------------------------------------------------------------------------------------------------ c c http://opensource.org/licenses/mit-license.php c c c The MIT License (MIT) c c c c Copyright (c) 2012 Hannes Hirzel c c Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated c documentation files (the "Software"), to deal in the Software without restriction, including without limitation c the rights c to use, c copy, c modify, c merge, c publish, c distribute, c sublicense, c and/or sell copies of the Software, c c and to permit persons to whom the Software is furnished to do so, c c subject to the following conditions: c c The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. c c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c MERCHANTABILITY, c FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE c FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, c WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN c CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c c c ================================ ===========================================================================================
Begin section
c ---------------------------------------------------------- c write out complete HTML header including style information c ---------------------------------------------------------- begin > '<?xml version="1.0" encoding="UTF-8"?>' nl '<html xmlns="http://www.w3.org/1999/xhtml">' nl '<header>' nl '<script language="JavaScript" type="text/javascript">' nl ' function test(file, titleString)' nl ' {' nl " //" nl ' }' nl '</script>' nl ' ' nl '<link href="theStyleSheet.css" rel="stylesheet" type="text/css" />' nl ' ' nl ' ' nl '<!-- additional styles --> ' nl '<!-- delete the examples and replace them with what you want --> ' nl '<style type="text/css">' nl "td.LexiconEntry {padding-bottom: 2px; color: black; font-size: 14; " nl ' padding-left: 10px; padding-right: 10px; background-color="#C0FFCC";}' nl nl "td.note {padding-bottom: 2px; color: black; font-size: 11;" nl 'padding-left: 10px; padding-right: 10px; background-color="#A0FFA0";}' nl nl '</style>' nl '</header>' nl ' ' nl ' ' nl "<body>" nl '<h2>' 'Nkonya lexicon data' '</h2>' nl '<table>' nl c ------------------------------------------------------------- c define output procedures c c c The output procedure will be called for each entry. c It produces one HTML table row. c Currently the row has two cells. c ------------------------------------------------------------- define(output_LexiconEntry) > if(lxFlag) begin "<tr>" c tr = table row; HTML table row mark '<td class="LexiconEntry">' out(lx) "</td>" nl '<td class="hm">' out(hm) '</td>' nl '<td class="ps">' out(ps) '</ td>' nl '<td class="ge">' out(ge) '</t d>' nl '<td class="sd">' nl out(sd) "</t d>" nl "</tr>" c end HTML table row nl nl c two new line commands do(clear_stores) c call procedure 'clear_Flags' defined below. end c if(lxFlag) define(clear_stores) > store(lx) endstore store(hm) endstore store(ps) endstore store(ge) endstore store(sd) endstore
Main section
c --------------------------------------------------------------------------------------- nl > "" c eliminate new lines '\lx ' > endstore c stop storing and output previous entry if(lxFlag) c only output if lx has been encountered before, do(output_LexiconEntry) c i.e. if we are not at the very first record end if c then store new entry store(lx) c 'lx ' is name of data store set(lxFlag) c set lxFlag so for that all subsequent occurenences of lx c there will be output. '\hm ' > store(hm) c hm (homonym number) data store '\ps ' > store(ps) c ps (part of speech) data store '\ge ' > store(ge) c ge (gloss English) data store '\' > store(away) c eliminate all other fields by storing them c in another store called 'away' which we will not use.
Endfile section
c ============================================================================================================ c c Treatment of last record and output of final HTML code c c ============================================================================================================ endfile > endstore do(output_LexiconEntry) c output last entry. "</table>" nl c end of table "</body>" nl "</html>" endfile