sudachi/dic/subset.rs
1/*
2 * Copyright (c) 2021-2025 Works Applications Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use bitflags::bitflags;
18
19bitflags! {
20 #[repr(transparent)]
21 #[derive(Copy, Clone, Eq, PartialEq, Debug)]
22 pub struct InfoSubset: u32 {
23 const POS_ID = (1 << 0);
24 const HEADWORD = (1 << 1);
25 const READING_FORM = (1 << 2);
26 const NORMALIZED_FORM = (1 << 3);
27 const DICTIONARY_FORM = (1 << 4);
28 const INDEX_FORM_LENGTH = (1 << 5);
29 const SPLIT_C = (1 << 6);
30 const SPLIT_B = (1 << 7);
31 const SPLIT_A = (1 << 8);
32 const WORD_STRUCTURE = (1 << 9);
33 const SYNONYM_GROUP_IDS = (1 << 10);
34 const USER_DATA = (1 << 11);
35 }
36}
37
38impl Default for InfoSubset {
39 fn default() -> Self {
40 Self::all()
41 }
42}
43
44impl InfoSubset {
45 pub fn normalize(mut self) -> Self {
46 // Normalized and dictionary forms are interpreted relative to the
47 // headword string, so parsers need HEADWORD even if callers did not
48 // request it explicitly.
49 if self.intersects(InfoSubset::NORMALIZED_FORM | InfoSubset::DICTIONARY_FORM) {
50 self |= InfoSubset::HEADWORD;
51 }
52
53 // Split requests need the index form length because split consumers use
54 // it when materializing the higher-level WordInfo view.
55 if self.intersects(InfoSubset::SPLIT_A | InfoSubset::SPLIT_B | InfoSubset::SPLIT_C) {
56 self |= InfoSubset::INDEX_FORM_LENGTH;
57 }
58
59 self
60 }
61}