Debian Codegraph @

src/Segmentation.hpp

raw symbols SCIP
1 /*
2 * Open Chinese Convert
3 *
4 * Copyright 2010-2014 Carbo Kuo <[email protected]>
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 <string>
22 #include <string_view>
23
24 #include "Common.hpp"
25
26 namespace opencc {
27 /**
28 * Abstract base for text segmentation.
29 *
30 * Splits a UTF-8 string into an ordered list of segments. Each segment is
31 * either a dictionary-matched word or a single unmatched code point / IDS
32 * sequence. The primary virtual is Segment(std::string_view); the
33 * @c const @c char* and @c const @c std::string& overloads are non-virtual
34 * convenience adapters that forward to it.
35 *
36 * @ingroup opencc_cpp_api
37 */
38 class OPENCC_EXPORT Segmentation {
39 public:
40 virtual ~Segmentation() {}
41
42 /**
43 * Splits @p text into segments and returns them.
44 * This is the primary override point for subclasses.
45 */
46 virtual SegmentsPtr Segment(std::string_view text) const = 0;
47
48 /** Convenience overload for null-terminated C strings. */
49 SegmentsPtr Segment(const char* text) const;
50
51 /** Convenience overload for std::string. */
52 SegmentsPtr Segment(const std::string& str) const;
53 };
54 } // namespace opencc