Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/training/ambiguous_words.cpp @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /////////////////////////////////////////////////////////////////////// | |
| 2 // File: ambiguous_words.cpp | |
| 3 // Description: A program that takes a text file with a list of words as | |
| 4 // input (one per line) and outputs a file with the words | |
| 5 // that were found in the dictionary followed by the words | |
| 6 // that are ambiguous to them. | |
| 7 // Author: Rika Antonova | |
| 8 // | |
| 9 // (C) Copyright 2011, Google Inc. | |
| 10 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 11 // you may not use this file except in compliance with the License. | |
| 12 // You may obtain a copy of the License at | |
| 13 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 14 // Unless required by applicable law or agreed to in writing, software | |
| 15 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 17 // See the License for the specific language governing permissions and | |
| 18 // limitations under the License. | |
| 19 // | |
| 20 /////////////////////////////////////////////////////////////////////// | |
| 21 // | |
| 22 | |
| 23 #include "commontraining.h" // CheckSharedLibraryVersion | |
| 24 #include "dict.h" | |
| 25 #include "tesseractclass.h" | |
| 26 | |
| 27 #include <tesseract/baseapi.h> | |
| 28 #include "helpers.h" | |
| 29 | |
| 30 int main(int argc, char **argv) { | |
| 31 tesseract::CheckSharedLibraryVersion(); | |
| 32 | |
| 33 // Parse input arguments. | |
| 34 if (argc > 1 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) { | |
| 35 printf("%s\n", tesseract::TessBaseAPI::Version()); | |
| 36 return EXIT_SUCCESS; | |
| 37 } else if (argc != 4 && (argc != 6 || strcmp(argv[1], "-l") != 0)) { | |
| 38 printf( | |
| 39 "Usage: %s -v | --version | %s [-l lang] tessdata_dir wordlist_file" | |
| 40 " output_ambiguous_wordlist_file\n", | |
| 41 argv[0], argv[0]); | |
| 42 return EXIT_FAILURE; | |
| 43 } | |
| 44 int argv_offset = 0; | |
| 45 std::string lang; | |
| 46 if (argc == 6) { | |
| 47 lang = argv[2]; | |
| 48 argv_offset = 2; | |
| 49 } else { | |
| 50 lang = "eng"; | |
| 51 } | |
| 52 const char *tessdata_dir = argv[++argv_offset]; | |
| 53 const char *input_file_str = argv[++argv_offset]; | |
| 54 const char *output_file_str = argv[++argv_offset]; | |
| 55 | |
| 56 // Initialize Tesseract. | |
| 57 tesseract::TessBaseAPI api; | |
| 58 std::vector<std::string> vars_vec; | |
| 59 std::vector<std::string> vars_values; | |
| 60 vars_vec.emplace_back("output_ambig_words_file"); | |
| 61 vars_values.emplace_back(output_file_str); | |
| 62 api.Init(tessdata_dir, lang.c_str(), tesseract::OEM_TESSERACT_ONLY, nullptr, 0, &vars_vec, | |
| 63 &vars_values, false); | |
| 64 tesseract::Dict &dict = api.tesseract()->getDict(); | |
| 65 FILE *input_file = fopen(input_file_str, "rb"); | |
| 66 if (input_file == nullptr) { | |
| 67 tesseract::tprintf("Failed to open input wordlist file %s\n", input_file_str); | |
| 68 return EXIT_FAILURE; | |
| 69 } | |
| 70 char str[CHARS_PER_LINE]; | |
| 71 | |
| 72 // Read word list and call Dict::NoDangerousAmbig() for each word | |
| 73 // to record ambiguities in the output file. | |
| 74 while (fgets(str, CHARS_PER_LINE, input_file) != nullptr) { | |
| 75 tesseract::chomp_string(str); // remove newline | |
| 76 tesseract::WERD_CHOICE word(str, dict.getUnicharset()); | |
| 77 dict.NoDangerousAmbig(&word, nullptr, false, nullptr); | |
| 78 } | |
| 79 // Clean up. | |
| 80 fclose(input_file); | |
| 81 return EXIT_SUCCESS; | |
| 82 } |
