Open Chinese Convert: ConversionAmbiguities.hpp Source File

Open Chinese Convert 1.4.2+g71621a0e1.dirty A project for conversion between Traditional and Simplified Chinese

Loading...
Searching...
No Matches
ConversionAmbiguities.hpp
1/*
2 * Open Chinese Convert
3 *
4 * Copyright 2010-2026 Carbo Kuo and contributors
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#pragma once
20
21#include <memory>
22#include <string>
23#include <string_view>
24#include <vector>
25
26#include "Common.hpp"
27#include "Converter.hpp"
28#include "Export.hpp"
29#include "StreamWindow.hpp"
30
31namespace opencc {
32
46 struct AmbiguousSpan {
47 size_t outputOffset;
48 size_t outputLength;
49 size_t sourceIndex;
50};
51
66 struct AnnotatedConversion {
67 std::string output;
68 std::vector<std::string> sources;
69 std::vector<AmbiguousSpan> ambiguities;
73 bool analyzed = true;
74};
75
99OPENCC_EXPORT AnnotatedConversion
100ConvertWithAmbiguities(const Converter& converter, std::string_view text);
101
117 class OPENCC_EXPORT AmbiguityStream {
118public:
119 struct Chunk {
120 std::string output;
121 std::vector<AmbiguousSpan> ambiguities;
122 std::vector<std::string> newSources;
126 bool analyzed = true;
127 };
128
129 explicit AmbiguityStream(
130 ConverterPtr converter,
131 size_t maxKeepChars = internal::kDefaultStreamKeepChars);
132 ~AmbiguityStream();
133
135 Chunk ConvertChunk(std::string_view input);
136
138 Chunk Finish(std::string_view input);
139
141 Chunk Finish();
142
144 size_t SourceCount() const;
145
146private:
147 Chunk ConvertWindow(std::string_view window);
148
149 class Impl;
150 std::unique_ptr<Impl> impl;
151};
152
153} // namespace opencc
opencc::AmbiguityStream::ConvertChunk
Chunk ConvertChunk(std::string_view input)
Appends input and flushes everything but the kept tail.
Definition ConversionAmbiguities.cpp:338
opencc::AmbiguityStream::SourceCount
size_t SourceCount() const
Number of distinct sources defined so far.
Definition ConversionAmbiguities.cpp:305
opencc::AmbiguityStream::Finish
Chunk Finish(std::string_view input)
Appends input and flushes everything, ending the stream.
Definition ConversionAmbiguities.cpp:355
opencc::Converter
Abstract base for full-text converters.
Definition Converter.hpp:48
opencc::AmbiguityStream::Chunk
Definition ConversionAmbiguities.hpp:119
opencc::AmbiguityStream::Chunk::analyzed
bool analyzed
Mirrors AnnotatedConversion::analyzed: false when the underlying converter could not be analyzed (no ...
Definition ConversionAmbiguities.hpp:126
opencc::AmbiguousSpan
One span of the converted output whose source maps to more than one candidate (a one-to-many dictiona...
Definition ConversionAmbiguities.hpp:46
opencc::AnnotatedConversion
Result of ConvertWithAmbiguities(): the converted text plus the spans where the conversion is one-to-...
Definition ConversionAmbiguities.hpp:66
opencc::AnnotatedConversion::analyzed
bool analyzed
False when the converter could not be analyzed (no single conversion chain, e.g.
Definition ConversionAmbiguities.hpp:73