HFST - Helsinki Finite-State Transducer Technology - C++ API  version 3.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarmonizeUnknownAndIdentitySymbols.h
1 // Copyright (c) 2016 University of Helsinki
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 3 of the License, or (at your option) any later version.
7 // See the file COPYING included with this distribution for more
8 // information.
9 
10 // --- licensing stuff here?
11 
12 #ifndef HARMONIZE_UNKNOWN_AND_IDENTITY_SYMBOLS
13 #define HARMONIZE_UNKNOWN_AND_IDENTITY_SYMBOLS
14 
15 // ---
16 /* A more generalized class that takes an template <class C, class W>
17  HfstTransitionGraph as its constructor arguments. The functions could
18  take a HfstTransitionGraph::HfstTransitionGraphAlphabet as their
19  arguments and use functions C::get_unknown() etc.
20  */
21 
22 #include <set>
23 #include <string>
24 #include <iostream> // --- in the cc-file instead?
25 #include <algorithm> // --- "" ---
26 #include <cassert> // --- "" ---
27 
28 #include "HfstDataTypes.h"
29 #include "HfstSymbolDefs.h"
30 
31 namespace hfst
32 {
35 
36 #ifdef TEST_HARMONIZE_UNKNOWN_AND_IDENTITY_SYMBOLS
37 #define debug_harmonize 1
38 #else
39 #define debug_harmonize 0
40 #endif // TEST_HARMONIZE_UNKNOWN_AND_IDENTITY_SYMBOLS
41 
42 #include "hfstdll.h"
43 
44 // --- a short documentation
45 class HarmonizeUnknownAndIdentitySymbols
46 {
47  // --- HfstSymbolDefs.h has members const std::string internal_identity
48  // and internal_unknown
49  public:
50  // --- const std::string instead
51  static const char * identity; // --- a short documentation
52  static const char * unknown; // --- "" ---
53 
54  // Constructor whose side effect it is to harmonize the identity and unknown
55  // symbols of its arguments.
56  HFSTDLL HarmonizeUnknownAndIdentitySymbols
58  protected:
59 
62  StringSet t1_symbol_set; // --- symbols known to t1?
63  StringSet t2_symbol_set; // --- symbols known to t2?
64 
65  // Collect the symbols from the transitions of the argument transducer
66  // and store them in the argument set. This is needed since the alphabet
67  // of HfstBasicTransducers can sometimes unexplainedly be empty...
68  // --- the alphabet can contain also symbols that are not found in
69  // transitions...
70  HFSTDLL void populate_symbol_set(const HfstBasicTransducer &,StringSet &);
71 
72  // Add all symbols in the StringSet to the alphabet of the transducer.
73  HFSTDLL void add_symbols_to_alphabet(HfstBasicTransducer &, const StringSet &);
74 
75  // For every x in the set, add x:x transitions for every identity:identity
76  // transition in the argument transducer (the source and target states as
77  // well as the weights are the same as in the original identity transition.
78  HFSTDLL void harmonize_identity_symbols
79  (HfstBasicTransducer &,const StringSet &);
80 
81  // For every x in the set
82  // 1. add, x:c transitions for every unknown:c transition in the argument
83  // transducer.
84  // 2. add, c:x transitions for every c:unknown transition in the argument
85  // transducer.
86  //
87  // For every x and y in the set with x != y, add x:y transitions for every
88  // unknown:unknown transition in the argument transducer.
89  //
90  // (the source and target states as well as the weights are the same as in
91  // the original identity transition)
92  HFSTDLL void harmonize_unknown_symbols
93  (HfstBasicTransducer &,const StringSet &);
94 };
95 
96 HFSTDLL void debug_harmonize_print(const StringSet &);
97 HFSTDLL void debug_harmonize_print(const std::string &);
98 // use name 'max_' to avoid collision with windows macro 'max'
99 HFSTDLL size_t max_(size_t t1,size_t t2); // --- a short documentation
100 
101 }
102 
103 
104 #endif // HARMONIZE_UNKNOWN_AND_IDENTITY_SYMBOLS --- good
Datatypes that are needed when using the HFST API.
HfstTransition< HfstTropicalTransducerTransitionData > HfstBasicTransition
An HfstTransition with transition data of type HfstTropicalTransducerTransitionData.
Definition: HfstDataTypes.h:121
HfstTransitionGraph< HfstTropicalTransducerTransitionData > HfstBasicTransducer
An HfstTransitionGraph with transitions of type HfstTropicalTransducerTransitionData and weight type ...
Definition: HfstDataTypes.h:113
Typedefs and functions for symbols, symbol pairs and sets of symbols.