#!/usr/local/bin/python # Project: ALICE mobile computing application server # Component: Speech data file regular expression generator. # Description: # This is not a module. build_regex_file is intended to build a base # list of regular expressions, generated from the language model file # Config/lm/alice.corpus. The file generated by this utility is read # by the Modules/speechrule.py module, and the lines within it are # used as keys in the speech data file hash table. # # Current Version: 1.00b # Author: (C) Copyright 2001-2002 Rupert Scammell # Date: 2002-02-11 # License: GNU General Public License """ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import os, sys, string, fileinput # Encapsulates a string in a regular expression that # causes only the exact string to be matched. # Input: text string # Output: Exact match regular expression string. def encap(instr): return '^'+string.strip(instr)+'$\n' if (len(sys.argv) == 1): infile = raw_input("input (corpus) file: ") outfile = raw_input("output (regex) file: ") else: infile = sys.argv[1] outfile = sys.argv[2] danger_string = """ *** IMPORTANT *** This program will write over any existing data that exists in your output file. Any data within this file that you wish to save should be backed up prior to continuing. To continue, type yes. To end, type no. """ print danger_string if (raw_input("> ") == 'no'): print 'No changes were made.' sys.exit(1) try: outfile_handle = open(outfile, 'w') except IOException: print 'Couldn\'t open output file. Ending program.' sys.exit(1) for line in fileinput.input([infile]): postproc = encap(line) print postproc if (postproc[:-1] != "^$"): outfile_handle.write(postproc) else: print 'Skipping blank line.' print 'Done.' outfile_handle.close()