dict/context.cpp File Reference

#include "context.h"
#include "tordvars.h"
#include "callcpp.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

Go to the source code of this file.

Functions

Variables


Function Documentation

void close_choices (  ) 

Close the choices file.

Note:
File: context.h (Formerly context.h)
Context checking functions
Author:
Mark Seaman, OCR Technology
Date:
Thu Feb 15 11:18:24 1990 Tue Jul 9 17:00:38 1991 (Mark Seaman) marks
 * (c) Copyright 1990, Hewlett-Packard Company.
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 ** http://www.apache.org/licenses/LICENSE-2.0
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.

Definition at line 41 of file context.cpp.

References choice_file.

Referenced by program_editdown().

00041                      { 
00042   if (choice_file)
00043     fclose(choice_file); 
00044 }

void fix_quotes ( char *  str  ) 

Fix up two single quote to make them two double quotes.

Definition at line 50 of file context.cpp.

00050                            { 
00051   int i;
00052   for (i = 0; i < strlen (str); i++) {
00053 
00054     if (((str[i] == '\'') || (str[i] == '`')) &&
00055     ((str[i + 1] == '\'') || (str[i + 1] == '`'))) {
00056       str[i] = '\"';
00057       strcpy (str + i + 1, str + i + 2);
00058     }
00059   }
00060 }

int punctuation_ok ( const char *  word  ) 

Check a string to see if it matches a set of punctuation rules.

Definition at line 66 of file context.cpp.

Referenced by AcceptableChoice(), AcceptableResult(), AdaptableWord(), adjust_non_word(), adjust_word(), and letter_is_okay().

00066                                      { 
00067   int punctuation_types[5];
00068   int trailing = 0;
00069   int num_puncts = 0;
00070   register int x;
00071   register char ch;
00072 
00073   for (x = 0; x < 5; x++)
00074     punctuation_types[x] = 0;
00075 
00076   for (x = 0; x < strlen (word); x++) {
00077 
00078     if (isalpha (word[x])) {
00079       if (trailing &&
00080         !(isalpha (word[x - 1]) ||
00081         (word[x - 1] == '\'' &&
00082         (word[x] == 's' || word[x] == 'd' || word[x] == 'l')) ||
00083         (word[x - 1] == '-')))
00084         return (-1);
00085       trailing = 1;
00086     }
00087     else {
00088       ch = word[x];
00089 
00090       if (ch == '.' && trailing) {
00091         if (punctuation_types[0])
00092           return (-1);
00093         (punctuation_types[0])++;
00094       }
00095 
00096       else if (((ch == '{') || (ch == '[') || (ch == '(')) && !trailing) {
00097         if (punctuation_types[1])
00098           return (-1);
00099         (punctuation_types[1])++;
00100       }
00101 
00102       else if (((ch == '}') || (ch == ']') || (ch == ')')) && trailing) {
00103         if (punctuation_types[2])
00104           return (-1);
00105         (punctuation_types[2])++;
00106       }
00107 
00108       else if (((ch == ':') ||
00109         (ch == ';') ||
00110         (ch == '!') ||
00111       (ch == '-') || (ch == ',') || (ch == '?')) && trailing) {
00112         if (punctuation_types[3])
00113           return (-1);
00114         (punctuation_types[3])++;
00115         if (ch == '-')
00116           punctuation_types[3] = 0;
00117       }
00118 
00119       else if ((ch == '`') || (ch == '\"') || (ch == '\'')) {
00120         if ((word[x + 1] == '`') || (word[x + 1] == '\'')) {
00121           x++;
00122         }
00123         (punctuation_types[4])++;
00124         if (punctuation_types[4] > 2)
00125           return (-1);
00126       }
00127 
00128       else if (!isdigit (ch))
00129         return (-1);
00130     }
00131   }
00132 
00133   for (x = 0; x < 5; x++) {
00134     if (punctuation_types[x])
00135       num_puncts++;
00136   }
00137 
00138   return (num_puncts);
00139 }

void write_choice_line (  ) 

Write a blank line to the choices file.

This will indicate that there is a new word that is following.

Definition at line 211 of file context.cpp.

References choice_file.

00211                          { 
00212   if (choice_file) {
00213     fprintf (choice_file, "\n");
00214     fflush(choice_file); 
00215   }
00216 }


Variable Documentation

FILE* choice_file = NULL [static]

File to save choices to

Definition at line 33 of file context.cpp.


Generated on Wed Feb 28 19:49:22 2007 for Tesseract by  doxygen 1.5.1