Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +6 -0
- cc-multilingual-main/cc_net/third_party/kenlm/COPYING.3 +674 -0
- cc-multilingual-main/cc_net/third_party/kenlm/MANIFEST.in +9 -0
- cc-multilingual-main/cc_net/third_party/kenlm/README.md +102 -0
- cc-multilingual-main/cc_net/third_party/kenlm/build/CMakeCache.txt +511 -0
- cc-multilingual-main/cc_net/third_party/kenlm/build/Makefile +371 -0
- cc-multilingual-main/cc_net/third_party/kenlm/build/cmake_install.cmake +248 -0
- cc-multilingual-main/cc_net/third_party/kenlm/build/kenlmConfig.cmake +26 -0
- cc-multilingual-main/cc_net/third_party/kenlm/cmake/KenLMFunctions.cmake +81 -0
- cc-multilingual-main/cc_net/third_party/kenlm/cmake/kenlmConfig.cmake.in +19 -0
- cc-multilingual-main/cc_net/third_party/kenlm/cmake/modules/FindEigen3.cmake +90 -0
- cc-multilingual-main/cc_net/third_party/kenlm/compile_query_only.sh +34 -0
- cc-multilingual-main/cc_net/third_party/kenlm/setup.py +62 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/CMakeFiles/sentencepiece_train-static.dir/builder.cc.o +3 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.a +3 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.so +3 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.so.0.0.0 +3 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece_train.a +3 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece_train.so.0 +3 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/CMakeLists.txt +288 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/bpe_model.cc +189 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/bpe_model_trainer.h +125 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/bpe_model_trainer_test.cc +129 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/builder.cc +581 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/builder.h +127 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/builder_test.cc +205 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/builtin_pb/sentencepiece.pb.cc +953 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/builtin_pb/sentencepiece_model.pb.cc +0 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/builtin_pb/sentencepiece_model.pb.h +0 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/char_model.h +34 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/char_model_test.cc +121 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/char_model_trainer.cc +60 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/char_model_trainer_test.cc +77 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/common.h +202 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/compile_charsmap_main.cc +189 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/error.cc +154 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/filesystem.cc +103 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/filesystem.h +58 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/filesystem_test.cc +54 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/flags.cc +223 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/flags.h +95 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/flags_test.cc +138 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/freelist.h +82 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/freelist_test.cc +34 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/model_factory.cc +51 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/model_factory_test.cc +58 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/model_interface.cc +142 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/model_interface_test.cc +373 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/normalization_rule.h +0 -0
- cc-multilingual-main/cc_net/third_party/sentencepiece/src/normalizer.cc +333 -0
.gitattributes
CHANGED
@@ -65,3 +65,9 @@ cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/CMakeFiles/sente
|
|
65 |
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.so.0 filter=lfs diff=lfs merge=lfs -text
|
66 |
cc-multilingual-main/cc_net/bin/lmplz filter=lfs diff=lfs merge=lfs -text
|
67 |
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece_train.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.so.0 filter=lfs diff=lfs merge=lfs -text
|
66 |
cc-multilingual-main/cc_net/bin/lmplz filter=lfs diff=lfs merge=lfs -text
|
67 |
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece_train.so filter=lfs diff=lfs merge=lfs -text
|
68 |
+
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.a filter=lfs diff=lfs merge=lfs -text
|
69 |
+
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.so filter=lfs diff=lfs merge=lfs -text
|
70 |
+
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece_train.so.0 filter=lfs diff=lfs merge=lfs -text
|
71 |
+
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.so.0.0.0 filter=lfs diff=lfs merge=lfs -text
|
72 |
+
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece_train.a filter=lfs diff=lfs merge=lfs -text
|
73 |
+
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/CMakeFiles/sentencepiece_train-static.dir/builder.cc.o filter=lfs diff=lfs merge=lfs -text
|
cc-multilingual-main/cc_net/third_party/kenlm/COPYING.3
ADDED
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 29 June 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
Preamble
|
9 |
+
|
10 |
+
The GNU General Public License is a free, copyleft license for
|
11 |
+
software and other kinds of works.
|
12 |
+
|
13 |
+
The licenses for most software and other practical works are designed
|
14 |
+
to take away your freedom to share and change the works. By contrast,
|
15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
16 |
+
share and change all versions of a program--to make sure it remains free
|
17 |
+
software for all its users. We, the Free Software Foundation, use the
|
18 |
+
GNU General Public License for most of our software; it applies also to
|
19 |
+
any other work released this way by its authors. You can apply it to
|
20 |
+
your programs, too.
|
21 |
+
|
22 |
+
When we speak of free software, we are referring to freedom, not
|
23 |
+
price. Our General Public Licenses are designed to make sure that you
|
24 |
+
have the freedom to distribute copies of free software (and charge for
|
25 |
+
them if you wish), that you receive source code or can get it if you
|
26 |
+
want it, that you can change the software or use pieces of it in new
|
27 |
+
free programs, and that you know you can do these things.
|
28 |
+
|
29 |
+
To protect your rights, we need to prevent others from denying you
|
30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
31 |
+
certain responsibilities if you distribute copies of the software, or if
|
32 |
+
you modify it: responsibilities to respect the freedom of others.
|
33 |
+
|
34 |
+
For example, if you distribute copies of such a program, whether
|
35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
36 |
+
freedoms that you received. You must make sure that they, too, receive
|
37 |
+
or can get the source code. And you must show them these terms so they
|
38 |
+
know their rights.
|
39 |
+
|
40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
43 |
+
|
44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
45 |
+
that there is no warranty for this free software. For both users' and
|
46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
47 |
+
changed, so that their problems will not be attributed erroneously to
|
48 |
+
authors of previous versions.
|
49 |
+
|
50 |
+
Some devices are designed to deny users access to install or run
|
51 |
+
modified versions of the software inside them, although the manufacturer
|
52 |
+
can do so. This is fundamentally incompatible with the aim of
|
53 |
+
protecting users' freedom to change the software. The systematic
|
54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
56 |
+
have designed this version of the GPL to prohibit the practice for those
|
57 |
+
products. If such problems arise substantially in other domains, we
|
58 |
+
stand ready to extend this provision to those domains in future versions
|
59 |
+
of the GPL, as needed to protect the freedom of users.
|
60 |
+
|
61 |
+
Finally, every program is threatened constantly by software patents.
|
62 |
+
States should not allow patents to restrict development and use of
|
63 |
+
software on general-purpose computers, but in those that do, we wish to
|
64 |
+
avoid the special danger that patents applied to a free program could
|
65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
66 |
+
patents cannot be used to render the program non-free.
|
67 |
+
|
68 |
+
The precise terms and conditions for copying, distribution and
|
69 |
+
modification follow.
|
70 |
+
|
71 |
+
TERMS AND CONDITIONS
|
72 |
+
|
73 |
+
0. Definitions.
|
74 |
+
|
75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
76 |
+
|
77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
78 |
+
works, such as semiconductor masks.
|
79 |
+
|
80 |
+
"The Program" refers to any copyrightable work licensed under this
|
81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
82 |
+
"recipients" may be individuals or organizations.
|
83 |
+
|
84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
85 |
+
in a fashion requiring copyright permission, other than the making of an
|
86 |
+
exact copy. The resulting work is called a "modified version" of the
|
87 |
+
earlier work or a work "based on" the earlier work.
|
88 |
+
|
89 |
+
A "covered work" means either the unmodified Program or a work based
|
90 |
+
on the Program.
|
91 |
+
|
92 |
+
To "propagate" a work means to do anything with it that, without
|
93 |
+
permission, would make you directly or secondarily liable for
|
94 |
+
infringement under applicable copyright law, except executing it on a
|
95 |
+
computer or modifying a private copy. Propagation includes copying,
|
96 |
+
distribution (with or without modification), making available to the
|
97 |
+
public, and in some countries other activities as well.
|
98 |
+
|
99 |
+
To "convey" a work means any kind of propagation that enables other
|
100 |
+
parties to make or receive copies. Mere interaction with a user through
|
101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
102 |
+
|
103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
104 |
+
to the extent that it includes a convenient and prominently visible
|
105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
106 |
+
tells the user that there is no warranty for the work (except to the
|
107 |
+
extent that warranties are provided), that licensees may convey the
|
108 |
+
work under this License, and how to view a copy of this License. If
|
109 |
+
the interface presents a list of user commands or options, such as a
|
110 |
+
menu, a prominent item in the list meets this criterion.
|
111 |
+
|
112 |
+
1. Source Code.
|
113 |
+
|
114 |
+
The "source code" for a work means the preferred form of the work
|
115 |
+
for making modifications to it. "Object code" means any non-source
|
116 |
+
form of a work.
|
117 |
+
|
118 |
+
A "Standard Interface" means an interface that either is an official
|
119 |
+
standard defined by a recognized standards body, or, in the case of
|
120 |
+
interfaces specified for a particular programming language, one that
|
121 |
+
is widely used among developers working in that language.
|
122 |
+
|
123 |
+
The "System Libraries" of an executable work include anything, other
|
124 |
+
than the work as a whole, that (a) is included in the normal form of
|
125 |
+
packaging a Major Component, but which is not part of that Major
|
126 |
+
Component, and (b) serves only to enable use of the work with that
|
127 |
+
Major Component, or to implement a Standard Interface for which an
|
128 |
+
implementation is available to the public in source code form. A
|
129 |
+
"Major Component", in this context, means a major essential component
|
130 |
+
(kernel, window system, and so on) of the specific operating system
|
131 |
+
(if any) on which the executable work runs, or a compiler used to
|
132 |
+
produce the work, or an object code interpreter used to run it.
|
133 |
+
|
134 |
+
The "Corresponding Source" for a work in object code form means all
|
135 |
+
the source code needed to generate, install, and (for an executable
|
136 |
+
work) run the object code and to modify the work, including scripts to
|
137 |
+
control those activities. However, it does not include the work's
|
138 |
+
System Libraries, or general-purpose tools or generally available free
|
139 |
+
programs which are used unmodified in performing those activities but
|
140 |
+
which are not part of the work. For example, Corresponding Source
|
141 |
+
includes interface definition files associated with source files for
|
142 |
+
the work, and the source code for shared libraries and dynamically
|
143 |
+
linked subprograms that the work is specifically designed to require,
|
144 |
+
such as by intimate data communication or control flow between those
|
145 |
+
subprograms and other parts of the work.
|
146 |
+
|
147 |
+
The Corresponding Source need not include anything that users
|
148 |
+
can regenerate automatically from other parts of the Corresponding
|
149 |
+
Source.
|
150 |
+
|
151 |
+
The Corresponding Source for a work in source code form is that
|
152 |
+
same work.
|
153 |
+
|
154 |
+
2. Basic Permissions.
|
155 |
+
|
156 |
+
All rights granted under this License are granted for the term of
|
157 |
+
copyright on the Program, and are irrevocable provided the stated
|
158 |
+
conditions are met. This License explicitly affirms your unlimited
|
159 |
+
permission to run the unmodified Program. The output from running a
|
160 |
+
covered work is covered by this License only if the output, given its
|
161 |
+
content, constitutes a covered work. This License acknowledges your
|
162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
163 |
+
|
164 |
+
You may make, run and propagate covered works that you do not
|
165 |
+
convey, without conditions so long as your license otherwise remains
|
166 |
+
in force. You may convey covered works to others for the sole purpose
|
167 |
+
of having them make modifications exclusively for you, or provide you
|
168 |
+
with facilities for running those works, provided that you comply with
|
169 |
+
the terms of this License in conveying all material for which you do
|
170 |
+
not control copyright. Those thus making or running the covered works
|
171 |
+
for you must do so exclusively on your behalf, under your direction
|
172 |
+
and control, on terms that prohibit them from making any copies of
|
173 |
+
your copyrighted material outside their relationship with you.
|
174 |
+
|
175 |
+
Conveying under any other circumstances is permitted solely under
|
176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
177 |
+
makes it unnecessary.
|
178 |
+
|
179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
180 |
+
|
181 |
+
No covered work shall be deemed part of an effective technological
|
182 |
+
measure under any applicable law fulfilling obligations under article
|
183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
184 |
+
similar laws prohibiting or restricting circumvention of such
|
185 |
+
measures.
|
186 |
+
|
187 |
+
When you convey a covered work, you waive any legal power to forbid
|
188 |
+
circumvention of technological measures to the extent such circumvention
|
189 |
+
is effected by exercising rights under this License with respect to
|
190 |
+
the covered work, and you disclaim any intention to limit operation or
|
191 |
+
modification of the work as a means of enforcing, against the work's
|
192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
193 |
+
technological measures.
|
194 |
+
|
195 |
+
4. Conveying Verbatim Copies.
|
196 |
+
|
197 |
+
You may convey verbatim copies of the Program's source code as you
|
198 |
+
receive it, in any medium, provided that you conspicuously and
|
199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
200 |
+
keep intact all notices stating that this License and any
|
201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
202 |
+
keep intact all notices of the absence of any warranty; and give all
|
203 |
+
recipients a copy of this License along with the Program.
|
204 |
+
|
205 |
+
You may charge any price or no price for each copy that you convey,
|
206 |
+
and you may offer support or warranty protection for a fee.
|
207 |
+
|
208 |
+
5. Conveying Modified Source Versions.
|
209 |
+
|
210 |
+
You may convey a work based on the Program, or the modifications to
|
211 |
+
produce it from the Program, in the form of source code under the
|
212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
213 |
+
|
214 |
+
a) The work must carry prominent notices stating that you modified
|
215 |
+
it, and giving a relevant date.
|
216 |
+
|
217 |
+
b) The work must carry prominent notices stating that it is
|
218 |
+
released under this License and any conditions added under section
|
219 |
+
7. This requirement modifies the requirement in section 4 to
|
220 |
+
"keep intact all notices".
|
221 |
+
|
222 |
+
c) You must license the entire work, as a whole, under this
|
223 |
+
License to anyone who comes into possession of a copy. This
|
224 |
+
License will therefore apply, along with any applicable section 7
|
225 |
+
additional terms, to the whole of the work, and all its parts,
|
226 |
+
regardless of how they are packaged. This License gives no
|
227 |
+
permission to license the work in any other way, but it does not
|
228 |
+
invalidate such permission if you have separately received it.
|
229 |
+
|
230 |
+
d) If the work has interactive user interfaces, each must display
|
231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
233 |
+
work need not make them do so.
|
234 |
+
|
235 |
+
A compilation of a covered work with other separate and independent
|
236 |
+
works, which are not by their nature extensions of the covered work,
|
237 |
+
and which are not combined with it such as to form a larger program,
|
238 |
+
in or on a volume of a storage or distribution medium, is called an
|
239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
240 |
+
used to limit the access or legal rights of the compilation's users
|
241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
242 |
+
in an aggregate does not cause this License to apply to the other
|
243 |
+
parts of the aggregate.
|
244 |
+
|
245 |
+
6. Conveying Non-Source Forms.
|
246 |
+
|
247 |
+
You may convey a covered work in object code form under the terms
|
248 |
+
of sections 4 and 5, provided that you also convey the
|
249 |
+
machine-readable Corresponding Source under the terms of this License,
|
250 |
+
in one of these ways:
|
251 |
+
|
252 |
+
a) Convey the object code in, or embodied in, a physical product
|
253 |
+
(including a physical distribution medium), accompanied by the
|
254 |
+
Corresponding Source fixed on a durable physical medium
|
255 |
+
customarily used for software interchange.
|
256 |
+
|
257 |
+
b) Convey the object code in, or embodied in, a physical product
|
258 |
+
(including a physical distribution medium), accompanied by a
|
259 |
+
written offer, valid for at least three years and valid for as
|
260 |
+
long as you offer spare parts or customer support for that product
|
261 |
+
model, to give anyone who possesses the object code either (1) a
|
262 |
+
copy of the Corresponding Source for all the software in the
|
263 |
+
product that is covered by this License, on a durable physical
|
264 |
+
medium customarily used for software interchange, for a price no
|
265 |
+
more than your reasonable cost of physically performing this
|
266 |
+
conveying of source, or (2) access to copy the
|
267 |
+
Corresponding Source from a network server at no charge.
|
268 |
+
|
269 |
+
c) Convey individual copies of the object code with a copy of the
|
270 |
+
written offer to provide the Corresponding Source. This
|
271 |
+
alternative is allowed only occasionally and noncommercially, and
|
272 |
+
only if you received the object code with such an offer, in accord
|
273 |
+
with subsection 6b.
|
274 |
+
|
275 |
+
d) Convey the object code by offering access from a designated
|
276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
277 |
+
Corresponding Source in the same way through the same place at no
|
278 |
+
further charge. You need not require recipients to copy the
|
279 |
+
Corresponding Source along with the object code. If the place to
|
280 |
+
copy the object code is a network server, the Corresponding Source
|
281 |
+
may be on a different server (operated by you or a third party)
|
282 |
+
that supports equivalent copying facilities, provided you maintain
|
283 |
+
clear directions next to the object code saying where to find the
|
284 |
+
Corresponding Source. Regardless of what server hosts the
|
285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
286 |
+
available for as long as needed to satisfy these requirements.
|
287 |
+
|
288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
289 |
+
you inform other peers where the object code and Corresponding
|
290 |
+
Source of the work are being offered to the general public at no
|
291 |
+
charge under subsection 6d.
|
292 |
+
|
293 |
+
A separable portion of the object code, whose source code is excluded
|
294 |
+
from the Corresponding Source as a System Library, need not be
|
295 |
+
included in conveying the object code work.
|
296 |
+
|
297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
298 |
+
tangible personal property which is normally used for personal, family,
|
299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
302 |
+
product received by a particular user, "normally used" refers to a
|
303 |
+
typical or common use of that class of product, regardless of the status
|
304 |
+
of the particular user or of the way in which the particular user
|
305 |
+
actually uses, or expects or is expected to use, the product. A product
|
306 |
+
is a consumer product regardless of whether the product has substantial
|
307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
308 |
+
the only significant mode of use of the product.
|
309 |
+
|
310 |
+
"Installation Information" for a User Product means any methods,
|
311 |
+
procedures, authorization keys, or other information required to install
|
312 |
+
and execute modified versions of a covered work in that User Product from
|
313 |
+
a modified version of its Corresponding Source. The information must
|
314 |
+
suffice to ensure that the continued functioning of the modified object
|
315 |
+
code is in no case prevented or interfered with solely because
|
316 |
+
modification has been made.
|
317 |
+
|
318 |
+
If you convey an object code work under this section in, or with, or
|
319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
320 |
+
part of a transaction in which the right of possession and use of the
|
321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
322 |
+
fixed term (regardless of how the transaction is characterized), the
|
323 |
+
Corresponding Source conveyed under this section must be accompanied
|
324 |
+
by the Installation Information. But this requirement does not apply
|
325 |
+
if neither you nor any third party retains the ability to install
|
326 |
+
modified object code on the User Product (for example, the work has
|
327 |
+
been installed in ROM).
|
328 |
+
|
329 |
+
The requirement to provide Installation Information does not include a
|
330 |
+
requirement to continue to provide support service, warranty, or updates
|
331 |
+
for a work that has been modified or installed by the recipient, or for
|
332 |
+
the User Product in which it has been modified or installed. Access to a
|
333 |
+
network may be denied when the modification itself materially and
|
334 |
+
adversely affects the operation of the network or violates the rules and
|
335 |
+
protocols for communication across the network.
|
336 |
+
|
337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
338 |
+
in accord with this section must be in a format that is publicly
|
339 |
+
documented (and with an implementation available to the public in
|
340 |
+
source code form), and must require no special password or key for
|
341 |
+
unpacking, reading or copying.
|
342 |
+
|
343 |
+
7. Additional Terms.
|
344 |
+
|
345 |
+
"Additional permissions" are terms that supplement the terms of this
|
346 |
+
License by making exceptions from one or more of its conditions.
|
347 |
+
Additional permissions that are applicable to the entire Program shall
|
348 |
+
be treated as though they were included in this License, to the extent
|
349 |
+
that they are valid under applicable law. If additional permissions
|
350 |
+
apply only to part of the Program, that part may be used separately
|
351 |
+
under those permissions, but the entire Program remains governed by
|
352 |
+
this License without regard to the additional permissions.
|
353 |
+
|
354 |
+
When you convey a copy of a covered work, you may at your option
|
355 |
+
remove any additional permissions from that copy, or from any part of
|
356 |
+
it. (Additional permissions may be written to require their own
|
357 |
+
removal in certain cases when you modify the work.) You may place
|
358 |
+
additional permissions on material, added by you to a covered work,
|
359 |
+
for which you have or can give appropriate copyright permission.
|
360 |
+
|
361 |
+
Notwithstanding any other provision of this License, for material you
|
362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
363 |
+
that material) supplement the terms of this License with terms:
|
364 |
+
|
365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
366 |
+
terms of sections 15 and 16 of this License; or
|
367 |
+
|
368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
369 |
+
author attributions in that material or in the Appropriate Legal
|
370 |
+
Notices displayed by works containing it; or
|
371 |
+
|
372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
373 |
+
requiring that modified versions of such material be marked in
|
374 |
+
reasonable ways as different from the original version; or
|
375 |
+
|
376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
377 |
+
authors of the material; or
|
378 |
+
|
379 |
+
e) Declining to grant rights under trademark law for use of some
|
380 |
+
trade names, trademarks, or service marks; or
|
381 |
+
|
382 |
+
f) Requiring indemnification of licensors and authors of that
|
383 |
+
material by anyone who conveys the material (or modified versions of
|
384 |
+
it) with contractual assumptions of liability to the recipient, for
|
385 |
+
any liability that these contractual assumptions directly impose on
|
386 |
+
those licensors and authors.
|
387 |
+
|
388 |
+
All other non-permissive additional terms are considered "further
|
389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
390 |
+
received it, or any part of it, contains a notice stating that it is
|
391 |
+
governed by this License along with a term that is a further
|
392 |
+
restriction, you may remove that term. If a license document contains
|
393 |
+
a further restriction but permits relicensing or conveying under this
|
394 |
+
License, you may add to a covered work material governed by the terms
|
395 |
+
of that license document, provided that the further restriction does
|
396 |
+
not survive such relicensing or conveying.
|
397 |
+
|
398 |
+
If you add terms to a covered work in accord with this section, you
|
399 |
+
must place, in the relevant source files, a statement of the
|
400 |
+
additional terms that apply to those files, or a notice indicating
|
401 |
+
where to find the applicable terms.
|
402 |
+
|
403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
404 |
+
form of a separately written license, or stated as exceptions;
|
405 |
+
the above requirements apply either way.
|
406 |
+
|
407 |
+
8. Termination.
|
408 |
+
|
409 |
+
You may not propagate or modify a covered work except as expressly
|
410 |
+
provided under this License. Any attempt otherwise to propagate or
|
411 |
+
modify it is void, and will automatically terminate your rights under
|
412 |
+
this License (including any patent licenses granted under the third
|
413 |
+
paragraph of section 11).
|
414 |
+
|
415 |
+
However, if you cease all violation of this License, then your
|
416 |
+
license from a particular copyright holder is reinstated (a)
|
417 |
+
provisionally, unless and until the copyright holder explicitly and
|
418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
419 |
+
holder fails to notify you of the violation by some reasonable means
|
420 |
+
prior to 60 days after the cessation.
|
421 |
+
|
422 |
+
Moreover, your license from a particular copyright holder is
|
423 |
+
reinstated permanently if the copyright holder notifies you of the
|
424 |
+
violation by some reasonable means, this is the first time you have
|
425 |
+
received notice of violation of this License (for any work) from that
|
426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
427 |
+
your receipt of the notice.
|
428 |
+
|
429 |
+
Termination of your rights under this section does not terminate the
|
430 |
+
licenses of parties who have received copies or rights from you under
|
431 |
+
this License. If your rights have been terminated and not permanently
|
432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
433 |
+
material under section 10.
|
434 |
+
|
435 |
+
9. Acceptance Not Required for Having Copies.
|
436 |
+
|
437 |
+
You are not required to accept this License in order to receive or
|
438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
440 |
+
to receive a copy likewise does not require acceptance. However,
|
441 |
+
nothing other than this License grants you permission to propagate or
|
442 |
+
modify any covered work. These actions infringe copyright if you do
|
443 |
+
not accept this License. Therefore, by modifying or propagating a
|
444 |
+
covered work, you indicate your acceptance of this License to do so.
|
445 |
+
|
446 |
+
10. Automatic Licensing of Downstream Recipients.
|
447 |
+
|
448 |
+
Each time you convey a covered work, the recipient automatically
|
449 |
+
receives a license from the original licensors, to run, modify and
|
450 |
+
propagate that work, subject to this License. You are not responsible
|
451 |
+
for enforcing compliance by third parties with this License.
|
452 |
+
|
453 |
+
An "entity transaction" is a transaction transferring control of an
|
454 |
+
organization, or substantially all assets of one, or subdividing an
|
455 |
+
organization, or merging organizations. If propagation of a covered
|
456 |
+
work results from an entity transaction, each party to that
|
457 |
+
transaction who receives a copy of the work also receives whatever
|
458 |
+
licenses to the work the party's predecessor in interest had or could
|
459 |
+
give under the previous paragraph, plus a right to possession of the
|
460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
461 |
+
the predecessor has it or can get it with reasonable efforts.
|
462 |
+
|
463 |
+
You may not impose any further restrictions on the exercise of the
|
464 |
+
rights granted or affirmed under this License. For example, you may
|
465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
466 |
+
rights granted under this License, and you may not initiate litigation
|
467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
468 |
+
any patent claim is infringed by making, using, selling, offering for
|
469 |
+
sale, or importing the Program or any portion of it.
|
470 |
+
|
471 |
+
11. Patents.
|
472 |
+
|
473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
474 |
+
License of the Program or a work on which the Program is based. The
|
475 |
+
work thus licensed is called the contributor's "contributor version".
|
476 |
+
|
477 |
+
A contributor's "essential patent claims" are all patent claims
|
478 |
+
owned or controlled by the contributor, whether already acquired or
|
479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
480 |
+
by this License, of making, using, or selling its contributor version,
|
481 |
+
but do not include claims that would be infringed only as a
|
482 |
+
consequence of further modification of the contributor version. For
|
483 |
+
purposes of this definition, "control" includes the right to grant
|
484 |
+
patent sublicenses in a manner consistent with the requirements of
|
485 |
+
this License.
|
486 |
+
|
487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
488 |
+
patent license under the contributor's essential patent claims, to
|
489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
490 |
+
propagate the contents of its contributor version.
|
491 |
+
|
492 |
+
In the following three paragraphs, a "patent license" is any express
|
493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
494 |
+
(such as an express permission to practice a patent or covenant not to
|
495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
496 |
+
party means to make such an agreement or commitment not to enforce a
|
497 |
+
patent against the party.
|
498 |
+
|
499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
500 |
+
and the Corresponding Source of the work is not available for anyone
|
501 |
+
to copy, free of charge and under the terms of this License, through a
|
502 |
+
publicly available network server or other readily accessible means,
|
503 |
+
then you must either (1) cause the Corresponding Source to be so
|
504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
506 |
+
consistent with the requirements of this License, to extend the patent
|
507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
508 |
+
actual knowledge that, but for the patent license, your conveying the
|
509 |
+
covered work in a country, or your recipient's use of the covered work
|
510 |
+
in a country, would infringe one or more identifiable patents in that
|
511 |
+
country that you have reason to believe are valid.
|
512 |
+
|
513 |
+
If, pursuant to or in connection with a single transaction or
|
514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
515 |
+
covered work, and grant a patent license to some of the parties
|
516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
517 |
+
or convey a specific copy of the covered work, then the patent license
|
518 |
+
you grant is automatically extended to all recipients of the covered
|
519 |
+
work and works based on it.
|
520 |
+
|
521 |
+
A patent license is "discriminatory" if it does not include within
|
522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
524 |
+
specifically granted under this License. You may not convey a covered
|
525 |
+
work if you are a party to an arrangement with a third party that is
|
526 |
+
in the business of distributing software, under which you make payment
|
527 |
+
to the third party based on the extent of your activity of conveying
|
528 |
+
the work, and under which the third party grants, to any of the
|
529 |
+
parties who would receive the covered work from you, a discriminatory
|
530 |
+
patent license (a) in connection with copies of the covered work
|
531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
532 |
+
for and in connection with specific products or compilations that
|
533 |
+
contain the covered work, unless you entered into that arrangement,
|
534 |
+
or that patent license was granted, prior to 28 March 2007.
|
535 |
+
|
536 |
+
Nothing in this License shall be construed as excluding or limiting
|
537 |
+
any implied license or other defenses to infringement that may
|
538 |
+
otherwise be available to you under applicable patent law.
|
539 |
+
|
540 |
+
12. No Surrender of Others' Freedom.
|
541 |
+
|
542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
543 |
+
otherwise) that contradict the conditions of this License, they do not
|
544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
546 |
+
License and any other pertinent obligations, then as a consequence you may
|
547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
548 |
+
to collect a royalty for further conveying from those to whom you convey
|
549 |
+
the Program, the only way you could satisfy both those terms and this
|
550 |
+
License would be to refrain entirely from conveying the Program.
|
551 |
+
|
552 |
+
13. Use with the GNU Affero General Public License.
|
553 |
+
|
554 |
+
Notwithstanding any other provision of this License, you have
|
555 |
+
permission to link or combine any covered work with a work licensed
|
556 |
+
under version 3 of the GNU Affero General Public License into a single
|
557 |
+
combined work, and to convey the resulting work. The terms of this
|
558 |
+
License will continue to apply to the part which is the covered work,
|
559 |
+
but the special requirements of the GNU Affero General Public License,
|
560 |
+
section 13, concerning interaction through a network will apply to the
|
561 |
+
combination as such.
|
562 |
+
|
563 |
+
14. Revised Versions of this License.
|
564 |
+
|
565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
566 |
+
the GNU General Public License from time to time. Such new versions will
|
567 |
+
be similar in spirit to the present version, but may differ in detail to
|
568 |
+
address new problems or concerns.
|
569 |
+
|
570 |
+
Each version is given a distinguishing version number. If the
|
571 |
+
Program specifies that a certain numbered version of the GNU General
|
572 |
+
Public License "or any later version" applies to it, you have the
|
573 |
+
option of following the terms and conditions either of that numbered
|
574 |
+
version or of any later version published by the Free Software
|
575 |
+
Foundation. If the Program does not specify a version number of the
|
576 |
+
GNU General Public License, you may choose any version ever published
|
577 |
+
by the Free Software Foundation.
|
578 |
+
|
579 |
+
If the Program specifies that a proxy can decide which future
|
580 |
+
versions of the GNU General Public License can be used, that proxy's
|
581 |
+
public statement of acceptance of a version permanently authorizes you
|
582 |
+
to choose that version for the Program.
|
583 |
+
|
584 |
+
Later license versions may give you additional or different
|
585 |
+
permissions. However, no additional obligations are imposed on any
|
586 |
+
author or copyright holder as a result of your choosing to follow a
|
587 |
+
later version.
|
588 |
+
|
589 |
+
15. Disclaimer of Warranty.
|
590 |
+
|
591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
599 |
+
|
600 |
+
16. Limitation of Liability.
|
601 |
+
|
602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
610 |
+
SUCH DAMAGES.
|
611 |
+
|
612 |
+
17. Interpretation of Sections 15 and 16.
|
613 |
+
|
614 |
+
If the disclaimer of warranty and limitation of liability provided
|
615 |
+
above cannot be given local legal effect according to their terms,
|
616 |
+
reviewing courts shall apply local law that most closely approximates
|
617 |
+
an absolute waiver of all civil liability in connection with the
|
618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
619 |
+
copy of the Program in return for a fee.
|
620 |
+
|
621 |
+
END OF TERMS AND CONDITIONS
|
622 |
+
|
623 |
+
How to Apply These Terms to Your New Programs
|
624 |
+
|
625 |
+
If you develop a new program, and you want it to be of the greatest
|
626 |
+
possible use to the public, the best way to achieve this is to make it
|
627 |
+
free software which everyone can redistribute and change under these terms.
|
628 |
+
|
629 |
+
To do so, attach the following notices to the program. It is safest
|
630 |
+
to attach them to the start of each source file to most effectively
|
631 |
+
state the exclusion of warranty; and each file should have at least
|
632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
633 |
+
|
634 |
+
<one line to give the program's name and a brief idea of what it does.>
|
635 |
+
Copyright (C) <year> <name of author>
|
636 |
+
|
637 |
+
This program is free software: you can redistribute it and/or modify
|
638 |
+
it under the terms of the GNU General Public License as published by
|
639 |
+
the Free Software Foundation, either version 3 of the License, or
|
640 |
+
(at your option) any later version.
|
641 |
+
|
642 |
+
This program is distributed in the hope that it will be useful,
|
643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
645 |
+
GNU General Public License for more details.
|
646 |
+
|
647 |
+
You should have received a copy of the GNU General Public License
|
648 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
649 |
+
|
650 |
+
Also add information on how to contact you by electronic and paper mail.
|
651 |
+
|
652 |
+
If the program does terminal interaction, make it output a short
|
653 |
+
notice like this when it starts in an interactive mode:
|
654 |
+
|
655 |
+
<program> Copyright (C) <year> <name of author>
|
656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
657 |
+
This is free software, and you are welcome to redistribute it
|
658 |
+
under certain conditions; type `show c' for details.
|
659 |
+
|
660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
661 |
+
parts of the General Public License. Of course, your program's commands
|
662 |
+
might be different; for a GUI interface, you would use an "about box".
|
663 |
+
|
664 |
+
You should also get your employer (if you work as a programmer) or school,
|
665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
667 |
+
<http://www.gnu.org/licenses/>.
|
668 |
+
|
669 |
+
The GNU General Public License does not permit incorporating your program
|
670 |
+
into proprietary programs. If your program is a subroutine library, you
|
671 |
+
may consider it more useful to permit linking proprietary applications with
|
672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
673 |
+
Public License instead of this License. But first, please read
|
674 |
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
cc-multilingual-main/cc_net/third_party/kenlm/MANIFEST.in
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# file GENERATED by distutils, do NOT edit
|
2 |
+
include setup.py
|
3 |
+
include lm/*.cc
|
4 |
+
include lm/*.hh
|
5 |
+
include python/*.cpp
|
6 |
+
include util/*.cc
|
7 |
+
include util/*.hh
|
8 |
+
include util/double-conversion/*.cc
|
9 |
+
include util/double-conversion/*.h
|
cc-multilingual-main/cc_net/third_party/kenlm/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# kenlm
|
2 |
+
|
3 |
+
Language model inference code by Kenneth Heafield (kenlm at kheafield.com)
|
4 |
+
|
5 |
+
The website https://kheafield.com/code/kenlm/ has more documentation. If you're a decoder developer, please download the latest version from there instead of copying from another decoder.
|
6 |
+
|
7 |
+
## Compiling
|
8 |
+
Use cmake, see [BUILDING](BUILDING) for build dependencies and more detail.
|
9 |
+
```bash
|
10 |
+
mkdir -p build
|
11 |
+
cd build
|
12 |
+
cmake ..
|
13 |
+
make -j 4
|
14 |
+
```
|
15 |
+
|
16 |
+
## Compiling with your own build system
|
17 |
+
If you want to compile with your own build system (Makefile etc) or to use as a library, there are a number of macros you can set on the g++ command line or in util/have.hh .
|
18 |
+
|
19 |
+
* `KENLM_MAX_ORDER` is the maximum order that can be loaded. This is done to make state an efficient POD rather than a vector.
|
20 |
+
* `HAVE_ICU` If your code links against ICU, define this to disable the internal StringPiece and replace it with ICU's copy of StringPiece, avoiding naming conflicts.
|
21 |
+
|
22 |
+
ARPA files can be read in compressed format with these options:
|
23 |
+
* `HAVE_ZLIB` Supports gzip. Link with -lz.
|
24 |
+
* `HAVE_BZLIB` Supports bzip2. Link with -lbz2.
|
25 |
+
* `HAVE_XZLIB` Supports xz. Link with -llzma.
|
26 |
+
|
27 |
+
Note that these macros impact only `read_compressed.cc` and `read_compressed_test.cc`. The bjam build system will auto-detect bzip2 and xz support.
|
28 |
+
|
29 |
+
## Estimation
|
30 |
+
lmplz estimates unpruned language models with modified Kneser-Ney smoothing. After compiling with bjam, run
|
31 |
+
```bash
|
32 |
+
bin/lmplz -o 5 <text >text.arpa
|
33 |
+
```
|
34 |
+
The algorithm is on-disk, using an amount of memory that you specify. See https://kheafield.com/code/kenlm/estimation/ for more.
|
35 |
+
|
36 |
+
MT Marathon 2012 team members Ivan Pouzyrevsky and Mohammed Mediani contributed to the computation design and early implementation. Jon Clark contributed to the design, clarified points about smoothing, and added logging.
|
37 |
+
|
38 |
+
## Filtering
|
39 |
+
|
40 |
+
filter takes an ARPA or count file and removes entries that will never be queried. The filter criterion can be corpus-level vocabulary, sentence-level vocabulary, or sentence-level phrases. Run
|
41 |
+
```bash
|
42 |
+
bin/filter
|
43 |
+
```
|
44 |
+
and see https://kheafield.com/code/kenlm/filter/ for more documentation.
|
45 |
+
|
46 |
+
## Querying
|
47 |
+
|
48 |
+
Two data structures are supported: probing and trie. Probing is a probing hash table with keys that are 64-bit hashes of n-grams and floats as values. Trie is a fairly standard trie but with bit-level packing so it uses the minimum number of bits to store word indices and pointers. The trie node entries are sorted by word index. Probing is the fastest and uses the most memory. Trie uses the least memory and is a bit slower.
|
49 |
+
|
50 |
+
As is the custom in language modeling, all probabilities are log base 10.
|
51 |
+
|
52 |
+
With trie, resident memory is 58% of IRST's smallest version and 21% of SRI's compact version. Simultaneously, trie CPU's use is 81% of IRST's fastest version and 84% of SRI's fast version. KenLM's probing hash table implementation goes even faster at the expense of using more memory. See https://kheafield.com/code/kenlm/benchmark/.
|
53 |
+
|
54 |
+
Binary format via mmap is supported. Run `./build_binary` to make one then pass the binary file name to the appropriate Model constructor.
|
55 |
+
|
56 |
+
## Platforms
|
57 |
+
`murmur_hash.cc` and `bit_packing.hh` perform unaligned reads and writes that make the code architecture-dependent.
|
58 |
+
It has been sucessfully tested on x86\_64, x86, and PPC64.
|
59 |
+
ARM support is reportedly working, at least on the iphone.
|
60 |
+
|
61 |
+
Runs on Linux, OS X, Cygwin, and MinGW.
|
62 |
+
|
63 |
+
Hideo Okuma and Tomoyuki Yoshimura from NICT contributed ports to ARM and MinGW.
|
64 |
+
|
65 |
+
## Decoder developers
|
66 |
+
- I recommend copying the code and distributing it with your decoder. However, please send improvements upstream.
|
67 |
+
|
68 |
+
- It's possible to compile the query-only code without Boost, but useful things like estimating models require Boost.
|
69 |
+
|
70 |
+
- Select the macros you want, listed in the previous section.
|
71 |
+
|
72 |
+
- There are two build systems: compile.sh and cmake. They're pretty simple and are intended to be reimplemented in your build system.
|
73 |
+
|
74 |
+
- Use either the interface in `lm/model.hh` or `lm/virtual_interface.hh`. Interface documentation is in comments of `lm/virtual_interface.hh` and `lm/model.hh`.
|
75 |
+
|
76 |
+
- There are several possible data structures in `model.hh`. Use `RecognizeBinary` in `binary_format.hh` to determine which one a user has provided. You probably already implement feature functions as an abstract virtual base class with several children. I suggest you co-opt this existing virtual dispatch by templatizing the language model feature implementation on the KenLM model identified by `RecognizeBinary`. This is the strategy used in Moses and cdec.
|
77 |
+
|
78 |
+
- See `lm/config.hh` for run-time tuning options.
|
79 |
+
|
80 |
+
## Contributors
|
81 |
+
Contributions to KenLM are welcome. Please base your contributions on https://github.com/kpu/kenlm and send pull requests (or I might give you commit access). Downstream copies in Moses and cdec are maintained by overwriting them so do not make changes there.
|
82 |
+
|
83 |
+
## Python module
|
84 |
+
Contributed by Victor Chahuneau.
|
85 |
+
|
86 |
+
### Installation
|
87 |
+
|
88 |
+
```bash
|
89 |
+
pip install https://github.com/kpu/kenlm/archive/master.zip
|
90 |
+
```
|
91 |
+
|
92 |
+
### Basic Usage
|
93 |
+
```python
|
94 |
+
import kenlm
|
95 |
+
model = kenlm.Model('lm/test.arpa')
|
96 |
+
print(model.score('this is a sentence .', bos = True, eos = True))
|
97 |
+
```
|
98 |
+
See [python/example.py](python/example.py) and [python/kenlm.pyx](python/kenlm.pyx) for more, including stateful APIs.
|
99 |
+
|
100 |
+
---
|
101 |
+
|
102 |
+
The name was Hieu Hoang's idea, not mine.
|
cc-multilingual-main/cc_net/third_party/kenlm/build/CMakeCache.txt
ADDED
@@ -0,0 +1,511 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This is the CMakeCache file.
|
2 |
+
# For build in directory: /home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build
|
3 |
+
# It was generated by CMake: /usr/bin/cmake
|
4 |
+
# You can edit this file to change values found and used by cmake.
|
5 |
+
# If you do not want to change any of the values, simply exit the editor.
|
6 |
+
# If you do want to change a value, simply edit, save, and exit the editor.
|
7 |
+
# The syntax for the file is as follows:
|
8 |
+
# KEY:TYPE=VALUE
|
9 |
+
# KEY is the name of a variable in the cache.
|
10 |
+
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.
|
11 |
+
# VALUE is the current value for the KEY.
|
12 |
+
|
13 |
+
########################
|
14 |
+
# EXTERNAL cache entries
|
15 |
+
########################
|
16 |
+
|
17 |
+
//Path to a file.
|
18 |
+
BZIP2_INCLUDE_DIR:PATH=/usr/include
|
19 |
+
|
20 |
+
//Path to a library.
|
21 |
+
BZIP2_LIBRARY_DEBUG:FILEPATH=BZIP2_LIBRARY_DEBUG-NOTFOUND
|
22 |
+
|
23 |
+
//Path to a library.
|
24 |
+
BZIP2_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libbz2.so
|
25 |
+
|
26 |
+
//The directory containing a CMake configuration file for Boost.
|
27 |
+
Boost_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0
|
28 |
+
|
29 |
+
//Path to a file.
|
30 |
+
Boost_INCLUDE_DIR:PATH=/usr/include
|
31 |
+
|
32 |
+
Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE:STRING=/usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.74.0
|
33 |
+
|
34 |
+
Boost_SYSTEM_LIBRARY_RELEASE:STRING=/usr/lib/x86_64-linux-gnu/libboost_system.so.1.74.0
|
35 |
+
|
36 |
+
Boost_THREAD_LIBRARY_RELEASE:STRING=/usr/lib/x86_64-linux-gnu/libboost_thread.so.1.74.0
|
37 |
+
|
38 |
+
Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE:STRING=/usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0
|
39 |
+
|
40 |
+
//Path to a program.
|
41 |
+
CMAKE_ADDR2LINE:FILEPATH=/usr/bin/addr2line
|
42 |
+
|
43 |
+
//Path to a program.
|
44 |
+
CMAKE_AR:FILEPATH=/usr/bin/ar
|
45 |
+
|
46 |
+
//Choose the type of build, options are: None Debug Release RelWithDebInfo
|
47 |
+
// MinSizeRel ...
|
48 |
+
CMAKE_BUILD_TYPE:STRING=
|
49 |
+
|
50 |
+
//Enable/Disable color output during build.
|
51 |
+
CMAKE_COLOR_MAKEFILE:BOOL=ON
|
52 |
+
|
53 |
+
//CXX compiler
|
54 |
+
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++
|
55 |
+
|
56 |
+
//A wrapper around 'ar' adding the appropriate '--plugin' option
|
57 |
+
// for the GCC compiler
|
58 |
+
CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-11
|
59 |
+
|
60 |
+
//A wrapper around 'ranlib' adding the appropriate '--plugin' option
|
61 |
+
// for the GCC compiler
|
62 |
+
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-11
|
63 |
+
|
64 |
+
//Flags used by the CXX compiler during all build types.
|
65 |
+
CMAKE_CXX_FLAGS:STRING=
|
66 |
+
|
67 |
+
//Flags used by the CXX compiler during DEBUG builds.
|
68 |
+
CMAKE_CXX_FLAGS_DEBUG:STRING=-g
|
69 |
+
|
70 |
+
//Flags used by the CXX compiler during MINSIZEREL builds.
|
71 |
+
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
|
72 |
+
|
73 |
+
//Flags used by the CXX compiler during RELEASE builds.
|
74 |
+
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
|
75 |
+
|
76 |
+
//Flags used by the CXX compiler during RELWITHDEBINFO builds.
|
77 |
+
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
|
78 |
+
|
79 |
+
//C compiler
|
80 |
+
CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc
|
81 |
+
|
82 |
+
//A wrapper around 'ar' adding the appropriate '--plugin' option
|
83 |
+
// for the GCC compiler
|
84 |
+
CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-11
|
85 |
+
|
86 |
+
//A wrapper around 'ranlib' adding the appropriate '--plugin' option
|
87 |
+
// for the GCC compiler
|
88 |
+
CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-11
|
89 |
+
|
90 |
+
//Flags used by the C compiler during all build types.
|
91 |
+
CMAKE_C_FLAGS:STRING=
|
92 |
+
|
93 |
+
//Flags used by the C compiler during DEBUG builds.
|
94 |
+
CMAKE_C_FLAGS_DEBUG:STRING=-g
|
95 |
+
|
96 |
+
//Flags used by the C compiler during MINSIZEREL builds.
|
97 |
+
CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
|
98 |
+
|
99 |
+
//Flags used by the C compiler during RELEASE builds.
|
100 |
+
CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
|
101 |
+
|
102 |
+
//Flags used by the C compiler during RELWITHDEBINFO builds.
|
103 |
+
CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
|
104 |
+
|
105 |
+
//Path to a program.
|
106 |
+
CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND
|
107 |
+
|
108 |
+
//Flags used by the linker during all build types.
|
109 |
+
CMAKE_EXE_LINKER_FLAGS:STRING=
|
110 |
+
|
111 |
+
//Flags used by the linker during DEBUG builds.
|
112 |
+
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=
|
113 |
+
|
114 |
+
//Flags used by the linker during MINSIZEREL builds.
|
115 |
+
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=
|
116 |
+
|
117 |
+
//Flags used by the linker during RELEASE builds.
|
118 |
+
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=
|
119 |
+
|
120 |
+
//Flags used by the linker during RELWITHDEBINFO builds.
|
121 |
+
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
|
122 |
+
|
123 |
+
//Enable/Disable output of compile commands during generation.
|
124 |
+
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=
|
125 |
+
|
126 |
+
//Install path prefix, prepended onto install directories.
|
127 |
+
CMAKE_INSTALL_PREFIX:PATH=/usr/local
|
128 |
+
|
129 |
+
//Path to a program.
|
130 |
+
CMAKE_LINKER:FILEPATH=/usr/bin/ld
|
131 |
+
|
132 |
+
//Path to a program.
|
133 |
+
CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/gmake
|
134 |
+
|
135 |
+
//Flags used by the linker during the creation of modules during
|
136 |
+
// all build types.
|
137 |
+
CMAKE_MODULE_LINKER_FLAGS:STRING=
|
138 |
+
|
139 |
+
//Flags used by the linker during the creation of modules during
|
140 |
+
// DEBUG builds.
|
141 |
+
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=
|
142 |
+
|
143 |
+
//Flags used by the linker during the creation of modules during
|
144 |
+
// MINSIZEREL builds.
|
145 |
+
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=
|
146 |
+
|
147 |
+
//Flags used by the linker during the creation of modules during
|
148 |
+
// RELEASE builds.
|
149 |
+
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=
|
150 |
+
|
151 |
+
//Flags used by the linker during the creation of modules during
|
152 |
+
// RELWITHDEBINFO builds.
|
153 |
+
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
|
154 |
+
|
155 |
+
//Path to a program.
|
156 |
+
CMAKE_NM:FILEPATH=/usr/bin/nm
|
157 |
+
|
158 |
+
//Path to a program.
|
159 |
+
CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy
|
160 |
+
|
161 |
+
//Path to a program.
|
162 |
+
CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump
|
163 |
+
|
164 |
+
//Value Computed by CMake
|
165 |
+
CMAKE_PROJECT_DESCRIPTION:STATIC=
|
166 |
+
|
167 |
+
//Value Computed by CMake
|
168 |
+
CMAKE_PROJECT_HOMEPAGE_URL:STATIC=
|
169 |
+
|
170 |
+
//Value Computed by CMake
|
171 |
+
CMAKE_PROJECT_NAME:STATIC=kenlm
|
172 |
+
|
173 |
+
//Path to a program.
|
174 |
+
CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib
|
175 |
+
|
176 |
+
//Path to a program.
|
177 |
+
CMAKE_READELF:FILEPATH=/usr/bin/readelf
|
178 |
+
|
179 |
+
//Flags used by the linker during the creation of shared libraries
|
180 |
+
// during all build types.
|
181 |
+
CMAKE_SHARED_LINKER_FLAGS:STRING=
|
182 |
+
|
183 |
+
//Flags used by the linker during the creation of shared libraries
|
184 |
+
// during DEBUG builds.
|
185 |
+
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=
|
186 |
+
|
187 |
+
//Flags used by the linker during the creation of shared libraries
|
188 |
+
// during MINSIZEREL builds.
|
189 |
+
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=
|
190 |
+
|
191 |
+
//Flags used by the linker during the creation of shared libraries
|
192 |
+
// during RELEASE builds.
|
193 |
+
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=
|
194 |
+
|
195 |
+
//Flags used by the linker during the creation of shared libraries
|
196 |
+
// during RELWITHDEBINFO builds.
|
197 |
+
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=
|
198 |
+
|
199 |
+
//If set, runtime paths are not added when installing shared libraries,
|
200 |
+
// but are added when building.
|
201 |
+
CMAKE_SKIP_INSTALL_RPATH:BOOL=NO
|
202 |
+
|
203 |
+
//If set, runtime paths are not added when using shared libraries.
|
204 |
+
CMAKE_SKIP_RPATH:BOOL=NO
|
205 |
+
|
206 |
+
//Flags used by the linker during the creation of static libraries
|
207 |
+
// during all build types.
|
208 |
+
CMAKE_STATIC_LINKER_FLAGS:STRING=
|
209 |
+
|
210 |
+
//Flags used by the linker during the creation of static libraries
|
211 |
+
// during DEBUG builds.
|
212 |
+
CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING=
|
213 |
+
|
214 |
+
//Flags used by the linker during the creation of static libraries
|
215 |
+
// during MINSIZEREL builds.
|
216 |
+
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING=
|
217 |
+
|
218 |
+
//Flags used by the linker during the creation of static libraries
|
219 |
+
// during RELEASE builds.
|
220 |
+
CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING=
|
221 |
+
|
222 |
+
//Flags used by the linker during the creation of static libraries
|
223 |
+
// during RELWITHDEBINFO builds.
|
224 |
+
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=
|
225 |
+
|
226 |
+
//Path to a program.
|
227 |
+
CMAKE_STRIP:FILEPATH=/usr/bin/strip
|
228 |
+
|
229 |
+
//If this value is on, makefiles will be generated without the
|
230 |
+
// .SILENT directive, and all commands will be echoed to the console
|
231 |
+
// during the make. This is useful for debugging only. With Visual
|
232 |
+
// Studio IDE projects all commands are done without /nologo.
|
233 |
+
CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
|
234 |
+
|
235 |
+
//Compile tests
|
236 |
+
COMPILE_TESTS:BOOL=OFF
|
237 |
+
|
238 |
+
//Build Python bindings
|
239 |
+
ENABLE_PYTHON:BOOL=OFF
|
240 |
+
|
241 |
+
//The directory containing a CMake configuration file for Eigen3.
|
242 |
+
Eigen3_DIR:PATH=Eigen3_DIR-NOTFOUND
|
243 |
+
|
244 |
+
//Build static executables
|
245 |
+
FORCE_STATIC:BOOL=OFF
|
246 |
+
|
247 |
+
//Maximum supported ngram order
|
248 |
+
KENLM_MAX_ORDER:STRING=6
|
249 |
+
|
250 |
+
//Path to a file.
|
251 |
+
LIBLZMA_INCLUDE_DIR:PATH=/usr/include
|
252 |
+
|
253 |
+
//Path to a library.
|
254 |
+
LIBLZMA_LIBRARY_DEBUG:FILEPATH=LIBLZMA_LIBRARY_DEBUG-NOTFOUND
|
255 |
+
|
256 |
+
//Path to a library.
|
257 |
+
LIBLZMA_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/liblzma.so
|
258 |
+
|
259 |
+
//Path to a file.
|
260 |
+
ZLIB_INCLUDE_DIR:PATH=/usr/include
|
261 |
+
|
262 |
+
//Path to a library.
|
263 |
+
ZLIB_LIBRARY_DEBUG:FILEPATH=ZLIB_LIBRARY_DEBUG-NOTFOUND
|
264 |
+
|
265 |
+
//Path to a library.
|
266 |
+
ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libz.so
|
267 |
+
|
268 |
+
//The directory containing a CMake configuration file for boost_atomic.
|
269 |
+
boost_atomic_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/boost_atomic-1.74.0
|
270 |
+
|
271 |
+
//The directory containing a CMake configuration file for boost_headers.
|
272 |
+
boost_headers_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/boost_headers-1.74.0
|
273 |
+
|
274 |
+
//The directory containing a CMake configuration file for boost_program_options.
|
275 |
+
boost_program_options_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/boost_program_options-1.74.0
|
276 |
+
|
277 |
+
//The directory containing a CMake configuration file for boost_system.
|
278 |
+
boost_system_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/boost_system-1.74.0
|
279 |
+
|
280 |
+
//The directory containing a CMake configuration file for boost_thread.
|
281 |
+
boost_thread_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/boost_thread-1.74.0
|
282 |
+
|
283 |
+
//The directory containing a CMake configuration file for boost_unit_test_framework.
|
284 |
+
boost_unit_test_framework_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/boost_unit_test_framework-1.74.0
|
285 |
+
|
286 |
+
//Value Computed by CMake
|
287 |
+
kenlm_BINARY_DIR:STATIC=/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build
|
288 |
+
|
289 |
+
//Value Computed by CMake
|
290 |
+
kenlm_IS_TOP_LEVEL:STATIC=ON
|
291 |
+
|
292 |
+
//Dependencies for the target
|
293 |
+
kenlm_LIB_DEPENDS:STATIC=general;kenlm_util;
|
294 |
+
|
295 |
+
//Value Computed by CMake
|
296 |
+
kenlm_SOURCE_DIR:STATIC=/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm
|
297 |
+
|
298 |
+
//Dependencies for the target
|
299 |
+
kenlm_builder_LIB_DEPENDS:STATIC=general;kenlm;general;kenlm_util;
|
300 |
+
|
301 |
+
//Dependencies for the target
|
302 |
+
kenlm_filter_LIB_DEPENDS:STATIC=general;kenlm_util;
|
303 |
+
|
304 |
+
//Dependencies for the target
|
305 |
+
kenlm_util_LIB_DEPENDS:STATIC=general;/usr/lib/x86_64-linux-gnu/libz.so;general;/usr/lib/x86_64-linux-gnu/libbz2.so;general;/usr/lib/x86_64-linux-gnu/liblzma.so;general;rt;
|
306 |
+
|
307 |
+
|
308 |
+
########################
|
309 |
+
# INTERNAL cache entries
|
310 |
+
########################
|
311 |
+
|
312 |
+
//ADVANCED property for variable: BZIP2_INCLUDE_DIR
|
313 |
+
BZIP2_INCLUDE_DIR-ADVANCED:INTERNAL=1
|
314 |
+
//ADVANCED property for variable: BZIP2_LIBRARY_DEBUG
|
315 |
+
BZIP2_LIBRARY_DEBUG-ADVANCED:INTERNAL=1
|
316 |
+
//ADVANCED property for variable: BZIP2_LIBRARY_RELEASE
|
317 |
+
BZIP2_LIBRARY_RELEASE-ADVANCED:INTERNAL=1
|
318 |
+
//Have symbol BZ2_bzCompressInit
|
319 |
+
BZIP2_NEED_PREFIX:INTERNAL=1
|
320 |
+
//ADVANCED property for variable: Boost_DIR
|
321 |
+
Boost_DIR-ADVANCED:INTERNAL=1
|
322 |
+
//ADVANCED property for variable: CMAKE_ADDR2LINE
|
323 |
+
CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1
|
324 |
+
//ADVANCED property for variable: CMAKE_AR
|
325 |
+
CMAKE_AR-ADVANCED:INTERNAL=1
|
326 |
+
//This is the directory where this CMakeCache.txt was created
|
327 |
+
CMAKE_CACHEFILE_DIR:INTERNAL=/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build
|
328 |
+
//Major version of cmake used to create the current loaded cache
|
329 |
+
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
|
330 |
+
//Minor version of cmake used to create the current loaded cache
|
331 |
+
CMAKE_CACHE_MINOR_VERSION:INTERNAL=22
|
332 |
+
//Patch version of cmake used to create the current loaded cache
|
333 |
+
CMAKE_CACHE_PATCH_VERSION:INTERNAL=1
|
334 |
+
//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
|
335 |
+
CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
|
336 |
+
//Path to CMake executable.
|
337 |
+
CMAKE_COMMAND:INTERNAL=/usr/bin/cmake
|
338 |
+
//Path to cpack program executable.
|
339 |
+
CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack
|
340 |
+
//Path to ctest program executable.
|
341 |
+
CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest
|
342 |
+
//ADVANCED property for variable: CMAKE_CXX_COMPILER
|
343 |
+
CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1
|
344 |
+
//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR
|
345 |
+
CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1
|
346 |
+
//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB
|
347 |
+
CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1
|
348 |
+
//ADVANCED property for variable: CMAKE_CXX_FLAGS
|
349 |
+
CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1
|
350 |
+
//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG
|
351 |
+
CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
352 |
+
//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL
|
353 |
+
CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
354 |
+
//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE
|
355 |
+
CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
356 |
+
//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
357 |
+
CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
358 |
+
//ADVANCED property for variable: CMAKE_C_COMPILER
|
359 |
+
CMAKE_C_COMPILER-ADVANCED:INTERNAL=1
|
360 |
+
//ADVANCED property for variable: CMAKE_C_COMPILER_AR
|
361 |
+
CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1
|
362 |
+
//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB
|
363 |
+
CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1
|
364 |
+
//ADVANCED property for variable: CMAKE_C_FLAGS
|
365 |
+
CMAKE_C_FLAGS-ADVANCED:INTERNAL=1
|
366 |
+
//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG
|
367 |
+
CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
368 |
+
//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL
|
369 |
+
CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
370 |
+
//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE
|
371 |
+
CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
372 |
+
//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO
|
373 |
+
CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
374 |
+
//ADVANCED property for variable: CMAKE_DLLTOOL
|
375 |
+
CMAKE_DLLTOOL-ADVANCED:INTERNAL=1
|
376 |
+
//Executable file format
|
377 |
+
CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF
|
378 |
+
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS
|
379 |
+
CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
380 |
+
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG
|
381 |
+
CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
382 |
+
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
|
383 |
+
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
384 |
+
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE
|
385 |
+
CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
386 |
+
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
|
387 |
+
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
388 |
+
//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS
|
389 |
+
CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1
|
390 |
+
//Name of external makefile project generator.
|
391 |
+
CMAKE_EXTRA_GENERATOR:INTERNAL=
|
392 |
+
//Name of generator.
|
393 |
+
CMAKE_GENERATOR:INTERNAL=Unix Makefiles
|
394 |
+
//Generator instance identifier.
|
395 |
+
CMAKE_GENERATOR_INSTANCE:INTERNAL=
|
396 |
+
//Name of generator platform.
|
397 |
+
CMAKE_GENERATOR_PLATFORM:INTERNAL=
|
398 |
+
//Name of generator toolset.
|
399 |
+
CMAKE_GENERATOR_TOOLSET:INTERNAL=
|
400 |
+
//Test CMAKE_HAVE_LIBC_PTHREAD
|
401 |
+
CMAKE_HAVE_LIBC_PTHREAD:INTERNAL=1
|
402 |
+
//Have include pthread.h
|
403 |
+
CMAKE_HAVE_PTHREAD_H:INTERNAL=1
|
404 |
+
//Source directory with the top level CMakeLists.txt file for this
|
405 |
+
// project
|
406 |
+
CMAKE_HOME_DIRECTORY:INTERNAL=/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm
|
407 |
+
//Install .so files without execute permission.
|
408 |
+
CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1
|
409 |
+
//ADVANCED property for variable: CMAKE_LINKER
|
410 |
+
CMAKE_LINKER-ADVANCED:INTERNAL=1
|
411 |
+
//ADVANCED property for variable: CMAKE_MAKE_PROGRAM
|
412 |
+
CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1
|
413 |
+
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS
|
414 |
+
CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
415 |
+
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG
|
416 |
+
CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
417 |
+
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL
|
418 |
+
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
419 |
+
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE
|
420 |
+
CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
421 |
+
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
|
422 |
+
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
423 |
+
//ADVANCED property for variable: CMAKE_NM
|
424 |
+
CMAKE_NM-ADVANCED:INTERNAL=1
|
425 |
+
//number of local generators
|
426 |
+
CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=9
|
427 |
+
//ADVANCED property for variable: CMAKE_OBJCOPY
|
428 |
+
CMAKE_OBJCOPY-ADVANCED:INTERNAL=1
|
429 |
+
//ADVANCED property for variable: CMAKE_OBJDUMP
|
430 |
+
CMAKE_OBJDUMP-ADVANCED:INTERNAL=1
|
431 |
+
//Platform information initialized
|
432 |
+
CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1
|
433 |
+
//ADVANCED property for variable: CMAKE_RANLIB
|
434 |
+
CMAKE_RANLIB-ADVANCED:INTERNAL=1
|
435 |
+
//ADVANCED property for variable: CMAKE_READELF
|
436 |
+
CMAKE_READELF-ADVANCED:INTERNAL=1
|
437 |
+
//Path to CMake installation.
|
438 |
+
CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.22
|
439 |
+
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
|
440 |
+
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
441 |
+
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG
|
442 |
+
CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
443 |
+
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
|
444 |
+
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
445 |
+
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE
|
446 |
+
CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
447 |
+
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
|
448 |
+
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
449 |
+
//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH
|
450 |
+
CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1
|
451 |
+
//ADVANCED property for variable: CMAKE_SKIP_RPATH
|
452 |
+
CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1
|
453 |
+
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS
|
454 |
+
CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
455 |
+
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG
|
456 |
+
CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
457 |
+
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL
|
458 |
+
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
459 |
+
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE
|
460 |
+
CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
461 |
+
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO
|
462 |
+
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
463 |
+
//ADVANCED property for variable: CMAKE_STRIP
|
464 |
+
CMAKE_STRIP-ADVANCED:INTERNAL=1
|
465 |
+
//uname command
|
466 |
+
CMAKE_UNAME:INTERNAL=/usr/bin/uname
|
467 |
+
//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE
|
468 |
+
CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1
|
469 |
+
//Details about finding BZip2
|
470 |
+
FIND_PACKAGE_MESSAGE_DETAILS_BZip2:INTERNAL=[/usr/lib/x86_64-linux-gnu/libbz2.so][/usr/include][v1.0.8()]
|
471 |
+
//Details about finding Boost
|
472 |
+
FIND_PACKAGE_MESSAGE_DETAILS_Boost:INTERNAL=[/usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake][cfound components: program_options system thread unit_test_framework ][v1.74.0(1.41.0)]
|
473 |
+
//Details about finding LibLZMA
|
474 |
+
FIND_PACKAGE_MESSAGE_DETAILS_LibLZMA:INTERNAL=[/usr/lib/x86_64-linux-gnu/liblzma.so][/usr/include][1][1][1][v5.2.5()]
|
475 |
+
//Details about finding Threads
|
476 |
+
FIND_PACKAGE_MESSAGE_DETAILS_Threads:INTERNAL=[TRUE][v()]
|
477 |
+
//Details about finding ZLIB
|
478 |
+
FIND_PACKAGE_MESSAGE_DETAILS_ZLIB:INTERNAL=[/usr/lib/x86_64-linux-gnu/libz.so][/usr/include][v1.2.11()]
|
479 |
+
//Have library rt
|
480 |
+
HAVE_CLOCKGETTIME_RT:INTERNAL=1
|
481 |
+
//Have library /usr/lib/x86_64-linux-gnu/liblzma.so
|
482 |
+
LIBLZMA_HAS_AUTO_DECODER:INTERNAL=1
|
483 |
+
//Have library /usr/lib/x86_64-linux-gnu/liblzma.so
|
484 |
+
LIBLZMA_HAS_EASY_ENCODER:INTERNAL=1
|
485 |
+
//Have library /usr/lib/x86_64-linux-gnu/liblzma.so
|
486 |
+
LIBLZMA_HAS_LZMA_PRESET:INTERNAL=1
|
487 |
+
//ADVANCED property for variable: LIBLZMA_INCLUDE_DIR
|
488 |
+
LIBLZMA_INCLUDE_DIR-ADVANCED:INTERNAL=1
|
489 |
+
//ADVANCED property for variable: LIBLZMA_LIBRARY_DEBUG
|
490 |
+
LIBLZMA_LIBRARY_DEBUG-ADVANCED:INTERNAL=1
|
491 |
+
//ADVANCED property for variable: LIBLZMA_LIBRARY_RELEASE
|
492 |
+
LIBLZMA_LIBRARY_RELEASE-ADVANCED:INTERNAL=1
|
493 |
+
//ADVANCED property for variable: ZLIB_INCLUDE_DIR
|
494 |
+
ZLIB_INCLUDE_DIR-ADVANCED:INTERNAL=1
|
495 |
+
//ADVANCED property for variable: ZLIB_LIBRARY_DEBUG
|
496 |
+
ZLIB_LIBRARY_DEBUG-ADVANCED:INTERNAL=1
|
497 |
+
//ADVANCED property for variable: ZLIB_LIBRARY_RELEASE
|
498 |
+
ZLIB_LIBRARY_RELEASE-ADVANCED:INTERNAL=1
|
499 |
+
//ADVANCED property for variable: boost_atomic_DIR
|
500 |
+
boost_atomic_DIR-ADVANCED:INTERNAL=1
|
501 |
+
//ADVANCED property for variable: boost_headers_DIR
|
502 |
+
boost_headers_DIR-ADVANCED:INTERNAL=1
|
503 |
+
//ADVANCED property for variable: boost_program_options_DIR
|
504 |
+
boost_program_options_DIR-ADVANCED:INTERNAL=1
|
505 |
+
//ADVANCED property for variable: boost_system_DIR
|
506 |
+
boost_system_DIR-ADVANCED:INTERNAL=1
|
507 |
+
//ADVANCED property for variable: boost_thread_DIR
|
508 |
+
boost_thread_DIR-ADVANCED:INTERNAL=1
|
509 |
+
//ADVANCED property for variable: boost_unit_test_framework_DIR
|
510 |
+
boost_unit_test_framework_DIR-ADVANCED:INTERNAL=1
|
511 |
+
|
cc-multilingual-main/cc_net/third_party/kenlm/build/Makefile
ADDED
@@ -0,0 +1,371 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# CMAKE generated file: DO NOT EDIT!
|
2 |
+
# Generated by "Unix Makefiles" Generator, CMake Version 3.22
|
3 |
+
|
4 |
+
# Default target executed when no arguments are given to make.
|
5 |
+
default_target: all
|
6 |
+
.PHONY : default_target
|
7 |
+
|
8 |
+
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
|
9 |
+
.NOTPARALLEL:
|
10 |
+
|
11 |
+
#=============================================================================
|
12 |
+
# Special targets provided by cmake.
|
13 |
+
|
14 |
+
# Disable implicit rules so canonical targets will work.
|
15 |
+
.SUFFIXES:
|
16 |
+
|
17 |
+
# Disable VCS-based implicit rules.
|
18 |
+
% : %,v
|
19 |
+
|
20 |
+
# Disable VCS-based implicit rules.
|
21 |
+
% : RCS/%
|
22 |
+
|
23 |
+
# Disable VCS-based implicit rules.
|
24 |
+
% : RCS/%,v
|
25 |
+
|
26 |
+
# Disable VCS-based implicit rules.
|
27 |
+
% : SCCS/s.%
|
28 |
+
|
29 |
+
# Disable VCS-based implicit rules.
|
30 |
+
% : s.%
|
31 |
+
|
32 |
+
.SUFFIXES: .hpux_make_needs_suffix_list
|
33 |
+
|
34 |
+
# Command-line flag to silence nested $(MAKE).
|
35 |
+
$(VERBOSE)MAKESILENT = -s
|
36 |
+
|
37 |
+
#Suppress display of executed commands.
|
38 |
+
$(VERBOSE).SILENT:
|
39 |
+
|
40 |
+
# A target that is always out of date.
|
41 |
+
cmake_force:
|
42 |
+
.PHONY : cmake_force
|
43 |
+
|
44 |
+
#=============================================================================
|
45 |
+
# Set environment variables for the build.
|
46 |
+
|
47 |
+
# The shell in which to execute make rules.
|
48 |
+
SHELL = /bin/sh
|
49 |
+
|
50 |
+
# The CMake executable.
|
51 |
+
CMAKE_COMMAND = /usr/bin/cmake
|
52 |
+
|
53 |
+
# The command to remove a file.
|
54 |
+
RM = /usr/bin/cmake -E rm -f
|
55 |
+
|
56 |
+
# Escaping for special characters.
|
57 |
+
EQUALS = =
|
58 |
+
|
59 |
+
# The top-level source directory on which CMake was run.
|
60 |
+
CMAKE_SOURCE_DIR = /home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm
|
61 |
+
|
62 |
+
# The top-level build directory on which CMake was run.
|
63 |
+
CMAKE_BINARY_DIR = /home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build
|
64 |
+
|
65 |
+
#=============================================================================
|
66 |
+
# Targets provided globally by CMake.
|
67 |
+
|
68 |
+
# Special rule for the target edit_cache
|
69 |
+
edit_cache:
|
70 |
+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
|
71 |
+
/usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
|
72 |
+
.PHONY : edit_cache
|
73 |
+
|
74 |
+
# Special rule for the target edit_cache
|
75 |
+
edit_cache/fast: edit_cache
|
76 |
+
.PHONY : edit_cache/fast
|
77 |
+
|
78 |
+
# Special rule for the target rebuild_cache
|
79 |
+
rebuild_cache:
|
80 |
+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
|
81 |
+
/usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
|
82 |
+
.PHONY : rebuild_cache
|
83 |
+
|
84 |
+
# Special rule for the target rebuild_cache
|
85 |
+
rebuild_cache/fast: rebuild_cache
|
86 |
+
.PHONY : rebuild_cache/fast
|
87 |
+
|
88 |
+
# Special rule for the target list_install_components
|
89 |
+
list_install_components:
|
90 |
+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\" \"headers\""
|
91 |
+
.PHONY : list_install_components
|
92 |
+
|
93 |
+
# Special rule for the target list_install_components
|
94 |
+
list_install_components/fast: list_install_components
|
95 |
+
.PHONY : list_install_components/fast
|
96 |
+
|
97 |
+
# Special rule for the target install
|
98 |
+
install: preinstall
|
99 |
+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
|
100 |
+
/usr/bin/cmake -P cmake_install.cmake
|
101 |
+
.PHONY : install
|
102 |
+
|
103 |
+
# Special rule for the target install
|
104 |
+
install/fast: preinstall/fast
|
105 |
+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
|
106 |
+
/usr/bin/cmake -P cmake_install.cmake
|
107 |
+
.PHONY : install/fast
|
108 |
+
|
109 |
+
# Special rule for the target install/local
|
110 |
+
install/local: preinstall
|
111 |
+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
|
112 |
+
/usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
|
113 |
+
.PHONY : install/local
|
114 |
+
|
115 |
+
# Special rule for the target install/local
|
116 |
+
install/local/fast: preinstall/fast
|
117 |
+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
|
118 |
+
/usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
|
119 |
+
.PHONY : install/local/fast
|
120 |
+
|
121 |
+
# Special rule for the target install/strip
|
122 |
+
install/strip: preinstall
|
123 |
+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
|
124 |
+
/usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
|
125 |
+
.PHONY : install/strip
|
126 |
+
|
127 |
+
# Special rule for the target install/strip
|
128 |
+
install/strip/fast: preinstall/fast
|
129 |
+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
|
130 |
+
/usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
|
131 |
+
.PHONY : install/strip/fast
|
132 |
+
|
133 |
+
# The main all target
|
134 |
+
all: cmake_check_build_system
|
135 |
+
$(CMAKE_COMMAND) -E cmake_progress_start /home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build/CMakeFiles /home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build//CMakeFiles/progress.marks
|
136 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all
|
137 |
+
$(CMAKE_COMMAND) -E cmake_progress_start /home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build/CMakeFiles 0
|
138 |
+
.PHONY : all
|
139 |
+
|
140 |
+
# The main clean target
|
141 |
+
clean:
|
142 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean
|
143 |
+
.PHONY : clean
|
144 |
+
|
145 |
+
# The main clean target
|
146 |
+
clean/fast: clean
|
147 |
+
.PHONY : clean/fast
|
148 |
+
|
149 |
+
# Prepare targets for installation.
|
150 |
+
preinstall: all
|
151 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
|
152 |
+
.PHONY : preinstall
|
153 |
+
|
154 |
+
# Prepare targets for installation.
|
155 |
+
preinstall/fast:
|
156 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
|
157 |
+
.PHONY : preinstall/fast
|
158 |
+
|
159 |
+
# clear depends
|
160 |
+
depend:
|
161 |
+
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
|
162 |
+
.PHONY : depend
|
163 |
+
|
164 |
+
#=============================================================================
|
165 |
+
# Target rules for targets named kenlm_util
|
166 |
+
|
167 |
+
# Build rule for target.
|
168 |
+
kenlm_util: cmake_check_build_system
|
169 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 kenlm_util
|
170 |
+
.PHONY : kenlm_util
|
171 |
+
|
172 |
+
# fast build rule for target.
|
173 |
+
kenlm_util/fast:
|
174 |
+
$(MAKE) $(MAKESILENT) -f util/CMakeFiles/kenlm_util.dir/build.make util/CMakeFiles/kenlm_util.dir/build
|
175 |
+
.PHONY : kenlm_util/fast
|
176 |
+
|
177 |
+
#=============================================================================
|
178 |
+
# Target rules for targets named probing_hash_table_benchmark
|
179 |
+
|
180 |
+
# Build rule for target.
|
181 |
+
probing_hash_table_benchmark: cmake_check_build_system
|
182 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 probing_hash_table_benchmark
|
183 |
+
.PHONY : probing_hash_table_benchmark
|
184 |
+
|
185 |
+
# fast build rule for target.
|
186 |
+
probing_hash_table_benchmark/fast:
|
187 |
+
$(MAKE) $(MAKESILENT) -f util/CMakeFiles/probing_hash_table_benchmark.dir/build.make util/CMakeFiles/probing_hash_table_benchmark.dir/build
|
188 |
+
.PHONY : probing_hash_table_benchmark/fast
|
189 |
+
|
190 |
+
#=============================================================================
|
191 |
+
# Target rules for targets named kenlm
|
192 |
+
|
193 |
+
# Build rule for target.
|
194 |
+
kenlm: cmake_check_build_system
|
195 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 kenlm
|
196 |
+
.PHONY : kenlm
|
197 |
+
|
198 |
+
# fast build rule for target.
|
199 |
+
kenlm/fast:
|
200 |
+
$(MAKE) $(MAKESILENT) -f lm/CMakeFiles/kenlm.dir/build.make lm/CMakeFiles/kenlm.dir/build
|
201 |
+
.PHONY : kenlm/fast
|
202 |
+
|
203 |
+
#=============================================================================
|
204 |
+
# Target rules for targets named query
|
205 |
+
|
206 |
+
# Build rule for target.
|
207 |
+
query: cmake_check_build_system
|
208 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 query
|
209 |
+
.PHONY : query
|
210 |
+
|
211 |
+
# fast build rule for target.
|
212 |
+
query/fast:
|
213 |
+
$(MAKE) $(MAKESILENT) -f lm/CMakeFiles/query.dir/build.make lm/CMakeFiles/query.dir/build
|
214 |
+
.PHONY : query/fast
|
215 |
+
|
216 |
+
#=============================================================================
|
217 |
+
# Target rules for targets named fragment
|
218 |
+
|
219 |
+
# Build rule for target.
|
220 |
+
fragment: cmake_check_build_system
|
221 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 fragment
|
222 |
+
.PHONY : fragment
|
223 |
+
|
224 |
+
# fast build rule for target.
|
225 |
+
fragment/fast:
|
226 |
+
$(MAKE) $(MAKESILENT) -f lm/CMakeFiles/fragment.dir/build.make lm/CMakeFiles/fragment.dir/build
|
227 |
+
.PHONY : fragment/fast
|
228 |
+
|
229 |
+
#=============================================================================
|
230 |
+
# Target rules for targets named build_binary
|
231 |
+
|
232 |
+
# Build rule for target.
|
233 |
+
build_binary: cmake_check_build_system
|
234 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 build_binary
|
235 |
+
.PHONY : build_binary
|
236 |
+
|
237 |
+
# fast build rule for target.
|
238 |
+
build_binary/fast:
|
239 |
+
$(MAKE) $(MAKESILENT) -f lm/CMakeFiles/build_binary.dir/build.make lm/CMakeFiles/build_binary.dir/build
|
240 |
+
.PHONY : build_binary/fast
|
241 |
+
|
242 |
+
#=============================================================================
|
243 |
+
# Target rules for targets named kenlm_benchmark
|
244 |
+
|
245 |
+
# Build rule for target.
|
246 |
+
kenlm_benchmark: cmake_check_build_system
|
247 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 kenlm_benchmark
|
248 |
+
.PHONY : kenlm_benchmark
|
249 |
+
|
250 |
+
# fast build rule for target.
|
251 |
+
kenlm_benchmark/fast:
|
252 |
+
$(MAKE) $(MAKESILENT) -f lm/CMakeFiles/kenlm_benchmark.dir/build.make lm/CMakeFiles/kenlm_benchmark.dir/build
|
253 |
+
.PHONY : kenlm_benchmark/fast
|
254 |
+
|
255 |
+
#=============================================================================
|
256 |
+
# Target rules for targets named kenlm_builder
|
257 |
+
|
258 |
+
# Build rule for target.
|
259 |
+
kenlm_builder: cmake_check_build_system
|
260 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 kenlm_builder
|
261 |
+
.PHONY : kenlm_builder
|
262 |
+
|
263 |
+
# fast build rule for target.
|
264 |
+
kenlm_builder/fast:
|
265 |
+
$(MAKE) $(MAKESILENT) -f lm/builder/CMakeFiles/kenlm_builder.dir/build.make lm/builder/CMakeFiles/kenlm_builder.dir/build
|
266 |
+
.PHONY : kenlm_builder/fast
|
267 |
+
|
268 |
+
#=============================================================================
|
269 |
+
# Target rules for targets named lmplz
|
270 |
+
|
271 |
+
# Build rule for target.
|
272 |
+
lmplz: cmake_check_build_system
|
273 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 lmplz
|
274 |
+
.PHONY : lmplz
|
275 |
+
|
276 |
+
# fast build rule for target.
|
277 |
+
lmplz/fast:
|
278 |
+
$(MAKE) $(MAKESILENT) -f lm/builder/CMakeFiles/lmplz.dir/build.make lm/builder/CMakeFiles/lmplz.dir/build
|
279 |
+
.PHONY : lmplz/fast
|
280 |
+
|
281 |
+
#=============================================================================
|
282 |
+
# Target rules for targets named count_ngrams
|
283 |
+
|
284 |
+
# Build rule for target.
|
285 |
+
count_ngrams: cmake_check_build_system
|
286 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 count_ngrams
|
287 |
+
.PHONY : count_ngrams
|
288 |
+
|
289 |
+
# fast build rule for target.
|
290 |
+
count_ngrams/fast:
|
291 |
+
$(MAKE) $(MAKESILENT) -f lm/builder/CMakeFiles/count_ngrams.dir/build.make lm/builder/CMakeFiles/count_ngrams.dir/build
|
292 |
+
.PHONY : count_ngrams/fast
|
293 |
+
|
294 |
+
#=============================================================================
|
295 |
+
# Target rules for targets named kenlm_filter
|
296 |
+
|
297 |
+
# Build rule for target.
|
298 |
+
kenlm_filter: cmake_check_build_system
|
299 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 kenlm_filter
|
300 |
+
.PHONY : kenlm_filter
|
301 |
+
|
302 |
+
# fast build rule for target.
|
303 |
+
kenlm_filter/fast:
|
304 |
+
$(MAKE) $(MAKESILENT) -f lm/filter/CMakeFiles/kenlm_filter.dir/build.make lm/filter/CMakeFiles/kenlm_filter.dir/build
|
305 |
+
.PHONY : kenlm_filter/fast
|
306 |
+
|
307 |
+
#=============================================================================
|
308 |
+
# Target rules for targets named filter
|
309 |
+
|
310 |
+
# Build rule for target.
|
311 |
+
filter: cmake_check_build_system
|
312 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 filter
|
313 |
+
.PHONY : filter
|
314 |
+
|
315 |
+
# fast build rule for target.
|
316 |
+
filter/fast:
|
317 |
+
$(MAKE) $(MAKESILENT) -f lm/filter/CMakeFiles/filter.dir/build.make lm/filter/CMakeFiles/filter.dir/build
|
318 |
+
.PHONY : filter/fast
|
319 |
+
|
320 |
+
#=============================================================================
|
321 |
+
# Target rules for targets named phrase_table_vocab
|
322 |
+
|
323 |
+
# Build rule for target.
|
324 |
+
phrase_table_vocab: cmake_check_build_system
|
325 |
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 phrase_table_vocab
|
326 |
+
.PHONY : phrase_table_vocab
|
327 |
+
|
328 |
+
# fast build rule for target.
|
329 |
+
phrase_table_vocab/fast:
|
330 |
+
$(MAKE) $(MAKESILENT) -f lm/filter/CMakeFiles/phrase_table_vocab.dir/build.make lm/filter/CMakeFiles/phrase_table_vocab.dir/build
|
331 |
+
.PHONY : phrase_table_vocab/fast
|
332 |
+
|
333 |
+
# Help Target
|
334 |
+
help:
|
335 |
+
@echo "The following are some of the valid targets for this Makefile:"
|
336 |
+
@echo "... all (the default if no target is provided)"
|
337 |
+
@echo "... clean"
|
338 |
+
@echo "... depend"
|
339 |
+
@echo "... edit_cache"
|
340 |
+
@echo "... install"
|
341 |
+
@echo "... install/local"
|
342 |
+
@echo "... install/strip"
|
343 |
+
@echo "... list_install_components"
|
344 |
+
@echo "... rebuild_cache"
|
345 |
+
@echo "... build_binary"
|
346 |
+
@echo "... count_ngrams"
|
347 |
+
@echo "... filter"
|
348 |
+
@echo "... fragment"
|
349 |
+
@echo "... kenlm"
|
350 |
+
@echo "... kenlm_benchmark"
|
351 |
+
@echo "... kenlm_builder"
|
352 |
+
@echo "... kenlm_filter"
|
353 |
+
@echo "... kenlm_util"
|
354 |
+
@echo "... lmplz"
|
355 |
+
@echo "... phrase_table_vocab"
|
356 |
+
@echo "... probing_hash_table_benchmark"
|
357 |
+
@echo "... query"
|
358 |
+
.PHONY : help
|
359 |
+
|
360 |
+
|
361 |
+
|
362 |
+
#=============================================================================
|
363 |
+
# Special targets to cleanup operation of make.
|
364 |
+
|
365 |
+
# Special rule to run CMake to check the build system integrity.
|
366 |
+
# No rule that depends on this can have commands that come from listfiles
|
367 |
+
# because they might be regenerated.
|
368 |
+
cmake_check_build_system:
|
369 |
+
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
|
370 |
+
.PHONY : cmake_check_build_system
|
371 |
+
|
cc-multilingual-main/cc_net/third_party/kenlm/build/cmake_install.cmake
ADDED
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Install script for directory: /home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm
|
2 |
+
|
3 |
+
# Set the install prefix
|
4 |
+
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
|
5 |
+
set(CMAKE_INSTALL_PREFIX "/usr/local")
|
6 |
+
endif()
|
7 |
+
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
8 |
+
|
9 |
+
# Set the install configuration name.
|
10 |
+
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
11 |
+
if(BUILD_TYPE)
|
12 |
+
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
|
13 |
+
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
|
14 |
+
else()
|
15 |
+
set(CMAKE_INSTALL_CONFIG_NAME "Release")
|
16 |
+
endif()
|
17 |
+
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
|
18 |
+
endif()
|
19 |
+
|
20 |
+
# Set the component getting installed.
|
21 |
+
if(NOT CMAKE_INSTALL_COMPONENT)
|
22 |
+
if(COMPONENT)
|
23 |
+
message(STATUS "Install component: \"${COMPONENT}\"")
|
24 |
+
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
|
25 |
+
else()
|
26 |
+
set(CMAKE_INSTALL_COMPONENT)
|
27 |
+
endif()
|
28 |
+
endif()
|
29 |
+
|
30 |
+
# Install shared libraries without execute permission?
|
31 |
+
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
|
32 |
+
set(CMAKE_INSTALL_SO_NO_EXE "1")
|
33 |
+
endif()
|
34 |
+
|
35 |
+
# Is this installation the result of a crosscompile?
|
36 |
+
if(NOT DEFINED CMAKE_CROSSCOMPILING)
|
37 |
+
set(CMAKE_CROSSCOMPILING "FALSE")
|
38 |
+
endif()
|
39 |
+
|
40 |
+
# Set default install directory permissions.
|
41 |
+
if(NOT DEFINED CMAKE_OBJDUMP)
|
42 |
+
set(CMAKE_OBJDUMP "/usr/bin/objdump")
|
43 |
+
endif()
|
44 |
+
|
45 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
|
46 |
+
if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/share/kenlm/cmake/kenlmTargets.cmake")
|
47 |
+
file(DIFFERENT EXPORT_FILE_CHANGED FILES
|
48 |
+
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/share/kenlm/cmake/kenlmTargets.cmake"
|
49 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build/CMakeFiles/Export/share/kenlm/cmake/kenlmTargets.cmake")
|
50 |
+
if(EXPORT_FILE_CHANGED)
|
51 |
+
file(GLOB OLD_CONFIG_FILES "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/share/kenlm/cmake/kenlmTargets-*.cmake")
|
52 |
+
if(OLD_CONFIG_FILES)
|
53 |
+
message(STATUS "Old export file \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/share/kenlm/cmake/kenlmTargets.cmake\" will be replaced. Removing files [${OLD_CONFIG_FILES}].")
|
54 |
+
file(REMOVE ${OLD_CONFIG_FILES})
|
55 |
+
endif()
|
56 |
+
endif()
|
57 |
+
endif()
|
58 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/share/kenlm/cmake" TYPE FILE FILES "/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build/CMakeFiles/Export/share/kenlm/cmake/kenlmTargets.cmake")
|
59 |
+
if("${CMAKE_INSTALL_CONFIG_NAME}" MATCHES "^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$")
|
60 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/share/kenlm/cmake" TYPE FILE FILES "/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build/CMakeFiles/Export/share/kenlm/cmake/kenlmTargets-release.cmake")
|
61 |
+
endif()
|
62 |
+
endif()
|
63 |
+
|
64 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xheadersx" OR NOT CMAKE_INSTALL_COMPONENT)
|
65 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/include/kenlm/util" TYPE FILE FILES
|
66 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/bit_packing.hh"
|
67 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/ersatz_progress.hh"
|
68 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/exception.hh"
|
69 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/fake_ostream.hh"
|
70 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/file.hh"
|
71 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/file_piece.hh"
|
72 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/file_stream.hh"
|
73 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/fixed_array.hh"
|
74 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/float_to_string.hh"
|
75 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/getopt.hh"
|
76 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/have.hh"
|
77 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/integer_to_string.hh"
|
78 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/joint_sort.hh"
|
79 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/mmap.hh"
|
80 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/multi_intersection.hh"
|
81 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/murmur_hash.hh"
|
82 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/parallel_read.hh"
|
83 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/pcqueue.hh"
|
84 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/pool.hh"
|
85 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/probing_hash_table.hh"
|
86 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/proxy_iterator.hh"
|
87 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/read_compressed.hh"
|
88 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/scoped.hh"
|
89 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/sized_iterator.hh"
|
90 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/sorted_uniform.hh"
|
91 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/spaces.hh"
|
92 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/string_piece.hh"
|
93 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/string_piece_hash.hh"
|
94 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/string_stream.hh"
|
95 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/thread_pool.hh"
|
96 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/tokenize_piece.hh"
|
97 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/usage.hh"
|
98 |
+
)
|
99 |
+
endif()
|
100 |
+
|
101 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xheadersx" OR NOT CMAKE_INSTALL_COMPONENT)
|
102 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/include/kenlm/util/double-conversion" TYPE FILE FILES
|
103 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/bignum-dtoa.h"
|
104 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/bignum.h"
|
105 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/cached-powers.h"
|
106 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/diy-fp.h"
|
107 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/double-conversion.h"
|
108 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/fast-dtoa.h"
|
109 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/fixed-dtoa.h"
|
110 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/ieee.h"
|
111 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/strtod.h"
|
112 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/double-conversion/utils.h"
|
113 |
+
)
|
114 |
+
endif()
|
115 |
+
|
116 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xheadersx" OR NOT CMAKE_INSTALL_COMPONENT)
|
117 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/include/kenlm/util/stream" TYPE FILE FILES
|
118 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/block.hh"
|
119 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/chain.hh"
|
120 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/config.hh"
|
121 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/count_records.hh"
|
122 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/io.hh"
|
123 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/line_input.hh"
|
124 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/multi_progress.hh"
|
125 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/multi_stream.hh"
|
126 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/rewindable_stream.hh"
|
127 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/sort.hh"
|
128 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/stream.hh"
|
129 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/util/stream/typed_stream.hh"
|
130 |
+
)
|
131 |
+
endif()
|
132 |
+
|
133 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xheadersx" OR NOT CMAKE_INSTALL_COMPONENT)
|
134 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/include/kenlm/lm" TYPE FILE FILES
|
135 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/bhiksha.hh"
|
136 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/binary_format.hh"
|
137 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/blank.hh"
|
138 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/config.hh"
|
139 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/enumerate_vocab.hh"
|
140 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/facade.hh"
|
141 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/left.hh"
|
142 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/lm_exception.hh"
|
143 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/max_order.hh"
|
144 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/model.hh"
|
145 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/model_type.hh"
|
146 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/ngram_query.hh"
|
147 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/partial.hh"
|
148 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/quantize.hh"
|
149 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/read_arpa.hh"
|
150 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/return.hh"
|
151 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/search_hashed.hh"
|
152 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/search_trie.hh"
|
153 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/sizes.hh"
|
154 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/state.hh"
|
155 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/trie.hh"
|
156 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/trie_sort.hh"
|
157 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/value.hh"
|
158 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/value_build.hh"
|
159 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/virtual_interface.hh"
|
160 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/vocab.hh"
|
161 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/weights.hh"
|
162 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/word_index.hh"
|
163 |
+
)
|
164 |
+
endif()
|
165 |
+
|
166 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xheadersx" OR NOT CMAKE_INSTALL_COMPONENT)
|
167 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/include/kenlm/lm/builder" TYPE FILE FILES
|
168 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/adjust_counts.hh"
|
169 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/combine_counts.hh"
|
170 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/corpus_count.hh"
|
171 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/debug_print.hh"
|
172 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/discount.hh"
|
173 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/hash_gamma.hh"
|
174 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/header_info.hh"
|
175 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/initial_probabilities.hh"
|
176 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/interpolate.hh"
|
177 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/output.hh"
|
178 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/payload.hh"
|
179 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/builder/pipeline.hh"
|
180 |
+
)
|
181 |
+
endif()
|
182 |
+
|
183 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xheadersx" OR NOT CMAKE_INSTALL_COMPONENT)
|
184 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/include/kenlm/lm/common" TYPE FILE FILES
|
185 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/common/compare.hh"
|
186 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/common/joint_order.hh"
|
187 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/common/model_buffer.hh"
|
188 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/common/ngram.hh"
|
189 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/common/ngram_stream.hh"
|
190 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/common/print.hh"
|
191 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/common/renumber.hh"
|
192 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/common/size_option.hh"
|
193 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/common/special.hh"
|
194 |
+
)
|
195 |
+
endif()
|
196 |
+
|
197 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xheadersx" OR NOT CMAKE_INSTALL_COMPONENT)
|
198 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/include/kenlm/lm/filter" TYPE FILE FILES
|
199 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/filter/arpa_io.hh"
|
200 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/filter/count_io.hh"
|
201 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/filter/format.hh"
|
202 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/filter/phrase.hh"
|
203 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/filter/thread.hh"
|
204 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/filter/vocab.hh"
|
205 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/filter/wrapper.hh"
|
206 |
+
)
|
207 |
+
endif()
|
208 |
+
|
209 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xheadersx" OR NOT CMAKE_INSTALL_COMPONENT)
|
210 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/include/kenlm/lm/interpolate" TYPE FILE FILES
|
211 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/backoff_matrix.hh"
|
212 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/backoff_reunification.hh"
|
213 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/bounded_sequence_encoding.hh"
|
214 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/interpolate_info.hh"
|
215 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/merge_probabilities.hh"
|
216 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/merge_vocab.hh"
|
217 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/normalize.hh"
|
218 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/pipeline.hh"
|
219 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/split_worker.hh"
|
220 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/tune_derivatives.hh"
|
221 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/tune_instances.hh"
|
222 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/tune_matrix.hh"
|
223 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/tune_weights.hh"
|
224 |
+
"/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/lm/interpolate/universal_vocab.hh"
|
225 |
+
)
|
226 |
+
endif()
|
227 |
+
|
228 |
+
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
|
229 |
+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/share/kenlm/cmake" TYPE FILE FILES "/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build/kenlmConfig.cmake")
|
230 |
+
endif()
|
231 |
+
|
232 |
+
if(NOT CMAKE_INSTALL_LOCAL_ONLY)
|
233 |
+
# Include the install script for each subdirectory.
|
234 |
+
include("/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build/util/cmake_install.cmake")
|
235 |
+
include("/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build/lm/cmake_install.cmake")
|
236 |
+
|
237 |
+
endif()
|
238 |
+
|
239 |
+
if(CMAKE_INSTALL_COMPONENT)
|
240 |
+
set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
|
241 |
+
else()
|
242 |
+
set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
|
243 |
+
endif()
|
244 |
+
|
245 |
+
string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
|
246 |
+
"${CMAKE_INSTALL_MANIFEST_FILES}")
|
247 |
+
file(WRITE "/home/sdp/Common_crawl/cc-multilingual-main/cc-multilingual-main/cc_net/third_party/kenlm/build/${CMAKE_INSTALL_MANIFEST}"
|
248 |
+
"${CMAKE_INSTALL_MANIFEST_CONTENT}")
|
cc-multilingual-main/cc_net/third_party/kenlm/build/kenlmConfig.cmake
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
|
3 |
+
####### Any changes to this file will be overwritten by the next CMake run ####
|
4 |
+
####### The input file was kenlmConfig.cmake.in ########
|
5 |
+
|
6 |
+
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
|
7 |
+
|
8 |
+
####################################################################################
|
9 |
+
|
10 |
+
include(CMakeFindDependencyMacro)
|
11 |
+
|
12 |
+
find_dependency(Boost)
|
13 |
+
find_dependency(Threads)
|
14 |
+
|
15 |
+
# Compression libs
|
16 |
+
if ()
|
17 |
+
find_dependency(ZLIB)
|
18 |
+
endif()
|
19 |
+
if ()
|
20 |
+
find_dependency(BZip2)
|
21 |
+
endif()
|
22 |
+
if ()
|
23 |
+
find_dependency(LibLZMA)
|
24 |
+
endif()
|
25 |
+
|
26 |
+
include("${CMAKE_CURRENT_LIST_DIR}/kenlmTargets.cmake")
|
cc-multilingual-main/cc_net/third_party/kenlm/cmake/KenLMFunctions.cmake
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Helper functions used across the CMake build system
|
2 |
+
|
3 |
+
include(CMakeParseArguments)
|
4 |
+
|
5 |
+
# Adds a bunch of executables to the build, each depending on the specified
|
6 |
+
# dependent object files and linking against the specified libraries
|
7 |
+
function(AddExes)
|
8 |
+
set(multiValueArgs EXES DEPENDS LIBRARIES)
|
9 |
+
cmake_parse_arguments(AddExes "" "" "${multiValueArgs}" ${ARGN})
|
10 |
+
|
11 |
+
# Iterate through the executable list
|
12 |
+
foreach(exe ${AddExes_EXES})
|
13 |
+
|
14 |
+
# Compile the executable, linking against the requisite dependent object files
|
15 |
+
add_executable(${exe} ${exe}_main.cc ${AddExes_DEPENDS})
|
16 |
+
|
17 |
+
# Link the executable against the supplied libraries
|
18 |
+
target_link_libraries(${exe} ${AddExes_LIBRARIES})
|
19 |
+
|
20 |
+
# Group executables together
|
21 |
+
set_target_properties(${exe} PROPERTIES FOLDER executables)
|
22 |
+
|
23 |
+
# End for loop
|
24 |
+
endforeach(exe)
|
25 |
+
|
26 |
+
# Install the executable files
|
27 |
+
install(TARGETS ${AddExes_EXES} DESTINATION bin)
|
28 |
+
endfunction()
|
29 |
+
|
30 |
+
# Adds a single test to the build, depending on the specified dependent
|
31 |
+
# object files, linking against the specified libraries, and with the
|
32 |
+
# specified command line arguments
|
33 |
+
function(KenLMAddTest)
|
34 |
+
cmake_parse_arguments(KenLMAddTest "" "TEST"
|
35 |
+
"DEPENDS;LIBRARIES;TEST_ARGS" ${ARGN})
|
36 |
+
|
37 |
+
# Compile the executable, linking against the requisite dependent object files
|
38 |
+
add_executable(${KenLMAddTest_TEST}
|
39 |
+
${KenLMAddTest_TEST}.cc
|
40 |
+
${KenLMAddTest_DEPENDS})
|
41 |
+
|
42 |
+
if (Boost_USE_STATIC_LIBS)
|
43 |
+
set(DYNLINK_FLAGS)
|
44 |
+
else()
|
45 |
+
set(DYNLINK_FLAGS COMPILE_FLAGS -DBOOST_TEST_DYN_LINK)
|
46 |
+
endif()
|
47 |
+
|
48 |
+
# Require the following compile flag
|
49 |
+
set_target_properties(${KenLMAddTest_TEST} PROPERTIES
|
50 |
+
${DYNLINK_FLAGS}
|
51 |
+
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
|
52 |
+
|
53 |
+
target_link_libraries(${KenLMAddTest_TEST} ${KenLMAddTest_LIBRARIES} ${TIMER_LINK})
|
54 |
+
|
55 |
+
set(test_params "")
|
56 |
+
if(KenLMAddTest_TEST_ARGS)
|
57 |
+
set(test_params ${KenLMAddTest_TEST_ARGS})
|
58 |
+
endif()
|
59 |
+
|
60 |
+
# Specify command arguments for how to run each unit test
|
61 |
+
add_test(NAME ${KenLMAddTest_TEST}
|
62 |
+
COMMAND ${KenLMAddTest_TEST} ${test_params})
|
63 |
+
|
64 |
+
# Group unit tests together
|
65 |
+
set_target_properties(${KenLMAddTest_TEST} PROPERTIES FOLDER "unit_tests")
|
66 |
+
endfunction()
|
67 |
+
|
68 |
+
# Adds a bunch of tests to the build, each depending on the specified
|
69 |
+
# dependent object files and linking against the specified libraries
|
70 |
+
function(AddTests)
|
71 |
+
set(multiValueArgs TESTS DEPENDS LIBRARIES TEST_ARGS)
|
72 |
+
cmake_parse_arguments(AddTests "" "" "${multiValueArgs}" ${ARGN})
|
73 |
+
|
74 |
+
# Iterate through the Boost tests list
|
75 |
+
foreach(test ${AddTests_TESTS})
|
76 |
+
KenLMAddTest(TEST ${test}
|
77 |
+
DEPENDS ${AddTests_DEPENDS}
|
78 |
+
LIBRARIES ${AddTests_LIBRARIES}
|
79 |
+
TEST_ARGS ${AddTests_TEST_ARGS})
|
80 |
+
endforeach(test)
|
81 |
+
endfunction()
|
cc-multilingual-main/cc_net/third_party/kenlm/cmake/kenlmConfig.cmake.in
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@PACKAGE_INIT@
|
2 |
+
|
3 |
+
include(CMakeFindDependencyMacro)
|
4 |
+
|
5 |
+
find_dependency(Boost)
|
6 |
+
find_dependency(Threads)
|
7 |
+
|
8 |
+
# Compression libs
|
9 |
+
if (@ZLIB_FOUND@)
|
10 |
+
find_dependency(ZLIB)
|
11 |
+
endif()
|
12 |
+
if (@BZIP2_FOUND@)
|
13 |
+
find_dependency(BZip2)
|
14 |
+
endif()
|
15 |
+
if (@LIBLZMA_FOUND@)
|
16 |
+
find_dependency(LibLZMA)
|
17 |
+
endif()
|
18 |
+
|
19 |
+
include("${CMAKE_CURRENT_LIST_DIR}/kenlmTargets.cmake")
|
cc-multilingual-main/cc_net/third_party/kenlm/cmake/modules/FindEigen3.cmake
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# - Try to find Eigen3 lib
|
2 |
+
#
|
3 |
+
# This module supports requiring a minimum version, e.g. you can do
|
4 |
+
# find_package(Eigen3 3.1.2)
|
5 |
+
# to require version 3.1.2 or newer of Eigen3.
|
6 |
+
#
|
7 |
+
# Once done this will define
|
8 |
+
#
|
9 |
+
# EIGEN3_FOUND - system has eigen lib with correct version
|
10 |
+
# EIGEN3_INCLUDE_DIR - the eigen include directory
|
11 |
+
# EIGEN3_VERSION - eigen version
|
12 |
+
#
|
13 |
+
# This module reads hints about search locations from
|
14 |
+
# the following enviroment variables:
|
15 |
+
#
|
16 |
+
# EIGEN3_ROOT
|
17 |
+
# EIGEN3_ROOT_DIR
|
18 |
+
|
19 |
+
# Copyright (c) 2006, 2007 Montel Laurent, <[email protected]>
|
20 |
+
# Copyright (c) 2008, 2009 Gael Guennebaud, <[email protected]>
|
21 |
+
# Copyright (c) 2009 Benoit Jacob <[email protected]>
|
22 |
+
# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
|
23 |
+
|
24 |
+
if(NOT Eigen3_FIND_VERSION)
|
25 |
+
if(NOT Eigen3_FIND_VERSION_MAJOR)
|
26 |
+
set(Eigen3_FIND_VERSION_MAJOR 2)
|
27 |
+
endif(NOT Eigen3_FIND_VERSION_MAJOR)
|
28 |
+
if(NOT Eigen3_FIND_VERSION_MINOR)
|
29 |
+
set(Eigen3_FIND_VERSION_MINOR 91)
|
30 |
+
endif(NOT Eigen3_FIND_VERSION_MINOR)
|
31 |
+
if(NOT Eigen3_FIND_VERSION_PATCH)
|
32 |
+
set(Eigen3_FIND_VERSION_PATCH 0)
|
33 |
+
endif(NOT Eigen3_FIND_VERSION_PATCH)
|
34 |
+
|
35 |
+
set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
|
36 |
+
endif(NOT Eigen3_FIND_VERSION)
|
37 |
+
|
38 |
+
macro(_eigen3_check_version)
|
39 |
+
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
|
40 |
+
|
41 |
+
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
|
42 |
+
set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
|
43 |
+
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
|
44 |
+
set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
|
45 |
+
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
|
46 |
+
set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
|
47 |
+
|
48 |
+
set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
|
49 |
+
if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
50 |
+
set(EIGEN3_VERSION_OK FALSE)
|
51 |
+
else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
52 |
+
set(EIGEN3_VERSION_OK TRUE)
|
53 |
+
endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
54 |
+
|
55 |
+
if(NOT EIGEN3_VERSION_OK)
|
56 |
+
|
57 |
+
message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
|
58 |
+
"but at least version ${Eigen3_FIND_VERSION} is required")
|
59 |
+
endif(NOT EIGEN3_VERSION_OK)
|
60 |
+
endmacro(_eigen3_check_version)
|
61 |
+
|
62 |
+
if (EIGEN3_INCLUDE_DIR)
|
63 |
+
|
64 |
+
# in cache already
|
65 |
+
_eigen3_check_version()
|
66 |
+
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
|
67 |
+
|
68 |
+
else (EIGEN3_INCLUDE_DIR)
|
69 |
+
|
70 |
+
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
|
71 |
+
HINTS
|
72 |
+
ENV EIGEN3_ROOT
|
73 |
+
ENV EIGEN3_ROOT_DIR
|
74 |
+
PATHS
|
75 |
+
${CMAKE_INSTALL_PREFIX}/include
|
76 |
+
${KDE4_INCLUDE_DIR}
|
77 |
+
PATH_SUFFIXES eigen3 eigen
|
78 |
+
)
|
79 |
+
|
80 |
+
if(EIGEN3_INCLUDE_DIR)
|
81 |
+
_eigen3_check_version()
|
82 |
+
endif(EIGEN3_INCLUDE_DIR)
|
83 |
+
|
84 |
+
include(FindPackageHandleStandardArgs)
|
85 |
+
find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
|
86 |
+
|
87 |
+
mark_as_advanced(EIGEN3_INCLUDE_DIR)
|
88 |
+
|
89 |
+
endif(EIGEN3_INCLUDE_DIR)
|
90 |
+
|
cc-multilingual-main/cc_net/third_party/kenlm/compile_query_only.sh
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
#This is just an example compilation. You should integrate these files into your build system. Boost jam is provided and preferred.
|
3 |
+
|
4 |
+
echo You must use ./bjam if you want language model estimation, filtering, or support for compressed files \(.gz, .bz2, .xz\) 1>&2
|
5 |
+
|
6 |
+
rm {lm,util}/*.o 2>/dev/null
|
7 |
+
set -e
|
8 |
+
|
9 |
+
CXX=${CXX:-g++}
|
10 |
+
|
11 |
+
CXXFLAGS+=" -I. -O3 -DNDEBUG -DKENLM_MAX_ORDER=6"
|
12 |
+
|
13 |
+
#If this fails for you, consider using bjam.
|
14 |
+
if [ ${#NPLM} != 0 ]; then
|
15 |
+
CXXFLAGS+=" -DHAVE_NPLM -lneuralLM -L$NPLM/src -I$NPLM/src -lboost_thread-mt -fopenmp"
|
16 |
+
ADDED_PATHS="lm/wrappers/*.cc"
|
17 |
+
fi
|
18 |
+
echo 'Compiling with '$CXX $CXXFLAGS
|
19 |
+
|
20 |
+
#Grab all cc files in these directories except those ending in test.cc or main.cc
|
21 |
+
objects=""
|
22 |
+
for i in util/double-conversion/*.cc util/*.cc lm/*.cc $ADDED_PATHS; do
|
23 |
+
if [ "${i%test.cc}" == "$i" ] && [ "${i%main.cc}" == "$i" ]; then
|
24 |
+
$CXX $CXXFLAGS -c $i -o ${i%.cc}.o
|
25 |
+
objects="$objects ${i%.cc}.o"
|
26 |
+
fi
|
27 |
+
done
|
28 |
+
|
29 |
+
mkdir -p bin
|
30 |
+
if [ "$(uname)" != Darwin ]; then
|
31 |
+
CXXFLAGS="$CXXFLAGS -lrt"
|
32 |
+
fi
|
33 |
+
$CXX lm/build_binary_main.cc $objects -o bin/build_binary $CXXFLAGS $LDFLAGS
|
34 |
+
$CXX lm/query_main.cc $objects -o bin/query $CXXFLAGS $LDFLAGS
|
cc-multilingual-main/cc_net/third_party/kenlm/setup.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from setuptools import setup, Extension
|
2 |
+
import glob
|
3 |
+
import platform
|
4 |
+
import os
|
5 |
+
import sys
|
6 |
+
import re
|
7 |
+
|
8 |
+
#Does gcc compile with this header and library?
|
9 |
+
def compile_test(header, library):
|
10 |
+
dummy_path = os.path.join(os.path.dirname(__file__), "dummy")
|
11 |
+
command = "bash -c \"g++ -include " + header + " -l" + library + " -x c++ - <<<'int main() {}' -o " + dummy_path + " >/dev/null 2>/dev/null && rm " + dummy_path + " 2>/dev/null\""
|
12 |
+
return os.system(command) == 0
|
13 |
+
|
14 |
+
max_order = "6"
|
15 |
+
is_max_order = [s for s in sys.argv if "--max_order" in s]
|
16 |
+
for element in is_max_order:
|
17 |
+
max_order = re.split('[= ]',element)[1]
|
18 |
+
sys.argv.remove(element)
|
19 |
+
|
20 |
+
FILES = glob.glob('util/*.cc') + glob.glob('lm/*.cc') + glob.glob('util/double-conversion/*.cc') + glob.glob('python/*.cc')
|
21 |
+
FILES = [fn for fn in FILES if not (fn.endswith('main.cc') or fn.endswith('test.cc'))]
|
22 |
+
|
23 |
+
if platform.system() == 'Linux':
|
24 |
+
LIBS = ['stdc++', 'rt']
|
25 |
+
elif platform.system() == 'Darwin':
|
26 |
+
LIBS = ['c++']
|
27 |
+
else:
|
28 |
+
LIBS = []
|
29 |
+
|
30 |
+
#We don't need -std=c++11 but python seems to be compiled with it now. https://github.com/kpu/kenlm/issues/86
|
31 |
+
ARGS = ['-O3', '-DNDEBUG', '-DKENLM_MAX_ORDER='+max_order, '-std=c++11']
|
32 |
+
|
33 |
+
#Attempted fix to https://github.com/kpu/kenlm/issues/186 and https://github.com/kpu/kenlm/issues/197
|
34 |
+
if platform.system() == 'Darwin':
|
35 |
+
ARGS += ["-stdlib=libc++", "-mmacosx-version-min=10.7"]
|
36 |
+
|
37 |
+
if compile_test('zlib.h', 'z'):
|
38 |
+
ARGS.append('-DHAVE_ZLIB')
|
39 |
+
LIBS.append('z')
|
40 |
+
|
41 |
+
if compile_test('bzlib.h', 'bz2'):
|
42 |
+
ARGS.append('-DHAVE_BZLIB')
|
43 |
+
LIBS.append('bz2')
|
44 |
+
|
45 |
+
if compile_test('lzma.h', 'lzma'):
|
46 |
+
ARGS.append('-DHAVE_XZLIB')
|
47 |
+
LIBS.append('lzma')
|
48 |
+
|
49 |
+
ext_modules = [
|
50 |
+
Extension(name='kenlm',
|
51 |
+
sources=FILES + ['python/kenlm.cpp'],
|
52 |
+
language='C++',
|
53 |
+
include_dirs=['.'],
|
54 |
+
libraries=LIBS,
|
55 |
+
extra_compile_args=ARGS)
|
56 |
+
]
|
57 |
+
|
58 |
+
setup(
|
59 |
+
name='kenlm',
|
60 |
+
ext_modules=ext_modules,
|
61 |
+
include_package_data=True,
|
62 |
+
)
|
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/CMakeFiles/sentencepiece_train-static.dir/builder.cc.o
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:976b84fde8bfb7971b25df0fc93e046d5ffd234aac0b2863eb43a0dab4307d8f
|
3 |
+
size 1117264
|
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.a
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:843738e17346c8b3edf05f5c13cc172f2291243fd855a261c6b46052bd0d839b
|
3 |
+
size 2025446
|
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d852b5a0f12c183a9a51eff748b3dafd9135e655d574228201f87387d793eb00
|
3 |
+
size 1126472
|
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece.so.0.0.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d852b5a0f12c183a9a51eff748b3dafd9135e655d574228201f87387d793eb00
|
3 |
+
size 1126472
|
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece_train.a
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:34b423aaa7273e14f6cd064179f3660c5f17047a410799da24937df72e49d75a
|
3 |
+
size 1921634
|
cc-multilingual-main/cc_net/third_party/sentencepiece/build/src/libsentencepiece_train.so.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2ec684eaf2a6f1d19285c97f5d3a0382c4a983fa08d78aeede21d6cf2563ff4d
|
3 |
+
size 1544648
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/CMakeLists.txt
ADDED
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2018 Google Inc.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.!
|
14 |
+
|
15 |
+
if (SPM_USE_BUILTIN_PROTOBUF)
|
16 |
+
set(SPM_PROTO_HDRS builtin_pb/sentencepiece.pb.h)
|
17 |
+
set(SPM_PROTO_SRCS builtin_pb/sentencepiece.pb.cc)
|
18 |
+
set(SPM_MODEL_PROTO_HDRS builtin_pb/sentencepiece_model.pb.h)
|
19 |
+
set(SPM_MODEL_PROTO_SRCS builtin_pb/sentencepiece_model.pb.cc)
|
20 |
+
set(PROTOBUF_LITE_LIBRARY "")
|
21 |
+
set(PROTOBUF_LITE_SRCS
|
22 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/arena.cc
|
23 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/arenastring.cc
|
24 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/bytestream.cc
|
25 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/coded_stream.cc
|
26 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/common.cc
|
27 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/extension_set.cc
|
28 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/generated_message_table_driven_lite.cc
|
29 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/generated_message_util.cc
|
30 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/implicit_weak_message.cc
|
31 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/int128.cc
|
32 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/io_win32.cc
|
33 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/message_lite.cc
|
34 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/repeated_field.cc
|
35 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/status.cc
|
36 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/statusor.cc
|
37 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/stringpiece.cc
|
38 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/stringprintf.cc
|
39 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/structurally_valid.cc
|
40 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/strutil.cc
|
41 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/time.cc
|
42 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/wire_format_lite.cc
|
43 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/zero_copy_stream.cc
|
44 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite/zero_copy_stream_impl_lite.cc)
|
45 |
+
if (MSVC)
|
46 |
+
add_definitions("/DHAVE_PTHREAD /wd4018 /wd4514")
|
47 |
+
else()
|
48 |
+
add_definitions("-pthread -DHAVE_PTHREAD=1 -Wno-sign-compare")
|
49 |
+
endif()
|
50 |
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite)
|
51 |
+
include_directories(builtin_pb)
|
52 |
+
else()
|
53 |
+
find_package(Protobuf REQUIRED)
|
54 |
+
include_directories(${Protobuf_INCLUDE_DIRS})
|
55 |
+
protobuf_generate_cpp(SPM_PROTO_SRCS SPM_PROTO_HDRS sentencepiece.proto)
|
56 |
+
protobuf_generate_cpp(SPM_MODEL_PROTO_SRCS SPM_MODEL_PROTO_HDRS sentencepiece_model.proto)
|
57 |
+
set(PROTOBUF_LITE_SRCS "")
|
58 |
+
include_directories(${PROTOBUF_INCLUDE_DIR})
|
59 |
+
endif()
|
60 |
+
|
61 |
+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
62 |
+
|
63 |
+
set(SPM_SRCS
|
64 |
+
${PROTOBUF_LITE_SRCS}
|
65 |
+
${SPM_PROTO_HDRS}
|
66 |
+
${SPM_PROTO_SRCS}
|
67 |
+
${SPM_MODEL_PROTO_HDRS}
|
68 |
+
${SPM_MODEL_PROTO_SRCS}
|
69 |
+
bpe_model.h
|
70 |
+
common.h
|
71 |
+
normalizer.h
|
72 |
+
util.h
|
73 |
+
freelist.h
|
74 |
+
filesystem.h
|
75 |
+
flags.h
|
76 |
+
sentencepiece_processor.h
|
77 |
+
word_model.h
|
78 |
+
model_factory.h
|
79 |
+
char_model.h
|
80 |
+
model_interface.h
|
81 |
+
testharness.h
|
82 |
+
unigram_model.h
|
83 |
+
bpe_model.cc
|
84 |
+
char_model.cc
|
85 |
+
error.cc
|
86 |
+
filesystem.cc
|
87 |
+
flags.cc
|
88 |
+
model_factory.cc
|
89 |
+
model_interface.cc
|
90 |
+
normalizer.cc
|
91 |
+
sentencepiece_processor.cc
|
92 |
+
unigram_model.cc
|
93 |
+
util.cc
|
94 |
+
word_model.cc
|
95 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/absl/strings/string_view.cc)
|
96 |
+
|
97 |
+
set(SPM_TRAIN_SRCS
|
98 |
+
${SPM_PROTO_HDRS}
|
99 |
+
${SPM_MODEL_PROTO_HDRS}
|
100 |
+
builder.h
|
101 |
+
normalization_rule.h
|
102 |
+
unicode_script.h
|
103 |
+
unicode_script_map.h
|
104 |
+
trainer_factory.h
|
105 |
+
trainer_interface.h
|
106 |
+
unigram_model_trainer.h
|
107 |
+
word_model_trainer.h
|
108 |
+
char_model_trainer.h
|
109 |
+
bpe_model_trainer.h
|
110 |
+
sentencepiece_trainer.h
|
111 |
+
builder.cc
|
112 |
+
unicode_script.cc
|
113 |
+
trainer_factory.cc
|
114 |
+
trainer_interface.cc
|
115 |
+
unigram_model_trainer.cc
|
116 |
+
word_model_trainer.cc
|
117 |
+
char_model_trainer.cc
|
118 |
+
bpe_model_trainer.cc
|
119 |
+
sentencepiece_trainer.cc)
|
120 |
+
|
121 |
+
set(SPM_TEST_SRCS
|
122 |
+
${SPM_PROTO_HDRS}
|
123 |
+
${SPM_MODEL_PROTO_HDRS}
|
124 |
+
testharness.h
|
125 |
+
bpe_model_test.cc
|
126 |
+
bpe_model_trainer_test.cc
|
127 |
+
builder_test.cc
|
128 |
+
char_model_test.cc
|
129 |
+
char_model_trainer_test.cc
|
130 |
+
filesystem_test.cc
|
131 |
+
flags_test.cc
|
132 |
+
model_factory_test.cc
|
133 |
+
model_interface_test.cc
|
134 |
+
normalizer_test.cc
|
135 |
+
sentencepiece_processor_test.cc
|
136 |
+
sentencepiece_trainer_test.cc
|
137 |
+
test_main.cc
|
138 |
+
testharness.cc
|
139 |
+
trainer_factory_test.cc
|
140 |
+
trainer_interface_test.cc
|
141 |
+
unicode_script_test.cc
|
142 |
+
unigram_model_test.cc
|
143 |
+
unigram_model_trainer_test.cc
|
144 |
+
util_test.cc
|
145 |
+
word_model_test.cc
|
146 |
+
word_model_trainer_test.cc)
|
147 |
+
|
148 |
+
find_package(Threads REQUIRED)
|
149 |
+
|
150 |
+
set(SPM_LIBS ${PROTOBUF_LITE_LIBRARY} Threads::Threads)
|
151 |
+
|
152 |
+
if (SPM_ENABLE_NFKC_COMPILE)
|
153 |
+
find_package(ICU 4.4 COMPONENTS i18n data uc REQUIRED)
|
154 |
+
include_directories(${ICU_INCLUDE_DIRS})
|
155 |
+
add_definitions(-DENABLE_NFKC_COMPILE)
|
156 |
+
list(APPEND SPM_LIBS ICU::i18n ICU::data ICU::uc)
|
157 |
+
endif()
|
158 |
+
|
159 |
+
if (SPM_ENABLE_TCMALLOC)
|
160 |
+
if (SPM_TCMALLOC_STATIC)
|
161 |
+
find_library(TCMALLOC_LIB NAMES libtcmalloc_minimal.a)
|
162 |
+
else()
|
163 |
+
find_library(TCMALLOC_LIB NAMES tcmalloc_minimal)
|
164 |
+
endif()
|
165 |
+
if (TCMALLOC_LIB)
|
166 |
+
message(STATUS "Found TCMalloc: ${TCMALLOC_LIB}")
|
167 |
+
list(APPEND SPM_LIBS ${TCMALLOC_LIB})
|
168 |
+
add_definitions(-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free)
|
169 |
+
else()
|
170 |
+
message(STATUS "Not Found TCMalloc: ${TCMALLOC_LIB}")
|
171 |
+
endif()
|
172 |
+
endif()
|
173 |
+
|
174 |
+
if (SPM_ENABLE_SHARED)
|
175 |
+
add_library(sentencepiece SHARED ${SPM_SRCS})
|
176 |
+
add_library(sentencepiece_train SHARED ${SPM_TRAIN_SRCS})
|
177 |
+
endif()
|
178 |
+
|
179 |
+
add_library(sentencepiece-static STATIC ${SPM_SRCS})
|
180 |
+
add_library(sentencepiece_train-static STATIC ${SPM_TRAIN_SRCS})
|
181 |
+
|
182 |
+
target_link_libraries(sentencepiece-static INTERFACE ${SPM_LIBS})
|
183 |
+
target_link_libraries(sentencepiece_train-static INTERFACE sentencepiece-static ${SPM_LIBS})
|
184 |
+
|
185 |
+
if (SPM_ENABLE_SHARED)
|
186 |
+
target_link_libraries(sentencepiece ${SPM_LIBS})
|
187 |
+
target_link_libraries(sentencepiece_train ${SPM_LIBS} sentencepiece)
|
188 |
+
set(SPM_INSTALLTARGETS sentencepiece sentencepiece_train sentencepiece-static sentencepiece_train-static)
|
189 |
+
set_target_properties(sentencepiece sentencepiece_train PROPERTIES SOVERSION 0 VERSION 0.0.0)
|
190 |
+
set_target_properties(sentencepiece PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)
|
191 |
+
set_target_properties(sentencepiece_train PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)
|
192 |
+
if (MSVC)
|
193 |
+
set_target_properties(sentencepiece PROPERTIES IMPORT_SUFFIX "_import.lib")
|
194 |
+
set_target_properties(sentencepiece_train PROPERTIES IMPORT_SUFFIX "_import.lib")
|
195 |
+
elseif (MINGW)
|
196 |
+
set_target_properties(sentencepiece PROPERTIES IMPORT_SUFFIX ".dll.a")
|
197 |
+
set_target_properties(sentencepiece_train PROPERTIES IMPORT_SUFFIX ".dll.a")
|
198 |
+
endif()
|
199 |
+
else()
|
200 |
+
add_library(sentencepiece ALIAS sentencepiece-static)
|
201 |
+
add_library(sentencepiece_train ALIAS sentencepiece_train-static)
|
202 |
+
set(SPM_INSTALLTARGETS sentencepiece-static sentencepiece_train-static)
|
203 |
+
endif()
|
204 |
+
|
205 |
+
set_target_properties(sentencepiece-static PROPERTIES OUTPUT_NAME "sentencepiece")
|
206 |
+
set_target_properties(sentencepiece_train-static PROPERTIES OUTPUT_NAME "sentencepiece_train")
|
207 |
+
|
208 |
+
if (NOT MSVC)
|
209 |
+
if (SPM_COVERAGE)
|
210 |
+
set(CMAKE_CXX_FLAGS "-O0 -Wall -fPIC -coverage ${CMAKE_CXX_FLAGS}")
|
211 |
+
else()
|
212 |
+
set(CMAKE_CXX_FLAGS "-O3 -Wall -fPIC ${CMAKE_CXX_FLAGS}")
|
213 |
+
endif()
|
214 |
+
if (SPM_ENABLE_TENSORFLOW_SHARED)
|
215 |
+
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
|
216 |
+
endif()
|
217 |
+
if (SPM_NO_THREADLOCAL)
|
218 |
+
add_definitions(-DSPM_NO_THREADLOCAL=1)
|
219 |
+
add_definitions(-DGOOGLE_PROTOBUF_NO_THREADLOCAL=1)
|
220 |
+
endif()
|
221 |
+
set_source_files_properties(
|
222 |
+
sentencepiece.pb.cc sentencepiece_model.pb.cc
|
223 |
+
PROPERTIES COMPILE_FLAGS "-Wno-misleading-indentation")
|
224 |
+
set_source_files_properties(${SPM_TEST_SRCS}
|
225 |
+
PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")
|
226 |
+
if (SPM_ENABLE_SHARED)
|
227 |
+
set_property(TARGET sentencepiece APPEND_STRING PROPERTY COMPILE_FLAGS " -DPIC")
|
228 |
+
set_property(TARGET sentencepiece_train APPEND_STRING PROPERTY COMPILE_FLAGS " -DPIC")
|
229 |
+
endif()
|
230 |
+
endif()
|
231 |
+
|
232 |
+
add_executable(spm_encode spm_encode_main.cc)
|
233 |
+
add_executable(spm_decode spm_decode_main.cc)
|
234 |
+
add_executable(spm_normalize spm_normalize_main.cc)
|
235 |
+
add_executable(spm_train spm_train_main.cc)
|
236 |
+
add_executable(spm_export_vocab spm_export_vocab_main.cc)
|
237 |
+
|
238 |
+
target_link_libraries(spm_encode sentencepiece)
|
239 |
+
target_link_libraries(spm_decode sentencepiece)
|
240 |
+
target_link_libraries(spm_normalize sentencepiece sentencepiece_train)
|
241 |
+
target_link_libraries(spm_train sentencepiece sentencepiece_train)
|
242 |
+
target_link_libraries(spm_export_vocab sentencepiece)
|
243 |
+
|
244 |
+
if (SPM_ENABLE_NFKC_COMPILE)
|
245 |
+
add_executable(compile_charsmap compile_charsmap_main.cc)
|
246 |
+
target_link_libraries(compile_charsmap sentencepiece sentencepiece_train)
|
247 |
+
endif()
|
248 |
+
|
249 |
+
list(APPEND SPM_INSTALLTARGETS
|
250 |
+
spm_encode spm_decode spm_normalize spm_train spm_export_vocab)
|
251 |
+
|
252 |
+
install(TARGETS ${SPM_INSTALLTARGETS}
|
253 |
+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
254 |
+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
255 |
+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
256 |
+
install(FILES sentencepiece_trainer.h sentencepiece_processor.h
|
257 |
+
DESTINATION ${CMAKE_INSTALL_INCDIR})
|
258 |
+
|
259 |
+
file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/data" data_dir)
|
260 |
+
|
261 |
+
if (SPM_BUILD_TEST OR SPM_COVERAGE)
|
262 |
+
enable_testing()
|
263 |
+
add_executable(spm_test test_main.cc ${SPM_TEST_SRCS})
|
264 |
+
|
265 |
+
if (SPM_COVERAGE)
|
266 |
+
target_link_libraries(spm_test sentencepiece sentencepiece_train "-lgcov")
|
267 |
+
else()
|
268 |
+
target_link_libraries(spm_test sentencepiece sentencepiece_train)
|
269 |
+
endif()
|
270 |
+
|
271 |
+
set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --show-leak-kinds=definite,possible --error-exitcode=1")
|
272 |
+
find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
|
273 |
+
include(Dart)
|
274 |
+
|
275 |
+
add_test(NAME sentencepiece_test
|
276 |
+
COMMAND $<TARGET_FILE:spm_test> --data_dir=${data_dir})
|
277 |
+
endif()
|
278 |
+
|
279 |
+
if (SPM_COVERAGE)
|
280 |
+
add_custom_target(coverage
|
281 |
+
COMMAND mkdir -p coverage
|
282 |
+
COMMAND $<TARGET_FILE:spm_test> --data_dir=${data_dir}
|
283 |
+
COMMAND lcov -c -d . -o coverage.info
|
284 |
+
COMMAND lcov --remove coverage.info "include*" "/c++" "_test*" "testharness*" "third_party*" ".pb.*" -o coverage.info
|
285 |
+
COMMAND mkdir -p lcov_html
|
286 |
+
COMMAND genhtml -o lcov_html coverage.info)
|
287 |
+
add_dependencies(coverage spm_test)
|
288 |
+
endif()
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/bpe_model.cc
ADDED
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "bpe_model.h"
|
16 |
+
|
17 |
+
#include <functional>
|
18 |
+
#include <memory>
|
19 |
+
#include <queue>
|
20 |
+
#include <unordered_map>
|
21 |
+
#include <utility>
|
22 |
+
#include <vector>
|
23 |
+
#include "freelist.h"
|
24 |
+
#include "util.h"
|
25 |
+
|
26 |
+
namespace sentencepiece {
|
27 |
+
namespace bpe {
|
28 |
+
|
29 |
+
Model::Model(const ModelProto &model_proto) {
|
30 |
+
model_proto_ = &model_proto;
|
31 |
+
InitializePieces();
|
32 |
+
}
|
33 |
+
|
34 |
+
Model::~Model() {}
|
35 |
+
|
36 |
+
std::vector<std::pair<absl::string_view, int>> Model::Encode(
|
37 |
+
absl::string_view normalized) const {
|
38 |
+
if (!status().ok() || normalized.empty()) {
|
39 |
+
return {};
|
40 |
+
}
|
41 |
+
|
42 |
+
struct SymbolPair {
|
43 |
+
int left; // left index of this pair
|
44 |
+
int right; // right index of this pair
|
45 |
+
float score; // score of this pair. large is better.
|
46 |
+
size_t size; // length of this piece
|
47 |
+
};
|
48 |
+
|
49 |
+
class SymbolPairComparator {
|
50 |
+
public:
|
51 |
+
const bool operator()(SymbolPair *h1, SymbolPair *h2) {
|
52 |
+
return (h1->score < h2->score ||
|
53 |
+
(h1->score == h2->score && h1->left > h2->left));
|
54 |
+
}
|
55 |
+
};
|
56 |
+
|
57 |
+
struct Symbol {
|
58 |
+
int prev; // prev index of this symbol. -1 for BOS.
|
59 |
+
int next; // next index of tihs symbol. -1 for EOS.
|
60 |
+
bool freeze; // this symbol is never be merged.
|
61 |
+
absl::string_view piece;
|
62 |
+
};
|
63 |
+
|
64 |
+
using Agenda = std::priority_queue<SymbolPair *, std::vector<SymbolPair *>,
|
65 |
+
SymbolPairComparator>;
|
66 |
+
Agenda agenda;
|
67 |
+
std::vector<Symbol> symbols;
|
68 |
+
symbols.reserve(normalized.size());
|
69 |
+
|
70 |
+
// Reverse merge rules.
|
71 |
+
// key: merged symbol, value: pair of original symbols.
|
72 |
+
std::unordered_map<absl::string_view,
|
73 |
+
std::pair<absl::string_view, absl::string_view>,
|
74 |
+
string_util::string_view_hash>
|
75 |
+
rev_merge;
|
76 |
+
|
77 |
+
// Pre-allocates SymbolPair for efficiency.
|
78 |
+
constexpr size_t kPreallocateSymbolPairSize = 256;
|
79 |
+
model::FreeList<SymbolPair> symbol_pair_allocator(kPreallocateSymbolPairSize);
|
80 |
+
|
81 |
+
// Lookup new symbol pair at [left, right] and inserts it to agenda.
|
82 |
+
auto MaybeAddNewSymbolPair = [this, &symbol_pair_allocator, &symbols, &agenda,
|
83 |
+
&rev_merge](int left, int right) {
|
84 |
+
if (left == -1 || right == -1 || symbols[left].freeze ||
|
85 |
+
symbols[right].freeze)
|
86 |
+
return;
|
87 |
+
const absl::string_view piece(
|
88 |
+
symbols[left].piece.data(),
|
89 |
+
symbols[left].piece.size() + symbols[right].piece.size());
|
90 |
+
const auto it = pieces_.find(piece);
|
91 |
+
if (it == pieces_.end()) {
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
auto *h = symbol_pair_allocator.Allocate();
|
95 |
+
h->left = left;
|
96 |
+
h->right = right;
|
97 |
+
h->score = GetScore(it->second);
|
98 |
+
h->size = piece.size();
|
99 |
+
agenda.push(h);
|
100 |
+
|
101 |
+
// Makes `rev_merge` for resegmentation.
|
102 |
+
if (IsUnusedInlined(it->second)) {
|
103 |
+
rev_merge[piece] =
|
104 |
+
std::make_pair(symbols[left].piece, symbols[right].piece);
|
105 |
+
}
|
106 |
+
};
|
107 |
+
|
108 |
+
// Splits the input into character sequence
|
109 |
+
int index = 0;
|
110 |
+
while (!normalized.empty()) {
|
111 |
+
Symbol s;
|
112 |
+
const int mblen = matcher_->PrefixMatch(normalized, &s.freeze);
|
113 |
+
s.piece = absl::string_view(normalized.data(), mblen);
|
114 |
+
s.prev = index == 0 ? -1 : index - 1;
|
115 |
+
normalized.remove_prefix(mblen);
|
116 |
+
s.next = normalized.empty() ? -1 : index + 1;
|
117 |
+
++index;
|
118 |
+
symbols.emplace_back(s);
|
119 |
+
}
|
120 |
+
|
121 |
+
if (symbols.empty()) {
|
122 |
+
return {};
|
123 |
+
}
|
124 |
+
|
125 |
+
// Lookup all bigrams.
|
126 |
+
for (size_t i = 1; i < symbols.size(); ++i) {
|
127 |
+
MaybeAddNewSymbolPair(i - 1, i);
|
128 |
+
}
|
129 |
+
|
130 |
+
// Main loop.
|
131 |
+
while (!agenda.empty()) {
|
132 |
+
SymbolPair *top = agenda.top();
|
133 |
+
agenda.pop();
|
134 |
+
|
135 |
+
// `top` is no longer available.
|
136 |
+
if (symbols[top->left].piece.empty() || symbols[top->right].piece.empty() ||
|
137 |
+
symbols[top->left].piece.size() + symbols[top->right].piece.size() !=
|
138 |
+
top->size) {
|
139 |
+
continue;
|
140 |
+
}
|
141 |
+
|
142 |
+
// Replaces symbols with `top` rule.
|
143 |
+
symbols[top->left].piece = absl::string_view(
|
144 |
+
symbols[top->left].piece.data(),
|
145 |
+
symbols[top->left].piece.size() + symbols[top->right].piece.size());
|
146 |
+
|
147 |
+
// Updates prev/next pointers.
|
148 |
+
symbols[top->left].next = symbols[top->right].next;
|
149 |
+
if (symbols[top->right].next >= 0) {
|
150 |
+
symbols[symbols[top->right].next].prev = top->left;
|
151 |
+
}
|
152 |
+
symbols[top->right].piece = absl::string_view("");
|
153 |
+
|
154 |
+
// Adds new symbol pairs which are newly added after symbol replacement.
|
155 |
+
MaybeAddNewSymbolPair(symbols[top->left].prev, top->left);
|
156 |
+
MaybeAddNewSymbolPair(top->left, symbols[top->left].next);
|
157 |
+
}
|
158 |
+
|
159 |
+
std::function<void(absl::string_view, EncodeResult *)> resegment;
|
160 |
+
resegment = [this, &resegment, &rev_merge](absl::string_view w,
|
161 |
+
EncodeResult *output) -> void {
|
162 |
+
const int id = PieceToId(w);
|
163 |
+
if (id == -1 || !IsUnusedInlined(id)) {
|
164 |
+
output->emplace_back(w, id);
|
165 |
+
return;
|
166 |
+
}
|
167 |
+
const auto p = rev_merge.find(w);
|
168 |
+
if (p == rev_merge.end()) {
|
169 |
+
// This block will never be called, as `rev_merge` stores all the
|
170 |
+
// resegmentation info for unused id.
|
171 |
+
output->emplace_back(w, id);
|
172 |
+
return;
|
173 |
+
}
|
174 |
+
// Recursively resegment left and right symbols.
|
175 |
+
resegment(p->second.first, output);
|
176 |
+
resegment(p->second.second, output);
|
177 |
+
};
|
178 |
+
|
179 |
+
EncodeResult output;
|
180 |
+
for (int index = 0; index != -1; index = symbols[index].next) {
|
181 |
+
CHECK_GE(index, 0);
|
182 |
+
CHECK_LT(index, static_cast<int>(symbols.size()));
|
183 |
+
resegment(symbols[index].piece, &output);
|
184 |
+
}
|
185 |
+
|
186 |
+
return output;
|
187 |
+
}
|
188 |
+
} // namespace bpe
|
189 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/bpe_model_trainer.h
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#ifndef BPE_MODEL_TRAINER_H_
|
16 |
+
#define BPE_MODEL_TRAINER_H_
|
17 |
+
|
18 |
+
#include <set>
|
19 |
+
#include <string>
|
20 |
+
#include <unordered_map>
|
21 |
+
#include <vector>
|
22 |
+
|
23 |
+
#include "sentencepiece_model.pb.h"
|
24 |
+
#include "trainer_interface.h"
|
25 |
+
|
26 |
+
namespace sentencepiece {
|
27 |
+
namespace bpe {
|
28 |
+
|
29 |
+
// Trainer class for BPE model.
|
30 |
+
class Trainer : public TrainerInterface {
|
31 |
+
public:
|
32 |
+
Trainer(const TrainerSpec &trainer_spec,
|
33 |
+
const NormalizerSpec &normalizer_spec)
|
34 |
+
: TrainerInterface::TrainerInterface(trainer_spec, normalizer_spec) {}
|
35 |
+
|
36 |
+
util::Status Train() override;
|
37 |
+
|
38 |
+
private:
|
39 |
+
// Symbol represents a character or symbol bigram.
|
40 |
+
struct Symbol {
|
41 |
+
const Symbol *left; // left symbol in bigram
|
42 |
+
const Symbol *right; // right symbol in bigram
|
43 |
+
string_util::UnicodeText chars; // all flattend chracter sequence
|
44 |
+
bool is_unk; // true if this symbol is unknown.
|
45 |
+
uint64 fp; // fingerprint of this symbol.
|
46 |
+
uint64 freq; // frequency of this symbol.
|
47 |
+
|
48 |
+
// Position list. Use set so that we can keep the order of occurrence.
|
49 |
+
// See EncodePos/DecodePos.
|
50 |
+
std::set<uint64> positions;
|
51 |
+
|
52 |
+
bool IsBigram() const { return left != nullptr && right != nullptr; }
|
53 |
+
std::string ToString() const;
|
54 |
+
Symbol() : left(nullptr), right(nullptr), is_unk(false), fp(0), freq(0) {}
|
55 |
+
};
|
56 |
+
|
57 |
+
struct Position {
|
58 |
+
int sid; // sentence id
|
59 |
+
int left; // left symbol index
|
60 |
+
int right; // right symbol index
|
61 |
+
};
|
62 |
+
|
63 |
+
// Encodes sid, left and right bigram index into uint64.
|
64 |
+
// Encoded value keeps the order of sid, left and right.
|
65 |
+
static uint64 EncodePos(int sid, int l, int r) {
|
66 |
+
CHECK_GE(l, 0);
|
67 |
+
CHECK_GE(r, 0);
|
68 |
+
CHECK_LE(l, kuint16max);
|
69 |
+
CHECK_LE(r, kuint16max);
|
70 |
+
const uint64 n = (static_cast<uint64>(sid) << 32 | (l << 16 | r));
|
71 |
+
return n;
|
72 |
+
}
|
73 |
+
|
74 |
+
// Decodes sid, left and right bigram index from uint64.
|
75 |
+
static Position DecodePos(uint64 n) {
|
76 |
+
Position p;
|
77 |
+
p.sid = n >> 32;
|
78 |
+
p.left = (n >> 16) & 0xffff;
|
79 |
+
p.right = n & 0xffff;
|
80 |
+
return p;
|
81 |
+
}
|
82 |
+
|
83 |
+
// Gets unary (character) symbol from the char code |c|.
|
84 |
+
// The return value is cached.
|
85 |
+
Symbol *GetCharSymbol(char32 c);
|
86 |
+
|
87 |
+
// Gets symbol pair from left/right symbols. The return value is cached.
|
88 |
+
Symbol *GetPairSymbol(const Symbol *left, const Symbol *right);
|
89 |
+
|
90 |
+
// Computes the frequency of |symbol| and update symbol->freq field.
|
91 |
+
void ComputeFreq(Symbol *symbol) const;
|
92 |
+
|
93 |
+
// Returns the valid index before symbols_[sid][index].
|
94 |
+
int GetNextIndex(int sid, int index) const;
|
95 |
+
|
96 |
+
// Returns the valid index after symbols_[sid][index].
|
97 |
+
int GetPrevIndex(int sid, int index) const;
|
98 |
+
|
99 |
+
// Makes a new bigram from [symbols_[sid][left], symbols_[sid][right]] and
|
100 |
+
// Adds it to symbols_cache_ and active_symbols_.
|
101 |
+
void AddNewPair(int sid, int left, int right);
|
102 |
+
|
103 |
+
// Resets the fequency of bigram [symbols_[sid][left] symbols_[sid][right]],
|
104 |
+
// if this bigram is not |best|.
|
105 |
+
void ResetFreq(int sid, int left, int right, const Symbol *best);
|
106 |
+
|
107 |
+
// Updates |active_symbols_| by copying the top 5% frequent symbols in
|
108 |
+
// symbols_cache_.
|
109 |
+
void UpdateActiveSymbols();
|
110 |
+
|
111 |
+
// All unique symbols. Key is a fingerprint of Symbol.
|
112 |
+
std::unordered_map<uint64, Symbol *> symbols_cache_;
|
113 |
+
|
114 |
+
// Set of symbols from which we find the best symbol in each iteration.
|
115 |
+
std::set<Symbol *> active_symbols_;
|
116 |
+
|
117 |
+
// Stores symbols allocated in heap so that we can delete them at onece.
|
118 |
+
std::vector<Symbol *> allocated_;
|
119 |
+
|
120 |
+
// Sentences. symbols_[sid][index] stores a symbol in sentence_[sid][index].
|
121 |
+
std::vector<std::vector<Symbol *>> symbols_;
|
122 |
+
};
|
123 |
+
} // namespace bpe
|
124 |
+
} // namespace sentencepiece
|
125 |
+
#endif // BPE_MODEL_TRAINER_H_
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/bpe_model_trainer_test.cc
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "bpe_model_trainer.h"
|
16 |
+
|
17 |
+
#include <string>
|
18 |
+
#include <vector>
|
19 |
+
#include "filesystem.h"
|
20 |
+
#include "flags.h"
|
21 |
+
#include "sentencepiece_processor.h"
|
22 |
+
#include "sentencepiece_trainer.h"
|
23 |
+
#include "testharness.h"
|
24 |
+
#include "util.h"
|
25 |
+
|
26 |
+
DECLARE_string(data_dir);
|
27 |
+
|
28 |
+
namespace sentencepiece {
|
29 |
+
namespace bpe {
|
30 |
+
namespace {
|
31 |
+
|
32 |
+
// Space symbol
|
33 |
+
#define WS "\xe2\x96\x81"
|
34 |
+
|
35 |
+
std::string RunTrainer(
|
36 |
+
const std::vector<std::string> &input, int size,
|
37 |
+
const std::vector<std::string> &user_defined_symbols = {}) {
|
38 |
+
test::ScopedTempFile input_scoped_file("input");
|
39 |
+
test::ScopedTempFile model_scoped_file("model");
|
40 |
+
const std::string input_file = input_scoped_file.filename();
|
41 |
+
const std::string model_prefix = model_scoped_file.filename();
|
42 |
+
{
|
43 |
+
auto output = filesystem::NewWritableFile(input_file);
|
44 |
+
for (const auto &line : input) {
|
45 |
+
output->WriteLine(line);
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
TrainerSpec trainer_spec;
|
50 |
+
trainer_spec.set_model_type(TrainerSpec::BPE);
|
51 |
+
trainer_spec.add_input(input_file);
|
52 |
+
trainer_spec.set_vocab_size(size - 3); // remove <unk>, <s>, </s>
|
53 |
+
trainer_spec.set_model_prefix(model_prefix);
|
54 |
+
|
55 |
+
NormalizerSpec normalizer_spec;
|
56 |
+
normalizer_spec.set_name("identity");
|
57 |
+
normalizer_spec.set_add_dummy_prefix(false);
|
58 |
+
|
59 |
+
for (const auto &w : user_defined_symbols) {
|
60 |
+
trainer_spec.add_user_defined_symbols(w);
|
61 |
+
}
|
62 |
+
|
63 |
+
Trainer trainer(trainer_spec, normalizer_spec);
|
64 |
+
EXPECT_OK(trainer.Train());
|
65 |
+
|
66 |
+
SentencePieceProcessor processor;
|
67 |
+
EXPECT_OK(processor.Load(model_prefix + ".model"));
|
68 |
+
|
69 |
+
const auto &model = processor.model_proto();
|
70 |
+
std::vector<std::string> pieces;
|
71 |
+
|
72 |
+
// remove <unk>, <s>, </s>
|
73 |
+
for (int i = 3; i < model.pieces_size(); ++i) {
|
74 |
+
pieces.emplace_back(model.pieces(i).piece());
|
75 |
+
}
|
76 |
+
|
77 |
+
return string_util::Join(pieces, " ");
|
78 |
+
}
|
79 |
+
|
80 |
+
TEST(BPETrainerTest, BasicTest) {
|
81 |
+
EXPECT_EQ("ab ra abra ad cad abracad abracadabra ac br a b r c d",
|
82 |
+
RunTrainer({"abracadabra"}, 20));
|
83 |
+
EXPECT_EQ("ap le app apple en in ine pen p e a l n i",
|
84 |
+
RunTrainer({"pen", "pineapple", "apple"}, 20));
|
85 |
+
EXPECT_EQ("he ll llo hello hellohe el lo oh hel ohe e h l o",
|
86 |
+
RunTrainer({"hellohe"}, 20));
|
87 |
+
EXPECT_EQ("app le en in ine pen pine ne pe e l n p i",
|
88 |
+
RunTrainer({"pen", "pineapple", "apple"}, 20, {"app"}));
|
89 |
+
}
|
90 |
+
|
91 |
+
TEST(BPETrainerTest, EndToEndTest) {
|
92 |
+
const test::ScopedTempFile sf("tmp_model");
|
93 |
+
const std::string input =
|
94 |
+
util::JoinPath(FLAGS_data_dir, "wagahaiwa_nekodearu.txt");
|
95 |
+
|
96 |
+
EXPECT_OK(SentencePieceTrainer::Train(string_util::StrCat(
|
97 |
+
"--model_prefix=", sf.filename(), " --input=", input,
|
98 |
+
" --vocab_size=8000 --normalization_rule_name=identity"
|
99 |
+
" --model_type=bpe --control_symbols=<ctrl> "
|
100 |
+
"--max_sentence_length=2048")));
|
101 |
+
|
102 |
+
SentencePieceProcessor sp;
|
103 |
+
EXPECT_OK(sp.Load(std::string(sf.filename()) + ".model"));
|
104 |
+
EXPECT_EQ(8000, sp.GetPieceSize());
|
105 |
+
|
106 |
+
const int cid = sp.PieceToId("<ctrl>");
|
107 |
+
EXPECT_TRUE(sp.IsControl(cid));
|
108 |
+
|
109 |
+
std::vector<std::string> tok;
|
110 |
+
EXPECT_OK(sp.Encode("", &tok));
|
111 |
+
EXPECT_TRUE(tok.empty());
|
112 |
+
|
113 |
+
EXPECT_OK(sp.Encode(
|
114 |
+
"吾輩《わがはい》は猫である。名前はまだ無い。"
|
115 |
+
"どこで生れたかとんと見当《けんとう》がつかぬ。"
|
116 |
+
"何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している"
|
117 |
+
"。",
|
118 |
+
&tok));
|
119 |
+
EXPECT_EQ(WS
|
120 |
+
" 吾輩 《 わが はい 》 は猫 である 。 名前 はまだ 無い 。 "
|
121 |
+
"どこで 生 れた か とん と見 当 《 けんとう 》 が つかぬ 。 "
|
122 |
+
"何でも 薄 暗 いじ め じ め した 所で ニャー ニャー 泣 いていた "
|
123 |
+
"事 だけは 記憶 している 。",
|
124 |
+
string_util::Join(tok, " "));
|
125 |
+
}
|
126 |
+
|
127 |
+
} // namespace
|
128 |
+
} // namespace bpe
|
129 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/builder.cc
ADDED
@@ -0,0 +1,581 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "builder.h"
|
16 |
+
#include <algorithm>
|
17 |
+
#include <functional>
|
18 |
+
#include <utility>
|
19 |
+
#include "filesystem.h"
|
20 |
+
|
21 |
+
#include "config.h"
|
22 |
+
|
23 |
+
#ifdef ENABLE_NFKC_COMPILE
|
24 |
+
#include <unicode/errorcode.h>
|
25 |
+
#include <unicode/locid.h>
|
26 |
+
#include <unicode/normlzr.h>
|
27 |
+
#include <unicode/numfmt.h>
|
28 |
+
#include <unicode/rbnf.h>
|
29 |
+
#include <unicode/utypes.h>
|
30 |
+
#endif
|
31 |
+
|
32 |
+
#include <set>
|
33 |
+
|
34 |
+
#include "normalization_rule.h"
|
35 |
+
#include "normalizer.h"
|
36 |
+
#include "third_party/darts_clone/darts.h"
|
37 |
+
#include "util.h"
|
38 |
+
|
39 |
+
namespace sentencepiece {
|
40 |
+
namespace normalizer {
|
41 |
+
namespace {
|
42 |
+
|
43 |
+
constexpr int kMaxUnicode = 0x10FFFF;
|
44 |
+
|
45 |
+
static constexpr char kDefaultNormalizerName[] = "nfkc";
|
46 |
+
|
47 |
+
#ifdef ENABLE_NFKC_COMPILE
|
48 |
+
// Normalize `input` with ICU's normalizer with `mode`.
|
49 |
+
Builder::Chars UnicodeNormalize(UNormalizationMode mode,
|
50 |
+
const Builder::Chars &input) {
|
51 |
+
const std::string utf8 = string_util::UnicodeTextToUTF8(input);
|
52 |
+
CHECK(!utf8.empty());
|
53 |
+
|
54 |
+
icu::UnicodeString ustr;
|
55 |
+
const size_t utf8_length = utf8.size();
|
56 |
+
UChar *utf16 = ustr.getBuffer(utf8.size() + 1);
|
57 |
+
int32 utf16_length = 0;
|
58 |
+
icu::ErrorCode icuerrorcode;
|
59 |
+
u_strFromUTF8Lenient(utf16, ustr.getCapacity(), &utf16_length, utf8.data(),
|
60 |
+
utf8_length, icuerrorcode);
|
61 |
+
ustr.releaseBuffer(utf16_length);
|
62 |
+
|
63 |
+
UErrorCode status = U_ZERO_ERROR;
|
64 |
+
icu::UnicodeString dst;
|
65 |
+
icu::Normalizer::normalize(ustr, mode, 0, dst, status);
|
66 |
+
CHECK(U_SUCCESS(status));
|
67 |
+
std::string normalized;
|
68 |
+
normalized.reserve(dst.length() * 3);
|
69 |
+
dst.toUTF8String(normalized);
|
70 |
+
return string_util::UTF8ToUnicodeText(normalized);
|
71 |
+
}
|
72 |
+
|
73 |
+
Builder::Chars ToNFKD(const Builder::Chars &input) {
|
74 |
+
return UnicodeNormalize(UNORM_NFKD, input);
|
75 |
+
}
|
76 |
+
|
77 |
+
Builder::Chars ToNFKC(const Builder::Chars &input) {
|
78 |
+
return UnicodeNormalize(UNORM_NFKC, input);
|
79 |
+
}
|
80 |
+
|
81 |
+
Builder::Chars ToNFC(const Builder::Chars &input) {
|
82 |
+
return UnicodeNormalize(UNORM_NFC, input);
|
83 |
+
}
|
84 |
+
|
85 |
+
Builder::Chars ToNFD(const Builder::Chars &input) {
|
86 |
+
return UnicodeNormalize(UNORM_NFD, input);
|
87 |
+
}
|
88 |
+
|
89 |
+
// Given an NFKD-normalized string, returns a set of all strings which are
|
90 |
+
// normalized into the same `nfkd`. `norm2orig` is the normalized to
|
91 |
+
// un-normalized character mapping.
|
92 |
+
std::vector<Builder::Chars> ExpandUnnormalized(
|
93 |
+
const Builder::Chars &nfkd,
|
94 |
+
const std::map<char32, std::set<char32>> &norm2orig) {
|
95 |
+
CHECK(!nfkd.empty());
|
96 |
+
std::vector<Builder::Chars> results;
|
97 |
+
for (const auto c : port::FindOrDie(norm2orig, nfkd[0])) {
|
98 |
+
results.push_back({c});
|
99 |
+
}
|
100 |
+
for (size_t i = 1; i < nfkd.size(); ++i) {
|
101 |
+
const auto &orig = port::FindOrDie(norm2orig, nfkd[i]);
|
102 |
+
std::vector<Builder::Chars> new_results;
|
103 |
+
for (const auto &r : results) {
|
104 |
+
for (const auto c : orig) {
|
105 |
+
new_results.emplace_back(r);
|
106 |
+
new_results.back().push_back(c);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
results = std::move(new_results);
|
110 |
+
}
|
111 |
+
CHECK_EQ(nfkd.size(), results[0].size());
|
112 |
+
return results;
|
113 |
+
}
|
114 |
+
#endif
|
115 |
+
|
116 |
+
// Normalizes `src` with `chars_map` and returns normalized Chars.
|
117 |
+
// `max_len` specifies the maximum length of the key in `chars_map`.
|
118 |
+
Builder::Chars Normalize(const Builder::CharsMap &chars_map,
|
119 |
+
const Builder::Chars &src, int max_len) {
|
120 |
+
CHECK_GE(max_len, 1);
|
121 |
+
Builder::Chars normalized;
|
122 |
+
|
123 |
+
for (size_t i = 0; i < src.size();) {
|
124 |
+
Builder::CharsMap::const_iterator it = chars_map.end();
|
125 |
+
const size_t slice = std::min<size_t>(i + max_len, src.size());
|
126 |
+
// starts with the longest prefix.
|
127 |
+
Builder::Chars key(src.begin() + i, src.begin() + slice);
|
128 |
+
while (!key.empty()) {
|
129 |
+
it = chars_map.find(key);
|
130 |
+
if (it != chars_map.end()) {
|
131 |
+
break;
|
132 |
+
}
|
133 |
+
key.pop_back(); // remove the last character.
|
134 |
+
}
|
135 |
+
|
136 |
+
// Consumes one character when no rule is found.
|
137 |
+
if (it == chars_map.end()) {
|
138 |
+
normalized.push_back(src[i]);
|
139 |
+
++i;
|
140 |
+
} else {
|
141 |
+
std::copy(it->second.begin(), it->second.end(),
|
142 |
+
std::back_inserter(normalized));
|
143 |
+
i += it->first.size();
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
return normalized;
|
148 |
+
}
|
149 |
+
} // namespace
|
150 |
+
|
151 |
+
// static
|
152 |
+
util::Status Builder::CompileCharsMap(const CharsMap &chars_map,
|
153 |
+
std::string *output) {
|
154 |
+
CHECK_OR_RETURN(output);
|
155 |
+
CHECK_OR_RETURN(!chars_map.empty());
|
156 |
+
|
157 |
+
LOG(INFO) << "Loading CharsMap of size=" << chars_map.size();
|
158 |
+
|
159 |
+
// Aggregates the same target strings to save footprint.
|
160 |
+
std::map<Chars, int> normalized2pos;
|
161 |
+
for (const auto &p : chars_map) {
|
162 |
+
normalized2pos[p.second] = 0;
|
163 |
+
}
|
164 |
+
|
165 |
+
std::string normalized;
|
166 |
+
for (auto &p : normalized2pos) {
|
167 |
+
p.second = normalized.size(); // stores the pointer (position).
|
168 |
+
const std::string utf8_out = string_util::UnicodeTextToUTF8(p.first);
|
169 |
+
CHECK_OR_RETURN(string_util::IsStructurallyValid(utf8_out));
|
170 |
+
normalized += utf8_out;
|
171 |
+
normalized += '\0';
|
172 |
+
}
|
173 |
+
|
174 |
+
std::vector<std::pair<std::string, int>> kv; // key-value of Trie.
|
175 |
+
for (const auto &p : chars_map) {
|
176 |
+
// The value of Trie stores the pointer to the normalized string.
|
177 |
+
const std::string utf8_in = string_util::UnicodeTextToUTF8(p.first);
|
178 |
+
CHECK_OR_RETURN(!utf8_in.empty());
|
179 |
+
CHECK_OR_RETURN(string_util::IsStructurallyValid(utf8_in));
|
180 |
+
kv.emplace_back(utf8_in, port::FindOrDie(normalized2pos, p.second));
|
181 |
+
}
|
182 |
+
|
183 |
+
std::sort(kv.begin(), kv.end());
|
184 |
+
std::vector<const char *> key(kv.size());
|
185 |
+
std::vector<int> value(kv.size());
|
186 |
+
for (size_t i = 0; i < kv.size(); ++i) {
|
187 |
+
key[i] = kv[i].first.c_str();
|
188 |
+
value[i] = kv[i].second;
|
189 |
+
}
|
190 |
+
|
191 |
+
Darts::DoubleArray trie;
|
192 |
+
CHECK_EQ_OR_RETURN(0, trie.build(key.size(), const_cast<char **>(&key[0]),
|
193 |
+
nullptr, &value[0]))
|
194 |
+
<< "cannot build double-array";
|
195 |
+
|
196 |
+
int max_nodes_size = 0;
|
197 |
+
std::vector<Darts::DoubleArray::result_pair_type> results(
|
198 |
+
2 * Normalizer::kMaxTrieResultsSize);
|
199 |
+
for (const char *str : key) {
|
200 |
+
const int num_nodes = trie.commonPrefixSearch(str, results.data(),
|
201 |
+
results.size(), strlen(str));
|
202 |
+
max_nodes_size = std::max(num_nodes, max_nodes_size);
|
203 |
+
}
|
204 |
+
CHECK_LT_OR_RETURN(max_nodes_size, Normalizer::kMaxTrieResultsSize)
|
205 |
+
<< "This charmaps contain many shared prefix. "
|
206 |
+
<< "The number of shared prefix must be less than "
|
207 |
+
<< Normalizer::kMaxTrieResultsSize;
|
208 |
+
|
209 |
+
absl::string_view trie_blob(static_cast<const char *>(trie.array()),
|
210 |
+
trie.size() * trie.unit_size());
|
211 |
+
*output = Normalizer::EncodePrecompiledCharsMap(trie_blob, normalized);
|
212 |
+
|
213 |
+
LOG(INFO) << "Generated normalizer blob. size=" << output->size();
|
214 |
+
|
215 |
+
return util::OkStatus();
|
216 |
+
}
|
217 |
+
|
218 |
+
// static
|
219 |
+
util::Status Builder::DecompileCharsMap(absl::string_view blob,
|
220 |
+
Builder::CharsMap *chars_map) {
|
221 |
+
CHECK_OR_RETURN(chars_map);
|
222 |
+
chars_map->clear();
|
223 |
+
|
224 |
+
absl::string_view trie_blob, normalized;
|
225 |
+
RETURN_IF_ERROR(
|
226 |
+
Normalizer::DecodePrecompiledCharsMap(blob, &trie_blob, &normalized));
|
227 |
+
|
228 |
+
Darts::DoubleArray trie;
|
229 |
+
trie.set_array(const_cast<char *>(trie_blob.data()),
|
230 |
+
trie_blob.size() / trie.unit_size());
|
231 |
+
|
232 |
+
std::string key;
|
233 |
+
std::function<void(size_t, size_t)> traverse;
|
234 |
+
|
235 |
+
// Given a Trie node at `node_pos` and the key position at `key_position`,
|
236 |
+
// Expands children nodes from `node_pos`.
|
237 |
+
// When leaf nodes are found, stores them into `chars_map`.
|
238 |
+
traverse = [&traverse, &key, &trie, &normalized, &chars_map](
|
239 |
+
size_t node_pos, size_t key_pos) -> void {
|
240 |
+
for (int c = 0; c <= 255; ++c) {
|
241 |
+
key.push_back(static_cast<char>(c));
|
242 |
+
size_t copied_node_pos = node_pos;
|
243 |
+
size_t copied_key_pos = key_pos;
|
244 |
+
// Note: `copied_(node|key)_pos` are non-const references.
|
245 |
+
// They store the new positions after node traversal.
|
246 |
+
const Darts::DoubleArray::result_type result = trie.traverse(
|
247 |
+
key.data(), copied_node_pos, copied_key_pos, key.size());
|
248 |
+
if (result >= -1) { // node exists.
|
249 |
+
if (result >= 0) { // has a value after transition.
|
250 |
+
const absl::string_view value = normalized.data() + result;
|
251 |
+
Chars key_chars, value_chars;
|
252 |
+
for (const auto c : string_util::UTF8ToUnicodeText(key))
|
253 |
+
key_chars.push_back(c);
|
254 |
+
for (const auto c : string_util::UTF8ToUnicodeText(value))
|
255 |
+
value_chars.push_back(c);
|
256 |
+
(*chars_map)[key_chars] = value_chars;
|
257 |
+
}
|
258 |
+
// Recursively traverse.
|
259 |
+
traverse(copied_node_pos, copied_key_pos);
|
260 |
+
}
|
261 |
+
key.pop_back();
|
262 |
+
}
|
263 |
+
};
|
264 |
+
|
265 |
+
traverse(0, 0);
|
266 |
+
|
267 |
+
return util::OkStatus();
|
268 |
+
}
|
269 |
+
|
270 |
+
// static
|
271 |
+
util::Status Builder::GetPrecompiledCharsMap(const std::string &name,
|
272 |
+
std::string *output) {
|
273 |
+
CHECK_OR_RETURN(output);
|
274 |
+
|
275 |
+
if (name == "identity") {
|
276 |
+
output->clear();
|
277 |
+
return util::OkStatus();
|
278 |
+
}
|
279 |
+
|
280 |
+
std::string result;
|
281 |
+
for (size_t i = 0; i < kNormalizationRules_size; ++i) {
|
282 |
+
const auto *blob = &kNormalizationRules_blob[i];
|
283 |
+
if (blob->name == name) {
|
284 |
+
output->assign(blob->data, blob->size);
|
285 |
+
return util::OkStatus();
|
286 |
+
}
|
287 |
+
}
|
288 |
+
return util::StatusBuilder(util::error::NOT_FOUND)
|
289 |
+
<< "No precompiled charsmap is found: " << name;
|
290 |
+
}
|
291 |
+
|
292 |
+
// static
|
293 |
+
util::Status Builder::BuildNFKCMap(CharsMap *chars_map) {
|
294 |
+
#ifdef ENABLE_NFKC_COMPILE
|
295 |
+
LOG(INFO) << "Running BuildNFKCMap";
|
296 |
+
|
297 |
+
// Set of fully NFKD decomposed characters.
|
298 |
+
std::set<Builder::Chars> nfkd_decomposed;
|
299 |
+
|
300 |
+
// Fully normalized one character to unnormalized one character map.
|
301 |
+
std::map<char32, std::set<char32>> norm2orig;
|
302 |
+
|
303 |
+
Builder::CharsMap nfkc_map; // The final NFKC mapping.
|
304 |
+
|
305 |
+
constexpr int kMaxUnicode = 0x10FFFF;
|
306 |
+
for (char32 cp = 1; cp <= kMaxUnicode; ++cp) {
|
307 |
+
if (!U_IS_UNICODE_CHAR(cp)) {
|
308 |
+
continue;
|
309 |
+
}
|
310 |
+
// Aggregates single character to fully NFKC normalized characters.
|
311 |
+
const auto nfkc = ToNFKC({cp});
|
312 |
+
if (nfkc.size() >= 2 || (nfkc.size() == 1 && nfkc[0] != cp)) {
|
313 |
+
nfkc_map[{cp}] = nfkc;
|
314 |
+
}
|
315 |
+
const auto nfkd = ToNFKD({cp});
|
316 |
+
if (nfkd.size() == 1) {
|
317 |
+
// Aggregates reverse mapping from normalized to unnormalized character.
|
318 |
+
norm2orig[nfkd[0]].insert(cp);
|
319 |
+
} else {
|
320 |
+
// One character is decomposed into multiple characters.
|
321 |
+
nfkd_decomposed.insert(nfkd);
|
322 |
+
}
|
323 |
+
}
|
324 |
+
|
325 |
+
for (const auto &nfkd : nfkd_decomposed) {
|
326 |
+
const auto nfkc = ToNFC(nfkd);
|
327 |
+
// This case is already covered by single-character to NFKC mapping.
|
328 |
+
if (nfkc == nfkd) {
|
329 |
+
continue;
|
330 |
+
}
|
331 |
+
// Expand all possible sequences which are normalized into the same
|
332 |
+
// `nfkd`.
|
333 |
+
for (const auto &nfkd_orig : ExpandUnnormalized(nfkd, norm2orig)) {
|
334 |
+
if (nfkd_orig != nfkc) {
|
335 |
+
nfkc_map[nfkd_orig] = nfkc;
|
336 |
+
}
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
RETURN_IF_ERROR(RemoveRedundantMap(&nfkc_map));
|
341 |
+
*chars_map = std::move(nfkc_map);
|
342 |
+
|
343 |
+
#else
|
344 |
+
LOG(ERROR) << "NFKC compile is not enabled."
|
345 |
+
<< " rebuild with ./configure --enable-nfkc-compile";
|
346 |
+
#endif
|
347 |
+
|
348 |
+
return util::OkStatus();
|
349 |
+
}
|
350 |
+
|
351 |
+
util::Status Builder::BuildNmtNFKCMap(CharsMap *chars_map) {
|
352 |
+
#ifdef ENABLE_NFKC_COMPILE
|
353 |
+
LOG(INFO) << "Running BuildNmtNFKCMap";
|
354 |
+
|
355 |
+
CharsMap nfkc_map;
|
356 |
+
RETURN_IF_ERROR(Builder::BuildNFKCMap(&nfkc_map));
|
357 |
+
|
358 |
+
// Other code points considered as whitespace.
|
359 |
+
nfkc_map[{0x0009}] = {0x20}; // TAB
|
360 |
+
nfkc_map[{0x000A}] = {0x20}; // LINE FEED
|
361 |
+
nfkc_map[{0x000C}] = {0x20}; // FORM FEED
|
362 |
+
nfkc_map[{0x000D}] = {0x20}; // CARRIAGE RETURN
|
363 |
+
nfkc_map[{0x1680}] = {0x20}; // OGHAM SPACE MARK
|
364 |
+
nfkc_map[{0x200B}] = {0x20}; // ZERO WIDTH SPACE
|
365 |
+
nfkc_map[{0x200E}] = {0x20}; // LEFT-TO-RIGHT MARK
|
366 |
+
nfkc_map[{0x200F}] = {0x20}; // RIGHT-TO-LEFT MARK
|
367 |
+
nfkc_map[{0x2028}] = {0x20}; // LINE SEPARATOR
|
368 |
+
nfkc_map[{0x2029}] = {0x20}; // PARAGRAPH SEPARATOR
|
369 |
+
nfkc_map[{0x2581}] = {0x20}; // LOWER ONE EIGHT BLOCK
|
370 |
+
nfkc_map[{0xFEFF}] = {0x20}; // ZERO WIDTH NO-BREAK
|
371 |
+
nfkc_map[{0xFFFD}] = {0x20}; // REPLACEMENT CHARACTER
|
372 |
+
nfkc_map[{0x200C}] = {0x20}; // ZERO WIDTH NON-JOINER
|
373 |
+
nfkc_map[{0x200D}] = {0x20}; // ZERO WIDTH JOINER
|
374 |
+
|
375 |
+
// Ascii Control characters
|
376 |
+
nfkc_map[{0x0001}] = {};
|
377 |
+
nfkc_map[{0x0002}] = {};
|
378 |
+
nfkc_map[{0x0003}] = {};
|
379 |
+
nfkc_map[{0x0004}] = {};
|
380 |
+
nfkc_map[{0x0005}] = {};
|
381 |
+
nfkc_map[{0x0006}] = {};
|
382 |
+
nfkc_map[{0x0007}] = {};
|
383 |
+
nfkc_map[{0x0008}] = {};
|
384 |
+
nfkc_map[{0x000B}] = {};
|
385 |
+
nfkc_map[{0x000E}] = {};
|
386 |
+
nfkc_map[{0x000F}] = {};
|
387 |
+
nfkc_map[{0x0010}] = {};
|
388 |
+
nfkc_map[{0x0011}] = {};
|
389 |
+
nfkc_map[{0x0012}] = {};
|
390 |
+
nfkc_map[{0x0013}] = {};
|
391 |
+
nfkc_map[{0x0014}] = {};
|
392 |
+
nfkc_map[{0x0015}] = {};
|
393 |
+
nfkc_map[{0x0016}] = {};
|
394 |
+
nfkc_map[{0x0017}] = {};
|
395 |
+
nfkc_map[{0x0018}] = {};
|
396 |
+
nfkc_map[{0x0019}] = {};
|
397 |
+
nfkc_map[{0x001A}] = {};
|
398 |
+
nfkc_map[{0x001B}] = {};
|
399 |
+
nfkc_map[{0x001C}] = {};
|
400 |
+
nfkc_map[{0x001D}] = {};
|
401 |
+
nfkc_map[{0x001E}] = {};
|
402 |
+
nfkc_map[{0x001F}] = {};
|
403 |
+
|
404 |
+
// <control-007F>..<control-009F>
|
405 |
+
nfkc_map[{0x007F}] = {};
|
406 |
+
nfkc_map[{0x008F}] = {};
|
407 |
+
nfkc_map[{0x009F}] = {};
|
408 |
+
|
409 |
+
// Do not normalize FULL_WIDTH TILDE, since FULL_WIDTH TILDE
|
410 |
+
// and HALF_WIDTH TILDE are used differently in Japanese.
|
411 |
+
nfkc_map.erase({0xFF5E});
|
412 |
+
|
413 |
+
RETURN_IF_ERROR(RemoveRedundantMap(&nfkc_map));
|
414 |
+
|
415 |
+
*chars_map = std::move(nfkc_map);
|
416 |
+
|
417 |
+
#else
|
418 |
+
LOG(ERROR) << "NFKC compile is not enabled."
|
419 |
+
<< " rebuild with ./configure --enable-nfkc-compile";
|
420 |
+
#endif
|
421 |
+
|
422 |
+
return util::OkStatus();
|
423 |
+
}
|
424 |
+
|
425 |
+
// static
|
426 |
+
util::Status Builder::MergeUnicodeCaseFoldMap(Builder::CharsMap *chars_map) {
|
427 |
+
#ifdef ENABLE_NFKC_COMPILE
|
428 |
+
for (auto &c : *chars_map) {
|
429 |
+
std::vector<char32> trg;
|
430 |
+
for (char32 c : c.second) trg.push_back(u_foldCase(c, U_FOLD_CASE_DEFAULT));
|
431 |
+
c.second = trg;
|
432 |
+
}
|
433 |
+
|
434 |
+
constexpr int kMaxUnicode = 0x10FFFF;
|
435 |
+
for (char32 cp = 1; cp <= kMaxUnicode; ++cp) {
|
436 |
+
if (!U_IS_UNICODE_CHAR(cp)) {
|
437 |
+
continue;
|
438 |
+
}
|
439 |
+
if (chars_map->find({cp}) != chars_map->end()) continue;
|
440 |
+
const char32 trg = u_foldCase(cp, U_FOLD_CASE_DEFAULT);
|
441 |
+
if (trg != cp) (*chars_map)[{cp}] = {trg};
|
442 |
+
}
|
443 |
+
|
444 |
+
RETURN_IF_ERROR(RemoveRedundantMap(chars_map));
|
445 |
+
#endif
|
446 |
+
|
447 |
+
return util::OkStatus();
|
448 |
+
}
|
449 |
+
|
450 |
+
// static
|
451 |
+
util::Status Builder::BuildNFKC_CFMap(CharsMap *chars_map) {
|
452 |
+
#ifdef ENABLE_NFKC_COMPILE
|
453 |
+
CharsMap nfkc_map;
|
454 |
+
RETURN_IF_ERROR(Builder::BuildNFKCMap(&nfkc_map));
|
455 |
+
RETURN_IF_ERROR(Builder::MergeUnicodeCaseFoldMap(&nfkc_map));
|
456 |
+
*chars_map = std::move(nfkc_map);
|
457 |
+
#else
|
458 |
+
LOG(ERROR) << "NFKC_CF compile is not enabled."
|
459 |
+
<< " rebuild with ./configure --enable-nfkc-compile";
|
460 |
+
#endif
|
461 |
+
|
462 |
+
return util::OkStatus();
|
463 |
+
}
|
464 |
+
|
465 |
+
// static
|
466 |
+
util::Status Builder::BuildNmtNFKC_CFMap(CharsMap *chars_map) {
|
467 |
+
#ifdef ENABLE_NFKC_COMPILE
|
468 |
+
CharsMap nfkc_map;
|
469 |
+
RETURN_IF_ERROR(Builder::BuildNmtNFKCMap(&nfkc_map));
|
470 |
+
RETURN_IF_ERROR(Builder::MergeUnicodeCaseFoldMap(&nfkc_map));
|
471 |
+
*chars_map = std::move(nfkc_map);
|
472 |
+
#else
|
473 |
+
LOG(ERROR) << "NMT_NFKC_CF compile is not enabled."
|
474 |
+
<< " rebuild with ./configure --enable-nfkc-compile";
|
475 |
+
#endif
|
476 |
+
|
477 |
+
return util::OkStatus();
|
478 |
+
}
|
479 |
+
|
480 |
+
// static
|
481 |
+
util::Status Builder::LoadCharsMap(absl::string_view filename,
|
482 |
+
CharsMap *chars_map) {
|
483 |
+
LOG(INFO) << "Loading maping file: " << filename.data();
|
484 |
+
CHECK_OR_RETURN(chars_map);
|
485 |
+
|
486 |
+
auto input = filesystem::NewReadableFile(filename);
|
487 |
+
|
488 |
+
RETURN_IF_ERROR(input->status());
|
489 |
+
|
490 |
+
std::string line;
|
491 |
+
chars_map->clear();
|
492 |
+
while (input->ReadLine(&line)) {
|
493 |
+
auto fields = string_util::SplitPiece(line, "\t", true /* allow empty*/);
|
494 |
+
CHECK_GE(fields.size(), 1);
|
495 |
+
if (fields.size() == 1) fields.push_back(""); // Deletion rule.
|
496 |
+
std::vector<char32> src, trg;
|
497 |
+
for (auto &s : string_util::SplitPiece(fields[0], " ")) {
|
498 |
+
if (s.empty()) continue;
|
499 |
+
string_util::ConsumePrefix(&s, "U+");
|
500 |
+
src.push_back(string_util::HexToInt<char32>(s));
|
501 |
+
}
|
502 |
+
for (auto &s : string_util::SplitPiece(fields[1], " ")) {
|
503 |
+
if (s.empty()) continue;
|
504 |
+
string_util::ConsumePrefix(&s, "U+");
|
505 |
+
trg.push_back(string_util::HexToInt<char32>(s));
|
506 |
+
}
|
507 |
+
CHECK_OR_RETURN(!src.empty());
|
508 |
+
(*chars_map)[src] = trg;
|
509 |
+
}
|
510 |
+
|
511 |
+
return util::OkStatus();
|
512 |
+
}
|
513 |
+
|
514 |
+
// static
|
515 |
+
util::Status Builder::SaveCharsMap(absl::string_view filename,
|
516 |
+
const Builder::CharsMap &chars_map) {
|
517 |
+
auto output = filesystem::NewWritableFile(filename);
|
518 |
+
RETURN_IF_ERROR(output->status());
|
519 |
+
|
520 |
+
for (const auto &c : chars_map) {
|
521 |
+
std::vector<std::string> src, trg;
|
522 |
+
string_util::UnicodeText srcu, trgu;
|
523 |
+
for (char32 v : c.first) {
|
524 |
+
src.push_back(string_util::IntToHex(v));
|
525 |
+
srcu.push_back(v);
|
526 |
+
}
|
527 |
+
for (char32 v : c.second) {
|
528 |
+
trg.push_back(string_util::IntToHex(v));
|
529 |
+
trgu.push_back(v);
|
530 |
+
}
|
531 |
+
std::string line = string_util::Join(src, " ") + "\t" +
|
532 |
+
string_util::Join(trg, " ") + "\t# " +
|
533 |
+
string_util::UnicodeTextToUTF8(c.first) + " => " +
|
534 |
+
string_util::UnicodeTextToUTF8(c.second);
|
535 |
+
line = string_util::StringReplace(line, "\b", " ", true);
|
536 |
+
line = string_util::StringReplace(line, "\v", " ", true);
|
537 |
+
line = string_util::StringReplace(line, "\f", " ", true);
|
538 |
+
line = string_util::StringReplace(line, "\n", " ", true);
|
539 |
+
line = string_util::StringReplace(line, "\r", " ", true);
|
540 |
+
output->WriteLine(line);
|
541 |
+
}
|
542 |
+
|
543 |
+
return util::OkStatus();
|
544 |
+
}
|
545 |
+
|
546 |
+
// static
|
547 |
+
util::Status Builder::RemoveRedundantMap(CharsMap *chars_map) {
|
548 |
+
CHECK_OR_RETURN(chars_map);
|
549 |
+
|
550 |
+
CharsMap new_chars_map;
|
551 |
+
size_t max_len = 0;
|
552 |
+
for (const auto &p : *chars_map) {
|
553 |
+
max_len = std::max(p.first.size(), max_len);
|
554 |
+
if (p.first.size() == 1) {
|
555 |
+
new_chars_map.insert(p);
|
556 |
+
}
|
557 |
+
}
|
558 |
+
CHECK_GT_OR_RETURN(max_len, 0);
|
559 |
+
|
560 |
+
// Checks whether the rules with size of `len` can be normalized by
|
561 |
+
// the rules with size of [1 .. len - 1].
|
562 |
+
for (size_t len = 2; len <= max_len; ++len) {
|
563 |
+
for (const auto &p : *chars_map) {
|
564 |
+
if (p.first.size() == len &&
|
565 |
+
p.second != Normalize(new_chars_map, p.first, len - 1)) {
|
566 |
+
new_chars_map.insert(p);
|
567 |
+
}
|
568 |
+
}
|
569 |
+
}
|
570 |
+
|
571 |
+
// Verify all characters in `chars_map` are normalized by `new_chars_map`.
|
572 |
+
for (const auto &p : *chars_map) {
|
573 |
+
CHECK_EQ_OR_RETURN(p.second, Normalize(new_chars_map, p.first, max_len));
|
574 |
+
}
|
575 |
+
|
576 |
+
*chars_map = std::move(new_chars_map);
|
577 |
+
|
578 |
+
return util::OkStatus();
|
579 |
+
}
|
580 |
+
} // namespace normalizer
|
581 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/builder.h
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#ifndef BUILDER_H_
|
16 |
+
#define BUILDER_H_
|
17 |
+
|
18 |
+
#include <map>
|
19 |
+
#include <string>
|
20 |
+
#include <vector>
|
21 |
+
#include "common.h"
|
22 |
+
#include "sentencepiece_model.pb.h"
|
23 |
+
#include "sentencepiece_processor.h"
|
24 |
+
#include "third_party/absl/strings/string_view.h"
|
25 |
+
|
26 |
+
namespace sentencepiece {
|
27 |
+
namespace normalizer {
|
28 |
+
|
29 |
+
// Builder creates a text normalization rule from user-defined string
|
30 |
+
// to string mappings. The normalization mapping is compiled into
|
31 |
+
// a single and compact blob index which is stored into the model proto.
|
32 |
+
// This class also provides pre-defined rules based on Unicode NFKC.
|
33 |
+
// https://en.wikipedia.org/wiki/Unicode_equivalence#Normalization
|
34 |
+
class Builder {
|
35 |
+
public:
|
36 |
+
Builder() = delete;
|
37 |
+
~Builder() = delete;
|
38 |
+
|
39 |
+
// Basic Unicode character sequence.
|
40 |
+
using Chars = std::vector<char32>;
|
41 |
+
|
42 |
+
// String-to-string mapping.
|
43 |
+
using CharsMap = std::map<Chars, Chars>;
|
44 |
+
|
45 |
+
static util::Status CompileCharsMap(const CharsMap &chars_map,
|
46 |
+
std::string *output);
|
47 |
+
|
48 |
+
// Decompiles `blob` into `chars_map`.
|
49 |
+
static util::Status DecompileCharsMap(absl::string_view blob,
|
50 |
+
CharsMap *chars_map);
|
51 |
+
|
52 |
+
// Returns a pre-compiled binary index with `name`.
|
53 |
+
static util::Status GetPrecompiledCharsMap(const std::string &name,
|
54 |
+
std::string *output);
|
55 |
+
|
56 |
+
// Makes a normalization mapping based on NFKC.
|
57 |
+
//
|
58 |
+
// Note that Normalizer/Builder classes do not support
|
59 |
+
// full NFKC normalization, since full NFKC normalization cannot
|
60 |
+
// be implemented with a simple longest matching string-to-string
|
61 |
+
// replacement. One unsupported normalization is multiple combining
|
62 |
+
// marks.
|
63 |
+
//
|
64 |
+
// Strings with multiple combining marks cannot correctly
|
65 |
+
// be normalized, because it needs to sort the combining marks
|
66 |
+
// with Canonical_Combining_Class (CCC).
|
67 |
+
// http://unicode.org/reports/tr15/#Multiple_Mark_Figure
|
68 |
+
//
|
69 |
+
// Example:
|
70 |
+
// Original: U+1E0B U+0323
|
71 |
+
// Decomposed: U+0064 U+0307 U+0323
|
72 |
+
// NFKD: U+0064 U+0323 U+0307 (Combining characters are sorted by CCC)
|
73 |
+
// NFKC: U+1E0D U+0307 (U+0064 U+0323 => U+1E0D)
|
74 |
+
//
|
75 |
+
// To support the normalization above with a longest matching, we need to
|
76 |
+
// enumerate all possible permutations of combining marks in advance,
|
77 |
+
// which is not feasible. For example, suppose the case there are three
|
78 |
+
// combining marks X, Y and Z, which are sorted into one canonical order
|
79 |
+
// Z, Y, X with NFK(D|C). In this case, all permutations (XYZ, XZY, YXZ...)
|
80 |
+
// are normalized into ZYX. When we implement this normalization with
|
81 |
+
// a longest matching, we need to have 3! rules. XYZ=>ZYX, XZY=>ZYX..
|
82 |
+
// Since Unicode has more than 100 combining characters, it is not possible
|
83 |
+
// to expand all permutations.
|
84 |
+
//
|
85 |
+
// We will not implement the full NFKC in SentencePiece because
|
86 |
+
// 1) It is unusual to see decomposed Unicode characters in real text.
|
87 |
+
// 2) Providing a flexible, user-customizable, and self-contained
|
88 |
+
// normalizer is the goal of SentencePiece.
|
89 |
+
//
|
90 |
+
// TODO(taku): Make NFC, NFD, and NFKD mapping if necessary.
|
91 |
+
static util::Status BuildNFKCMap(CharsMap *chars_map);
|
92 |
+
|
93 |
+
// Makes an NFKC-based mapping with NMT specific modifications around
|
94 |
+
// whitespaces.
|
95 |
+
static util::Status BuildNmtNFKCMap(CharsMap *chars_map);
|
96 |
+
|
97 |
+
// Merge Unicode case folding mapping into `chars_map`.
|
98 |
+
static util::Status MergeUnicodeCaseFoldMap(CharsMap *chars_map);
|
99 |
+
|
100 |
+
// Makes NFKC with Unicode case folding.
|
101 |
+
static util::Status BuildNFKC_CFMap(CharsMap *chars_map);
|
102 |
+
|
103 |
+
// Makes NMT NFKC with Unicode case folding.
|
104 |
+
static util::Status BuildNmtNFKC_CFMap(CharsMap *chars_map);
|
105 |
+
|
106 |
+
// Builds Chars map save in `filename`.
|
107 |
+
// Format:
|
108 |
+
// src_uchar1 src_uchar2 ... <tab> trg_uchar1 trg_uchar2...
|
109 |
+
// (src|trg)_ucharX must be a hex of Unicode code point.
|
110 |
+
static util::Status LoadCharsMap(absl::string_view filename,
|
111 |
+
CharsMap *chars_map);
|
112 |
+
|
113 |
+
// Saves Chars map to `filename` as TSV.
|
114 |
+
static util::Status SaveCharsMap(absl::string_view filename,
|
115 |
+
const CharsMap &chars_map);
|
116 |
+
|
117 |
+
private:
|
118 |
+
FRIEND_TEST(BuilderTest, RemoveRedundantMapTest);
|
119 |
+
|
120 |
+
// Removes redundant rules from `chars_map`.
|
121 |
+
// When char_maps have "aa" => "bb" and "a" => "b", the first
|
122 |
+
// rule is not necessary since the second rule can cover the first rule.
|
123 |
+
static util::Status RemoveRedundantMap(CharsMap *chars_map);
|
124 |
+
};
|
125 |
+
} // namespace normalizer
|
126 |
+
} // namespace sentencepiece
|
127 |
+
#endif // BUILDER_H_
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/builder_test.cc
ADDED
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "builder.h"
|
16 |
+
#include "common.h"
|
17 |
+
#include "filesystem.h"
|
18 |
+
#include "flags.h"
|
19 |
+
#include "normalizer.h"
|
20 |
+
#include "sentencepiece_trainer.h"
|
21 |
+
#include "testharness.h"
|
22 |
+
#include "util.h"
|
23 |
+
|
24 |
+
DECLARE_string(data_dir);
|
25 |
+
|
26 |
+
namespace sentencepiece {
|
27 |
+
namespace normalizer {
|
28 |
+
|
29 |
+
// Space symbol
|
30 |
+
#define WS "\xe2\x96\x81"
|
31 |
+
|
32 |
+
TEST(BuilderTest, RemoveRedundantMapTest) {
|
33 |
+
Builder::CharsMap chars_map;
|
34 |
+
|
35 |
+
// ab => AB, a => A, b => B, abc => BCA
|
36 |
+
chars_map[{0x0061}] = {0x0041};
|
37 |
+
chars_map[{0x0062}] = {0x0042};
|
38 |
+
chars_map[{0x0061, 0x0062}] = {0x0041, 0x0042};
|
39 |
+
chars_map[{0x0061, 0x0062, 0x0063}] = {0x0043, 0x0042, 0x0041};
|
40 |
+
|
41 |
+
EXPECT_OK(Builder::RemoveRedundantMap(&chars_map));
|
42 |
+
EXPECT_EQ(3, chars_map.size());
|
43 |
+
EXPECT_EQ(chars_map.end(), chars_map.find({0x0061, 0x0062}));
|
44 |
+
EXPECT_NE(chars_map.end(), chars_map.find({0x0061}));
|
45 |
+
EXPECT_NE(chars_map.end(), chars_map.find({0x0062}));
|
46 |
+
EXPECT_NE(chars_map.end(), chars_map.find({0x0061, 0x0062, 0x0063}));
|
47 |
+
}
|
48 |
+
|
49 |
+
TEST(BuilderTest, GetPrecompiledCharsMapWithInvalidNameTest) {
|
50 |
+
std::string output;
|
51 |
+
EXPECT_NOT_OK(Builder::GetPrecompiledCharsMap("", &output));
|
52 |
+
EXPECT_NOT_OK(Builder::GetPrecompiledCharsMap("__UNKNOWN__", &output));
|
53 |
+
}
|
54 |
+
|
55 |
+
TEST(BuilderTest, BuildNFKCMapTest) {
|
56 |
+
Builder::CharsMap chars_map;
|
57 |
+
#ifdef ENABLE_NFKC_COMPILE
|
58 |
+
EXPECT_OK(Builder::BuildNFKCMap(&chars_map));
|
59 |
+
EXPECT_TRUE(!chars_map.empty());
|
60 |
+
#else
|
61 |
+
EXPECT_OK(Builder::BuildNFKCMap(&chars_map));
|
62 |
+
#endif
|
63 |
+
}
|
64 |
+
|
65 |
+
TEST(BuilderTest, GetPrecompiledCharsMapTest) {
|
66 |
+
{
|
67 |
+
const NormalizerSpec spec =
|
68 |
+
SentencePieceTrainer::GetNormalizerSpec("nmt_nfkc");
|
69 |
+
const Normalizer normalizer(spec);
|
70 |
+
EXPECT_EQ(WS "ABC", normalizer.Normalize("ABC"));
|
71 |
+
EXPECT_EQ(WS "(株)", normalizer.Normalize("㈱"));
|
72 |
+
EXPECT_EQ(WS "グーグル", normalizer.Normalize("グーグル"));
|
73 |
+
}
|
74 |
+
|
75 |
+
{
|
76 |
+
const NormalizerSpec spec =
|
77 |
+
SentencePieceTrainer::GetNormalizerSpec("nfkc_cf");
|
78 |
+
const Normalizer normalizer(spec);
|
79 |
+
EXPECT_EQ(WS "abc", normalizer.Normalize("ABC"));
|
80 |
+
EXPECT_EQ(WS "abc", normalizer.Normalize("ABC"));
|
81 |
+
}
|
82 |
+
|
83 |
+
{
|
84 |
+
const NormalizerSpec spec =
|
85 |
+
SentencePieceTrainer::GetNormalizerSpec("nmt_nfkc_cf");
|
86 |
+
const Normalizer normalizer(spec);
|
87 |
+
EXPECT_EQ(WS "abc", normalizer.Normalize("ABC"));
|
88 |
+
EXPECT_EQ(WS "abc", normalizer.Normalize("ABC"));
|
89 |
+
}
|
90 |
+
|
91 |
+
{
|
92 |
+
const NormalizerSpec spec =
|
93 |
+
SentencePieceTrainer::GetNormalizerSpec("identity");
|
94 |
+
EXPECT_TRUE(spec.precompiled_charsmap().empty());
|
95 |
+
const Normalizer normalizer(spec);
|
96 |
+
EXPECT_EQ(WS "ABC", normalizer.Normalize("ABC"));
|
97 |
+
EXPECT_EQ(WS "㈱", normalizer.Normalize("㈱"));
|
98 |
+
EXPECT_EQ(WS "グーグル", normalizer.Normalize("グーグル"));
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
TEST(BuilderTest, CompileCharsMap) {
|
103 |
+
Builder::CharsMap chars_map;
|
104 |
+
|
105 |
+
// Lowercase => Uppercase
|
106 |
+
for (char32 lc = static_cast<char32>('a'); lc <= static_cast<char32>('z');
|
107 |
+
++lc) {
|
108 |
+
const char32 uc = lc + 'A' - 'a';
|
109 |
+
chars_map[{lc}] = {uc};
|
110 |
+
}
|
111 |
+
|
112 |
+
// あいう => abc
|
113 |
+
chars_map[{0x3042, 0x3044, 0x3046}] = {0x0061, 0x0062, 0x0063};
|
114 |
+
|
115 |
+
// えお => remove
|
116 |
+
chars_map[{0x3048, 0x304A}] = {};
|
117 |
+
|
118 |
+
NormalizerSpec spec;
|
119 |
+
EXPECT_OK(
|
120 |
+
Builder::CompileCharsMap(chars_map, spec.mutable_precompiled_charsmap()));
|
121 |
+
Builder::CharsMap decompiled_chars_map;
|
122 |
+
EXPECT_OK(Builder::DecompileCharsMap(spec.precompiled_charsmap(),
|
123 |
+
&decompiled_chars_map));
|
124 |
+
EXPECT_EQ(chars_map, decompiled_chars_map);
|
125 |
+
|
126 |
+
spec.set_add_dummy_prefix(false);
|
127 |
+
const Normalizer normalizer(spec);
|
128 |
+
|
129 |
+
EXPECT_EQ("ABC", normalizer.Normalize("abc"));
|
130 |
+
EXPECT_EQ("ABC", normalizer.Normalize("ABC"));
|
131 |
+
EXPECT_EQ("XY" WS "Z", normalizer.Normalize("xy z"));
|
132 |
+
|
133 |
+
EXPECT_EQ("あ", normalizer.Normalize("あ"));
|
134 |
+
EXPECT_EQ("abc", normalizer.Normalize("あいう"));
|
135 |
+
EXPECT_EQ("abcえ", normalizer.Normalize("あいうえ"));
|
136 |
+
EXPECT_EQ("ABCabcD", normalizer.Normalize("abcあいうd"));
|
137 |
+
EXPECT_EQ("abcか", normalizer.Normalize("あいうえおか"));
|
138 |
+
}
|
139 |
+
|
140 |
+
TEST(BuilderTest, LoadCharsMapTest) {
|
141 |
+
Builder::CharsMap chars_map;
|
142 |
+
EXPECT_OK(Builder::LoadCharsMap(util::JoinPath(FLAGS_data_dir, "nfkc.tsv"),
|
143 |
+
&chars_map));
|
144 |
+
|
145 |
+
std::string precompiled, expected;
|
146 |
+
EXPECT_OK(Builder::CompileCharsMap(chars_map, &precompiled));
|
147 |
+
|
148 |
+
// Round-trip.
|
149 |
+
Builder::CharsMap decompiled_chars_map;
|
150 |
+
EXPECT_OK(Builder::DecompileCharsMap(precompiled, &decompiled_chars_map));
|
151 |
+
EXPECT_EQ(chars_map, decompiled_chars_map);
|
152 |
+
|
153 |
+
test::ScopedTempFile output_tsv("output.tsv");
|
154 |
+
EXPECT_OK(Builder::SaveCharsMap(output_tsv.filename(), chars_map));
|
155 |
+
|
156 |
+
Builder::CharsMap saved_chars_map;
|
157 |
+
EXPECT_OK(Builder::LoadCharsMap(output_tsv.filename(), &saved_chars_map));
|
158 |
+
EXPECT_EQ(chars_map, saved_chars_map);
|
159 |
+
|
160 |
+
#ifdef ENABLE_NFKC_COMPILE
|
161 |
+
Builder::CharsMap nfkc_map;
|
162 |
+
EXPECT_OK(Builder::BuildNFKCMap(&nfkc_map));
|
163 |
+
EXPECT_OK(Builder::CompileCharsMap(nfkc_map, &expected));
|
164 |
+
#endif
|
165 |
+
}
|
166 |
+
|
167 |
+
TEST(BuilderTest, LoadCharsMapWithEmptyeTest) {
|
168 |
+
test::ScopedTempFile test_tsv("test.tsv");
|
169 |
+
test::ScopedTempFile test_out_tsv("test_out.tsv");
|
170 |
+
{
|
171 |
+
auto output = filesystem::NewWritableFile(test_tsv.filename());
|
172 |
+
output->WriteLine("0061\t0041");
|
173 |
+
output->WriteLine("0062");
|
174 |
+
output->WriteLine("0063\t\t#foo=>bar");
|
175 |
+
}
|
176 |
+
|
177 |
+
Builder::CharsMap chars_map;
|
178 |
+
EXPECT_OK(Builder::LoadCharsMap(test_tsv.filename(), &chars_map));
|
179 |
+
|
180 |
+
EXPECT_EQ(3, chars_map.size());
|
181 |
+
EXPECT_EQ(std::vector<char32>({0x0041}), chars_map[{0x0061}]);
|
182 |
+
EXPECT_EQ(std::vector<char32>({}), chars_map[{0x0062}]);
|
183 |
+
EXPECT_EQ(std::vector<char32>({}), chars_map[{0x0063}]);
|
184 |
+
|
185 |
+
EXPECT_OK(Builder::SaveCharsMap(test_out_tsv.filename(), chars_map));
|
186 |
+
|
187 |
+
Builder::CharsMap new_chars_map;
|
188 |
+
EXPECT_OK(Builder::LoadCharsMap(test_out_tsv.filename(), &new_chars_map));
|
189 |
+
EXPECT_EQ(chars_map, new_chars_map);
|
190 |
+
}
|
191 |
+
|
192 |
+
TEST(BuilderTest, ContainsTooManySharedPrefixTest) {
|
193 |
+
Builder::CharsMap chars_map;
|
194 |
+
std::vector<char32> keys;
|
195 |
+
// chars_map contains too many shared prefix ("aaaa...");
|
196 |
+
for (int i = 0; i < 100; ++i) {
|
197 |
+
keys.push_back('a');
|
198 |
+
chars_map[keys] = {'b'};
|
199 |
+
}
|
200 |
+
std::string output;
|
201 |
+
EXPECT_FALSE(Builder::CompileCharsMap(chars_map, &output).ok());
|
202 |
+
}
|
203 |
+
|
204 |
+
} // namespace normalizer
|
205 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/builtin_pb/sentencepiece.pb.cc
ADDED
@@ -0,0 +1,953 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
2 |
+
// source: sentencepiece.proto
|
3 |
+
|
4 |
+
#include "sentencepiece.pb.h"
|
5 |
+
|
6 |
+
#include <algorithm>
|
7 |
+
|
8 |
+
#include <google/protobuf/stubs/common.h>
|
9 |
+
#include <google/protobuf/stubs/port.h>
|
10 |
+
#include <google/protobuf/io/coded_stream.h>
|
11 |
+
#include <google/protobuf/wire_format_lite_inl.h>
|
12 |
+
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
13 |
+
// This is a temporary google only hack
|
14 |
+
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
|
15 |
+
#include "third_party/protobuf/version.h"
|
16 |
+
#endif
|
17 |
+
// @@protoc_insertion_point(includes)
|
18 |
+
|
19 |
+
namespace protobuf_sentencepiece_2eproto {
|
20 |
+
extern PROTOBUF_INTERNAL_EXPORT_protobuf_sentencepiece_2eproto ::google::protobuf::internal::SCCInfo<0> scc_info_SentencePieceText_SentencePiece;
|
21 |
+
extern PROTOBUF_INTERNAL_EXPORT_protobuf_sentencepiece_2eproto ::google::protobuf::internal::SCCInfo<1> scc_info_SentencePieceText;
|
22 |
+
} // namespace protobuf_sentencepiece_2eproto
|
23 |
+
namespace sentencepiece {
|
24 |
+
class SentencePieceText_SentencePieceDefaultTypeInternal {
|
25 |
+
public:
|
26 |
+
::google::protobuf::internal::ExplicitlyConstructed<SentencePieceText_SentencePiece>
|
27 |
+
_instance;
|
28 |
+
} _SentencePieceText_SentencePiece_default_instance_;
|
29 |
+
class SentencePieceTextDefaultTypeInternal {
|
30 |
+
public:
|
31 |
+
::google::protobuf::internal::ExplicitlyConstructed<SentencePieceText>
|
32 |
+
_instance;
|
33 |
+
} _SentencePieceText_default_instance_;
|
34 |
+
class NBestSentencePieceTextDefaultTypeInternal {
|
35 |
+
public:
|
36 |
+
::google::protobuf::internal::ExplicitlyConstructed<NBestSentencePieceText>
|
37 |
+
_instance;
|
38 |
+
} _NBestSentencePieceText_default_instance_;
|
39 |
+
} // namespace sentencepiece
|
40 |
+
namespace protobuf_sentencepiece_2eproto {
|
41 |
+
static void InitDefaultsSentencePieceText_SentencePiece() {
|
42 |
+
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
43 |
+
|
44 |
+
{
|
45 |
+
void* ptr = &::sentencepiece::_SentencePieceText_SentencePiece_default_instance_;
|
46 |
+
new (ptr) ::sentencepiece::SentencePieceText_SentencePiece();
|
47 |
+
::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
|
48 |
+
}
|
49 |
+
::sentencepiece::SentencePieceText_SentencePiece::InitAsDefaultInstance();
|
50 |
+
}
|
51 |
+
|
52 |
+
::google::protobuf::internal::SCCInfo<0> scc_info_SentencePieceText_SentencePiece =
|
53 |
+
{{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsSentencePieceText_SentencePiece}, {}};
|
54 |
+
|
55 |
+
static void InitDefaultsSentencePieceText() {
|
56 |
+
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
57 |
+
|
58 |
+
{
|
59 |
+
void* ptr = &::sentencepiece::_SentencePieceText_default_instance_;
|
60 |
+
new (ptr) ::sentencepiece::SentencePieceText();
|
61 |
+
::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
|
62 |
+
}
|
63 |
+
::sentencepiece::SentencePieceText::InitAsDefaultInstance();
|
64 |
+
}
|
65 |
+
|
66 |
+
::google::protobuf::internal::SCCInfo<1> scc_info_SentencePieceText =
|
67 |
+
{{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsSentencePieceText}, {
|
68 |
+
&protobuf_sentencepiece_2eproto::scc_info_SentencePieceText_SentencePiece.base,}};
|
69 |
+
|
70 |
+
static void InitDefaultsNBestSentencePieceText() {
|
71 |
+
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
72 |
+
|
73 |
+
{
|
74 |
+
void* ptr = &::sentencepiece::_NBestSentencePieceText_default_instance_;
|
75 |
+
new (ptr) ::sentencepiece::NBestSentencePieceText();
|
76 |
+
::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
|
77 |
+
}
|
78 |
+
::sentencepiece::NBestSentencePieceText::InitAsDefaultInstance();
|
79 |
+
}
|
80 |
+
|
81 |
+
::google::protobuf::internal::SCCInfo<1> scc_info_NBestSentencePieceText =
|
82 |
+
{{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsNBestSentencePieceText}, {
|
83 |
+
&protobuf_sentencepiece_2eproto::scc_info_SentencePieceText.base,}};
|
84 |
+
|
85 |
+
void InitDefaults() {
|
86 |
+
::google::protobuf::internal::InitSCC(&scc_info_SentencePieceText_SentencePiece.base);
|
87 |
+
::google::protobuf::internal::InitSCC(&scc_info_SentencePieceText.base);
|
88 |
+
::google::protobuf::internal::InitSCC(&scc_info_NBestSentencePieceText.base);
|
89 |
+
}
|
90 |
+
|
91 |
+
} // namespace protobuf_sentencepiece_2eproto
|
92 |
+
namespace sentencepiece {
|
93 |
+
|
94 |
+
// ===================================================================
|
95 |
+
|
96 |
+
void SentencePieceText_SentencePiece::InitAsDefaultInstance() {
|
97 |
+
}
|
98 |
+
#if !defined(_MSC_VER) || _MSC_VER >= 1900
|
99 |
+
const int SentencePieceText_SentencePiece::kPieceFieldNumber;
|
100 |
+
const int SentencePieceText_SentencePiece::kIdFieldNumber;
|
101 |
+
const int SentencePieceText_SentencePiece::kSurfaceFieldNumber;
|
102 |
+
const int SentencePieceText_SentencePiece::kBeginFieldNumber;
|
103 |
+
const int SentencePieceText_SentencePiece::kEndFieldNumber;
|
104 |
+
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
|
105 |
+
|
106 |
+
SentencePieceText_SentencePiece::SentencePieceText_SentencePiece()
|
107 |
+
: ::google::protobuf::MessageLite(), _internal_metadata_(NULL) {
|
108 |
+
::google::protobuf::internal::InitSCC(
|
109 |
+
&protobuf_sentencepiece_2eproto::scc_info_SentencePieceText_SentencePiece.base);
|
110 |
+
SharedCtor();
|
111 |
+
// @@protoc_insertion_point(constructor:sentencepiece.SentencePieceText.SentencePiece)
|
112 |
+
}
|
113 |
+
SentencePieceText_SentencePiece::SentencePieceText_SentencePiece(const SentencePieceText_SentencePiece& from)
|
114 |
+
: ::google::protobuf::MessageLite(),
|
115 |
+
_internal_metadata_(NULL),
|
116 |
+
_has_bits_(from._has_bits_) {
|
117 |
+
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
118 |
+
_extensions_.MergeFrom(from._extensions_);
|
119 |
+
piece_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
|
120 |
+
if (from.has_piece()) {
|
121 |
+
piece_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.piece_);
|
122 |
+
}
|
123 |
+
surface_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
|
124 |
+
if (from.has_surface()) {
|
125 |
+
surface_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.surface_);
|
126 |
+
}
|
127 |
+
::memcpy(&id_, &from.id_,
|
128 |
+
static_cast<size_t>(reinterpret_cast<char*>(&end_) -
|
129 |
+
reinterpret_cast<char*>(&id_)) + sizeof(end_));
|
130 |
+
// @@protoc_insertion_point(copy_constructor:sentencepiece.SentencePieceText.SentencePiece)
|
131 |
+
}
|
132 |
+
|
133 |
+
void SentencePieceText_SentencePiece::SharedCtor() {
|
134 |
+
piece_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
|
135 |
+
surface_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
|
136 |
+
::memset(&id_, 0, static_cast<size_t>(
|
137 |
+
reinterpret_cast<char*>(&end_) -
|
138 |
+
reinterpret_cast<char*>(&id_)) + sizeof(end_));
|
139 |
+
}
|
140 |
+
|
141 |
+
SentencePieceText_SentencePiece::~SentencePieceText_SentencePiece() {
|
142 |
+
// @@protoc_insertion_point(destructor:sentencepiece.SentencePieceText.SentencePiece)
|
143 |
+
SharedDtor();
|
144 |
+
}
|
145 |
+
|
146 |
+
void SentencePieceText_SentencePiece::SharedDtor() {
|
147 |
+
piece_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
|
148 |
+
surface_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
|
149 |
+
}
|
150 |
+
|
151 |
+
void SentencePieceText_SentencePiece::SetCachedSize(int size) const {
|
152 |
+
_cached_size_.Set(size);
|
153 |
+
}
|
154 |
+
const SentencePieceText_SentencePiece& SentencePieceText_SentencePiece::default_instance() {
|
155 |
+
::google::protobuf::internal::InitSCC(&protobuf_sentencepiece_2eproto::scc_info_SentencePieceText_SentencePiece.base);
|
156 |
+
return *internal_default_instance();
|
157 |
+
}
|
158 |
+
|
159 |
+
|
160 |
+
void SentencePieceText_SentencePiece::Clear() {
|
161 |
+
// @@protoc_insertion_point(message_clear_start:sentencepiece.SentencePieceText.SentencePiece)
|
162 |
+
::google::protobuf::uint32 cached_has_bits = 0;
|
163 |
+
// Prevent compiler warnings about cached_has_bits being unused
|
164 |
+
(void) cached_has_bits;
|
165 |
+
|
166 |
+
_extensions_.Clear();
|
167 |
+
cached_has_bits = _has_bits_[0];
|
168 |
+
if (cached_has_bits & 3u) {
|
169 |
+
if (cached_has_bits & 0x00000001u) {
|
170 |
+
piece_.ClearNonDefaultToEmptyNoArena();
|
171 |
+
}
|
172 |
+
if (cached_has_bits & 0x00000002u) {
|
173 |
+
surface_.ClearNonDefaultToEmptyNoArena();
|
174 |
+
}
|
175 |
+
}
|
176 |
+
if (cached_has_bits & 28u) {
|
177 |
+
::memset(&id_, 0, static_cast<size_t>(
|
178 |
+
reinterpret_cast<char*>(&end_) -
|
179 |
+
reinterpret_cast<char*>(&id_)) + sizeof(end_));
|
180 |
+
}
|
181 |
+
_has_bits_.Clear();
|
182 |
+
_internal_metadata_.Clear();
|
183 |
+
}
|
184 |
+
|
185 |
+
bool SentencePieceText_SentencePiece::MergePartialFromCodedStream(
|
186 |
+
::google::protobuf::io::CodedInputStream* input) {
|
187 |
+
#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
|
188 |
+
::google::protobuf::uint32 tag;
|
189 |
+
::google::protobuf::internal::LiteUnknownFieldSetter unknown_fields_setter(
|
190 |
+
&_internal_metadata_);
|
191 |
+
::google::protobuf::io::StringOutputStream unknown_fields_output(
|
192 |
+
unknown_fields_setter.buffer());
|
193 |
+
::google::protobuf::io::CodedOutputStream unknown_fields_stream(
|
194 |
+
&unknown_fields_output, false);
|
195 |
+
// @@protoc_insertion_point(parse_start:sentencepiece.SentencePieceText.SentencePiece)
|
196 |
+
for (;;) {
|
197 |
+
::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
|
198 |
+
tag = p.first;
|
199 |
+
if (!p.second) goto handle_unusual;
|
200 |
+
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
|
201 |
+
// optional string piece = 1;
|
202 |
+
case 1: {
|
203 |
+
if (static_cast< ::google::protobuf::uint8>(tag) ==
|
204 |
+
static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
|
205 |
+
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
|
206 |
+
input, this->mutable_piece()));
|
207 |
+
} else {
|
208 |
+
goto handle_unusual;
|
209 |
+
}
|
210 |
+
break;
|
211 |
+
}
|
212 |
+
|
213 |
+
// optional uint32 id = 2;
|
214 |
+
case 2: {
|
215 |
+
if (static_cast< ::google::protobuf::uint8>(tag) ==
|
216 |
+
static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) {
|
217 |
+
set_has_id();
|
218 |
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
|
219 |
+
::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
|
220 |
+
input, &id_)));
|
221 |
+
} else {
|
222 |
+
goto handle_unusual;
|
223 |
+
}
|
224 |
+
break;
|
225 |
+
}
|
226 |
+
|
227 |
+
// optional string surface = 3;
|
228 |
+
case 3: {
|
229 |
+
if (static_cast< ::google::protobuf::uint8>(tag) ==
|
230 |
+
static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) {
|
231 |
+
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
|
232 |
+
input, this->mutable_surface()));
|
233 |
+
} else {
|
234 |
+
goto handle_unusual;
|
235 |
+
}
|
236 |
+
break;
|
237 |
+
}
|
238 |
+
|
239 |
+
// optional uint32 begin = 4;
|
240 |
+
case 4: {
|
241 |
+
if (static_cast< ::google::protobuf::uint8>(tag) ==
|
242 |
+
static_cast< ::google::protobuf::uint8>(32u /* 32 & 0xFF */)) {
|
243 |
+
set_has_begin();
|
244 |
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
|
245 |
+
::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
|
246 |
+
input, &begin_)));
|
247 |
+
} else {
|
248 |
+
goto handle_unusual;
|
249 |
+
}
|
250 |
+
break;
|
251 |
+
}
|
252 |
+
|
253 |
+
// optional uint32 end = 5;
|
254 |
+
case 5: {
|
255 |
+
if (static_cast< ::google::protobuf::uint8>(tag) ==
|
256 |
+
static_cast< ::google::protobuf::uint8>(40u /* 40 & 0xFF */)) {
|
257 |
+
set_has_end();
|
258 |
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
|
259 |
+
::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
|
260 |
+
input, &end_)));
|
261 |
+
} else {
|
262 |
+
goto handle_unusual;
|
263 |
+
}
|
264 |
+
break;
|
265 |
+
}
|
266 |
+
|
267 |
+
default: {
|
268 |
+
handle_unusual:
|
269 |
+
if (tag == 0) {
|
270 |
+
goto success;
|
271 |
+
}
|
272 |
+
if ((1600u <= tag)) {
|
273 |
+
DO_(_extensions_.ParseField(tag, input,
|
274 |
+
internal_default_instance(),
|
275 |
+
&unknown_fields_stream));
|
276 |
+
continue;
|
277 |
+
}
|
278 |
+
DO_(::google::protobuf::internal::WireFormatLite::SkipField(
|
279 |
+
input, tag, &unknown_fields_stream));
|
280 |
+
break;
|
281 |
+
}
|
282 |
+
}
|
283 |
+
}
|
284 |
+
success:
|
285 |
+
// @@protoc_insertion_point(parse_success:sentencepiece.SentencePieceText.SentencePiece)
|
286 |
+
return true;
|
287 |
+
failure:
|
288 |
+
// @@protoc_insertion_point(parse_failure:sentencepiece.SentencePieceText.SentencePiece)
|
289 |
+
return false;
|
290 |
+
#undef DO_
|
291 |
+
}
|
292 |
+
|
293 |
+
void SentencePieceText_SentencePiece::SerializeWithCachedSizes(
|
294 |
+
::google::protobuf::io::CodedOutputStream* output) const {
|
295 |
+
// @@protoc_insertion_point(serialize_start:sentencepiece.SentencePieceText.SentencePiece)
|
296 |
+
::google::protobuf::uint32 cached_has_bits = 0;
|
297 |
+
(void) cached_has_bits;
|
298 |
+
|
299 |
+
cached_has_bits = _has_bits_[0];
|
300 |
+
// optional string piece = 1;
|
301 |
+
if (cached_has_bits & 0x00000001u) {
|
302 |
+
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
|
303 |
+
1, this->piece(), output);
|
304 |
+
}
|
305 |
+
|
306 |
+
// optional uint32 id = 2;
|
307 |
+
if (cached_has_bits & 0x00000004u) {
|
308 |
+
::google::protobuf::internal::WireFormatLite::WriteUInt32(2, this->id(), output);
|
309 |
+
}
|
310 |
+
|
311 |
+
// optional string surface = 3;
|
312 |
+
if (cached_has_bits & 0x00000002u) {
|
313 |
+
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
|
314 |
+
3, this->surface(), output);
|
315 |
+
}
|
316 |
+
|
317 |
+
// optional uint32 begin = 4;
|
318 |
+
if (cached_has_bits & 0x00000008u) {
|
319 |
+
::google::protobuf::internal::WireFormatLite::WriteUInt32(4, this->begin(), output);
|
320 |
+
}
|
321 |
+
|
322 |
+
// optional uint32 end = 5;
|
323 |
+
if (cached_has_bits & 0x00000010u) {
|
324 |
+
::google::protobuf::internal::WireFormatLite::WriteUInt32(5, this->end(), output);
|
325 |
+
}
|
326 |
+
|
327 |
+
// Extension range [200, 536870912)
|
328 |
+
_extensions_.SerializeWithCachedSizes(
|
329 |
+
200, 536870912, output);
|
330 |
+
|
331 |
+
output->WriteRaw(_internal_metadata_.unknown_fields().data(),
|
332 |
+
static_cast<int>(_internal_metadata_.unknown_fields().size()));
|
333 |
+
// @@protoc_insertion_point(serialize_end:sentencepiece.SentencePieceText.SentencePiece)
|
334 |
+
}
|
335 |
+
|
336 |
+
size_t SentencePieceText_SentencePiece::ByteSizeLong() const {
|
337 |
+
// @@protoc_insertion_point(message_byte_size_start:sentencepiece.SentencePieceText.SentencePiece)
|
338 |
+
size_t total_size = 0;
|
339 |
+
|
340 |
+
total_size += _extensions_.ByteSize();
|
341 |
+
|
342 |
+
total_size += _internal_metadata_.unknown_fields().size();
|
343 |
+
|
344 |
+
if (_has_bits_[0 / 32] & 31u) {
|
345 |
+
// optional string piece = 1;
|
346 |
+
if (has_piece()) {
|
347 |
+
total_size += 1 +
|
348 |
+
::google::protobuf::internal::WireFormatLite::StringSize(
|
349 |
+
this->piece());
|
350 |
+
}
|
351 |
+
|
352 |
+
// optional string surface = 3;
|
353 |
+
if (has_surface()) {
|
354 |
+
total_size += 1 +
|
355 |
+
::google::protobuf::internal::WireFormatLite::StringSize(
|
356 |
+
this->surface());
|
357 |
+
}
|
358 |
+
|
359 |
+
// optional uint32 id = 2;
|
360 |
+
if (has_id()) {
|
361 |
+
total_size += 1 +
|
362 |
+
::google::protobuf::internal::WireFormatLite::UInt32Size(
|
363 |
+
this->id());
|
364 |
+
}
|
365 |
+
|
366 |
+
// optional uint32 begin = 4;
|
367 |
+
if (has_begin()) {
|
368 |
+
total_size += 1 +
|
369 |
+
::google::protobuf::internal::WireFormatLite::UInt32Size(
|
370 |
+
this->begin());
|
371 |
+
}
|
372 |
+
|
373 |
+
// optional uint32 end = 5;
|
374 |
+
if (has_end()) {
|
375 |
+
total_size += 1 +
|
376 |
+
::google::protobuf::internal::WireFormatLite::UInt32Size(
|
377 |
+
this->end());
|
378 |
+
}
|
379 |
+
|
380 |
+
}
|
381 |
+
int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
|
382 |
+
SetCachedSize(cached_size);
|
383 |
+
return total_size;
|
384 |
+
}
|
385 |
+
|
386 |
+
void SentencePieceText_SentencePiece::CheckTypeAndMergeFrom(
|
387 |
+
const ::google::protobuf::MessageLite& from) {
|
388 |
+
MergeFrom(*::google::protobuf::down_cast<const SentencePieceText_SentencePiece*>(&from));
|
389 |
+
}
|
390 |
+
|
391 |
+
void SentencePieceText_SentencePiece::MergeFrom(const SentencePieceText_SentencePiece& from) {
|
392 |
+
// @@protoc_insertion_point(class_specific_merge_from_start:sentencepiece.SentencePieceText.SentencePiece)
|
393 |
+
GOOGLE_DCHECK_NE(&from, this);
|
394 |
+
_extensions_.MergeFrom(from._extensions_);
|
395 |
+
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
396 |
+
::google::protobuf::uint32 cached_has_bits = 0;
|
397 |
+
(void) cached_has_bits;
|
398 |
+
|
399 |
+
cached_has_bits = from._has_bits_[0];
|
400 |
+
if (cached_has_bits & 31u) {
|
401 |
+
if (cached_has_bits & 0x00000001u) {
|
402 |
+
set_has_piece();
|
403 |
+
piece_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.piece_);
|
404 |
+
}
|
405 |
+
if (cached_has_bits & 0x00000002u) {
|
406 |
+
set_has_surface();
|
407 |
+
surface_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.surface_);
|
408 |
+
}
|
409 |
+
if (cached_has_bits & 0x00000004u) {
|
410 |
+
id_ = from.id_;
|
411 |
+
}
|
412 |
+
if (cached_has_bits & 0x00000008u) {
|
413 |
+
begin_ = from.begin_;
|
414 |
+
}
|
415 |
+
if (cached_has_bits & 0x00000010u) {
|
416 |
+
end_ = from.end_;
|
417 |
+
}
|
418 |
+
_has_bits_[0] |= cached_has_bits;
|
419 |
+
}
|
420 |
+
}
|
421 |
+
|
422 |
+
void SentencePieceText_SentencePiece::CopyFrom(const SentencePieceText_SentencePiece& from) {
|
423 |
+
// @@protoc_insertion_point(class_specific_copy_from_start:sentencepiece.SentencePieceText.SentencePiece)
|
424 |
+
if (&from == this) return;
|
425 |
+
Clear();
|
426 |
+
MergeFrom(from);
|
427 |
+
}
|
428 |
+
|
429 |
+
bool SentencePieceText_SentencePiece::IsInitialized() const {
|
430 |
+
if (!_extensions_.IsInitialized()) {
|
431 |
+
return false;
|
432 |
+
}
|
433 |
+
|
434 |
+
return true;
|
435 |
+
}
|
436 |
+
|
437 |
+
void SentencePieceText_SentencePiece::Swap(SentencePieceText_SentencePiece* other) {
|
438 |
+
if (other == this) return;
|
439 |
+
InternalSwap(other);
|
440 |
+
}
|
441 |
+
void SentencePieceText_SentencePiece::InternalSwap(SentencePieceText_SentencePiece* other) {
|
442 |
+
using std::swap;
|
443 |
+
piece_.Swap(&other->piece_, &::google::protobuf::internal::GetEmptyStringAlreadyInited(),
|
444 |
+
GetArenaNoVirtual());
|
445 |
+
surface_.Swap(&other->surface_, &::google::protobuf::internal::GetEmptyStringAlreadyInited(),
|
446 |
+
GetArenaNoVirtual());
|
447 |
+
swap(id_, other->id_);
|
448 |
+
swap(begin_, other->begin_);
|
449 |
+
swap(end_, other->end_);
|
450 |
+
swap(_has_bits_[0], other->_has_bits_[0]);
|
451 |
+
_internal_metadata_.Swap(&other->_internal_metadata_);
|
452 |
+
_extensions_.Swap(&other->_extensions_);
|
453 |
+
}
|
454 |
+
|
455 |
+
::std::string SentencePieceText_SentencePiece::GetTypeName() const {
|
456 |
+
return "sentencepiece.SentencePieceText.SentencePiece";
|
457 |
+
}
|
458 |
+
|
459 |
+
|
460 |
+
// ===================================================================
|
461 |
+
|
462 |
+
void SentencePieceText::InitAsDefaultInstance() {
|
463 |
+
}
|
464 |
+
#if !defined(_MSC_VER) || _MSC_VER >= 1900
|
465 |
+
const int SentencePieceText::kTextFieldNumber;
|
466 |
+
const int SentencePieceText::kPiecesFieldNumber;
|
467 |
+
const int SentencePieceText::kScoreFieldNumber;
|
468 |
+
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
|
469 |
+
|
470 |
+
SentencePieceText::SentencePieceText()
|
471 |
+
: ::google::protobuf::MessageLite(), _internal_metadata_(NULL) {
|
472 |
+
::google::protobuf::internal::InitSCC(
|
473 |
+
&protobuf_sentencepiece_2eproto::scc_info_SentencePieceText.base);
|
474 |
+
SharedCtor();
|
475 |
+
// @@protoc_insertion_point(constructor:sentencepiece.SentencePieceText)
|
476 |
+
}
|
477 |
+
SentencePieceText::SentencePieceText(const SentencePieceText& from)
|
478 |
+
: ::google::protobuf::MessageLite(),
|
479 |
+
_internal_metadata_(NULL),
|
480 |
+
_has_bits_(from._has_bits_),
|
481 |
+
pieces_(from.pieces_) {
|
482 |
+
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
483 |
+
_extensions_.MergeFrom(from._extensions_);
|
484 |
+
text_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
|
485 |
+
if (from.has_text()) {
|
486 |
+
text_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.text_);
|
487 |
+
}
|
488 |
+
score_ = from.score_;
|
489 |
+
// @@protoc_insertion_point(copy_constructor:sentencepiece.SentencePieceText)
|
490 |
+
}
|
491 |
+
|
492 |
+
void SentencePieceText::SharedCtor() {
|
493 |
+
text_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
|
494 |
+
score_ = 0;
|
495 |
+
}
|
496 |
+
|
497 |
+
SentencePieceText::~SentencePieceText() {
|
498 |
+
// @@protoc_insertion_point(destructor:sentencepiece.SentencePieceText)
|
499 |
+
SharedDtor();
|
500 |
+
}
|
501 |
+
|
502 |
+
void SentencePieceText::SharedDtor() {
|
503 |
+
text_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
|
504 |
+
}
|
505 |
+
|
506 |
+
void SentencePieceText::SetCachedSize(int size) const {
|
507 |
+
_cached_size_.Set(size);
|
508 |
+
}
|
509 |
+
const SentencePieceText& SentencePieceText::default_instance() {
|
510 |
+
::google::protobuf::internal::InitSCC(&protobuf_sentencepiece_2eproto::scc_info_SentencePieceText.base);
|
511 |
+
return *internal_default_instance();
|
512 |
+
}
|
513 |
+
|
514 |
+
|
515 |
+
void SentencePieceText::Clear() {
|
516 |
+
// @@protoc_insertion_point(message_clear_start:sentencepiece.SentencePieceText)
|
517 |
+
::google::protobuf::uint32 cached_has_bits = 0;
|
518 |
+
// Prevent compiler warnings about cached_has_bits being unused
|
519 |
+
(void) cached_has_bits;
|
520 |
+
|
521 |
+
_extensions_.Clear();
|
522 |
+
pieces_.Clear();
|
523 |
+
cached_has_bits = _has_bits_[0];
|
524 |
+
if (cached_has_bits & 0x00000001u) {
|
525 |
+
text_.ClearNonDefaultToEmptyNoArena();
|
526 |
+
}
|
527 |
+
score_ = 0;
|
528 |
+
_has_bits_.Clear();
|
529 |
+
_internal_metadata_.Clear();
|
530 |
+
}
|
531 |
+
|
532 |
+
bool SentencePieceText::MergePartialFromCodedStream(
|
533 |
+
::google::protobuf::io::CodedInputStream* input) {
|
534 |
+
#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
|
535 |
+
::google::protobuf::uint32 tag;
|
536 |
+
::google::protobuf::internal::LiteUnknownFieldSetter unknown_fields_setter(
|
537 |
+
&_internal_metadata_);
|
538 |
+
::google::protobuf::io::StringOutputStream unknown_fields_output(
|
539 |
+
unknown_fields_setter.buffer());
|
540 |
+
::google::protobuf::io::CodedOutputStream unknown_fields_stream(
|
541 |
+
&unknown_fields_output, false);
|
542 |
+
// @@protoc_insertion_point(parse_start:sentencepiece.SentencePieceText)
|
543 |
+
for (;;) {
|
544 |
+
::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
|
545 |
+
tag = p.first;
|
546 |
+
if (!p.second) goto handle_unusual;
|
547 |
+
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
|
548 |
+
// optional string text = 1;
|
549 |
+
case 1: {
|
550 |
+
if (static_cast< ::google::protobuf::uint8>(tag) ==
|
551 |
+
static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
|
552 |
+
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
|
553 |
+
input, this->mutable_text()));
|
554 |
+
} else {
|
555 |
+
goto handle_unusual;
|
556 |
+
}
|
557 |
+
break;
|
558 |
+
}
|
559 |
+
|
560 |
+
// repeated .sentencepiece.SentencePieceText.SentencePiece pieces = 2;
|
561 |
+
case 2: {
|
562 |
+
if (static_cast< ::google::protobuf::uint8>(tag) ==
|
563 |
+
static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) {
|
564 |
+
DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(
|
565 |
+
input, add_pieces()));
|
566 |
+
} else {
|
567 |
+
goto handle_unusual;
|
568 |
+
}
|
569 |
+
break;
|
570 |
+
}
|
571 |
+
|
572 |
+
// optional float score = 3;
|
573 |
+
case 3: {
|
574 |
+
if (static_cast< ::google::protobuf::uint8>(tag) ==
|
575 |
+
static_cast< ::google::protobuf::uint8>(29u /* 29 & 0xFF */)) {
|
576 |
+
set_has_score();
|
577 |
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
|
578 |
+
float, ::google::protobuf::internal::WireFormatLite::TYPE_FLOAT>(
|
579 |
+
input, &score_)));
|
580 |
+
} else {
|
581 |
+
goto handle_unusual;
|
582 |
+
}
|
583 |
+
break;
|
584 |
+
}
|
585 |
+
|
586 |
+
default: {
|
587 |
+
handle_unusual:
|
588 |
+
if (tag == 0) {
|
589 |
+
goto success;
|
590 |
+
}
|
591 |
+
if ((1600u <= tag)) {
|
592 |
+
DO_(_extensions_.ParseField(tag, input,
|
593 |
+
internal_default_instance(),
|
594 |
+
&unknown_fields_stream));
|
595 |
+
continue;
|
596 |
+
}
|
597 |
+
DO_(::google::protobuf::internal::WireFormatLite::SkipField(
|
598 |
+
input, tag, &unknown_fields_stream));
|
599 |
+
break;
|
600 |
+
}
|
601 |
+
}
|
602 |
+
}
|
603 |
+
success:
|
604 |
+
// @@protoc_insertion_point(parse_success:sentencepiece.SentencePieceText)
|
605 |
+
return true;
|
606 |
+
failure:
|
607 |
+
// @@protoc_insertion_point(parse_failure:sentencepiece.SentencePieceText)
|
608 |
+
return false;
|
609 |
+
#undef DO_
|
610 |
+
}
|
611 |
+
|
612 |
+
void SentencePieceText::SerializeWithCachedSizes(
|
613 |
+
::google::protobuf::io::CodedOutputStream* output) const {
|
614 |
+
// @@protoc_insertion_point(serialize_start:sentencepiece.SentencePieceText)
|
615 |
+
::google::protobuf::uint32 cached_has_bits = 0;
|
616 |
+
(void) cached_has_bits;
|
617 |
+
|
618 |
+
cached_has_bits = _has_bits_[0];
|
619 |
+
// optional string text = 1;
|
620 |
+
if (cached_has_bits & 0x00000001u) {
|
621 |
+
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
|
622 |
+
1, this->text(), output);
|
623 |
+
}
|
624 |
+
|
625 |
+
// repeated .sentencepiece.SentencePieceText.SentencePiece pieces = 2;
|
626 |
+
for (unsigned int i = 0,
|
627 |
+
n = static_cast<unsigned int>(this->pieces_size()); i < n; i++) {
|
628 |
+
::google::protobuf::internal::WireFormatLite::WriteMessage(
|
629 |
+
2,
|
630 |
+
this->pieces(static_cast<int>(i)),
|
631 |
+
output);
|
632 |
+
}
|
633 |
+
|
634 |
+
// optional float score = 3;
|
635 |
+
if (cached_has_bits & 0x00000002u) {
|
636 |
+
::google::protobuf::internal::WireFormatLite::WriteFloat(3, this->score(), output);
|
637 |
+
}
|
638 |
+
|
639 |
+
// Extension range [200, 536870912)
|
640 |
+
_extensions_.SerializeWithCachedSizes(
|
641 |
+
200, 536870912, output);
|
642 |
+
|
643 |
+
output->WriteRaw(_internal_metadata_.unknown_fields().data(),
|
644 |
+
static_cast<int>(_internal_metadata_.unknown_fields().size()));
|
645 |
+
// @@protoc_insertion_point(serialize_end:sentencepiece.SentencePieceText)
|
646 |
+
}
|
647 |
+
|
648 |
+
size_t SentencePieceText::ByteSizeLong() const {
|
649 |
+
// @@protoc_insertion_point(message_byte_size_start:sentencepiece.SentencePieceText)
|
650 |
+
size_t total_size = 0;
|
651 |
+
|
652 |
+
total_size += _extensions_.ByteSize();
|
653 |
+
|
654 |
+
total_size += _internal_metadata_.unknown_fields().size();
|
655 |
+
|
656 |
+
// repeated .sentencepiece.SentencePieceText.SentencePiece pieces = 2;
|
657 |
+
{
|
658 |
+
unsigned int count = static_cast<unsigned int>(this->pieces_size());
|
659 |
+
total_size += 1UL * count;
|
660 |
+
for (unsigned int i = 0; i < count; i++) {
|
661 |
+
total_size +=
|
662 |
+
::google::protobuf::internal::WireFormatLite::MessageSize(
|
663 |
+
this->pieces(static_cast<int>(i)));
|
664 |
+
}
|
665 |
+
}
|
666 |
+
|
667 |
+
if (_has_bits_[0 / 32] & 3u) {
|
668 |
+
// optional string text = 1;
|
669 |
+
if (has_text()) {
|
670 |
+
total_size += 1 +
|
671 |
+
::google::protobuf::internal::WireFormatLite::StringSize(
|
672 |
+
this->text());
|
673 |
+
}
|
674 |
+
|
675 |
+
// optional float score = 3;
|
676 |
+
if (has_score()) {
|
677 |
+
total_size += 1 + 4;
|
678 |
+
}
|
679 |
+
|
680 |
+
}
|
681 |
+
int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
|
682 |
+
SetCachedSize(cached_size);
|
683 |
+
return total_size;
|
684 |
+
}
|
685 |
+
|
686 |
+
void SentencePieceText::CheckTypeAndMergeFrom(
|
687 |
+
const ::google::protobuf::MessageLite& from) {
|
688 |
+
MergeFrom(*::google::protobuf::down_cast<const SentencePieceText*>(&from));
|
689 |
+
}
|
690 |
+
|
691 |
+
void SentencePieceText::MergeFrom(const SentencePieceText& from) {
|
692 |
+
// @@protoc_insertion_point(class_specific_merge_from_start:sentencepiece.SentencePieceText)
|
693 |
+
GOOGLE_DCHECK_NE(&from, this);
|
694 |
+
_extensions_.MergeFrom(from._extensions_);
|
695 |
+
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
696 |
+
::google::protobuf::uint32 cached_has_bits = 0;
|
697 |
+
(void) cached_has_bits;
|
698 |
+
|
699 |
+
pieces_.MergeFrom(from.pieces_);
|
700 |
+
cached_has_bits = from._has_bits_[0];
|
701 |
+
if (cached_has_bits & 3u) {
|
702 |
+
if (cached_has_bits & 0x00000001u) {
|
703 |
+
set_has_text();
|
704 |
+
text_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.text_);
|
705 |
+
}
|
706 |
+
if (cached_has_bits & 0x00000002u) {
|
707 |
+
score_ = from.score_;
|
708 |
+
}
|
709 |
+
_has_bits_[0] |= cached_has_bits;
|
710 |
+
}
|
711 |
+
}
|
712 |
+
|
713 |
+
void SentencePieceText::CopyFrom(const SentencePieceText& from) {
|
714 |
+
// @@protoc_insertion_point(class_specific_copy_from_start:sentencepiece.SentencePieceText)
|
715 |
+
if (&from == this) return;
|
716 |
+
Clear();
|
717 |
+
MergeFrom(from);
|
718 |
+
}
|
719 |
+
|
720 |
+
bool SentencePieceText::IsInitialized() const {
|
721 |
+
if (!_extensions_.IsInitialized()) {
|
722 |
+
return false;
|
723 |
+
}
|
724 |
+
|
725 |
+
if (!::google::protobuf::internal::AllAreInitialized(this->pieces())) return false;
|
726 |
+
return true;
|
727 |
+
}
|
728 |
+
|
729 |
+
void SentencePieceText::Swap(SentencePieceText* other) {
|
730 |
+
if (other == this) return;
|
731 |
+
InternalSwap(other);
|
732 |
+
}
|
733 |
+
void SentencePieceText::InternalSwap(SentencePieceText* other) {
|
734 |
+
using std::swap;
|
735 |
+
CastToBase(&pieces_)->InternalSwap(CastToBase(&other->pieces_));
|
736 |
+
text_.Swap(&other->text_, &::google::protobuf::internal::GetEmptyStringAlreadyInited(),
|
737 |
+
GetArenaNoVirtual());
|
738 |
+
swap(score_, other->score_);
|
739 |
+
swap(_has_bits_[0], other->_has_bits_[0]);
|
740 |
+
_internal_metadata_.Swap(&other->_internal_metadata_);
|
741 |
+
_extensions_.Swap(&other->_extensions_);
|
742 |
+
}
|
743 |
+
|
744 |
+
::std::string SentencePieceText::GetTypeName() const {
|
745 |
+
return "sentencepiece.SentencePieceText";
|
746 |
+
}
|
747 |
+
|
748 |
+
|
749 |
+
// ===================================================================
|
750 |
+
|
751 |
+
void NBestSentencePieceText::InitAsDefaultInstance() {
|
752 |
+
}
|
753 |
+
#if !defined(_MSC_VER) || _MSC_VER >= 1900
|
754 |
+
const int NBestSentencePieceText::kNbestsFieldNumber;
|
755 |
+
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
|
756 |
+
|
757 |
+
NBestSentencePieceText::NBestSentencePieceText()
|
758 |
+
: ::google::protobuf::MessageLite(), _internal_metadata_(NULL) {
|
759 |
+
::google::protobuf::internal::InitSCC(
|
760 |
+
&protobuf_sentencepiece_2eproto::scc_info_NBestSentencePieceText.base);
|
761 |
+
SharedCtor();
|
762 |
+
// @@protoc_insertion_point(constructor:sentencepiece.NBestSentencePieceText)
|
763 |
+
}
|
764 |
+
NBestSentencePieceText::NBestSentencePieceText(const NBestSentencePieceText& from)
|
765 |
+
: ::google::protobuf::MessageLite(),
|
766 |
+
_internal_metadata_(NULL),
|
767 |
+
_has_bits_(from._has_bits_),
|
768 |
+
nbests_(from.nbests_) {
|
769 |
+
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
770 |
+
// @@protoc_insertion_point(copy_constructor:sentencepiece.NBestSentencePieceText)
|
771 |
+
}
|
772 |
+
|
773 |
+
void NBestSentencePieceText::SharedCtor() {
|
774 |
+
}
|
775 |
+
|
776 |
+
NBestSentencePieceText::~NBestSentencePieceText() {
|
777 |
+
// @@protoc_insertion_point(destructor:sentencepiece.NBestSentencePieceText)
|
778 |
+
SharedDtor();
|
779 |
+
}
|
780 |
+
|
781 |
+
void NBestSentencePieceText::SharedDtor() {
|
782 |
+
}
|
783 |
+
|
784 |
+
void NBestSentencePieceText::SetCachedSize(int size) const {
|
785 |
+
_cached_size_.Set(size);
|
786 |
+
}
|
787 |
+
const NBestSentencePieceText& NBestSentencePieceText::default_instance() {
|
788 |
+
::google::protobuf::internal::InitSCC(&protobuf_sentencepiece_2eproto::scc_info_NBestSentencePieceText.base);
|
789 |
+
return *internal_default_instance();
|
790 |
+
}
|
791 |
+
|
792 |
+
|
793 |
+
void NBestSentencePieceText::Clear() {
|
794 |
+
// @@protoc_insertion_point(message_clear_start:sentencepiece.NBestSentencePieceText)
|
795 |
+
::google::protobuf::uint32 cached_has_bits = 0;
|
796 |
+
// Prevent compiler warnings about cached_has_bits being unused
|
797 |
+
(void) cached_has_bits;
|
798 |
+
|
799 |
+
nbests_.Clear();
|
800 |
+
_has_bits_.Clear();
|
801 |
+
_internal_metadata_.Clear();
|
802 |
+
}
|
803 |
+
|
804 |
+
bool NBestSentencePieceText::MergePartialFromCodedStream(
|
805 |
+
::google::protobuf::io::CodedInputStream* input) {
|
806 |
+
#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
|
807 |
+
::google::protobuf::uint32 tag;
|
808 |
+
::google::protobuf::internal::LiteUnknownFieldSetter unknown_fields_setter(
|
809 |
+
&_internal_metadata_);
|
810 |
+
::google::protobuf::io::StringOutputStream unknown_fields_output(
|
811 |
+
unknown_fields_setter.buffer());
|
812 |
+
::google::protobuf::io::CodedOutputStream unknown_fields_stream(
|
813 |
+
&unknown_fields_output, false);
|
814 |
+
// @@protoc_insertion_point(parse_start:sentencepiece.NBestSentencePieceText)
|
815 |
+
for (;;) {
|
816 |
+
::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
|
817 |
+
tag = p.first;
|
818 |
+
if (!p.second) goto handle_unusual;
|
819 |
+
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
|
820 |
+
// repeated .sentencepiece.SentencePieceText nbests = 1;
|
821 |
+
case 1: {
|
822 |
+
if (static_cast< ::google::protobuf::uint8>(tag) ==
|
823 |
+
static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
|
824 |
+
DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(
|
825 |
+
input, add_nbests()));
|
826 |
+
} else {
|
827 |
+
goto handle_unusual;
|
828 |
+
}
|
829 |
+
break;
|
830 |
+
}
|
831 |
+
|
832 |
+
default: {
|
833 |
+
handle_unusual:
|
834 |
+
if (tag == 0) {
|
835 |
+
goto success;
|
836 |
+
}
|
837 |
+
DO_(::google::protobuf::internal::WireFormatLite::SkipField(
|
838 |
+
input, tag, &unknown_fields_stream));
|
839 |
+
break;
|
840 |
+
}
|
841 |
+
}
|
842 |
+
}
|
843 |
+
success:
|
844 |
+
// @@protoc_insertion_point(parse_success:sentencepiece.NBestSentencePieceText)
|
845 |
+
return true;
|
846 |
+
failure:
|
847 |
+
// @@protoc_insertion_point(parse_failure:sentencepiece.NBestSentencePieceText)
|
848 |
+
return false;
|
849 |
+
#undef DO_
|
850 |
+
}
|
851 |
+
|
852 |
+
void NBestSentencePieceText::SerializeWithCachedSizes(
|
853 |
+
::google::protobuf::io::CodedOutputStream* output) const {
|
854 |
+
// @@protoc_insertion_point(serialize_start:sentencepiece.NBestSentencePieceText)
|
855 |
+
::google::protobuf::uint32 cached_has_bits = 0;
|
856 |
+
(void) cached_has_bits;
|
857 |
+
|
858 |
+
// repeated .sentencepiece.SentencePieceText nbests = 1;
|
859 |
+
for (unsigned int i = 0,
|
860 |
+
n = static_cast<unsigned int>(this->nbests_size()); i < n; i++) {
|
861 |
+
::google::protobuf::internal::WireFormatLite::WriteMessage(
|
862 |
+
1,
|
863 |
+
this->nbests(static_cast<int>(i)),
|
864 |
+
output);
|
865 |
+
}
|
866 |
+
|
867 |
+
output->WriteRaw(_internal_metadata_.unknown_fields().data(),
|
868 |
+
static_cast<int>(_internal_metadata_.unknown_fields().size()));
|
869 |
+
// @@protoc_insertion_point(serialize_end:sentencepiece.NBestSentencePieceText)
|
870 |
+
}
|
871 |
+
|
872 |
+
size_t NBestSentencePieceText::ByteSizeLong() const {
|
873 |
+
// @@protoc_insertion_point(message_byte_size_start:sentencepiece.NBestSentencePieceText)
|
874 |
+
size_t total_size = 0;
|
875 |
+
|
876 |
+
total_size += _internal_metadata_.unknown_fields().size();
|
877 |
+
|
878 |
+
// repeated .sentencepiece.SentencePieceText nbests = 1;
|
879 |
+
{
|
880 |
+
unsigned int count = static_cast<unsigned int>(this->nbests_size());
|
881 |
+
total_size += 1UL * count;
|
882 |
+
for (unsigned int i = 0; i < count; i++) {
|
883 |
+
total_size +=
|
884 |
+
::google::protobuf::internal::WireFormatLite::MessageSize(
|
885 |
+
this->nbests(static_cast<int>(i)));
|
886 |
+
}
|
887 |
+
}
|
888 |
+
|
889 |
+
int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
|
890 |
+
SetCachedSize(cached_size);
|
891 |
+
return total_size;
|
892 |
+
}
|
893 |
+
|
894 |
+
void NBestSentencePieceText::CheckTypeAndMergeFrom(
|
895 |
+
const ::google::protobuf::MessageLite& from) {
|
896 |
+
MergeFrom(*::google::protobuf::down_cast<const NBestSentencePieceText*>(&from));
|
897 |
+
}
|
898 |
+
|
899 |
+
void NBestSentencePieceText::MergeFrom(const NBestSentencePieceText& from) {
|
900 |
+
// @@protoc_insertion_point(class_specific_merge_from_start:sentencepiece.NBestSentencePieceText)
|
901 |
+
GOOGLE_DCHECK_NE(&from, this);
|
902 |
+
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
903 |
+
::google::protobuf::uint32 cached_has_bits = 0;
|
904 |
+
(void) cached_has_bits;
|
905 |
+
|
906 |
+
nbests_.MergeFrom(from.nbests_);
|
907 |
+
}
|
908 |
+
|
909 |
+
void NBestSentencePieceText::CopyFrom(const NBestSentencePieceText& from) {
|
910 |
+
// @@protoc_insertion_point(class_specific_copy_from_start:sentencepiece.NBestSentencePieceText)
|
911 |
+
if (&from == this) return;
|
912 |
+
Clear();
|
913 |
+
MergeFrom(from);
|
914 |
+
}
|
915 |
+
|
916 |
+
bool NBestSentencePieceText::IsInitialized() const {
|
917 |
+
if (!::google::protobuf::internal::AllAreInitialized(this->nbests())) return false;
|
918 |
+
return true;
|
919 |
+
}
|
920 |
+
|
921 |
+
void NBestSentencePieceText::Swap(NBestSentencePieceText* other) {
|
922 |
+
if (other == this) return;
|
923 |
+
InternalSwap(other);
|
924 |
+
}
|
925 |
+
void NBestSentencePieceText::InternalSwap(NBestSentencePieceText* other) {
|
926 |
+
using std::swap;
|
927 |
+
CastToBase(&nbests_)->InternalSwap(CastToBase(&other->nbests_));
|
928 |
+
swap(_has_bits_[0], other->_has_bits_[0]);
|
929 |
+
_internal_metadata_.Swap(&other->_internal_metadata_);
|
930 |
+
}
|
931 |
+
|
932 |
+
::std::string NBestSentencePieceText::GetTypeName() const {
|
933 |
+
return "sentencepiece.NBestSentencePieceText";
|
934 |
+
}
|
935 |
+
|
936 |
+
|
937 |
+
// @@protoc_insertion_point(namespace_scope)
|
938 |
+
} // namespace sentencepiece
|
939 |
+
namespace google {
|
940 |
+
namespace protobuf {
|
941 |
+
template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::sentencepiece::SentencePieceText_SentencePiece* Arena::CreateMaybeMessage< ::sentencepiece::SentencePieceText_SentencePiece >(Arena* arena) {
|
942 |
+
return Arena::CreateInternal< ::sentencepiece::SentencePieceText_SentencePiece >(arena);
|
943 |
+
}
|
944 |
+
template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::sentencepiece::SentencePieceText* Arena::CreateMaybeMessage< ::sentencepiece::SentencePieceText >(Arena* arena) {
|
945 |
+
return Arena::CreateInternal< ::sentencepiece::SentencePieceText >(arena);
|
946 |
+
}
|
947 |
+
template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::sentencepiece::NBestSentencePieceText* Arena::CreateMaybeMessage< ::sentencepiece::NBestSentencePieceText >(Arena* arena) {
|
948 |
+
return Arena::CreateInternal< ::sentencepiece::NBestSentencePieceText >(arena);
|
949 |
+
}
|
950 |
+
} // namespace protobuf
|
951 |
+
} // namespace google
|
952 |
+
|
953 |
+
// @@protoc_insertion_point(global_scope)
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/builtin_pb/sentencepiece_model.pb.cc
ADDED
The diff for this file is too large to render.
See raw diff
|
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/builtin_pb/sentencepiece_model.pb.h
ADDED
The diff for this file is too large to render.
See raw diff
|
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/char_model.h
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#ifndef CHAR_MODEL_H_
|
16 |
+
#define CHAR_MODEL_H_
|
17 |
+
|
18 |
+
#include "model_interface.h"
|
19 |
+
#include "sentencepiece_model.pb.h"
|
20 |
+
|
21 |
+
namespace sentencepiece {
|
22 |
+
namespace character {
|
23 |
+
|
24 |
+
// Tokenize text into character sequence
|
25 |
+
class Model : public ModelInterface {
|
26 |
+
public:
|
27 |
+
explicit Model(const ModelProto &model_proto);
|
28 |
+
~Model() override;
|
29 |
+
|
30 |
+
EncodeResult Encode(absl::string_view normalized) const override;
|
31 |
+
};
|
32 |
+
} // namespace character
|
33 |
+
} // namespace sentencepiece
|
34 |
+
#endif // CHAR_MODEL_H_
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/char_model_test.cc
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "char_model.h"
|
16 |
+
|
17 |
+
#include <string>
|
18 |
+
#include <unordered_map>
|
19 |
+
#include <unordered_set>
|
20 |
+
|
21 |
+
#include "testharness.h"
|
22 |
+
#include "util.h"
|
23 |
+
|
24 |
+
namespace sentencepiece {
|
25 |
+
namespace character {
|
26 |
+
namespace {
|
27 |
+
|
28 |
+
// Space symbol (U+2581)
|
29 |
+
#define WS "\xe2\x96\x81"
|
30 |
+
|
31 |
+
ModelProto MakeBaseModelProto() {
|
32 |
+
ModelProto model_proto;
|
33 |
+
auto *sp1 = model_proto.add_pieces();
|
34 |
+
auto *sp2 = model_proto.add_pieces();
|
35 |
+
auto *sp3 = model_proto.add_pieces();
|
36 |
+
|
37 |
+
sp1->set_type(ModelProto::SentencePiece::UNKNOWN);
|
38 |
+
sp1->set_piece("<unk>");
|
39 |
+
sp2->set_type(ModelProto::SentencePiece::CONTROL);
|
40 |
+
sp2->set_piece("<s>");
|
41 |
+
sp3->set_type(ModelProto::SentencePiece::CONTROL);
|
42 |
+
sp3->set_piece("</s>");
|
43 |
+
|
44 |
+
return model_proto;
|
45 |
+
}
|
46 |
+
|
47 |
+
void AddPiece(ModelProto *model_proto, const std::string &piece,
|
48 |
+
float score = 0.0) {
|
49 |
+
auto *sp = model_proto->add_pieces();
|
50 |
+
sp->set_piece(piece);
|
51 |
+
sp->set_score(score);
|
52 |
+
}
|
53 |
+
|
54 |
+
TEST(ModelTest, EncodeTest) {
|
55 |
+
ModelProto model_proto = MakeBaseModelProto();
|
56 |
+
|
57 |
+
AddPiece(&model_proto, WS, 0.0);
|
58 |
+
AddPiece(&model_proto, "a", 0.1);
|
59 |
+
AddPiece(&model_proto, "b", 0.2);
|
60 |
+
AddPiece(&model_proto, "c", 0.3);
|
61 |
+
AddPiece(&model_proto, "d", 0.4);
|
62 |
+
AddPiece(&model_proto, "ABC", 0.4);
|
63 |
+
model_proto.mutable_pieces(8)->set_type(
|
64 |
+
ModelProto::SentencePiece::USER_DEFINED);
|
65 |
+
|
66 |
+
const Model model(model_proto);
|
67 |
+
|
68 |
+
EncodeResult result;
|
69 |
+
|
70 |
+
result = model.Encode("");
|
71 |
+
EXPECT_TRUE(result.empty());
|
72 |
+
|
73 |
+
result = model.Encode(WS "a" WS "b" WS "c");
|
74 |
+
EXPECT_EQ(6, result.size());
|
75 |
+
EXPECT_EQ(WS, result[0].first);
|
76 |
+
EXPECT_EQ("a", result[1].first);
|
77 |
+
EXPECT_EQ(WS, result[2].first);
|
78 |
+
EXPECT_EQ("b", result[3].first);
|
79 |
+
EXPECT_EQ(WS, result[4].first);
|
80 |
+
EXPECT_EQ("c", result[5].first);
|
81 |
+
|
82 |
+
result = model.Encode(WS "ab" WS "cd" WS "abc");
|
83 |
+
EXPECT_EQ(10, result.size());
|
84 |
+
EXPECT_EQ(WS, result[0].first);
|
85 |
+
EXPECT_EQ("a", result[1].first);
|
86 |
+
EXPECT_EQ("b", result[2].first);
|
87 |
+
EXPECT_EQ(WS, result[3].first);
|
88 |
+
EXPECT_EQ("c", result[4].first);
|
89 |
+
EXPECT_EQ("d", result[5].first);
|
90 |
+
EXPECT_EQ(WS, result[6].first);
|
91 |
+
EXPECT_EQ("a", result[7].first);
|
92 |
+
EXPECT_EQ("b", result[8].first);
|
93 |
+
EXPECT_EQ("c", result[9].first);
|
94 |
+
|
95 |
+
// makes a broken utf-8
|
96 |
+
const std::string broken_utf8 = std::string("あ").substr(0, 1);
|
97 |
+
result = model.Encode(broken_utf8);
|
98 |
+
EXPECT_EQ(1, result.size());
|
99 |
+
EXPECT_EQ(broken_utf8, result[0].first);
|
100 |
+
|
101 |
+
// "ABC" is treated as one piece, as it is USER_DEFINED.
|
102 |
+
result = model.Encode(WS "abABCcd");
|
103 |
+
EXPECT_EQ(6, result.size());
|
104 |
+
EXPECT_EQ(WS, result[0].first);
|
105 |
+
EXPECT_EQ("a", result[1].first);
|
106 |
+
EXPECT_EQ("b", result[2].first);
|
107 |
+
EXPECT_EQ("ABC", result[3].first);
|
108 |
+
EXPECT_EQ("c", result[4].first);
|
109 |
+
EXPECT_EQ("d", result[5].first);
|
110 |
+
}
|
111 |
+
|
112 |
+
TEST(CharModelTest, NotSupportedTest) {
|
113 |
+
ModelProto model_proto = MakeBaseModelProto();
|
114 |
+
const Model model(model_proto);
|
115 |
+
EXPECT_EQ(NBestEncodeResult(), model.NBestEncode("test", 10));
|
116 |
+
EXPECT_EQ(EncodeResult(), model.SampleEncode("test", 0.1));
|
117 |
+
}
|
118 |
+
|
119 |
+
} // namespace
|
120 |
+
} // namespace character
|
121 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/char_model_trainer.cc
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "char_model_trainer.h"
|
16 |
+
|
17 |
+
#include <cmath>
|
18 |
+
|
19 |
+
#include "char_model.h"
|
20 |
+
#include "util.h"
|
21 |
+
|
22 |
+
namespace sentencepiece {
|
23 |
+
namespace character {
|
24 |
+
|
25 |
+
util::Status Trainer::Train() {
|
26 |
+
RETURN_IF_ERROR(status());
|
27 |
+
|
28 |
+
CHECK_OR_RETURN(normalizer_spec_.escape_whitespaces());
|
29 |
+
CHECK_EQ_OR_RETURN(TrainerSpec::CHAR, trainer_spec_.model_type());
|
30 |
+
|
31 |
+
RETURN_IF_ERROR(LoadSentences());
|
32 |
+
|
33 |
+
const int vocab_size = trainer_spec_.vocab_size() - meta_pieces_.size();
|
34 |
+
CHECK_GE_OR_RETURN(vocab_size, 0);
|
35 |
+
|
36 |
+
uint64 sum = 0;
|
37 |
+
for (const auto &it : required_chars_) {
|
38 |
+
sum += it.second;
|
39 |
+
}
|
40 |
+
|
41 |
+
const float logsum = log(sum);
|
42 |
+
|
43 |
+
CHECK_OR_RETURN(final_pieces_.empty());
|
44 |
+
for (const auto &it : Sorted(required_chars_)) {
|
45 |
+
if (!trainer_spec_.use_all_vocab() &&
|
46 |
+
final_pieces_.size() == static_cast<size_t>(vocab_size)) {
|
47 |
+
break;
|
48 |
+
}
|
49 |
+
final_pieces_.emplace_back(string_util::UnicodeCharToUTF8(it.first),
|
50 |
+
log(it.second) - logsum);
|
51 |
+
}
|
52 |
+
|
53 |
+
if (trainer_spec_.use_all_vocab()) {
|
54 |
+
trainer_spec_.set_vocab_size(final_pieces_.size() + meta_pieces_.size());
|
55 |
+
}
|
56 |
+
|
57 |
+
return Save();
|
58 |
+
}
|
59 |
+
} // namespace character
|
60 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/char_model_trainer_test.cc
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "char_model_trainer.h"
|
16 |
+
#include <string>
|
17 |
+
#include <vector>
|
18 |
+
#include "filesystem.h"
|
19 |
+
#include "sentencepiece_processor.h"
|
20 |
+
#include "testharness.h"
|
21 |
+
#include "util.h"
|
22 |
+
|
23 |
+
namespace sentencepiece {
|
24 |
+
namespace character {
|
25 |
+
namespace {
|
26 |
+
|
27 |
+
// Space symbol (U+2581)
|
28 |
+
#define WS "\xE2\x96\x81"
|
29 |
+
|
30 |
+
std::string RunTrainer(const std::vector<std::string> &input, int size) {
|
31 |
+
test::ScopedTempFile input_scoped_file("input");
|
32 |
+
test::ScopedTempFile model_scoped_file("model");
|
33 |
+
const std::string input_file = input_scoped_file.filename();
|
34 |
+
const std::string model_prefix = model_scoped_file.filename();
|
35 |
+
{
|
36 |
+
auto output = filesystem::NewWritableFile(input_file);
|
37 |
+
for (const auto &line : input) {
|
38 |
+
output->WriteLine(line);
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
TrainerSpec trainer_spec;
|
43 |
+
trainer_spec.set_model_type(TrainerSpec::CHAR);
|
44 |
+
trainer_spec.add_input(input_file);
|
45 |
+
trainer_spec.set_vocab_size(size);
|
46 |
+
trainer_spec.set_model_prefix(model_prefix);
|
47 |
+
|
48 |
+
NormalizerSpec normalizer_spec;
|
49 |
+
normalizer_spec.set_name("identity");
|
50 |
+
|
51 |
+
Trainer trainer(trainer_spec, normalizer_spec);
|
52 |
+
EXPECT_OK(trainer.Train());
|
53 |
+
|
54 |
+
SentencePieceProcessor processor;
|
55 |
+
EXPECT_OK(processor.Load(model_prefix + ".model"));
|
56 |
+
|
57 |
+
const auto &model = processor.model_proto();
|
58 |
+
std::vector<std::string> pieces;
|
59 |
+
|
60 |
+
// remove <unk>, <s>, </s>
|
61 |
+
for (int i = 3; i < model.pieces_size(); ++i) {
|
62 |
+
pieces.emplace_back(model.pieces(i).piece());
|
63 |
+
}
|
64 |
+
|
65 |
+
return string_util::Join(pieces, " ");
|
66 |
+
}
|
67 |
+
|
68 |
+
TEST(TrainerTest, BasicTest) {
|
69 |
+
EXPECT_EQ(WS " a e p n I h l v",
|
70 |
+
RunTrainer({"I have a pen", "I have an apple", "apple pen"}, 100));
|
71 |
+
EXPECT_EQ(WS " a", // <unk>, <s>, </s>, _, a
|
72 |
+
RunTrainer({"I have a pen", "I have an apple", "apple pen"}, 5));
|
73 |
+
}
|
74 |
+
|
75 |
+
} // namespace
|
76 |
+
} // namespace character
|
77 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/common.h
ADDED
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#ifndef COMMON_H_
|
16 |
+
#define COMMON_H_
|
17 |
+
|
18 |
+
#include <setjmp.h>
|
19 |
+
#include <stdint.h>
|
20 |
+
#include <stdlib.h>
|
21 |
+
#include <string.h>
|
22 |
+
#include <iostream>
|
23 |
+
#include <memory>
|
24 |
+
#include <string>
|
25 |
+
#include <utility>
|
26 |
+
#include <vector>
|
27 |
+
|
28 |
+
#include "config.h"
|
29 |
+
#include "flags.h"
|
30 |
+
|
31 |
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
32 |
+
#define OS_WIN
|
33 |
+
#else
|
34 |
+
#define OS_UNIX
|
35 |
+
#endif
|
36 |
+
|
37 |
+
#ifdef OS_WIN
|
38 |
+
#ifndef NOMINMAX
|
39 |
+
#define NOMINMAX
|
40 |
+
#endif
|
41 |
+
#include <windows.h>
|
42 |
+
#endif
|
43 |
+
|
44 |
+
typedef int8_t int8;
|
45 |
+
typedef int16_t int16;
|
46 |
+
typedef int32_t int32;
|
47 |
+
typedef int64_t int64;
|
48 |
+
typedef uint8_t uint8;
|
49 |
+
typedef uint16_t uint16;
|
50 |
+
typedef uint32_t char32;
|
51 |
+
typedef uint32_t uint32;
|
52 |
+
typedef uint64_t uint64;
|
53 |
+
|
54 |
+
static constexpr uint8 kuint8max = ((uint8)0xFF);
|
55 |
+
static constexpr uint16 kuint16max = ((uint16)0xFFFF);
|
56 |
+
static constexpr uint32 kuint32max = ((uint32)0xFFFFFFFF);
|
57 |
+
static constexpr uint64 kuint64max = ((uint64)(0xFFFFFFFFFFFFFFFF));
|
58 |
+
static constexpr int8 kint8min = ((int8)~0x7F);
|
59 |
+
static constexpr int8 kint8max = ((int8)0x7F);
|
60 |
+
static constexpr int16 kint16min = ((int16)~0x7FFF);
|
61 |
+
static constexpr int16 kint16max = ((int16)0x7FFF);
|
62 |
+
static constexpr int32 kint32min = ((int32)~0x7FFFFFFF);
|
63 |
+
static constexpr int32 kint32max = ((int32)0x7FFFFFFF);
|
64 |
+
static constexpr int64 kint64min = ((int64)(~0x7FFFFFFFFFFFFFFF));
|
65 |
+
static constexpr int64 kint64max = ((int64)(0x7FFFFFFFFFFFFFFF));
|
66 |
+
|
67 |
+
static constexpr uint32 kUnicodeError = 0xFFFD;
|
68 |
+
|
69 |
+
#if defined(OS_WIN) && defined(UNICODE) && defined(_UNICODE)
|
70 |
+
#define WPATH(path) (::sentencepiece::win32::Utf8ToWide(path).c_str())
|
71 |
+
#else
|
72 |
+
#define WPATH(path) (path)
|
73 |
+
#endif
|
74 |
+
|
75 |
+
template <typename T, size_t N>
|
76 |
+
char (&ArraySizeHelper(T (&array)[N]))[N];
|
77 |
+
|
78 |
+
#ifndef _MSC_VER
|
79 |
+
template <typename T, size_t N>
|
80 |
+
char (&ArraySizeHelper(const T (&array)[N]))[N];
|
81 |
+
#endif // !_MSC_VER
|
82 |
+
|
83 |
+
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
|
84 |
+
|
85 |
+
namespace sentencepiece {
|
86 |
+
#ifdef OS_WIN
|
87 |
+
namespace win32 {
|
88 |
+
std::wstring Utf8ToWide(const std::string &input);
|
89 |
+
std::string WideToUtf8(const std::wstring &input);
|
90 |
+
} // namespace win32
|
91 |
+
#endif
|
92 |
+
|
93 |
+
namespace flags {
|
94 |
+
int GetMinLogLevel();
|
95 |
+
void SetMinLogLevel(int minloglevel);
|
96 |
+
} // namespace flags
|
97 |
+
|
98 |
+
namespace error {
|
99 |
+
|
100 |
+
void Abort();
|
101 |
+
void Exit(int code);
|
102 |
+
void SetTestCounter(int c);
|
103 |
+
void ResetTestMode();
|
104 |
+
bool GetTestCounter();
|
105 |
+
|
106 |
+
class Die {
|
107 |
+
public:
|
108 |
+
explicit Die(bool die) : die_(die) {}
|
109 |
+
~Die() {
|
110 |
+
std::cerr << std::endl;
|
111 |
+
if (die_) {
|
112 |
+
Abort();
|
113 |
+
}
|
114 |
+
}
|
115 |
+
int operator&(std::ostream &) { return 0; }
|
116 |
+
|
117 |
+
private:
|
118 |
+
bool die_;
|
119 |
+
};
|
120 |
+
|
121 |
+
template <typename T>
|
122 |
+
T &&CheckNotNull(const char *file, int line, const char *exprtext, T &&t) {
|
123 |
+
if (t == nullptr) {
|
124 |
+
std::cerr << file << "(" << line << ") " << exprtext;
|
125 |
+
Abort();
|
126 |
+
}
|
127 |
+
return std::forward<T>(t);
|
128 |
+
}
|
129 |
+
} // namespace error
|
130 |
+
|
131 |
+
namespace logging {
|
132 |
+
enum LogSeverity {
|
133 |
+
LOG_INFO = 0,
|
134 |
+
LOG_WARNING = 1,
|
135 |
+
LOG_ERROR = 2,
|
136 |
+
LOG_FATAL = 3,
|
137 |
+
LOG_SEVERITY_SIZE = 4,
|
138 |
+
};
|
139 |
+
|
140 |
+
inline const char *BaseName(const char *path) {
|
141 |
+
#ifdef OS_WIN
|
142 |
+
const char *p = strrchr(path, '\\');
|
143 |
+
#else
|
144 |
+
const char *p = strrchr(path, '/');
|
145 |
+
#endif
|
146 |
+
if (p == nullptr) return path;
|
147 |
+
return p + 1;
|
148 |
+
}
|
149 |
+
} // namespace logging
|
150 |
+
} // namespace sentencepiece
|
151 |
+
|
152 |
+
#define LOG(severity) \
|
153 |
+
(sentencepiece::flags::GetMinLogLevel() > \
|
154 |
+
::sentencepiece::logging::LOG_##severity) \
|
155 |
+
? 0 \
|
156 |
+
: ::sentencepiece::error::Die( \
|
157 |
+
::sentencepiece::logging::LOG_##severity >= \
|
158 |
+
::sentencepiece::logging::LOG_FATAL) & \
|
159 |
+
std::cerr << ::sentencepiece::logging::BaseName(__FILE__) << "(" \
|
160 |
+
<< __LINE__ << ") " \
|
161 |
+
<< "LOG(" << #severity << ") "
|
162 |
+
|
163 |
+
#define CHECK(condition) \
|
164 |
+
(condition) ? 0 \
|
165 |
+
: ::sentencepiece::error::Die(true) & \
|
166 |
+
std::cerr << ::sentencepiece::logging::BaseName(__FILE__) \
|
167 |
+
<< "(" << __LINE__ << ") [" << #condition \
|
168 |
+
<< "] "
|
169 |
+
|
170 |
+
#define CHECK_STREQ(a, b) CHECK_EQ(std::string(a), std::string(b))
|
171 |
+
#define CHECK_EQ(a, b) CHECK((a) == (b))
|
172 |
+
#define CHECK_NE(a, b) CHECK((a) != (b))
|
173 |
+
#define CHECK_GE(a, b) CHECK((a) >= (b))
|
174 |
+
#define CHECK_LE(a, b) CHECK((a) <= (b))
|
175 |
+
#define CHECK_GT(a, b) CHECK((a) > (b))
|
176 |
+
#define CHECK_LT(a, b) CHECK((a) < (b))
|
177 |
+
#define CHECK_NOTNULL(val) \
|
178 |
+
::sentencepiece::error::CheckNotNull( \
|
179 |
+
::sentencepiece::logging::BaseName(__FILE__), __LINE__, \
|
180 |
+
"'" #val "' Must be non NULL", (val))
|
181 |
+
|
182 |
+
#define FRIEND_TEST(a, b) friend class a##_Test_##b;
|
183 |
+
|
184 |
+
#define CHECK_OK(expr) \
|
185 |
+
do { \
|
186 |
+
const auto _status = expr; \
|
187 |
+
CHECK(_status.ok()) << _status.ToString(); \
|
188 |
+
} while (0)
|
189 |
+
|
190 |
+
#define CHECK_NOT_OK(expr) \
|
191 |
+
do { \
|
192 |
+
const auto _status = expr; \
|
193 |
+
CHECK(!_status.ok()) << _status.ToString(); \
|
194 |
+
} while (0)
|
195 |
+
|
196 |
+
#define RETURN_IF_ERROR(expr) \
|
197 |
+
do { \
|
198 |
+
const auto _status = expr; \
|
199 |
+
if (!_status.ok()) return _status; \
|
200 |
+
} while (0)
|
201 |
+
|
202 |
+
#endif // COMMON_H_
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/compile_charsmap_main.cc
ADDED
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include <functional>
|
16 |
+
#include <iomanip>
|
17 |
+
#include <iostream>
|
18 |
+
#include <sstream>
|
19 |
+
#include <string>
|
20 |
+
#include "builder.h"
|
21 |
+
#include "filesystem.h"
|
22 |
+
#include "flags.h"
|
23 |
+
#include "sentencepiece_processor.h"
|
24 |
+
#include "third_party/absl/strings/string_view.h"
|
25 |
+
|
26 |
+
using sentencepiece::normalizer::Builder;
|
27 |
+
using sentencepiece::util::Status;
|
28 |
+
|
29 |
+
DEFINE_bool(output_precompiled_header, false, "make normalization_rule.h file");
|
30 |
+
|
31 |
+
namespace sentencepiece {
|
32 |
+
namespace {
|
33 |
+
|
34 |
+
std::string ToHexUInt64Array(
|
35 |
+
const std::vector<std::pair<std::string, std::string>> &data,
|
36 |
+
std::vector<size_t> *offset) {
|
37 |
+
std::stringstream os;
|
38 |
+
os.setf(std::ios_base::hex, std::ios_base::basefield);
|
39 |
+
os.setf(std::ios_base::uppercase);
|
40 |
+
os.setf(std::ios_base::right);
|
41 |
+
os.fill('0');
|
42 |
+
os.unsetf(std::ios_base::showbase);
|
43 |
+
|
44 |
+
size_t num = 0;
|
45 |
+
for (const auto &p : data) {
|
46 |
+
const char *begin = p.second.data();
|
47 |
+
const char *end = p.second.data() + p.second.size();
|
48 |
+
|
49 |
+
offset->push_back(num);
|
50 |
+
while (begin < end) {
|
51 |
+
unsigned long long int n = 0;
|
52 |
+
unsigned char *buf = reinterpret_cast<unsigned char *>(&n);
|
53 |
+
const size_t size = std::min<size_t>(end - begin, sizeof(n));
|
54 |
+
for (size_t i = 0; i < size; ++i) {
|
55 |
+
buf[i] = static_cast<unsigned char>(begin[i]);
|
56 |
+
}
|
57 |
+
begin += sizeof(n);
|
58 |
+
os << "0x" << std::setw(2 * sizeof(n)) << n << ", ";
|
59 |
+
if (++num % 8 == 0) {
|
60 |
+
os << "\n";
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
return os.str();
|
66 |
+
}
|
67 |
+
|
68 |
+
std::string ToHexData(absl::string_view data) {
|
69 |
+
const char *begin = data.data();
|
70 |
+
const char *end = data.data() + data.size();
|
71 |
+
constexpr char kHex[] = "0123456789ABCDEF";
|
72 |
+
constexpr size_t kNumOfBytesOnOneLine = 20;
|
73 |
+
|
74 |
+
size_t output_count = 0;
|
75 |
+
std::stringstream os;
|
76 |
+
while (begin < end) {
|
77 |
+
const size_t bucket_size =
|
78 |
+
std::min<size_t>(end - begin, kNumOfBytesOnOneLine -
|
79 |
+
output_count % kNumOfBytesOnOneLine);
|
80 |
+
if (output_count % kNumOfBytesOnOneLine == 0 && bucket_size > 0) {
|
81 |
+
os << "\"";
|
82 |
+
}
|
83 |
+
for (size_t i = 0; i < bucket_size; ++i) {
|
84 |
+
os << "\\x" << kHex[(*begin & 0xF0) >> 4] << kHex[(*begin & 0x0F) >> 0];
|
85 |
+
++begin;
|
86 |
+
}
|
87 |
+
output_count += bucket_size;
|
88 |
+
if (output_count % kNumOfBytesOnOneLine == 0 && bucket_size > 0 &&
|
89 |
+
begin < end) {
|
90 |
+
os << "\"\n";
|
91 |
+
}
|
92 |
+
}
|
93 |
+
os << "\"\n";
|
94 |
+
|
95 |
+
return os.str();
|
96 |
+
}
|
97 |
+
|
98 |
+
std::string MakeHeader(
|
99 |
+
const std::vector<std::pair<std::string, std::string>> &data) {
|
100 |
+
constexpr char kHeader[] =
|
101 |
+
R"(#ifndef NORMALIZATION_RULE_H_
|
102 |
+
#define NORMALIZATION_RULE_H_
|
103 |
+
#include <cstdio>
|
104 |
+
namespace sentencepiece {
|
105 |
+
namespace {
|
106 |
+
|
107 |
+
struct BinaryBlob {
|
108 |
+
const char *name;
|
109 |
+
size_t size;
|
110 |
+
const char *data;
|
111 |
+
};
|
112 |
+
|
113 |
+
)";
|
114 |
+
|
115 |
+
constexpr char kFooter[] = R"(
|
116 |
+
} // namespace
|
117 |
+
} // namespace sentencepiece
|
118 |
+
#endif // NORMALIZATION_RULE_H_
|
119 |
+
)";
|
120 |
+
|
121 |
+
std::stringstream os;
|
122 |
+
os << kHeader;
|
123 |
+
|
124 |
+
os << "#if defined(_WIN32) && !defined(__CYGWIN__)\n";
|
125 |
+
os << "constexpr unsigned long long int kNormalizationRules_blob_uint64[] = "
|
126 |
+
"{\n";
|
127 |
+
std::vector<size_t> offset;
|
128 |
+
os << ToHexUInt64Array(data, &offset);
|
129 |
+
CHECK_EQ(offset.size(), data.size());
|
130 |
+
os << "};\n\n";
|
131 |
+
os << "const BinaryBlob kNormalizationRules_blob[] = {\n";
|
132 |
+
for (size_t i = 0; i < data.size(); ++i) {
|
133 |
+
os << "{ \"" << data[i].first << "\", " << data[i].second.size() << ", ";
|
134 |
+
os << "reinterpret_cast<const char *>(kNormalizationRules_blob_uint64 + "
|
135 |
+
<< offset[i] << ") },\n";
|
136 |
+
}
|
137 |
+
os << "};\n";
|
138 |
+
os << "#else\n";
|
139 |
+
os << "constexpr BinaryBlob kNormalizationRules_blob[] = {\n";
|
140 |
+
for (size_t i = 0; i < data.size(); ++i) {
|
141 |
+
os << "{ \"" << data[i].first << "\", " << data[i].second.size() << ", ";
|
142 |
+
os << ToHexData(data[i].second) << "},\n";
|
143 |
+
}
|
144 |
+
os << "};\n";
|
145 |
+
os << "#endif\n";
|
146 |
+
|
147 |
+
os << "constexpr size_t kNormalizationRules_size = " << data.size() << ";\n";
|
148 |
+
os << kFooter;
|
149 |
+
|
150 |
+
return os.str();
|
151 |
+
}
|
152 |
+
|
153 |
+
} // namespace
|
154 |
+
} // namespace sentencepiece
|
155 |
+
|
156 |
+
int main(int argc, char **argv) {
|
157 |
+
sentencepiece::flags::ParseCommandLineFlags(argc, argv);
|
158 |
+
|
159 |
+
const std::vector<
|
160 |
+
std::pair<std::string, std::function<Status(Builder::CharsMap *)>>>
|
161 |
+
kRuleList = {{"nfkc", Builder::BuildNFKCMap},
|
162 |
+
{"nmt_nfkc", Builder::BuildNmtNFKCMap},
|
163 |
+
{"nfkc_cf", Builder::BuildNFKC_CFMap},
|
164 |
+
{"nmt_nfkc_cf", Builder::BuildNmtNFKC_CFMap}};
|
165 |
+
|
166 |
+
std::vector<std::pair<std::string, std::string>> data;
|
167 |
+
for (const auto &p : kRuleList) {
|
168 |
+
Builder::CharsMap normalized_map;
|
169 |
+
CHECK_OK(p.second(&normalized_map));
|
170 |
+
|
171 |
+
// Write Header.
|
172 |
+
std::string index;
|
173 |
+
CHECK_OK(Builder::CompileCharsMap(normalized_map, &index));
|
174 |
+
data.emplace_back(p.first, index);
|
175 |
+
|
176 |
+
// Write TSV file.
|
177 |
+
CHECK_OK(Builder::SaveCharsMap(p.first + ".tsv", normalized_map));
|
178 |
+
}
|
179 |
+
|
180 |
+
if (FLAGS_output_precompiled_header) {
|
181 |
+
constexpr char kPrecompiledHeaderFileName[] = "normalization_rule.h";
|
182 |
+
auto output =
|
183 |
+
sentencepiece::filesystem::NewWritableFile(kPrecompiledHeaderFileName);
|
184 |
+
CHECK_OK(output->status());
|
185 |
+
output->Write(sentencepiece::MakeHeader(data));
|
186 |
+
}
|
187 |
+
|
188 |
+
return 0;
|
189 |
+
}
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/error.cc
ADDED
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include <cstring>
|
16 |
+
#include "common.h"
|
17 |
+
#include "sentencepiece_processor.h"
|
18 |
+
|
19 |
+
namespace sentencepiece {
|
20 |
+
namespace error {
|
21 |
+
int gTestCounter = 0;
|
22 |
+
|
23 |
+
void Abort() {
|
24 |
+
if (GetTestCounter() == 1) {
|
25 |
+
SetTestCounter(2);
|
26 |
+
} else {
|
27 |
+
std::cerr << "Program terminated with an unrecoverable error." << std::endl;
|
28 |
+
exit(-1);
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
void Exit(int code) {
|
33 |
+
if (GetTestCounter() == 1) {
|
34 |
+
SetTestCounter(2);
|
35 |
+
} else {
|
36 |
+
exit(code);
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
void SetTestCounter(int c) { gTestCounter = c; }
|
41 |
+
bool GetTestCounter() { return gTestCounter; }
|
42 |
+
} // namespace error
|
43 |
+
|
44 |
+
namespace util {
|
45 |
+
|
46 |
+
Status::Status() {}
|
47 |
+
Status::~Status() {}
|
48 |
+
|
49 |
+
struct Status::Rep {
|
50 |
+
error::Code code;
|
51 |
+
std::string error_message;
|
52 |
+
};
|
53 |
+
|
54 |
+
Status::Status(error::Code code, const char* error_message) : rep_(new Rep) {
|
55 |
+
rep_->code = code;
|
56 |
+
rep_->error_message = error_message;
|
57 |
+
}
|
58 |
+
|
59 |
+
Status::Status(error::Code code, const std::string& error_message)
|
60 |
+
: rep_(new Rep) {
|
61 |
+
rep_->code = code;
|
62 |
+
rep_->error_message = error_message;
|
63 |
+
}
|
64 |
+
|
65 |
+
Status::Status(const Status& s)
|
66 |
+
: rep_((s.rep_ == nullptr) ? nullptr : new Rep(*s.rep_)) {}
|
67 |
+
|
68 |
+
void Status::operator=(const Status& s) {
|
69 |
+
if (rep_ != s.rep_)
|
70 |
+
rep_.reset((s.rep_ == nullptr) ? nullptr : new Rep(*s.rep_));
|
71 |
+
}
|
72 |
+
|
73 |
+
bool Status::operator==(const Status& s) const { return (rep_ == s.rep_); }
|
74 |
+
|
75 |
+
bool Status::operator!=(const Status& s) const { return (rep_ != s.rep_); }
|
76 |
+
|
77 |
+
const char* Status::error_message() const {
|
78 |
+
return ok() ? "" : rep_->error_message.c_str();
|
79 |
+
}
|
80 |
+
|
81 |
+
void Status::set_error_message(const char* str) {
|
82 |
+
if (rep_ == nullptr) rep_.reset(new Rep);
|
83 |
+
rep_->error_message = str;
|
84 |
+
}
|
85 |
+
|
86 |
+
error::Code Status::code() const { return ok() ? error::OK : rep_->code; }
|
87 |
+
|
88 |
+
std::string Status::ToString() const {
|
89 |
+
if (rep_ == nullptr) return "OK";
|
90 |
+
|
91 |
+
std::string result;
|
92 |
+
switch (code()) {
|
93 |
+
case error::CANCELLED:
|
94 |
+
result = "Cancelled";
|
95 |
+
break;
|
96 |
+
case error::UNKNOWN:
|
97 |
+
result = "Unknown";
|
98 |
+
break;
|
99 |
+
case error::INVALID_ARGUMENT:
|
100 |
+
result = "Invalid argument";
|
101 |
+
break;
|
102 |
+
case error::DEADLINE_EXCEEDED:
|
103 |
+
result = "Deadline exceeded";
|
104 |
+
break;
|
105 |
+
case error::NOT_FOUND:
|
106 |
+
result = "Not found";
|
107 |
+
break;
|
108 |
+
case error::ALREADY_EXISTS:
|
109 |
+
result = "Already exists";
|
110 |
+
break;
|
111 |
+
case error::PERMISSION_DENIED:
|
112 |
+
result = "Permission denied";
|
113 |
+
break;
|
114 |
+
case error::UNAUTHENTICATED:
|
115 |
+
result = "Unauthenticated";
|
116 |
+
break;
|
117 |
+
case error::RESOURCE_EXHAUSTED:
|
118 |
+
result = "Resource exhausted";
|
119 |
+
break;
|
120 |
+
case error::FAILED_PRECONDITION:
|
121 |
+
result = "Failed precondition";
|
122 |
+
break;
|
123 |
+
case error::ABORTED:
|
124 |
+
result = "Aborted";
|
125 |
+
break;
|
126 |
+
case error::OUT_OF_RANGE:
|
127 |
+
result = "Out of range";
|
128 |
+
break;
|
129 |
+
case error::UNIMPLEMENTED:
|
130 |
+
result = "Unimplemented";
|
131 |
+
break;
|
132 |
+
case error::INTERNAL:
|
133 |
+
result = "Internal";
|
134 |
+
break;
|
135 |
+
case error::UNAVAILABLE:
|
136 |
+
result = "Unavailable";
|
137 |
+
break;
|
138 |
+
case error::DATA_LOSS:
|
139 |
+
result = "Data loss";
|
140 |
+
break;
|
141 |
+
default:
|
142 |
+
result = "Unkown code:";
|
143 |
+
break;
|
144 |
+
}
|
145 |
+
|
146 |
+
result += ": ";
|
147 |
+
result += rep_->error_message;
|
148 |
+
return result;
|
149 |
+
}
|
150 |
+
|
151 |
+
void Status::IgnoreError() {}
|
152 |
+
|
153 |
+
} // namespace util
|
154 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/filesystem.cc
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "filesystem.h"
|
16 |
+
#include <iostream>
|
17 |
+
|
18 |
+
#include "util.h"
|
19 |
+
|
20 |
+
namespace sentencepiece {
|
21 |
+
namespace filesystem {
|
22 |
+
|
23 |
+
class PosixReadableFile : public ReadableFile {
|
24 |
+
public:
|
25 |
+
PosixReadableFile(absl::string_view filename, bool is_binary = false)
|
26 |
+
: is_(filename.empty()
|
27 |
+
? &std::cin
|
28 |
+
: new std::ifstream(WPATH(filename.data()),
|
29 |
+
is_binary ? std::ios::binary | std::ios::in
|
30 |
+
: std::ios::in)) {
|
31 |
+
if (!*is_)
|
32 |
+
status_ = util::StatusBuilder(util::error::NOT_FOUND)
|
33 |
+
<< "\"" << filename.data() << "\": " << util::StrError(errno);
|
34 |
+
}
|
35 |
+
|
36 |
+
~PosixReadableFile() {
|
37 |
+
if (is_ != &std::cin) delete is_;
|
38 |
+
}
|
39 |
+
|
40 |
+
util::Status status() const { return status_; }
|
41 |
+
|
42 |
+
bool ReadLine(std::string *line) {
|
43 |
+
return static_cast<bool>(std::getline(*is_, *line));
|
44 |
+
}
|
45 |
+
|
46 |
+
bool ReadAll(std::string *line) {
|
47 |
+
if (is_ == &std::cin) {
|
48 |
+
LOG(ERROR) << "ReadAll is not supported for stdin.";
|
49 |
+
return false;
|
50 |
+
}
|
51 |
+
line->assign(std::istreambuf_iterator<char>(*is_),
|
52 |
+
std::istreambuf_iterator<char>());
|
53 |
+
return true;
|
54 |
+
}
|
55 |
+
|
56 |
+
private:
|
57 |
+
util::Status status_;
|
58 |
+
std::istream *is_;
|
59 |
+
};
|
60 |
+
|
61 |
+
class PosixWritableFile : public WritableFile {
|
62 |
+
public:
|
63 |
+
PosixWritableFile(absl::string_view filename, bool is_binary = false)
|
64 |
+
: os_(filename.empty()
|
65 |
+
? &std::cout
|
66 |
+
: new std::ofstream(WPATH(filename.data()),
|
67 |
+
is_binary ? std::ios::binary | std::ios::out
|
68 |
+
: std::ios::out)) {
|
69 |
+
if (!*os_)
|
70 |
+
status_ = util::StatusBuilder(util::error::PERMISSION_DENIED)
|
71 |
+
<< "\"" << filename.data() << "\": " << util::StrError(errno);
|
72 |
+
}
|
73 |
+
|
74 |
+
~PosixWritableFile() {
|
75 |
+
if (os_ != &std::cout) delete os_;
|
76 |
+
}
|
77 |
+
|
78 |
+
util::Status status() const { return status_; }
|
79 |
+
|
80 |
+
bool Write(absl::string_view text) {
|
81 |
+
os_->write(text.data(), text.size());
|
82 |
+
return os_->good();
|
83 |
+
}
|
84 |
+
|
85 |
+
bool WriteLine(absl::string_view text) { return Write(text) && Write("\n"); }
|
86 |
+
|
87 |
+
private:
|
88 |
+
util::Status status_;
|
89 |
+
std::ostream *os_;
|
90 |
+
};
|
91 |
+
|
92 |
+
std::unique_ptr<ReadableFile> NewReadableFile(absl::string_view filename,
|
93 |
+
bool is_binary) {
|
94 |
+
return port::MakeUnique<PosixReadableFile>(filename, is_binary);
|
95 |
+
}
|
96 |
+
|
97 |
+
std::unique_ptr<WritableFile> NewWritableFile(absl::string_view filename,
|
98 |
+
bool is_binary) {
|
99 |
+
return port::MakeUnique<PosixWritableFile>(filename, is_binary);
|
100 |
+
}
|
101 |
+
|
102 |
+
} // namespace filesystem
|
103 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/filesystem.h
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#ifndef FILESYSTEM_H_
|
16 |
+
#define FILESYSTEM_H_
|
17 |
+
|
18 |
+
#include <stdio.h>
|
19 |
+
|
20 |
+
#include <fstream>
|
21 |
+
#include <memory>
|
22 |
+
#include <string>
|
23 |
+
#include "common.h"
|
24 |
+
#include "sentencepiece_processor.h"
|
25 |
+
#include "third_party/absl/strings/string_view.h"
|
26 |
+
|
27 |
+
namespace sentencepiece {
|
28 |
+
namespace filesystem {
|
29 |
+
class ReadableFile {
|
30 |
+
public:
|
31 |
+
ReadableFile() {}
|
32 |
+
explicit ReadableFile(absl::string_view filename, bool is_binary = false) {}
|
33 |
+
virtual ~ReadableFile() {}
|
34 |
+
|
35 |
+
virtual util::Status status() const = 0;
|
36 |
+
virtual bool ReadLine(std::string *line) = 0;
|
37 |
+
virtual bool ReadAll(std::string *line) = 0;
|
38 |
+
};
|
39 |
+
|
40 |
+
class WritableFile {
|
41 |
+
public:
|
42 |
+
WritableFile() {}
|
43 |
+
explicit WritableFile(absl::string_view filename, bool is_binary = false) {}
|
44 |
+
virtual ~WritableFile() {}
|
45 |
+
|
46 |
+
virtual util::Status status() const = 0;
|
47 |
+
virtual bool Write(absl::string_view text) = 0;
|
48 |
+
virtual bool WriteLine(absl::string_view text) = 0;
|
49 |
+
};
|
50 |
+
|
51 |
+
std::unique_ptr<ReadableFile> NewReadableFile(absl::string_view filename,
|
52 |
+
bool is_binary = false);
|
53 |
+
std::unique_ptr<WritableFile> NewWritableFile(absl::string_view filename,
|
54 |
+
bool is_binary = false);
|
55 |
+
|
56 |
+
} // namespace filesystem
|
57 |
+
} // namespace sentencepiece
|
58 |
+
#endif // FILESYSTEM_H_
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/filesystem_test.cc
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "filesystem.h"
|
16 |
+
|
17 |
+
#include "testharness.h"
|
18 |
+
#include "util.h"
|
19 |
+
|
20 |
+
namespace sentencepiece {
|
21 |
+
|
22 |
+
TEST(UtilTest, FilesystemTest) {
|
23 |
+
test::ScopedTempFile sf("test_file");
|
24 |
+
|
25 |
+
const char *kData[] = {
|
26 |
+
"This"
|
27 |
+
"is"
|
28 |
+
"a"
|
29 |
+
"test"};
|
30 |
+
|
31 |
+
{
|
32 |
+
auto output = filesystem::NewWritableFile(sf.filename());
|
33 |
+
for (size_t i = 0; i < arraysize(kData); ++i) {
|
34 |
+
output->WriteLine(kData[i]);
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
{
|
39 |
+
auto input = filesystem::NewReadableFile(sf.filename());
|
40 |
+
std::string line;
|
41 |
+
for (size_t i = 0; i < arraysize(kData); ++i) {
|
42 |
+
EXPECT_TRUE(input->ReadLine(&line));
|
43 |
+
EXPECT_EQ(kData[i], line);
|
44 |
+
}
|
45 |
+
EXPECT_FALSE(input->ReadLine(&line));
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
TEST(UtilTest, FilesystemInvalidFileTest) {
|
50 |
+
auto input = filesystem::NewReadableFile("__UNKNOWN__FILE__");
|
51 |
+
EXPECT_NOT_OK(input->status());
|
52 |
+
}
|
53 |
+
|
54 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/flags.cc
ADDED
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "flags.h"
|
16 |
+
|
17 |
+
#include <algorithm>
|
18 |
+
#include <cctype>
|
19 |
+
#include <iostream>
|
20 |
+
#include <map>
|
21 |
+
#include <sstream>
|
22 |
+
#include <string>
|
23 |
+
#include <utility>
|
24 |
+
|
25 |
+
#include "common.h"
|
26 |
+
#include "config.h"
|
27 |
+
#include "util.h"
|
28 |
+
|
29 |
+
namespace sentencepiece {
|
30 |
+
namespace flags {
|
31 |
+
|
32 |
+
struct Flag {
|
33 |
+
int type;
|
34 |
+
void *storage;
|
35 |
+
const void *default_storage;
|
36 |
+
std::string help;
|
37 |
+
};
|
38 |
+
|
39 |
+
static int32 g_minloglevel = 0;
|
40 |
+
|
41 |
+
int GetMinLogLevel() { return g_minloglevel; }
|
42 |
+
void SetMinLogLevel(int minloglevel) { g_minloglevel = minloglevel; }
|
43 |
+
|
44 |
+
namespace {
|
45 |
+
using FlagMap = std::map<std::string, Flag *>;
|
46 |
+
|
47 |
+
FlagMap *GetFlagMap() {
|
48 |
+
static FlagMap flag_map;
|
49 |
+
return &flag_map;
|
50 |
+
}
|
51 |
+
|
52 |
+
bool SetFlag(const std::string &name, const std::string &value) {
|
53 |
+
auto it = GetFlagMap()->find(name);
|
54 |
+
if (it == GetFlagMap()->end()) {
|
55 |
+
return false;
|
56 |
+
}
|
57 |
+
|
58 |
+
std::string v = value;
|
59 |
+
Flag *flag = it->second;
|
60 |
+
|
61 |
+
// If empty value is set, we assume true or emtpy string is set
|
62 |
+
// for boolean or string option. With other types, setting fails.
|
63 |
+
if (value.empty()) {
|
64 |
+
switch (flag->type) {
|
65 |
+
case B:
|
66 |
+
v = "true";
|
67 |
+
break;
|
68 |
+
case S:
|
69 |
+
v = "";
|
70 |
+
break;
|
71 |
+
default:
|
72 |
+
return false;
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
#define DEFINE_ARG(FLAG_TYPE, CPP_TYPE) \
|
77 |
+
case FLAG_TYPE: { \
|
78 |
+
CPP_TYPE *s = reinterpret_cast<CPP_TYPE *>(flag->storage); \
|
79 |
+
CHECK(string_util::lexical_cast<CPP_TYPE>(v, s)); \
|
80 |
+
break; \
|
81 |
+
}
|
82 |
+
|
83 |
+
switch (flag->type) {
|
84 |
+
DEFINE_ARG(I, int32);
|
85 |
+
DEFINE_ARG(B, bool);
|
86 |
+
DEFINE_ARG(I64, int64);
|
87 |
+
DEFINE_ARG(U64, uint64);
|
88 |
+
DEFINE_ARG(D, double);
|
89 |
+
DEFINE_ARG(S, std::string);
|
90 |
+
default:
|
91 |
+
break;
|
92 |
+
}
|
93 |
+
|
94 |
+
return true;
|
95 |
+
} // namespace
|
96 |
+
|
97 |
+
bool CommandLineGetFlag(int argc, char **argv, std::string *key,
|
98 |
+
std::string *value, int *used_args) {
|
99 |
+
key->clear();
|
100 |
+
value->clear();
|
101 |
+
|
102 |
+
*used_args = 1;
|
103 |
+
const char *start = argv[0];
|
104 |
+
if (start[0] != '-') {
|
105 |
+
return false;
|
106 |
+
}
|
107 |
+
|
108 |
+
++start;
|
109 |
+
if (start[0] == '-') ++start;
|
110 |
+
const std::string arg = start;
|
111 |
+
const size_t n = arg.find("=");
|
112 |
+
if (n != std::string::npos) {
|
113 |
+
*key = arg.substr(0, n);
|
114 |
+
*value = arg.substr(n + 1, arg.size() - n);
|
115 |
+
return true;
|
116 |
+
}
|
117 |
+
|
118 |
+
key->assign(arg);
|
119 |
+
value->clear();
|
120 |
+
|
121 |
+
if (argc == 1) {
|
122 |
+
return true;
|
123 |
+
}
|
124 |
+
start = argv[1];
|
125 |
+
if (start[0] == '-') {
|
126 |
+
return true;
|
127 |
+
}
|
128 |
+
|
129 |
+
*used_args = 2;
|
130 |
+
value->assign(start);
|
131 |
+
return true;
|
132 |
+
}
|
133 |
+
} // namespace
|
134 |
+
|
135 |
+
FlagRegister::FlagRegister(const char *name, void *storage,
|
136 |
+
const void *default_storage, int shortype,
|
137 |
+
const char *help)
|
138 |
+
: flag_(new Flag) {
|
139 |
+
flag_->type = shortype;
|
140 |
+
flag_->storage = storage;
|
141 |
+
flag_->default_storage = default_storage;
|
142 |
+
flag_->help = help;
|
143 |
+
GetFlagMap()->insert(std::make_pair(std::string(name), flag_.get()));
|
144 |
+
}
|
145 |
+
|
146 |
+
FlagRegister::~FlagRegister() {}
|
147 |
+
|
148 |
+
std::string PrintHelp(const char *programname) {
|
149 |
+
std::ostringstream os;
|
150 |
+
os << PACKAGE_STRING << "\n\n";
|
151 |
+
os << "Usage: " << programname << " [options] files\n\n";
|
152 |
+
|
153 |
+
for (const auto &it : *GetFlagMap()) {
|
154 |
+
os << " --" << it.first << " (" << it.second->help << ")";
|
155 |
+
const Flag *flag = it.second;
|
156 |
+
switch (flag->type) {
|
157 |
+
case I:
|
158 |
+
os << " type: int32 default: "
|
159 |
+
<< *(reinterpret_cast<const int *>(flag->default_storage)) << '\n';
|
160 |
+
break;
|
161 |
+
case B:
|
162 |
+
os << " type: bool default: "
|
163 |
+
<< (*(reinterpret_cast<const bool *>(flag->default_storage))
|
164 |
+
? "true"
|
165 |
+
: "false")
|
166 |
+
<< '\n';
|
167 |
+
break;
|
168 |
+
case I64:
|
169 |
+
os << " type: int64 default: "
|
170 |
+
<< *(reinterpret_cast<const int64 *>(flag->default_storage)) << '\n';
|
171 |
+
break;
|
172 |
+
case U64:
|
173 |
+
os << " type: uint64 default: "
|
174 |
+
<< *(reinterpret_cast<const uint64 *>(flag->default_storage))
|
175 |
+
<< '\n';
|
176 |
+
break;
|
177 |
+
case D:
|
178 |
+
os << " type: double default: "
|
179 |
+
<< *(reinterpret_cast<const double *>(flag->default_storage))
|
180 |
+
<< '\n';
|
181 |
+
break;
|
182 |
+
case S:
|
183 |
+
os << " type: string default: "
|
184 |
+
<< *(reinterpret_cast<const std::string *>(flag->default_storage))
|
185 |
+
<< '\n';
|
186 |
+
break;
|
187 |
+
default:
|
188 |
+
break;
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
os << "\n\n";
|
193 |
+
|
194 |
+
return os.str();
|
195 |
+
}
|
196 |
+
|
197 |
+
void ParseCommandLineFlags(int argc, char **argv,
|
198 |
+
std::vector<std::string> *rest_flags) {
|
199 |
+
int used_argc = 0;
|
200 |
+
std::string key, value;
|
201 |
+
|
202 |
+
for (int i = 1; i < argc; i += used_argc) {
|
203 |
+
if (!CommandLineGetFlag(argc - i, argv + i, &key, &value, &used_argc)) {
|
204 |
+
if (rest_flags) rest_flags->push_back(std::string(argv[i]));
|
205 |
+
continue;
|
206 |
+
}
|
207 |
+
if (key == "help") {
|
208 |
+
std::cout << PrintHelp(argv[0]);
|
209 |
+
error::Exit(0);
|
210 |
+
} else if (key == "version") {
|
211 |
+
std::cout << PACKAGE_STRING << " " << VERSION << std::endl;
|
212 |
+
error::Exit(0);
|
213 |
+
} else if (key == "minloglevel") {
|
214 |
+
flags::SetMinLogLevel(atoi(value.c_str()));
|
215 |
+
} else if (!SetFlag(key, value)) {
|
216 |
+
std::cerr << "Unknown/Invalid flag " << key << "\n\n"
|
217 |
+
<< PrintHelp(argv[0]);
|
218 |
+
error::Exit(1);
|
219 |
+
}
|
220 |
+
}
|
221 |
+
}
|
222 |
+
} // namespace flags
|
223 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/flags.h
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#ifndef FLAGS_H_
|
16 |
+
#define FLAGS_H_
|
17 |
+
|
18 |
+
#include <memory>
|
19 |
+
#include <string>
|
20 |
+
#include <vector>
|
21 |
+
|
22 |
+
namespace sentencepiece {
|
23 |
+
namespace flags {
|
24 |
+
|
25 |
+
enum { I, B, I64, U64, D, S };
|
26 |
+
|
27 |
+
struct Flag;
|
28 |
+
|
29 |
+
class FlagRegister {
|
30 |
+
public:
|
31 |
+
FlagRegister(const char *name, void *storage, const void *default_storage,
|
32 |
+
int shorttpe, const char *help);
|
33 |
+
~FlagRegister();
|
34 |
+
|
35 |
+
private:
|
36 |
+
std::unique_ptr<Flag> flag_;
|
37 |
+
};
|
38 |
+
|
39 |
+
std::string PrintHelp(const char *programname);
|
40 |
+
|
41 |
+
void ParseCommandLineFlags(int argc, char **argv,
|
42 |
+
std::vector<std::string> *rest_args = nullptr);
|
43 |
+
} // namespace flags
|
44 |
+
} // namespace sentencepiece
|
45 |
+
|
46 |
+
#define DEFINE_VARIABLE(type, shorttype, name, value, help) \
|
47 |
+
namespace sentencepiece_flags_fL##shorttype { \
|
48 |
+
using namespace sentencepiece::flags; \
|
49 |
+
type FLAGS_##name = value; \
|
50 |
+
static const type FLAGS_DEFAULT_##name = value; \
|
51 |
+
static const sentencepiece::flags::FlagRegister fL##name( \
|
52 |
+
#name, reinterpret_cast<void *>(&FLAGS_##name), \
|
53 |
+
reinterpret_cast<const void *>(&FLAGS_DEFAULT_##name), shorttype, \
|
54 |
+
help); \
|
55 |
+
} \
|
56 |
+
using sentencepiece_flags_fL##shorttype::FLAGS_##name
|
57 |
+
|
58 |
+
#define DECLARE_VARIABLE(type, shorttype, name) \
|
59 |
+
namespace sentencepiece_flags_fL##shorttype { \
|
60 |
+
extern type FLAGS_##name; \
|
61 |
+
} \
|
62 |
+
using sentencepiece_flags_fL##shorttype::FLAGS_##name
|
63 |
+
|
64 |
+
#define DEFINE_int32(name, value, help) \
|
65 |
+
DEFINE_VARIABLE(int32, I, name, value, help)
|
66 |
+
#define DECLARE_int32(name) DECLARE_VARIABLE(int32, I, name)
|
67 |
+
|
68 |
+
#define DEFINE_int64(name, value, help) \
|
69 |
+
DEFINE_VARIABLE(int64, I64, name, value, help)
|
70 |
+
#define DECLARE_int64(name) DECLARE_VARIABLE(int64, I64, name)
|
71 |
+
|
72 |
+
#define DEFINE_uint64(name, value, help) \
|
73 |
+
DEFINE_VARIABLE(uint64, U64, name, value, help)
|
74 |
+
#define DECLARE_uint64(name) DECLARE_VARIABLE(uint64, U64, name)
|
75 |
+
|
76 |
+
#define DEFINE_double(name, value, help) \
|
77 |
+
DEFINE_VARIABLE(double, D, name, value, help)
|
78 |
+
#define DECLARE_double(name) DECLARE_VARIABLE(double, D, name)
|
79 |
+
|
80 |
+
#define DEFINE_bool(name, value, help) \
|
81 |
+
DEFINE_VARIABLE(bool, B, name, value, help)
|
82 |
+
#define DECLARE_bool(name) DECLARE_VARIABLE(bool, B, name)
|
83 |
+
|
84 |
+
#define DEFINE_string(name, value, help) \
|
85 |
+
DEFINE_VARIABLE(std::string, S, name, value, help)
|
86 |
+
#define DECLARE_string(name) DECLARE_VARIABLE(std::string, S, name)
|
87 |
+
|
88 |
+
#define CHECK_OR_HELP(flag) \
|
89 |
+
if (FLAGS_##flag.empty()) { \
|
90 |
+
std::cout << "ERROR: --" << #flag << " must not be empty\n\n"; \
|
91 |
+
std::cout << sentencepiece::flags::PrintHelp(PACKAGE_STRING); \
|
92 |
+
sentencepiece::error::Exit(0); \
|
93 |
+
}
|
94 |
+
|
95 |
+
#endif // FLAGS_H_
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/flags_test.cc
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "flags.h"
|
16 |
+
#include "common.h"
|
17 |
+
#include "testharness.h"
|
18 |
+
|
19 |
+
DEFINE_int32(int32_f, 10, "int32_flags");
|
20 |
+
DEFINE_bool(bool_f, false, "bool_flags");
|
21 |
+
DEFINE_int64(int64_f, 20, "int64_flags");
|
22 |
+
DEFINE_uint64(uint64_f, 30, "uint64_flags");
|
23 |
+
DEFINE_double(double_f, 40.0, "double_flags");
|
24 |
+
DEFINE_string(string_f, "str", "string_flags");
|
25 |
+
|
26 |
+
namespace sentencepiece {
|
27 |
+
namespace flags {
|
28 |
+
|
29 |
+
TEST(FlagsTest, DefaultValueTest) {
|
30 |
+
EXPECT_EQ(10, FLAGS_int32_f);
|
31 |
+
EXPECT_EQ(false, FLAGS_bool_f);
|
32 |
+
EXPECT_EQ(20, FLAGS_int64_f);
|
33 |
+
EXPECT_EQ(30, FLAGS_uint64_f);
|
34 |
+
EXPECT_EQ(40.0, FLAGS_double_f);
|
35 |
+
EXPECT_EQ("str", FLAGS_string_f);
|
36 |
+
}
|
37 |
+
|
38 |
+
TEST(FlagsTest, PrintHelpTest) {
|
39 |
+
const std::string help = PrintHelp("foobar");
|
40 |
+
EXPECT_NE(std::string::npos, help.find("foobar"));
|
41 |
+
EXPECT_NE(std::string::npos, help.find("int32_flags"));
|
42 |
+
EXPECT_NE(std::string::npos, help.find("bool_flags"));
|
43 |
+
EXPECT_NE(std::string::npos, help.find("int64_flags"));
|
44 |
+
EXPECT_NE(std::string::npos, help.find("uint64_flags"));
|
45 |
+
EXPECT_NE(std::string::npos, help.find("double_flags"));
|
46 |
+
EXPECT_NE(std::string::npos, help.find("string_flags"));
|
47 |
+
}
|
48 |
+
|
49 |
+
TEST(FlagsTest, ParseCommandLineFlagsTest) {
|
50 |
+
const char *kFlags[] = {"program", "--int32_f=100", "other1",
|
51 |
+
"--bool_f=true", "--int64_f=200", "--uint64_f=300",
|
52 |
+
"--double_f=400", "--string_f=foo", "other2",
|
53 |
+
"other3"};
|
54 |
+
|
55 |
+
std::vector<std::string> rest;
|
56 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags), &rest);
|
57 |
+
|
58 |
+
EXPECT_EQ(100, FLAGS_int32_f);
|
59 |
+
EXPECT_EQ(true, FLAGS_bool_f);
|
60 |
+
EXPECT_EQ(200, FLAGS_int64_f);
|
61 |
+
EXPECT_EQ(300, FLAGS_uint64_f);
|
62 |
+
EXPECT_EQ(400.0, FLAGS_double_f);
|
63 |
+
EXPECT_EQ("foo", FLAGS_string_f);
|
64 |
+
EXPECT_EQ(3, rest.size());
|
65 |
+
EXPECT_EQ("other1", rest[0]);
|
66 |
+
EXPECT_EQ("other2", rest[1]);
|
67 |
+
EXPECT_EQ("other3", rest[2]);
|
68 |
+
}
|
69 |
+
|
70 |
+
TEST(FlagsTest, ParseCommandLineFlagsTest2) {
|
71 |
+
const char *kFlags[] = {"program", "--int32_f", "500",
|
72 |
+
"-int64_f=600", "-uint64_f", "700",
|
73 |
+
"--bool_f=FALSE"};
|
74 |
+
|
75 |
+
std::vector<std::string> rest;
|
76 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags), &rest);
|
77 |
+
|
78 |
+
EXPECT_EQ(500, FLAGS_int32_f);
|
79 |
+
EXPECT_EQ(600, FLAGS_int64_f);
|
80 |
+
EXPECT_EQ(700, FLAGS_uint64_f);
|
81 |
+
EXPECT_FALSE(FLAGS_bool_f);
|
82 |
+
EXPECT_TRUE(rest.empty());
|
83 |
+
}
|
84 |
+
|
85 |
+
TEST(FlagsTest, ParseCommandLineFlagsTest3) {
|
86 |
+
const char *kFlags[] = {"program", "--bool_f", "--int32_f", "800"};
|
87 |
+
|
88 |
+
std::vector<std::string> rest;
|
89 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags), &rest);
|
90 |
+
|
91 |
+
EXPECT_TRUE(FLAGS_bool_f);
|
92 |
+
EXPECT_EQ(800, FLAGS_int32_f);
|
93 |
+
EXPECT_TRUE(rest.empty());
|
94 |
+
}
|
95 |
+
|
96 |
+
TEST(FlagsTest, ParseCommandLineFlagsHelpTest) {
|
97 |
+
const char *kFlags[] = {"program", "--help"};
|
98 |
+
EXPECT_DEATH(
|
99 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags)));
|
100 |
+
}
|
101 |
+
|
102 |
+
TEST(FlagsTest, ParseCommandLineFlagsVersionTest) {
|
103 |
+
const char *kFlags[] = {"program", "--version"};
|
104 |
+
EXPECT_DEATH(
|
105 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags)));
|
106 |
+
}
|
107 |
+
|
108 |
+
TEST(FlagsTest, ParseCommandLineFlagsUnknownTest) {
|
109 |
+
const char *kFlags[] = {"program", "--foo"};
|
110 |
+
EXPECT_DEATH(
|
111 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags)));
|
112 |
+
}
|
113 |
+
|
114 |
+
TEST(FlagsTest, ParseCommandLineFlagsInvalidBoolTest) {
|
115 |
+
const char *kFlags[] = {"program", "--bool_f=X"};
|
116 |
+
EXPECT_DEATH(
|
117 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags)));
|
118 |
+
}
|
119 |
+
|
120 |
+
TEST(FlagsTest, ParseCommandLineFlagsEmptyStringArgs) {
|
121 |
+
const char *kFlags[] = {"program", "--string_f="};
|
122 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags));
|
123 |
+
EXPECT_EQ("", FLAGS_string_f);
|
124 |
+
}
|
125 |
+
|
126 |
+
TEST(FlagsTest, ParseCommandLineFlagsEmptyBoolArgs) {
|
127 |
+
const char *kFlags[] = {"program", "--bool_f"};
|
128 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags));
|
129 |
+
EXPECT_TRUE(FLAGS_bool_f);
|
130 |
+
}
|
131 |
+
|
132 |
+
TEST(FlagsTest, ParseCommandLineFlagsEmptyIntArgs) {
|
133 |
+
const char *kFlags[] = {"program", "--int32_f"};
|
134 |
+
EXPECT_DEATH(
|
135 |
+
ParseCommandLineFlags(arraysize(kFlags), const_cast<char **>(kFlags)));
|
136 |
+
}
|
137 |
+
} // namespace flags
|
138 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/freelist.h
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2018 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#ifndef FREELIST_H_
|
16 |
+
#define FREELIST_H_
|
17 |
+
|
18 |
+
#include <string.h>
|
19 |
+
#include <vector>
|
20 |
+
|
21 |
+
namespace sentencepiece {
|
22 |
+
namespace model {
|
23 |
+
|
24 |
+
// Simple FreeList that allocates a chunk of T at once.
|
25 |
+
template <class T>
|
26 |
+
class FreeList {
|
27 |
+
public:
|
28 |
+
FreeList() = delete;
|
29 |
+
explicit FreeList(size_t chunk_size) : chunk_size_(chunk_size) {}
|
30 |
+
virtual ~FreeList() {
|
31 |
+
for (auto& chunk : freelist_) delete[] chunk;
|
32 |
+
}
|
33 |
+
|
34 |
+
// `Free` doesn't free the object but reuse the allocated memory chunks.
|
35 |
+
void Free() {
|
36 |
+
const int size = std::min<int>(chunk_index_ + 1, freelist_.size());
|
37 |
+
for (int i = 0; i < size; ++i) {
|
38 |
+
T* chunk = freelist_[i];
|
39 |
+
memset(chunk, 0, sizeof(*chunk) * chunk_size_);
|
40 |
+
}
|
41 |
+
chunk_index_ = 0;
|
42 |
+
element_index_ = 0;
|
43 |
+
}
|
44 |
+
|
45 |
+
// Returns the number of allocated elements.
|
46 |
+
size_t size() const { return chunk_size_ * chunk_index_ + element_index_; }
|
47 |
+
|
48 |
+
// Returns the element as an array.
|
49 |
+
T* operator[](size_t index) const {
|
50 |
+
return freelist_[index / chunk_size_] + index % chunk_size_;
|
51 |
+
}
|
52 |
+
|
53 |
+
// Allocates new element.
|
54 |
+
T* Allocate() {
|
55 |
+
if (element_index_ >= chunk_size_) {
|
56 |
+
++chunk_index_;
|
57 |
+
element_index_ = 0;
|
58 |
+
}
|
59 |
+
|
60 |
+
if (chunk_index_ == freelist_.size()) {
|
61 |
+
T* chunk = new T[chunk_size_];
|
62 |
+
memset(chunk, 0, sizeof(*chunk) * chunk_size_);
|
63 |
+
freelist_.push_back(chunk);
|
64 |
+
}
|
65 |
+
|
66 |
+
T* result = freelist_[chunk_index_] + element_index_;
|
67 |
+
++element_index_;
|
68 |
+
|
69 |
+
return result;
|
70 |
+
}
|
71 |
+
|
72 |
+
private:
|
73 |
+
std::vector<T*> freelist_;
|
74 |
+
|
75 |
+
// The last element is stored at freelist_[chunk_index_][element_index_]
|
76 |
+
size_t element_index_ = 0;
|
77 |
+
size_t chunk_index_ = 0;
|
78 |
+
const size_t chunk_size_ = 0;
|
79 |
+
};
|
80 |
+
} // namespace model
|
81 |
+
} // namespace sentencepiece
|
82 |
+
#endif // FREELIST_H_
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/freelist_test.cc
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include "freelist.h"
|
2 |
+
#include "testharness.h"
|
3 |
+
|
4 |
+
namespace sentencepiece {
|
5 |
+
namespace model {
|
6 |
+
|
7 |
+
TEST(FreeListTest, BasicTest) {
|
8 |
+
FreeList<int> l(5);
|
9 |
+
EXPECT_EQ(0, l.size());
|
10 |
+
|
11 |
+
constexpr size_t kSize = 32;
|
12 |
+
|
13 |
+
for (size_t i = 0; i < kSize; ++i) {
|
14 |
+
int *n = l.Allocate();
|
15 |
+
EXPECT_EQ(0, *n);
|
16 |
+
*n = i;
|
17 |
+
}
|
18 |
+
|
19 |
+
EXPECT_EQ(kSize, l.size());
|
20 |
+
for (size_t i = 0; i < kSize; ++i) {
|
21 |
+
EXPECT_EQ(i, *l[i]);
|
22 |
+
}
|
23 |
+
|
24 |
+
l.Free();
|
25 |
+
EXPECT_EQ(0, l.size());
|
26 |
+
|
27 |
+
// Zero-initialized after `Free`.
|
28 |
+
for (size_t i = 0; i < kSize; ++i) {
|
29 |
+
int *n = l.Allocate();
|
30 |
+
EXPECT_EQ(0, *n);
|
31 |
+
}
|
32 |
+
}
|
33 |
+
} // namespace model
|
34 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/model_factory.cc
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "model_factory.h"
|
16 |
+
|
17 |
+
#include "bpe_model.h"
|
18 |
+
#include "char_model.h"
|
19 |
+
#include "unigram_model.h"
|
20 |
+
#include "util.h"
|
21 |
+
#include "word_model.h"
|
22 |
+
|
23 |
+
namespace sentencepiece {
|
24 |
+
|
25 |
+
// Instantiate Model instance from |model_proto|
|
26 |
+
std::unique_ptr<ModelInterface> ModelFactory::Create(
|
27 |
+
const ModelProto& model_proto) {
|
28 |
+
const auto& trainer_spec = model_proto.trainer_spec();
|
29 |
+
|
30 |
+
switch (trainer_spec.model_type()) {
|
31 |
+
case TrainerSpec::UNIGRAM:
|
32 |
+
return port::MakeUnique<unigram::Model>(model_proto);
|
33 |
+
break;
|
34 |
+
case TrainerSpec::BPE:
|
35 |
+
return port::MakeUnique<bpe::Model>(model_proto);
|
36 |
+
break;
|
37 |
+
case TrainerSpec::WORD:
|
38 |
+
return port::MakeUnique<word::Model>(model_proto);
|
39 |
+
break;
|
40 |
+
case TrainerSpec::CHAR:
|
41 |
+
return port::MakeUnique<character::Model>(model_proto);
|
42 |
+
break;
|
43 |
+
default:
|
44 |
+
LOG(ERROR) << "Unknown model_type: " << trainer_spec.model_type();
|
45 |
+
return nullptr;
|
46 |
+
break;
|
47 |
+
}
|
48 |
+
|
49 |
+
return port::MakeUnique<unigram::Model>(model_proto);
|
50 |
+
}
|
51 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/model_factory_test.cc
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "model_factory.h"
|
16 |
+
#include "testharness.h"
|
17 |
+
|
18 |
+
namespace sentencepiece {
|
19 |
+
|
20 |
+
TEST(ModelFactoryTest, BasicTest) {
|
21 |
+
ModelProto model_proto;
|
22 |
+
|
23 |
+
auto *sp1 = model_proto.add_pieces();
|
24 |
+
auto *sp2 = model_proto.add_pieces();
|
25 |
+
auto *sp3 = model_proto.add_pieces();
|
26 |
+
|
27 |
+
sp1->set_type(ModelProto::SentencePiece::UNKNOWN);
|
28 |
+
sp1->set_piece("<unk>");
|
29 |
+
sp2->set_type(ModelProto::SentencePiece::CONTROL);
|
30 |
+
sp2->set_piece("<s>");
|
31 |
+
sp3->set_type(ModelProto::SentencePiece::CONTROL);
|
32 |
+
sp3->set_piece("</s>");
|
33 |
+
|
34 |
+
auto *sp4 = model_proto.add_pieces();
|
35 |
+
sp4->set_piece("test");
|
36 |
+
sp4->set_score(1.0);
|
37 |
+
|
38 |
+
{
|
39 |
+
model_proto.mutable_trainer_spec()->set_model_type(TrainerSpec::UNIGRAM);
|
40 |
+
auto m = ModelFactory::Create(model_proto);
|
41 |
+
}
|
42 |
+
|
43 |
+
{
|
44 |
+
model_proto.mutable_trainer_spec()->set_model_type(TrainerSpec::BPE);
|
45 |
+
auto m = ModelFactory::Create(model_proto);
|
46 |
+
}
|
47 |
+
|
48 |
+
{
|
49 |
+
model_proto.mutable_trainer_spec()->set_model_type(TrainerSpec::WORD);
|
50 |
+
auto m = ModelFactory::Create(model_proto);
|
51 |
+
}
|
52 |
+
|
53 |
+
{
|
54 |
+
model_proto.mutable_trainer_spec()->set_model_type(TrainerSpec::CHAR);
|
55 |
+
auto m = ModelFactory::Create(model_proto);
|
56 |
+
}
|
57 |
+
}
|
58 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/model_interface.cc
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "model_interface.h"
|
16 |
+
|
17 |
+
#include <algorithm>
|
18 |
+
#include "sentencepiece_model.pb.h"
|
19 |
+
#include "util.h"
|
20 |
+
|
21 |
+
namespace sentencepiece {
|
22 |
+
|
23 |
+
ModelInterface::ModelInterface(const ModelProto &model_proto)
|
24 |
+
: model_proto_(&model_proto), status_(util::OkStatus()) {}
|
25 |
+
ModelInterface::~ModelInterface() {}
|
26 |
+
|
27 |
+
#define RETURN_PIECE(name, default_value) \
|
28 |
+
if (model_proto_->trainer_spec().name().empty()) return default_value; \
|
29 |
+
return model_proto_->trainer_spec().name();
|
30 |
+
|
31 |
+
absl::string_view ModelInterface::unk_piece() const {
|
32 |
+
RETURN_PIECE(unk_piece, "<unk>");
|
33 |
+
}
|
34 |
+
|
35 |
+
absl::string_view ModelInterface::bos_piece() const {
|
36 |
+
RETURN_PIECE(bos_piece, "<s>");
|
37 |
+
}
|
38 |
+
|
39 |
+
absl::string_view ModelInterface::eos_piece() const {
|
40 |
+
RETURN_PIECE(eos_piece, "</s>");
|
41 |
+
}
|
42 |
+
|
43 |
+
absl::string_view ModelInterface::pad_piece() const {
|
44 |
+
RETURN_PIECE(pad_piece, "<pad>");
|
45 |
+
}
|
46 |
+
|
47 |
+
#undef RETURN_PIECE
|
48 |
+
|
49 |
+
int ModelInterface::PieceToId(absl::string_view piece) const {
|
50 |
+
auto it = reserved_id_map_.find(piece);
|
51 |
+
if (it != reserved_id_map_.end()) {
|
52 |
+
return it->second;
|
53 |
+
}
|
54 |
+
auto it2 = pieces_.find(piece);
|
55 |
+
if (it2 != pieces_.end()) {
|
56 |
+
return it2->second;
|
57 |
+
}
|
58 |
+
return unk_id_;
|
59 |
+
}
|
60 |
+
|
61 |
+
void ModelInterface::InitializePieces() {
|
62 |
+
pieces_.clear();
|
63 |
+
reserved_id_map_.clear();
|
64 |
+
unk_id_ = -1;
|
65 |
+
|
66 |
+
std::set<absl::string_view> user_defined_symbols;
|
67 |
+
|
68 |
+
for (int i = 0; i < model_proto_->pieces_size(); ++i) {
|
69 |
+
const auto &sp = model_proto_->pieces(i);
|
70 |
+
if (sp.piece().empty()) {
|
71 |
+
status_ = util::InternalError("piece must not be empty.");
|
72 |
+
return;
|
73 |
+
}
|
74 |
+
|
75 |
+
const bool is_normal_piece =
|
76 |
+
(sp.type() == ModelProto::SentencePiece::NORMAL ||
|
77 |
+
sp.type() == ModelProto::SentencePiece::USER_DEFINED ||
|
78 |
+
sp.type() == ModelProto::SentencePiece::UNUSED);
|
79 |
+
if (!port::InsertIfNotPresent(
|
80 |
+
is_normal_piece ? &pieces_ : &reserved_id_map_, sp.piece(), i)) {
|
81 |
+
status_ = util::InternalError(sp.piece() + " is already defined.");
|
82 |
+
return;
|
83 |
+
}
|
84 |
+
|
85 |
+
if (sp.type() == ModelProto::SentencePiece::USER_DEFINED) {
|
86 |
+
user_defined_symbols.insert(sp.piece());
|
87 |
+
}
|
88 |
+
|
89 |
+
if (sp.type() == ModelProto::SentencePiece::UNKNOWN) {
|
90 |
+
if (unk_id_ >= 0) {
|
91 |
+
status_ = util::InternalError("unk is already defined.");
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
unk_id_ = i;
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
if (unk_id_ == -1) {
|
99 |
+
status_ = util::InternalError("unk is not defined.");
|
100 |
+
return;
|
101 |
+
}
|
102 |
+
|
103 |
+
matcher_ = port::MakeUnique<normalizer::PrefixMatcher>(user_defined_symbols);
|
104 |
+
}
|
105 |
+
|
106 |
+
std::vector<absl::string_view> SplitIntoWords(absl::string_view text,
|
107 |
+
bool treat_whitespace_as_suffix) {
|
108 |
+
const char *begin = text.data();
|
109 |
+
const char *end = text.data() + text.size();
|
110 |
+
|
111 |
+
// Space symbol (U+2581)
|
112 |
+
const absl::string_view kSpaceSymbol = "\xe2\x96\x81";
|
113 |
+
|
114 |
+
std::vector<absl::string_view> result;
|
115 |
+
if (treat_whitespace_as_suffix) {
|
116 |
+
if (begin < end) result.emplace_back(begin, 0);
|
117 |
+
while (begin < end) {
|
118 |
+
const int mblen =
|
119 |
+
std::min<int>(string_util::OneCharLen(begin), end - begin);
|
120 |
+
const bool is_ws = absl::string_view(begin, mblen) == kSpaceSymbol;
|
121 |
+
result.back() =
|
122 |
+
absl::string_view(result.back().data(), result.back().size() + mblen);
|
123 |
+
begin += mblen;
|
124 |
+
if (begin < end && is_ws) result.emplace_back(begin, 0);
|
125 |
+
}
|
126 |
+
} else {
|
127 |
+
while (begin < end) {
|
128 |
+
const int mblen =
|
129 |
+
std::min<int>(string_util::OneCharLen(begin), end - begin);
|
130 |
+
if (begin == text.data() ||
|
131 |
+
absl::string_view(begin, mblen) == kSpaceSymbol)
|
132 |
+
result.emplace_back(begin, 0); // add empty string piece.
|
133 |
+
result.back() =
|
134 |
+
absl::string_view(result.back().data(), result.back().size() + mblen);
|
135 |
+
begin += mblen;
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
return result;
|
140 |
+
}
|
141 |
+
|
142 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/model_interface_test.cc
ADDED
@@ -0,0 +1,373 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "model_interface.h"
|
16 |
+
#include "model_factory.h"
|
17 |
+
#include "testharness.h"
|
18 |
+
#include "util.h"
|
19 |
+
|
20 |
+
namespace sentencepiece {
|
21 |
+
namespace {
|
22 |
+
|
23 |
+
#define WS "\xe2\x96\x81"
|
24 |
+
|
25 |
+
const std::vector<TrainerSpec::ModelType> kModelTypes = {
|
26 |
+
TrainerSpec::UNIGRAM, TrainerSpec::BPE, TrainerSpec::WORD,
|
27 |
+
TrainerSpec::CHAR};
|
28 |
+
|
29 |
+
ModelProto MakeBaseModelProto(TrainerSpec::ModelType type) {
|
30 |
+
ModelProto model_proto;
|
31 |
+
auto *sp1 = model_proto.add_pieces();
|
32 |
+
auto *sp2 = model_proto.add_pieces();
|
33 |
+
auto *sp3 = model_proto.add_pieces();
|
34 |
+
model_proto.mutable_trainer_spec()->set_model_type(type);
|
35 |
+
|
36 |
+
sp1->set_type(ModelProto::SentencePiece::UNKNOWN);
|
37 |
+
sp1->set_piece("<unk>");
|
38 |
+
sp2->set_type(ModelProto::SentencePiece::CONTROL);
|
39 |
+
sp2->set_piece("<s>");
|
40 |
+
sp3->set_type(ModelProto::SentencePiece::CONTROL);
|
41 |
+
sp3->set_piece("</s>");
|
42 |
+
|
43 |
+
return model_proto;
|
44 |
+
}
|
45 |
+
|
46 |
+
void AddPiece(ModelProto *model_proto, const std::string &piece,
|
47 |
+
float score = 0.0) {
|
48 |
+
auto *sp = model_proto->add_pieces();
|
49 |
+
sp->set_piece(piece);
|
50 |
+
sp->set_score(score);
|
51 |
+
}
|
52 |
+
|
53 |
+
TEST(ModelInterfaceTest, GetDefaultPieceTest) {
|
54 |
+
{
|
55 |
+
ModelProto model_proto;
|
56 |
+
EXPECT_EQ("<unk>", model_proto.trainer_spec().unk_piece());
|
57 |
+
EXPECT_EQ("<s>", model_proto.trainer_spec().bos_piece());
|
58 |
+
EXPECT_EQ("</s>", model_proto.trainer_spec().eos_piece());
|
59 |
+
EXPECT_EQ("<pad>", model_proto.trainer_spec().pad_piece());
|
60 |
+
}
|
61 |
+
|
62 |
+
{
|
63 |
+
ModelProto model_proto = MakeBaseModelProto(TrainerSpec::UNIGRAM);
|
64 |
+
AddPiece(&model_proto, "a");
|
65 |
+
auto model = ModelFactory::Create(model_proto);
|
66 |
+
EXPECT_EQ("<unk>", model->unk_piece());
|
67 |
+
EXPECT_EQ("<s>", model->bos_piece());
|
68 |
+
EXPECT_EQ("</s>", model->eos_piece());
|
69 |
+
EXPECT_EQ("<pad>", model->pad_piece());
|
70 |
+
}
|
71 |
+
|
72 |
+
{
|
73 |
+
ModelProto model_proto = MakeBaseModelProto(TrainerSpec::UNIGRAM);
|
74 |
+
AddPiece(&model_proto, "a");
|
75 |
+
model_proto.mutable_trainer_spec()->clear_unk_piece();
|
76 |
+
model_proto.mutable_trainer_spec()->clear_bos_piece();
|
77 |
+
model_proto.mutable_trainer_spec()->clear_eos_piece();
|
78 |
+
model_proto.mutable_trainer_spec()->clear_pad_piece();
|
79 |
+
auto model = ModelFactory::Create(model_proto);
|
80 |
+
EXPECT_EQ("<unk>", model->unk_piece());
|
81 |
+
EXPECT_EQ("<s>", model->bos_piece());
|
82 |
+
EXPECT_EQ("</s>", model->eos_piece());
|
83 |
+
EXPECT_EQ("<pad>", model->pad_piece());
|
84 |
+
}
|
85 |
+
|
86 |
+
{
|
87 |
+
ModelProto model_proto = MakeBaseModelProto(TrainerSpec::UNIGRAM);
|
88 |
+
AddPiece(&model_proto, "a");
|
89 |
+
model_proto.mutable_trainer_spec()->set_unk_piece("UNK");
|
90 |
+
model_proto.mutable_trainer_spec()->set_bos_piece("BOS");
|
91 |
+
model_proto.mutable_trainer_spec()->set_eos_piece("EOS");
|
92 |
+
model_proto.mutable_trainer_spec()->set_pad_piece("PAD");
|
93 |
+
auto model = ModelFactory::Create(model_proto);
|
94 |
+
EXPECT_EQ("UNK", model->unk_piece());
|
95 |
+
EXPECT_EQ("BOS", model->bos_piece());
|
96 |
+
EXPECT_EQ("EOS", model->eos_piece());
|
97 |
+
EXPECT_EQ("PAD", model->pad_piece());
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
TEST(ModelInterfaceTest, SetModelInterfaceTest) {
|
102 |
+
for (const auto type : kModelTypes) {
|
103 |
+
ModelProto model_proto = MakeBaseModelProto(type);
|
104 |
+
AddPiece(&model_proto, "a");
|
105 |
+
AddPiece(&model_proto, "b");
|
106 |
+
AddPiece(&model_proto, "c");
|
107 |
+
AddPiece(&model_proto, "d");
|
108 |
+
|
109 |
+
auto model = ModelFactory::Create(model_proto);
|
110 |
+
EXPECT_EQ(model_proto.SerializeAsString(),
|
111 |
+
model->model_proto().SerializeAsString());
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
TEST(ModelInterfaceTest, PieceToIdTest) {
|
116 |
+
for (const auto type : kModelTypes) {
|
117 |
+
ModelProto model_proto = MakeBaseModelProto(type);
|
118 |
+
|
119 |
+
AddPiece(&model_proto, "a", 0.1); // 3
|
120 |
+
AddPiece(&model_proto, "b", 0.2); // 4
|
121 |
+
AddPiece(&model_proto, "c", 0.3); // 5
|
122 |
+
AddPiece(&model_proto, "d", 0.4); // 6
|
123 |
+
AddPiece(&model_proto, "e", 0.5); // 7
|
124 |
+
model_proto.mutable_pieces(6)->set_type(ModelProto::SentencePiece::UNUSED);
|
125 |
+
model_proto.mutable_pieces(7)->set_type(
|
126 |
+
ModelProto::SentencePiece::USER_DEFINED);
|
127 |
+
|
128 |
+
auto model = ModelFactory::Create(model_proto);
|
129 |
+
|
130 |
+
EXPECT_EQ(model_proto.SerializeAsString(),
|
131 |
+
model->model_proto().SerializeAsString());
|
132 |
+
|
133 |
+
EXPECT_EQ(0, model->PieceToId("<unk>"));
|
134 |
+
EXPECT_EQ(1, model->PieceToId("<s>"));
|
135 |
+
EXPECT_EQ(2, model->PieceToId("</s>"));
|
136 |
+
EXPECT_EQ(3, model->PieceToId("a"));
|
137 |
+
EXPECT_EQ(4, model->PieceToId("b"));
|
138 |
+
EXPECT_EQ(5, model->PieceToId("c"));
|
139 |
+
EXPECT_EQ(6, model->PieceToId("d"));
|
140 |
+
EXPECT_EQ(7, model->PieceToId("e"));
|
141 |
+
EXPECT_EQ(0, model->PieceToId("f")); // unk
|
142 |
+
EXPECT_EQ(0, model->PieceToId("")); // unk
|
143 |
+
|
144 |
+
EXPECT_EQ("<unk>", model->IdToPiece(0));
|
145 |
+
EXPECT_EQ("<s>", model->IdToPiece(1));
|
146 |
+
EXPECT_EQ("</s>", model->IdToPiece(2));
|
147 |
+
EXPECT_EQ("a", model->IdToPiece(3));
|
148 |
+
EXPECT_EQ("b", model->IdToPiece(4));
|
149 |
+
EXPECT_EQ("c", model->IdToPiece(5));
|
150 |
+
EXPECT_EQ("d", model->IdToPiece(6));
|
151 |
+
EXPECT_EQ("e", model->IdToPiece(7));
|
152 |
+
|
153 |
+
EXPECT_TRUE(model->IsUnknown(0));
|
154 |
+
EXPECT_FALSE(model->IsUnknown(1));
|
155 |
+
EXPECT_FALSE(model->IsUnknown(2));
|
156 |
+
EXPECT_FALSE(model->IsUnknown(3));
|
157 |
+
EXPECT_FALSE(model->IsUnknown(4));
|
158 |
+
EXPECT_FALSE(model->IsUnknown(5));
|
159 |
+
EXPECT_FALSE(model->IsUnknown(6));
|
160 |
+
EXPECT_FALSE(model->IsUnknown(7));
|
161 |
+
|
162 |
+
EXPECT_FALSE(model->IsControl(0));
|
163 |
+
EXPECT_TRUE(model->IsControl(1));
|
164 |
+
EXPECT_TRUE(model->IsControl(2));
|
165 |
+
EXPECT_FALSE(model->IsControl(3));
|
166 |
+
EXPECT_FALSE(model->IsControl(4));
|
167 |
+
EXPECT_FALSE(model->IsControl(5));
|
168 |
+
EXPECT_FALSE(model->IsControl(6));
|
169 |
+
EXPECT_FALSE(model->IsControl(7));
|
170 |
+
|
171 |
+
EXPECT_FALSE(model->IsUnused(0));
|
172 |
+
EXPECT_FALSE(model->IsUnused(1));
|
173 |
+
EXPECT_FALSE(model->IsUnused(2));
|
174 |
+
EXPECT_FALSE(model->IsUnused(3));
|
175 |
+
EXPECT_FALSE(model->IsUnused(4));
|
176 |
+
EXPECT_FALSE(model->IsUnused(5));
|
177 |
+
EXPECT_TRUE(model->IsUnused(6));
|
178 |
+
EXPECT_FALSE(model->IsUnused(7));
|
179 |
+
|
180 |
+
EXPECT_FALSE(model->IsUserDefined(0));
|
181 |
+
EXPECT_FALSE(model->IsUserDefined(1));
|
182 |
+
EXPECT_FALSE(model->IsUserDefined(2));
|
183 |
+
EXPECT_FALSE(model->IsUserDefined(3));
|
184 |
+
EXPECT_FALSE(model->IsUserDefined(4));
|
185 |
+
EXPECT_FALSE(model->IsUserDefined(5));
|
186 |
+
EXPECT_FALSE(model->IsUserDefined(6));
|
187 |
+
EXPECT_TRUE(model->IsUserDefined(7));
|
188 |
+
|
189 |
+
EXPECT_NEAR(0, model->GetScore(0), 0.0001);
|
190 |
+
EXPECT_NEAR(0, model->GetScore(1), 0.0001);
|
191 |
+
EXPECT_NEAR(0, model->GetScore(2), 0.0001);
|
192 |
+
EXPECT_NEAR(0.1, model->GetScore(3), 0.0001);
|
193 |
+
EXPECT_NEAR(0.2, model->GetScore(4), 0.0001);
|
194 |
+
EXPECT_NEAR(0.3, model->GetScore(5), 0.0001);
|
195 |
+
EXPECT_NEAR(0.4, model->GetScore(6), 0.0001);
|
196 |
+
EXPECT_NEAR(0.5, model->GetScore(7), 0.0001);
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
TEST(ModelInterfaceTest, InvalidModelTest) {
|
201 |
+
// Empty piece.
|
202 |
+
{
|
203 |
+
ModelProto model_proto = MakeBaseModelProto(TrainerSpec::UNIGRAM);
|
204 |
+
AddPiece(&model_proto, "");
|
205 |
+
auto model = ModelFactory::Create(model_proto);
|
206 |
+
EXPECT_FALSE(model->status().ok());
|
207 |
+
}
|
208 |
+
|
209 |
+
// Duplicated pieces.
|
210 |
+
{
|
211 |
+
ModelProto model_proto = MakeBaseModelProto(TrainerSpec::UNIGRAM);
|
212 |
+
AddPiece(&model_proto, "a");
|
213 |
+
AddPiece(&model_proto, "a");
|
214 |
+
auto model = ModelFactory::Create(model_proto);
|
215 |
+
EXPECT_FALSE(model->status().ok());
|
216 |
+
}
|
217 |
+
|
218 |
+
// Multiple unknowns.
|
219 |
+
{
|
220 |
+
ModelProto model_proto = MakeBaseModelProto(TrainerSpec::UNIGRAM);
|
221 |
+
model_proto.mutable_pieces(1)->set_type(ModelProto::SentencePiece::UNKNOWN);
|
222 |
+
auto model = ModelFactory::Create(model_proto);
|
223 |
+
EXPECT_FALSE(model->status().ok());
|
224 |
+
}
|
225 |
+
|
226 |
+
// No unknown.
|
227 |
+
{
|
228 |
+
ModelProto model_proto = MakeBaseModelProto(TrainerSpec::UNIGRAM);
|
229 |
+
model_proto.mutable_pieces(0)->set_type(ModelProto::SentencePiece::CONTROL);
|
230 |
+
auto model = ModelFactory::Create(model_proto);
|
231 |
+
EXPECT_FALSE(model->status().ok());
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
std::string RandomString(int length) {
|
236 |
+
const char kAlphaNum[] =
|
237 |
+
"0123456789"
|
238 |
+
"!@#$%^&*"
|
239 |
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
240 |
+
"abcdefghijklmnopqrstuvwxyz";
|
241 |
+
const int kAlphaSize = sizeof(kAlphaNum) - 1;
|
242 |
+
const int size = rand() % length + 1;
|
243 |
+
std::string result;
|
244 |
+
for (int i = 0; i < size; ++i) {
|
245 |
+
result += kAlphaNum[rand() % kAlphaSize];
|
246 |
+
}
|
247 |
+
return result;
|
248 |
+
}
|
249 |
+
|
250 |
+
TEST(ModelInterfaceTest, PieceToIdStressTest) {
|
251 |
+
for (const auto type : kModelTypes) {
|
252 |
+
for (int i = 0; i < 100; ++i) {
|
253 |
+
std::unordered_map<std::string, int> expected_p2i;
|
254 |
+
std::unordered_map<int, std::string> expected_i2p;
|
255 |
+
ModelProto model_proto = MakeBaseModelProto(type);
|
256 |
+
for (int n = 0; n < 1000; ++n) {
|
257 |
+
const std::string piece = RandomString(10);
|
258 |
+
if (expected_p2i.find(piece) != expected_p2i.end()) {
|
259 |
+
continue;
|
260 |
+
}
|
261 |
+
expected_p2i[piece] = model_proto.pieces_size();
|
262 |
+
expected_i2p[model_proto.pieces_size()] = piece;
|
263 |
+
AddPiece(&model_proto, piece);
|
264 |
+
}
|
265 |
+
|
266 |
+
auto model = ModelFactory::Create(model_proto);
|
267 |
+
for (const auto &it : expected_p2i) {
|
268 |
+
EXPECT_EQ(it.second, model->PieceToId(it.first));
|
269 |
+
}
|
270 |
+
for (const auto &it : expected_i2p) {
|
271 |
+
EXPECT_EQ(it.second, model->IdToPiece(it.first));
|
272 |
+
}
|
273 |
+
}
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
+
TEST(ModelInterfaceTest, SplitIntoWordsTest) {
|
278 |
+
{
|
279 |
+
const auto v = SplitIntoWords(WS "this" WS "is" WS "a" WS "pen");
|
280 |
+
EXPECT_EQ(4, v.size());
|
281 |
+
EXPECT_EQ(WS "this", v[0]);
|
282 |
+
EXPECT_EQ(WS "is", v[1]);
|
283 |
+
EXPECT_EQ(WS "a", v[2]);
|
284 |
+
EXPECT_EQ(WS "pen", v[3]);
|
285 |
+
}
|
286 |
+
|
287 |
+
{
|
288 |
+
const auto v = SplitIntoWords("this" WS "is" WS "a" WS "pen");
|
289 |
+
EXPECT_EQ(4, v.size());
|
290 |
+
EXPECT_EQ("this", v[0]);
|
291 |
+
EXPECT_EQ(WS "is", v[1]);
|
292 |
+
EXPECT_EQ(WS "a", v[2]);
|
293 |
+
EXPECT_EQ(WS "pen", v[3]);
|
294 |
+
}
|
295 |
+
|
296 |
+
{
|
297 |
+
const auto v = SplitIntoWords(WS "this" WS WS "is");
|
298 |
+
EXPECT_EQ(3, v.size());
|
299 |
+
EXPECT_EQ(WS "this", v[0]);
|
300 |
+
EXPECT_EQ(WS, v[1]);
|
301 |
+
EXPECT_EQ(WS "is", v[2]);
|
302 |
+
}
|
303 |
+
|
304 |
+
{
|
305 |
+
const auto v = SplitIntoWords("");
|
306 |
+
EXPECT_TRUE(v.empty());
|
307 |
+
}
|
308 |
+
|
309 |
+
{
|
310 |
+
const auto v = SplitIntoWords("hello");
|
311 |
+
EXPECT_EQ(1, v.size());
|
312 |
+
EXPECT_EQ("hello", v[0]);
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
TEST(ModelInterfaceTest, SplitIntoWordsSuffixTest) {
|
317 |
+
{
|
318 |
+
const auto v = SplitIntoWords("this" WS "is" WS "a" WS "pen" WS, true);
|
319 |
+
EXPECT_EQ(4, v.size());
|
320 |
+
EXPECT_EQ("this" WS, v[0]);
|
321 |
+
EXPECT_EQ("is" WS, v[1]);
|
322 |
+
EXPECT_EQ("a" WS, v[2]);
|
323 |
+
EXPECT_EQ("pen" WS, v[3]);
|
324 |
+
}
|
325 |
+
|
326 |
+
{
|
327 |
+
const auto v = SplitIntoWords("this" WS "is" WS "a" WS "pen", true);
|
328 |
+
EXPECT_EQ(4, v.size());
|
329 |
+
EXPECT_EQ("this" WS, v[0]);
|
330 |
+
EXPECT_EQ("is" WS, v[1]);
|
331 |
+
EXPECT_EQ("a" WS, v[2]);
|
332 |
+
EXPECT_EQ("pen", v[3]);
|
333 |
+
}
|
334 |
+
|
335 |
+
{
|
336 |
+
const auto v = SplitIntoWords(WS "this" WS WS "is", true);
|
337 |
+
EXPECT_EQ(4, v.size());
|
338 |
+
EXPECT_EQ(WS, v[0]);
|
339 |
+
EXPECT_EQ("this" WS, v[1]);
|
340 |
+
EXPECT_EQ(WS, v[2]);
|
341 |
+
EXPECT_EQ("is", v[3]);
|
342 |
+
}
|
343 |
+
|
344 |
+
{
|
345 |
+
const auto v = SplitIntoWords("", true);
|
346 |
+
EXPECT_TRUE(v.empty());
|
347 |
+
}
|
348 |
+
|
349 |
+
{
|
350 |
+
const auto v = SplitIntoWords("hello", true);
|
351 |
+
EXPECT_EQ(1, v.size());
|
352 |
+
EXPECT_EQ("hello", v[0]);
|
353 |
+
}
|
354 |
+
|
355 |
+
{
|
356 |
+
const auto v = SplitIntoWords("hello" WS WS, true);
|
357 |
+
EXPECT_EQ(2, v.size());
|
358 |
+
EXPECT_EQ("hello" WS, v[0]);
|
359 |
+
EXPECT_EQ(WS, v[1]);
|
360 |
+
}
|
361 |
+
|
362 |
+
{
|
363 |
+
const auto v = SplitIntoWords(WS WS "hello" WS WS, true);
|
364 |
+
EXPECT_EQ(4, v.size());
|
365 |
+
EXPECT_EQ(WS, v[0]);
|
366 |
+
EXPECT_EQ(WS, v[1]);
|
367 |
+
EXPECT_EQ("hello" WS, v[2]);
|
368 |
+
EXPECT_EQ(WS, v[3]);
|
369 |
+
}
|
370 |
+
}
|
371 |
+
|
372 |
+
} // namespace
|
373 |
+
} // namespace sentencepiece
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/normalization_rule.h
ADDED
The diff for this file is too large to render.
See raw diff
|
|
cc-multilingual-main/cc_net/third_party/sentencepiece/src/normalizer.cc
ADDED
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright 2016 Google Inc.
|
2 |
+
//
|
3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
// you may not use this file except in compliance with the License.
|
5 |
+
// You may obtain a copy of the License at
|
6 |
+
//
|
7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
//
|
9 |
+
// Unless required by applicable law or agreed to in writing, software
|
10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
// See the License for the specific language governing permissions and
|
13 |
+
// limitations under the License.!
|
14 |
+
|
15 |
+
#include "normalizer.h"
|
16 |
+
|
17 |
+
#include <utility>
|
18 |
+
#include <vector>
|
19 |
+
#include "common.h"
|
20 |
+
#include "third_party/absl/strings/string_view.h"
|
21 |
+
#include "third_party/darts_clone/darts.h"
|
22 |
+
#include "util.h"
|
23 |
+
|
24 |
+
namespace sentencepiece {
|
25 |
+
namespace normalizer {
|
26 |
+
|
27 |
+
constexpr int Normalizer::kMaxTrieResultsSize;
|
28 |
+
|
29 |
+
Normalizer::Normalizer(const NormalizerSpec &spec,
|
30 |
+
const TrainerSpec &trainer_spec)
|
31 |
+
: spec_(&spec),
|
32 |
+
treat_whitespace_as_suffix_(trainer_spec.treat_whitespace_as_suffix()),
|
33 |
+
status_(util::OkStatus()) {
|
34 |
+
Init();
|
35 |
+
}
|
36 |
+
|
37 |
+
Normalizer::Normalizer(const NormalizerSpec &spec)
|
38 |
+
: spec_(&spec), status_(util::OkStatus()) {
|
39 |
+
Init();
|
40 |
+
}
|
41 |
+
|
42 |
+
Normalizer::~Normalizer() {}
|
43 |
+
|
44 |
+
void Normalizer::Init() {
|
45 |
+
absl::string_view index = spec_->precompiled_charsmap();
|
46 |
+
if (index.empty()) {
|
47 |
+
LOG(INFO) << "precompiled_charsmap is empty. use identity normalization.";
|
48 |
+
} else {
|
49 |
+
absl::string_view trie_blob, normalized;
|
50 |
+
status_ = DecodePrecompiledCharsMap(index, &trie_blob, &normalized);
|
51 |
+
if (!status_.ok()) return;
|
52 |
+
|
53 |
+
// Reads the body of double array.
|
54 |
+
trie_ = port::MakeUnique<Darts::DoubleArray>();
|
55 |
+
|
56 |
+
// The second arg of set_array is not the size of blob,
|
57 |
+
// but the number of double array units.
|
58 |
+
trie_->set_array(const_cast<char *>(trie_blob.data()),
|
59 |
+
trie_blob.size() / trie_->unit_size());
|
60 |
+
|
61 |
+
normalized_ = normalized.data();
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
util::Status Normalizer::Normalize(absl::string_view input,
|
66 |
+
std::string *normalized,
|
67 |
+
std::vector<size_t> *norm_to_orig) const {
|
68 |
+
norm_to_orig->clear();
|
69 |
+
normalized->clear();
|
70 |
+
|
71 |
+
if (input.empty()) {
|
72 |
+
return util::OkStatus();
|
73 |
+
}
|
74 |
+
|
75 |
+
RETURN_IF_ERROR(status());
|
76 |
+
|
77 |
+
int consumed = 0;
|
78 |
+
|
79 |
+
// Ignores heading space.
|
80 |
+
if (spec_->remove_extra_whitespaces()) {
|
81 |
+
while (!input.empty()) {
|
82 |
+
const auto p = NormalizePrefix(input);
|
83 |
+
if (p.first != " ") {
|
84 |
+
break;
|
85 |
+
}
|
86 |
+
input.remove_prefix(p.second);
|
87 |
+
consumed += p.second;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
// all chars are whitespace.
|
92 |
+
if (input.empty()) {
|
93 |
+
return util::OkStatus();
|
94 |
+
}
|
95 |
+
|
96 |
+
// Reserves the output buffer to avoid re-allocations.
|
97 |
+
const size_t kReservedSize = input.size() * 3;
|
98 |
+
normalized->reserve(kReservedSize);
|
99 |
+
norm_to_orig->reserve(kReservedSize);
|
100 |
+
|
101 |
+
// Replaces white space with U+2581 (LOWER ONE EIGHT BLOCK)
|
102 |
+
// if escape_whitespaces() is set (default = true).
|
103 |
+
const absl::string_view kSpaceSymbol = "\xe2\x96\x81";
|
104 |
+
|
105 |
+
// adds kSpaceSymbol to the current context.
|
106 |
+
auto add_ws = [this, &consumed, &normalized, &norm_to_orig, &kSpaceSymbol]() {
|
107 |
+
if (spec_->escape_whitespaces()) {
|
108 |
+
normalized->append(kSpaceSymbol.data(), kSpaceSymbol.size());
|
109 |
+
for (size_t n = 0; n < kSpaceSymbol.size(); ++n) {
|
110 |
+
norm_to_orig->push_back(consumed);
|
111 |
+
}
|
112 |
+
} else {
|
113 |
+
normalized->append(" ");
|
114 |
+
norm_to_orig->push_back(consumed);
|
115 |
+
}
|
116 |
+
};
|
117 |
+
|
118 |
+
// Adds a space symbol as a prefix (default is true)
|
119 |
+
// With this prefix, "world" and "hello world" are converted into
|
120 |
+
// "_world" and "_hello_world", which help the trainer to extract
|
121 |
+
// "_world" as one symbol.
|
122 |
+
if (!treat_whitespace_as_suffix_ && spec_->add_dummy_prefix()) add_ws();
|
123 |
+
|
124 |
+
bool is_prev_space = spec_->remove_extra_whitespaces();
|
125 |
+
while (!input.empty()) {
|
126 |
+
auto p = NormalizePrefix(input);
|
127 |
+
absl::string_view sp = p.first;
|
128 |
+
|
129 |
+
// Removes heading spaces in sentence piece,
|
130 |
+
// if the previous sentence piece ends with whitespace.
|
131 |
+
while (is_prev_space && string_util::ConsumePrefix(&sp, " ")) {
|
132 |
+
}
|
133 |
+
|
134 |
+
if (!sp.empty()) {
|
135 |
+
const char *data = sp.data();
|
136 |
+
for (size_t n = 0; n < sp.size(); ++n) {
|
137 |
+
if (spec_->escape_whitespaces() && data[n] == ' ') {
|
138 |
+
// replace ' ' with kSpaceSymbol.
|
139 |
+
normalized->append(kSpaceSymbol.data(), kSpaceSymbol.size());
|
140 |
+
for (size_t m = 0; m < kSpaceSymbol.size(); ++m) {
|
141 |
+
norm_to_orig->push_back(consumed);
|
142 |
+
}
|
143 |
+
} else {
|
144 |
+
*normalized += data[n];
|
145 |
+
norm_to_orig->push_back(consumed);
|
146 |
+
}
|
147 |
+
}
|
148 |
+
// Checks whether the last character of sp is whitespace.
|
149 |
+
is_prev_space = string_util::EndsWith(sp, " ");
|
150 |
+
}
|
151 |
+
|
152 |
+
consumed += p.second;
|
153 |
+
input.remove_prefix(p.second);
|
154 |
+
if (!spec_->remove_extra_whitespaces()) {
|
155 |
+
is_prev_space = false;
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
// Ignores tailing space.
|
160 |
+
if (spec_->remove_extra_whitespaces()) {
|
161 |
+
const absl::string_view space =
|
162 |
+
spec_->escape_whitespaces() ? kSpaceSymbol : " ";
|
163 |
+
while (string_util::EndsWith(*normalized, space)) {
|
164 |
+
const int length = normalized->size() - space.size();
|
165 |
+
CHECK_GE_OR_RETURN(length, 0);
|
166 |
+
consumed = (*norm_to_orig)[length];
|
167 |
+
normalized->resize(length);
|
168 |
+
norm_to_orig->resize(length);
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
// Adds a space symbol as a suffix (default is false)
|
173 |
+
if (treat_whitespace_as_suffix_ && spec_->add_dummy_prefix()) add_ws();
|
174 |
+
|
175 |
+
norm_to_orig->push_back(consumed);
|
176 |
+
|
177 |
+
CHECK_EQ_OR_RETURN(norm_to_orig->size(), normalized->size() + 1);
|
178 |
+
|
179 |
+
return util::OkStatus();
|
180 |
+
}
|
181 |
+
|
182 |
+
std::string Normalizer::Normalize(absl::string_view input) const {
|
183 |
+
std::vector<size_t> norm_to_orig;
|
184 |
+
std::string normalized;
|
185 |
+
Normalize(input, &normalized, &norm_to_orig);
|
186 |
+
return normalized;
|
187 |
+
}
|
188 |
+
|
189 |
+
std::pair<absl::string_view, int> Normalizer::NormalizePrefix(
|
190 |
+
absl::string_view input) const {
|
191 |
+
std::pair<absl::string_view, int> result;
|
192 |
+
|
193 |
+
if (input.empty()) return result;
|
194 |
+
|
195 |
+
if (matcher_ != nullptr) {
|
196 |
+
bool found = false;
|
197 |
+
const int mblen = matcher_->PrefixMatch(input, &found);
|
198 |
+
if (found) return std::make_pair(input.substr(0, mblen), mblen);
|
199 |
+
}
|
200 |
+
|
201 |
+
size_t longest_length = 0;
|
202 |
+
int longest_value = 0;
|
203 |
+
|
204 |
+
if (trie_ != nullptr) {
|
205 |
+
// Allocates trie_results in stack, which makes the encoding speed 36%
|
206 |
+
// faster. (38k sentences/sec => 60k sentences/sec). Builder checks that the
|
207 |
+
// result size never exceeds kMaxTrieResultsSize. This array consumes
|
208 |
+
// 0.5kByte in stack, which is less than default stack frames (16kByte).
|
209 |
+
Darts::DoubleArray::result_pair_type
|
210 |
+
trie_results[Normalizer::kMaxTrieResultsSize];
|
211 |
+
|
212 |
+
const size_t num_nodes = trie_->commonPrefixSearch(
|
213 |
+
input.data(), trie_results, Normalizer::kMaxTrieResultsSize,
|
214 |
+
input.size());
|
215 |
+
|
216 |
+
// Finds the longest rule.
|
217 |
+
for (size_t k = 0; k < num_nodes; ++k) {
|
218 |
+
if (longest_length == 0 || trie_results[k].length > longest_length) {
|
219 |
+
longest_length = trie_results[k].length; // length of prefix
|
220 |
+
longest_value = trie_results[k].value; // pointer to |normalized_|.
|
221 |
+
}
|
222 |
+
}
|
223 |
+
}
|
224 |
+
|
225 |
+
if (longest_length == 0) {
|
226 |
+
size_t length = 0;
|
227 |
+
if (!string_util::IsValidDecodeUTF8(input, &length)) {
|
228 |
+
// Found a malformed utf8.
|
229 |
+
// The rune is set to be 0xFFFD (REPLACEMENT CHARACTER),
|
230 |
+
// which is a valid Unicode of three bytes in utf8,
|
231 |
+
// but here we only consume one byte.
|
232 |
+
result.second = 1;
|
233 |
+
static const char kReplacementChar[] = "\xEF\xBF\xBD";
|
234 |
+
result.first = absl::string_view(kReplacementChar);
|
235 |
+
} else {
|
236 |
+
result.second = length;
|
237 |
+
result.first = absl::string_view(input.data(), result.second);
|
238 |
+
}
|
239 |
+
} else {
|
240 |
+
result.second = longest_length;
|
241 |
+
// No need to pass the size of normalized sentence,
|
242 |
+
// since |normalized| is delimitered by "\0".
|
243 |
+
result.first = absl::string_view(&normalized_[longest_value]);
|
244 |
+
}
|
245 |
+
|
246 |
+
return result;
|
247 |
+
}
|
248 |
+
|
249 |
+
// static
|
250 |
+
std::string Normalizer::EncodePrecompiledCharsMap(
|
251 |
+
absl::string_view trie_blob, absl::string_view normalized) {
|
252 |
+
// <trie size(4byte)><double array trie><normalized string>
|
253 |
+
std::string blob;
|
254 |
+
blob.append(string_util::EncodePOD<uint32>(trie_blob.size()));
|
255 |
+
blob.append(trie_blob.data(), trie_blob.size());
|
256 |
+
blob.append(normalized.data(), normalized.size());
|
257 |
+
return blob;
|
258 |
+
}
|
259 |
+
|
260 |
+
// static
|
261 |
+
util::Status Normalizer::DecodePrecompiledCharsMap(
|
262 |
+
absl::string_view blob, absl::string_view *trie_blob,
|
263 |
+
absl::string_view *normalized) {
|
264 |
+
uint32 trie_blob_size = 0;
|
265 |
+
if (blob.size() <= sizeof(trie_blob_size) ||
|
266 |
+
!string_util::DecodePOD<uint32>(
|
267 |
+
absl::string_view(blob.data(), sizeof(trie_blob_size)),
|
268 |
+
&trie_blob_size) ||
|
269 |
+
trie_blob_size >= blob.size()) {
|
270 |
+
return util::InternalError("Blob for normalization rule is broken.");
|
271 |
+
}
|
272 |
+
|
273 |
+
blob.remove_prefix(sizeof(trie_blob_size));
|
274 |
+
*trie_blob = absl::string_view(blob.data(), trie_blob_size);
|
275 |
+
|
276 |
+
blob.remove_prefix(trie_blob_size);
|
277 |
+
*normalized = absl::string_view(blob.data(), blob.size());
|
278 |
+
|
279 |
+
return util::OkStatus();
|
280 |
+
}
|
281 |
+
|
282 |
+
PrefixMatcher::PrefixMatcher(const std::set<absl::string_view> &dic) {
|
283 |
+
if (dic.empty()) return;
|
284 |
+
std::vector<const char *> key;
|
285 |
+
key.reserve(dic.size());
|
286 |
+
for (const auto &it : dic) key.push_back(it.data());
|
287 |
+
trie_ = port::MakeUnique<Darts::DoubleArray>();
|
288 |
+
CHECK_EQ(0, trie_->build(key.size(), const_cast<char **>(&key[0]), nullptr,
|
289 |
+
nullptr));
|
290 |
+
}
|
291 |
+
|
292 |
+
int PrefixMatcher::PrefixMatch(absl::string_view w, bool *found) const {
|
293 |
+
if (trie_ == nullptr) {
|
294 |
+
if (found) *found = false;
|
295 |
+
return std::min<int>(w.size(), string_util::OneCharLen(w.data()));
|
296 |
+
}
|
297 |
+
|
298 |
+
constexpr int kResultSize = 64;
|
299 |
+
Darts::DoubleArray::result_pair_type trie_results[kResultSize];
|
300 |
+
const int num_nodes =
|
301 |
+
trie_->commonPrefixSearch(w.data(), trie_results, kResultSize, w.size());
|
302 |
+
|
303 |
+
if (found) *found = (num_nodes > 0);
|
304 |
+
if (num_nodes == 0) {
|
305 |
+
return std::min<int>(w.size(), string_util::OneCharLen(w.data()));
|
306 |
+
}
|
307 |
+
|
308 |
+
int mblen = 0;
|
309 |
+
for (int i = 0; i < num_nodes; ++i) {
|
310 |
+
mblen = std::max<int>(trie_results[i].length, mblen);
|
311 |
+
}
|
312 |
+
|
313 |
+
return mblen;
|
314 |
+
}
|
315 |
+
|
316 |
+
std::string PrefixMatcher::GlobalReplace(absl::string_view w,
|
317 |
+
absl::string_view out) const {
|
318 |
+
std::string result;
|
319 |
+
while (!w.empty()) {
|
320 |
+
bool found = false;
|
321 |
+
const int mblen = PrefixMatch(w, &found);
|
322 |
+
if (found) {
|
323 |
+
result.append(out.data(), out.size());
|
324 |
+
} else {
|
325 |
+
result.append(w.data(), mblen);
|
326 |
+
}
|
327 |
+
w.remove_prefix(mblen);
|
328 |
+
}
|
329 |
+
return result;
|
330 |
+
}
|
331 |
+
|
332 |
+
} // namespace normalizer
|
333 |
+
} // namespace sentencepiece
|