9 #include <QJsonDocument>
10 #include <QJsonObject>
19 * \brief データベースとの通信に使うデータ構造です。
21 class sentence_data_type
24 typedef std::shared_ptr<sentence_data_type> pointer;
25 typedef std::shared_ptr<sentence_data_type const> const_pointer;
29 bool operator < (sentence_data_type const &rhs);
30 bool operator == (sentence_data_type const &rhs);
32 static pointer create();
34 quint32 sentence_id; /*!< DBによって自動的に付与される文ID */
35 quint32 source_id; /*!< 原文は0固定、訳文は原文のsentence_id */
36 QString sentence; /*!< 文本体の文字列 */
37 QByteArray json; /*!< 原文は空、訳文はリンク情報のJSON */
38 quint32 crc; /*!< 検索に使う文のCRC */
39 quint32 previous_crc;/*!< 原文は文脈一致に使う前方文のCRC、訳文は0固定 */
40 quint32 next_crc; /*!< 原文は文脈一致に使う後方文のCRC、訳文は0固定 */
41 quint32 user_id; /*!< レコードを更新したユーザーのID */
42 quint64 time; /*!< 更新時刻 */
44 quint32 quality; /*!< 訳文は訳語の品質、原文は0 */
45 QList<QPair<int,int> > words; /*!< データベース登録時に、sentenceの単語の範囲を示すリスト */
49 * \brief 単語間のリンクを表現するクラスです。
51 * 原単語と訳単語の多対多のリンクを表現します。
56 typedef std::shared_ptr<WordLink> pointer;
57 typedef QList<Text::pointer> storage_type;
60 enum : int { Source, Target, };
67 void append(int place, Text::pointer word);
68 void remove(int place, Text::pointer word);
70 bool is_valid() const;
71 bool is_empty() const;
72 bool contains(int place, Text::pointer word);
73 int size(int place) const;
75 storage_type* sources();
76 storage_type* targets();
78 QJsonArray to_json_array() const;
80 QString debug_dump() const;
82 static pointer create();
85 storage_type m_sources;
86 storage_type m_targets;
90 * \brief 単語間のリンクを作成・保持するクラスです。
92 * 複数の単語間リンクを保持するコンテナとしての機能を持ちます。
93 * 現在編集中の単語間リンクを明示する機能があります。
95 * ある特定の単語間リンクを編集するには、start()を呼び出し編集を開始し、
96 * append()呼び出しによってリンクへ単語を追加し、
97 * commit()呼び出しによって編集を終了します。
102 typedef QList<WordLink::pointer> storage_type;
103 typedef storage_type::iterator iterator;
104 typedef storage_type::const_iterator const_iterator;
111 void append(int place, Text::pointer word);
112 void remove(int place, Text::pointer word);
113 void toggle(int place, Text::pointer word);
115 WordLink::pointer current();
117 WordLink::pointer find(Text::pointer word);
118 WordLink::pointer find(int place, Text::pointer word);
120 int index_of(WordLink::pointer link) const;
125 QJsonArray to_json_array() const;
127 QString debug_dump() const;
130 WordLink::pointer m_current_link;
131 storage_type m_links;
137 typedef std::shared_ptr<TextSentence> pointer;
140 TextSentence(int segment_id, int index, quint32 crc, Text::pointer source_sentence);
142 Text::pointer source_sentence();
143 Text::pointer target_sentence();
144 void set_target_sentence(Text::pointer target_sentence);
146 WordLinker* linker();
147 QByteArray to_json();
148 void set_json(QByteArray json);
150 void set_json_links(QJsonObject const &jobject);
151 void set_json_link(QJsonArray const &link_array);
152 QList<QPair<int, int> > stuff_json_link(QJsonArray const &ranges);
154 QList<Text::pointer> find_words_by_range(Text::pointer sentence, int first, int tail);
156 int segment_id() const;
160 quint32 previous_crc() const;
161 quint32 next_crc() const;
162 void set_previous_crc(quint32 crc);
163 void set_next_crc(quint32 crc);
165 quint32 source_id() const;
166 void set_source_id(quint32 source_id);
167 quint32 target_id() const;
168 void set_target_id(quint32 source_id);
170 void append(sentence_data_type::pointer sentence);
171 const QList<sentence_data_type::const_pointer> &candidates() const;
173 bool is_loaded() const;
174 void set_loaded(bool loaded);
176 QString debug_dump() const;
178 static pointer create(int segment_id, int index,
179 quint32 crc, Text::pointer source_sentence);
182 Text::pointer m_source_sentence;
183 Text::pointer m_target_sentence;
190 quint32 m_previous_crc;
196 QList<sentence_data_type::const_pointer> m_candidates; /*!< 訳文候補 */
198 bool m_loaded; /*!< 完全一致訳文の初期検索が終了していればtrue */