1 // Data, algorithms, and interface shared by CPrefix and CSuffix
2 // Copyright © 2009 The University of Chicago
7 namespace linguistica
{
8 /// #include "affix_list_view_item.tcc" for definition
11 /// struct Prefix_or_suffix {
12 /// double ComputeDL(int char_count);
13 /// double GetLengthOfPointerToMe() const;
14 /// int GetCorpusCount() const;
15 /// int GetUseCount() const;
16 /// CParse* GetStemString();
18 template<class Prefix_or_suffix
> class affix_list_view_item
;
21 #include <Q3ListViewItem>
25 template<class K
, class V
> class QMap
;
27 /// Affix bookkeeping type for suffix/signature-based morphology code.
28 /// Most words can be parsed as stem + suffix or prefix + stem, where
29 /// the suffix or prefix is possibly empty. Instances of this class
30 /// hold information on all instances of a particular prefix or
31 /// suffix. A single string (e.g., “es” in Spanish) might be
32 /// represented by multiple different affixes, but a single string
33 /// in the context of a single signature (e.g., “es” of “∅.es” in
34 /// Spanish) will have a single associated affix opject.
36 /// Affixes are stored in the m_pSuffixes and m_pPrefixes members of
37 /// each mini-lexicon. They are created whenever a particular affix
38 /// is being investigated as possibly useful and stored if it
40 class CAffix
: public CLParse
{
44 QList
<class CStem
*>* m_StemPtrList
;
45 double m_CompressedLength
;
48 double m_LengthOfPointerToMe
;
49 double m_PhonologicalInformationContent
;
50 double m_UnigramLogProb
;
51 double m_BigramLogProb
;
53 // construction/destruction.
54 CAffix(class CMiniLexicon
* owner
);
55 CAffix(const class CStringSurrogate
& text
, class CMiniLexicon
* owner
);
56 virtual ~CAffix() = 0;
58 // copying forbidden for now.
59 CAffix(const CAffix
& x
);
60 CAffix
& operator=(const CAffix
& x
);
62 // description length.
63 double GetCompressedLength() const { return m_CompressedLength
; }
64 int GetUseCount() const { return m_UseCount
; }
65 double GetLengthOfPointerToMe();
66 double GetPhonologicalInformationContent();
67 void CalculatePhonologicalInformationContent(class CLexicon
* lexicon
);
68 void IncrementUseCount(int num_stems
= 1);
69 void SetCompressedLength(double m
) { m_CompressedLength
= m
; }
70 void SetUseCount(int n
) { m_UseCount
= n
; }
73 CParse
* GetDeletees() { return &m_Deletees
; }
74 void AddDeletee(class CStringSurrogate deletee
);
75 void AddMorphee(class CStringSurrogate pattern
,
76 class CStringSurrogate subst
);
79 int GetNumberOfStems() const { return m_StemString
.Size(); }
80 CParse
* GetStemString() { return &m_StemString
; }
81 QList
<CStem
*>* GetStems() { return m_StemPtrList
; }
82 CStem
* GetAtStem(int i
) { return m_StemPtrList
->at(i
); }
83 void AddStem(CStem
* stem
);
84 void AppendToStemString(const class CStringSurrogate
& stem_text
);
85 void RemoveFromStemPtrList(CStem
* stem
);
86 void ClearStemPtrList() { m_StemPtrList
->clear(); }
87 void RemoveStemString(const class CStringSurrogate
& stem_text
);
90 QString
ExpressAffix(bool ExpressDeletees
= true);
94 class linguistica::affix_list_view_item
: public Q3ListViewItem
{
96 QMap
<QString
, QString
>* m_filter
;
99 // construction/destruction.
101 explicit affix_list_view_item(class Q3ListView
* parent
= 0,
102 QString affix_text
= QString(), Affix
* affix
= 0,
103 QMap
<QString
, QString
>* filter
= 0,
104 int char_count
= 27);
105 explicit affix_list_view_item(Q3ListViewItem
* parent
,
106 QString affix_text
= QString(), Affix
* affix
= 0,
107 QMap
<QString
, QString
>* filter
= 0,
108 int char_count
= 27);
112 affix_list_view_item(const affix_list_view_item
& x
)
115 m_filter(x
.m_filter
),
116 m_char_count(x
.m_char_count
) { }
117 affix_list_view_item
& operator=(const affix_list_view_item
& x
)
119 Q3ListViewItem::operator=(x
);
121 m_filter
= x
.m_filter
;
122 m_char_count
= x
.m_char_count
;
126 // Qt3 list view item interface.
128 virtual QString
text(int column_index
) const;
129 int compare(Q3ListViewItem
* other
, int column
, bool ascending
) const;
130 virtual QString
key(int column
, bool ascending
) const;
132 // underlying affix object.
134 Affix
* GetAffix() const { return m_affix
; }
135 void SetAffix(Affix
* affix
) { m_affix
= affix
; }