13 #include <QJsonDocument>
14 #include <QJsonObject>
23 class SocketConnection;
25 class TextSegmentList;
28 * \brief データベースとの通信に使うデータ構造です。
30 class sentence_data_type
41 quint32 sentence_id; /*!< DBによって自動的に付与される文ID */
42 quint32 source_id; /*!< 原文は0固定、訳文は原文のsentence_id */
43 QString sentence; /*!< 文本体の文字列 */
44 QByteArray json; /*!< 原文は空、訳文はリンク情報のJSON */
45 quint32 crc; /*!< 検索に使う文のCRC */
46 quint32 previous_crc;/*!< 原文は文脈一致に使う前方文のCRC、訳文は0固定 */
47 quint32 next_crc; /*!< 原文は文脈一致に使う後方文のCRC、訳文は0固定 */
48 quint32 user_id; /*!< レコードを更新したユーザーのID */
49 quint64 time; /*!< 更新時刻 */
53 * データベース登録時に、sentenceの単語を示すリスト。
60 * \brief 候補文のためのデータ構造です。
62 class candidate_data_type
66 sentence_data_type source;
67 sentence_data_type target;
71 * \brief 単語間のリンクを表現するクラスです。
73 * 原単語と訳単語の多対多のリンクを表現します。
78 typedef std::shared_ptr<WordLink> pointer;
79 typedef QList<Text::pointer> storage_type;
82 enum : int { Source, Target, };
89 void append(int place, Text::pointer word);
90 void remove(int place, Text::pointer word);
92 bool is_valid() const;
93 bool is_empty() const;
94 bool contains(int place, Text::pointer word);
95 int size(int place) const;
97 storage_type* sources();
98 storage_type* targets();
100 QJsonArray to_json_array() const;
102 QString debug_dump() const;
104 static pointer create();
107 storage_type m_sources;
108 storage_type m_targets;
112 * \brief 単語間のリンクを作成・保持するクラスです。
114 * 複数の単語間リンクを保持するコンテナとしての機能を持ちます。
115 * 現在編集中の単語間リンクを明示する機能があります。
117 * ある特定の単語間リンクを編集するには、start()を呼び出し編集を開始し、
118 * append()呼び出しによってリンクへ単語を追加し、
119 * commit()呼び出しによって編集を終了します。
124 typedef QList<WordLink::pointer> storage_type;
125 typedef storage_type::iterator iterator;
126 typedef storage_type::const_iterator const_iterator;
133 void append(int place, Text::pointer word);
134 void remove(int place, Text::pointer word);
135 void toggle(int place, Text::pointer word);
137 WordLink::pointer current();
139 WordLink::pointer find(Text::pointer word);
140 WordLink::pointer find(int place, Text::pointer word);
142 int index_of(WordLink::pointer link) const;
147 QJsonArray to_json_array() const;
149 QString debug_dump() const;
152 WordLink::pointer m_current_link;
153 storage_type m_links;
157 * \brief エディタで編集される対訳構造のためのクラスです。
159 * SocketConnection内でTextSegmentに内蔵されて保持されます。
164 typedef std::shared_ptr<TextSentence> pointer;
165 typedef std::weak_ptr<TextSentence> weak_pointer;
167 typedef std::shared_ptr<TextSegment> parent_pointer;
168 typedef std::weak_ptr<TextSegment> parent_weak_pointer;
170 typedef std::shared_ptr<TextSegmentList> segment_list_pointer;
173 TextSentence(int index, Text::pointer ssentence, parent_pointer parent);
175 Text::pointer ssentence();
176 Text::pointer tsentence();
177 void set_tsentence(Text::pointer tsentence);
178 void set_tsentence(QString tsentence, QByteArray json = QByteArray());
179 void set_tsentence(quint32 previous_crc_, quint32 next_crc_,
180 QString tstring, QByteArray json = QByteArray());
181 sentence_data_type ssentence_data();
182 sentence_data_type tsentence_data();
184 WordLinker* linker();
185 QByteArray to_json();
186 void set_json(QByteArray json);
188 void set_json_links(QJsonObject const &jobject);
189 void set_json_link(QJsonArray const &link_array);
190 QList<QPair<int, int> > stuff_json_link(QJsonArray const &ranges);
192 QList<Text::pointer> find_words_by_range(Text::pointer sentence, int first, int tail);
201 segment_list_pointer segment_list();
203 parent_pointer parent();
207 quint32 source_id() const;
208 void set_source_id(quint32 source_id);
209 quint32 target_id() const;
210 void set_target_id(quint32 source_id);
213 quint32 previous_crc();
216 quint32 user_id() { return 0; }
218 bool append_candidate(candidate_data_type const &candidate);
219 QList<candidate_data_type> const & candidates() const;
220 void clear_candidates();
222 bool is_loaded() const;
223 //void set_loaded(bool loaded);
225 QString debug_dump() const;
227 static pointer create(int index, Text::pointer ssentence, parent_pointer parent);
230 Text::pointer m_source_sentence; // 原文
231 Text::pointer m_target_sentence; // 訳文
232 WordLinker m_linker; // 単語間のリンク
234 quint32 m_source_id; /*!< 原文のID */
235 quint32 m_target_id; /*!< 訳文のID */
237 int m_quality; /*!< 訳文の品質 */
239 QList<candidate_data_type> m_candidates; /*!< 訳文候補 */
241 parent_weak_pointer m_parent;
242 int m_index; /*!< セグメント内における位置 */
248 * \brief セグメントとHTMLを対応付けるためのデータ構造です。
250 class HtmlData : public RangeData
253 typedef std::shared_ptr<HtmlData> pointer;
255 enum : int { Type = UserData::User + 1, };
258 HtmlData(HtmlNode node_, int begin_, int tail_);
263 UserData::pointer clone();
265 QString debug_dump() const;
267 static pointer create(HtmlNode node_, int begin_, int tail_);
274 * \brief 一つのパラグラフを保持するクラスです。
276 * 一つのパラグラフには複数の文があります。
281 typedef std::shared_ptr<TextSegment> pointer;
282 typedef std::weak_ptr<TextSegment> weak_pointer;
284 typedef QList<TextSentence::pointer> storage_type;
285 typedef storage_type::iterator iterator;
287 typedef std::shared_ptr<TextSegmentList> parent_pointer;
288 typedef std::weak_ptr<TextSegmentList> parent_weak_pointer;
291 TextSegment(int segment_id, parent_weak_pointer parent);
294 parent_pointer parent();
295 int segment_id() const;
298 TextSentence::pointer at(int index);
302 void set_html(QString html);
304 QString to_html_from_source(TextSentence::pointer sentence);
305 QString to_html_from_target(TextSentence::pointer sentence);
307 HtmlNode::pointer find_html_node_by_offset(int offset);
309 static pointer create(int segment_id, QString html, parent_weak_pointer parent);
313 int m_segment_id; /*!< data-wordring-segmentの値によるセグメントのID。 */
316 HtmlDocument m_document; /*!< セグメントのHtmlDocument。 */
317 Text::pointer m_text; /*!< セグメントのHtmlData付テキスト。 */
320 QList<TextSentence::pointer> m_sentences; /*!< 編集用センテンスのリスト。 */
323 parent_weak_pointer m_parent;
328 * \brief 一つのHTMLページを表現するクラスです。
330 * オーナーはSocketConnectionです。
331 * 編集スレッド内では、このデータ構造を参照します。
333 class TextSegmentList
336 typedef std::shared_ptr<TextSegmentList> pointer;
337 typedef std::weak_ptr<TextSegmentList> weak_pointer;
340 TextSegmentList(Service *service, SocketConnection *connection);
344 bool contains(int segment_id);
345 TextSegment::pointer at(int segment_id);
346 TextSegment::pointer append(int segment_id, QString html_source);
350 QList<TextSentence::pointer> find_sentences(QString ssentence);
353 TextSegment::pointer current_segment();
354 bool set_current_segment(TextSegment::pointer segment);
355 TextSentence::pointer current_sentence();
356 void set_current_sentence(TextSentence::pointer sentence);
358 SocketConnection* connection();
363 void set_scode(int code);
364 void set_tcode(int code);
368 void set_url(QUrl url);
369 QString host() const;
374 static pointer create(Service *service, SocketConnection *connection);
379 SocketConnection *m_connection; /*!< このリストのオーナーとなるコネクション */
380 int m_scode; /*!< 原文言語コード。*/
381 int m_tcode; /*!< 訳文言語コード。 */
384 QMap<int, TextSegment::pointer> m_segments; /*!< HTML内のdata-wordring-segmentの値とセグメントのマップ */
385 TextSegment::pointer m_current_segment; /*!< 編集中のセグメントを表す。(ブラウザから変更)*/
386 TextSentence::pointer m_current_sentence; /*!< 編集中のセンテンスを表す。(エディタから変更) */
388 /*! 正規化原文と編集文のマルチ・マップ。 */
389 QMap<QString, TextSentence::pointer> m_source_map;