#!/usr/bin/tclsh # renumber - sentence renumbering script # Copyright (C) 2004-2007 Richard Moot (Richard.Moot@labri.fr) # Copyright (C) 2004-2007 CNRS (http://www.cnrs.fr) # Copyright (C) 2004-2007 INRIA (http://www.inria.fr) # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # a script for converting a number of .syn files into a single one which # Tigersearch will accept. # # a typical invocation will be # # renumber.tcl header.txt *.syn > cgn.ts # # Updated so that nothing will be output for empty sentences. 20050204 RM set sentno 0 set header 0 proc loadcgn {file} { global sentno header set f [open $file r] # read the cgn output file and convert it to an array set content 1 while {[gets $f line] >= 0} { if {[regexp {^#BOS ([0-9]+)(.*)$} $line a b rest]} { set content 0 } elseif {[regexp {^#EOS ([0-9]+)(.*)$} $line x line y z]} { if {$content != 0} { puts "#EOS $sentno $z" } } elseif {[regexp {^#FORMAT} $line]} { if {$header == 0} { set header 1 puts $line } } else { if {![regexp {^#} $line] && $content == 0} { set content 1 incr sentno puts "#BOS $sentno $rest" } puts $line } } close $f } foreach f $argv { if {[file readable $f]} { puts stderr "File: $f" loadcgn $f } else { puts stderr "File $f does not exist or is unreadable" exit 1 } }