Skip to main content

cidian/
model.rs

1use std::collections::BTreeMap;
2
3/// A parsed dictionary and its source metadata.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct Dictionary {
6    /// Metadata supplied by the source dictionary.
7    pub metadata: Metadata,
8    /// Entries in source order.
9    pub entries: Vec<Entry>,
10}
11
12/// Metadata shared by supported dictionary formats.
13#[derive(Debug, Clone, Default, PartialEq, Eq)]
14pub struct Metadata {
15    /// Human-readable dictionary name.
16    pub name: Option<String>,
17    /// Dictionary category, when supplied by the source.
18    pub category: Option<String>,
19    /// Dictionary description, when supplied by the source.
20    pub description: Option<String>,
21    /// Source-specific textual metadata that has no common field.
22    pub extra: BTreeMap<String, String>,
23}
24
25/// A single dictionary entry.
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct Entry {
28    /// The word or phrase exactly as represented by the source.
29    pub word: String,
30    /// Source coding components in source order.
31    ///
32    /// The representation depends on the dictionary format:
33    ///
34    /// - **SCEL**: pinyin syllables, including embedded Latin code letters when
35    ///   the source uses them.
36    /// - **QCEL**: pinyin syllables, explicit Latin codes, or codes resolved
37    ///   through QCEL's built-in table when the source omits its table.
38    /// - **QPYD**: apostrophe-delimited pinyin components stored with the entry.
39    /// - **BDICT/BCD regular entries**: decoded pinyin syllables or embedded
40    ///   Latin code letters.
41    /// - **BDICT/BCD English and mixed entries**: the directly stored code as a
42    ///   single component.
43    /// - **Other formats**: another source-specific coding system may be used.
44    pub code: Vec<String>,
45    /// An optional source-defined numeric weight.
46    ///
47    /// The representation depends on the dictionary format:
48    ///
49    /// - **SCEL**: the first little-endian `u16` in the word extension, when
50    ///   the extension contains at least two bytes.
51    /// - **QCEL**: the first little-endian `u32` in the word extension, when
52    ///   the extension contains at least four bytes.
53    /// - **BDICT/BCD**: the numeric field in regular, English, and weighted
54    ///   mixed records. Mixed records without a documented weight use `None`.
55    /// - **QPYD**: always `None`; its undocumented four-byte index field is not
56    ///   exposed as a weight.
57    ///
58    /// These formats do not document precise statistical semantics, so this
59    /// field does not promise a corpus frequency.
60    pub weight: Option<u32>,
61}