Typecraft v2.5
Jump to: navigation, search

How to create a XHTML word list with a Toolbox export process

Revision as of 12:42, 11 October 2012 by Hannes Hirzel (Talk | contribs) (Begin section)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 (see below) 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.

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 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 a XHTML 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 In Toolbox 
 c    choose menu "File" / "export"
 c    choose "Add a new export process"
 c    click "Standard Format" button
 c    give a process name, e.g. WordListTableInXHTML
 c    and add this file as the changes table
 c
 c    export the database file
 c
 c
 c For subsequent execution do
 c     choose "File export"
 c     select the process 'WordListTableInXHTML'
 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   c XML header
 			'<html xmlns="http://www.w3.org/1999/xhtml">'           nl   c root element -- HTML with name space declaration
                        '<header>'                                              nl   c start of HTML header
                        '<script language="JavaScript" type="text/javascript">' nl   c dummy JavaScript area; replace with your code
                        ' function test(file, titleString)'                     nl
                        '   {'                                                  nl
                        '     //'                                               nl
                        '   }'                                                  nl
                        '</script>'                                             nl
                        ' '
                                                                                nl
           '<link href="theStyleSheet.css" rel="stylesheet" type="text/css" />' nl   c link to a CSS style sheet / fill in your css name 
           ' ' 
                                                                                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   c end of HTML header 
       ' ' 
                                                                                nl
       ' '
                                                                                nl
       '<body>'                                                                 nl   c start of HTML body
       '<h2>'
       'Nkonya lexicon data'                                                         c title, replace with your title.
       '</h2>'                                                                  nl


       '<table>'                                                                nl   c start of lexical data / table form





 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 code (consistent changes table)

The code has four parts

  1. a comment section which describes the table
  2. a begin section which is executed once before the processing of the input file.
  3. a main section (not labeled) which contains the processing rules.
  4. 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 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 In Toolbox 
 c    choose menu "File" / "export"
 c    choose "Add a new export process"
 c    click "Standard Format" button
 c    give a process name, e.g. WordListTableInXHTML
 c    and add this file as the changes table
 c
 c    export the database file
 c
 c
 c For subsequent execution do
 c     choose "File export"
 c     select the process 'WordListTableInXHTML'
 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   c XML header
 			'<html xmlns="http://www.w3.org/1999/xhtml">'           nl   c root element -- HTML with name space declaration
                        '<header>'                                              nl   c start of HTML header
                        '<script language="JavaScript" type="text/javascript">' nl   c dummy JavaScript area; replace with your code
                        ' function test(file, titleString)'                     nl
                        '   {'                                                  nl
                        '     //'                                               nl
                        '   }'                                                  nl
                        '</script>'                                             nl
                        ' '
                                                                                nl
           '<link href="theStyleSheet.css" rel="stylesheet" type="text/css" />' nl   c link to a CSS style sheet / fill in your css name 
           ' ' 
                                                                                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   c end of HTML header 
       ' ' 
                                                                                nl
       ' '
                                                                                nl
       '<body>'                                                                 nl   c start of HTML body
       '<h2>'
       'Nkonya lexicon data'                                                         c title, replace with your title.
       '</h2>'                                                                  nl


       '<table>'                                                                nl   c start of lexical data / table form


 
 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



License

The content of this wiki page is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. The script code is under the MIT license.

This means you can use it in any project for anything as long as you attribute the source. You may as well copy this page to another web page and enhance it as long as you provide a link back to this page.