Debian Codegraph @

src/PipelineConverter.hpp

raw symbols SCIP
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 <utility>
22 #include <vector>
23
24 #include "Converter.hpp"
25
26 namespace opencc {
27 /**
28 * A @c Converter that passes text through a sequence of @c Converter stages
29 * in order, feeding the output of each stage as input to the next.
30 *
31 * This enables multi-step conversion schemes where different segmentation
32 * strategies or dictionary sets are needed at each step. For example, the
33 * @c s2twp config first converts Simplified to Traditional (stage 1) and then
34 * applies Taiwan-specific phrase substitution (stage 2).
35 *
36 * @note @c GetConversionChain() always returns @c nullptr because a pipeline
37 * has no single chain. @c GetSegmentation() returns the last stage's
38 * segmentation as a best-effort representative.
39 *
40 * @ingroup opencc_cpp_api
41 */
42 class OPENCC_EXPORT PipelineConverter : public Converter {
43 public:
44 /** @param stages Ordered list of converters to apply in sequence. */
45 explicit PipelineConverter(std::vector<ConverterPtr> stages)
46 : stages(std::move(stages)) {}
47
48 std::string Convert(std::string_view text) const override;
49
50 /**
51 * Returns an inspection result with @c input and @c output populated.
52 * Per-stage segment detail is not available at the pipeline level.
53 */
54 ConversionInspectionResult Inspect(std::string_view text) const override;
55
56 /** Returns the last stage's segmentation, or @c nullptr for an empty pipeline. */
57 SegmentationPtr GetSegmentation() const override;
58
59 /** Always returns @c nullptr; a pipeline has no single conversion chain. */
60 ConversionChainPtr GetConversionChain() const override { return nullptr; }
61
62 private:
63 const std::vector<ConverterPtr> stages;
64 };
65 } // namespace opencc