#!/usr/bin/tclsh # treecount - auxiliary corpus 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 # Simple Tcl script reading a series of lexicon files and counting # the number of occurrences of each lexical formulas. Outputs data # indicating the total number of formulas found as well as the # amount trees and corpus coverage we will have if we eliminate all # formulas occurring less than a certain number of times. # # The output of this script is required for the cutoff2forms script # which produces several auxiliary files given a cutoff. set total 0 foreach f $argv { if {[file readable $f]} { puts stderr "File: $f" set fh [open $f r] while {[gets $fh line] >= 0} { if {[regexp {^lex\(\"(.*)\"\, (.*)\, (.*)\, (.*)\, (.*)\, (.*)\, (.*)\, (.*)\, (.*)\)} $line all pros form sem file sent wrdn trig big uni]} { incr total if {[catch {set formula($form)}]} { set formula($form) 1 } else { set formula($form) [expr $formula($form)+1] } } } close $fh } else { puts stderr "File $f does not exist or is unreadable" exit 1 } } foreach i [array names formula] { puts "$formula($i) $i" } puts "" puts "Total Words : $total" puts "Total Formulas : [array size formula]" puts "" foreach cutoff {1 2 3 4 5 6 7 8 9 10 15 20 25 50 75 100 150 200 250} { set reducedform 0 set reducedtotal 0 foreach i [array names formula] { set n $formula($i) if ($n>=$cutoff) { set reducedtotal [expr $reducedtotal+$n] incr reducedform } } puts "Total Words (>=$cutoff) : $reducedtotal" puts "Total Formulas (>=$cutoff): $reducedform" puts "Word Accuracy: [expr (double($reducedtotal)/double($total))*100] %" puts "" }