CMiniLexicon::FindMajorSignatures(): use log file routines
[linguistica.git] / Affix.h
blobdace65d75505843434aedb5826d1cca8e7c608e5
1 // Data, algorithms, and interface shared by CPrefix and CSuffix
2 // Copyright © 2009 The University of Chicago
3 #ifndef AFFIX_H
4 #define AFFIX_H
6 class CAffix;
7 namespace linguistica {
8 /// #include "affix_list_view_item.tcc" for definition
9 /// requires:
10 ///
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();
17 /// };
18 template<class Prefix_or_suffix> class affix_list_view_item;
21 #include <Q3ListViewItem>
22 #include <QString>
23 #include "LParse.h"
24 #include "Parse.h"
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.
35 ///
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
39 /// proves so.
40 class CAffix : public CLParse {
41 protected:
42 int m_UseCount;
43 CParse m_StemString;
44 QList<class CStem*>* m_StemPtrList;
45 double m_CompressedLength;
46 CParse m_Deletees;
47 CParse m_Morphees;
48 double m_LengthOfPointerToMe;
49 double m_PhonologicalInformationContent;
50 double m_UnigramLogProb;
51 double m_BigramLogProb;
52 public:
53 // construction/destruction.
54 CAffix(class CMiniLexicon* owner);
55 CAffix(const class CStringSurrogate& text, class CMiniLexicon* owner);
56 virtual ~CAffix() = 0;
57 private:
58 // copying forbidden for now.
59 CAffix(const CAffix& x);
60 CAffix& operator=(const CAffix& x);
61 public:
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; }
72 // allomorphy.
73 CParse* GetDeletees() { return &m_Deletees; }
74 void AddDeletee(class CStringSurrogate deletee);
75 void AddMorphee(class CStringSurrogate pattern,
76 class CStringSurrogate subst);
78 // associated stems.
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);
89 // display.
90 QString ExpressAffix(bool ExpressDeletees = true);
93 template<class Affix>
94 class linguistica::affix_list_view_item : public Q3ListViewItem {
95 Affix* m_affix;
96 QMap<QString, QString>* m_filter;
97 int m_char_count;
98 public:
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);
110 // copy.
112 affix_list_view_item(const affix_list_view_item& x)
113 : Q3ListViewItem(x),
114 m_affix(x.m_affix),
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);
120 m_affix = x.m_affix;
121 m_filter = x.m_filter;
122 m_char_count = x.m_char_count;
123 return *this;
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; }
138 #endif // AFFIX_H