1 // Compound type for compound discovery and display
2 // Copyright © 2009 The University of Chicago
7 class CCompoundListViewItem
;
10 #include <q3listview.h>
11 #include <q3ptrvector.h>
18 class CCompoundCollection
;
21 typedef QList
<CStem
*> StemSet
;
22 typedef QMap
<int,StemSet
*> Components
;
23 typedef QMap
<int,CLinker
*> Linkers
;
25 class CCompoundListViewItem
: public Q3ListViewItem
{
26 CCompound
* m_compound
;
29 QString m_mostFreqPiece
;
31 QString m_pieceCounts
;
35 QMap
<QString
, QString
>* m_filter
;
37 // construction/destruction.
39 explicit CCompoundListViewItem(Q3ListView
* parent
= 0,
40 QString compound_text
= QString(), CCompound
* compound
= 0,
41 int = -1, double = -1.0, QString
= QString(),
42 double = 0.0, QString
= QString(),
43 double = 0.0, double = 0.0, int = 1,
44 QMap
<QString
, QString
>* filter
= 0);
45 explicit CCompoundListViewItem(Q3ListViewItem
*parent
,
46 QString compound_text
= QString(), CCompound
* compound
= 0,
47 int = -1, double = -1.0, QString
= QString(),
48 double = 0.0, QString
= QString(),
49 double = 0.0, double = 0.0, int = 1,
50 QMap
<QString
, QString
>* filter
= 0);
51 // destructor implicitly defined
55 CCompoundListViewItem(const CCompoundListViewItem
& x
)
57 m_compound(x
.m_compound
),
60 m_mostFreqPiece(x
.m_mostFreqPiece
),
61 m_MFPCount(x
.m_MFPCount
),
62 m_pieceCounts(x
.m_pieceCounts
),
63 m_prefixness(x
.m_prefixness
),
64 m_suffixness(x
.m_suffixness
),
65 m_parseCount(x
.m_parseCount
),
66 m_filter(x
.m_filter
) { }
67 CCompoundListViewItem
& operator=(const CCompoundListViewItem
& x
)
69 Q3ListViewItem::operator=(x
);
70 m_compound
= x
.m_compound
;
73 m_mostFreqPiece
= x
.m_mostFreqPiece
;
74 m_MFPCount
= x
.m_MFPCount
;
75 m_pieceCounts
= x
.m_pieceCounts
;
76 m_prefixness
= x
.m_prefixness
;
77 m_suffixness
= x
.m_suffixness
;
78 m_parseCount
= x
.m_parseCount
;
79 m_filter
= x
.m_filter
;
83 // Qt3 list view item interface.
85 virtual QString
text(int column_index
) const;
86 virtual QString
key(int column
, bool ascending
) const;
88 // underlying compound object.
90 CCompound
* GetCompound() const { return m_compound
; }
91 void SetCompound(CCompound
* pCompound
) { m_compound
= pCompound
; }
93 // compound properties.
95 void SetMFSCount(double d
) { m_MFPCount
= d
; }
96 void SetScore(double d
) { m_score
= d
; }
97 void SetPrefixness(double d
) { m_prefixness
= d
; }
98 void SetSuffixness(double d
) { m_suffixness
= d
; }
99 int GetParse() { return m_parse
; }
102 class CCompound
: public CLParse
{
103 // The word components and linkers of the compound, but
104 // only those reflected in the best parse (see m_BestParse)
105 // and the CParse structure of the compound
106 QMap
<int, QList
<CStem
*>*>* m_MyComponents
;
107 QMap
<int, CLinker
*>* m_MyLinkers
;
109 /// All "possible" parses of the compound as found
110 /// by the Earley Parser and not deleted thereafter
111 Q3PtrList
<CEdge
>* m_Parses
;
113 /// This is the "best" parse chosen from the list above. This
114 /// parse is reflected in the CParse structure of the compound.
118 CLexicon
* m_pLexicon
;
120 // construction/destruction.
122 explicit CCompound(CMiniLexicon
* mini
= 0);
123 explicit CCompound(const CStringSurrogate
& str
, CMiniLexicon
* mini
= 0);
124 virtual ~CCompound();
128 CCompound(const CCompound
& x
);
129 CCompound
& operator=(const CCompound
& x
);
132 QString
DisplayBestParse(QMap
<QString
, QString
>* filter
= 0)
133 { return DisplayParse(m_BestParse
, filter
); }
134 QString
DisplayParse(int, QMap
<QString
, QString
>* filter
= 0);
135 int GetNumberComponents() { return m_MyComponents
->count(); }
136 void CompoundListDisplay(Q3ListView
* widget
,
137 QMap
<QString
, QString
>* filter
= 0, QChar separator
= QChar());
138 int GetBestParse() { return m_BestParse
; }
139 QList
<CStem
* >* GetComponent(int) const;
140 Components
* GetComponents() { return m_MyComponents
; }
141 CLinker
* GetLinker(int) const;
142 Linkers
* GetLinkers() { return m_MyLinkers
; }
143 CEdge
* GetParse(int i
) { return m_Parses
->at(i
); }
144 Q3PtrList
<CEdge
>* GetParses() { return m_Parses
; }
145 double GetPrefixness();
146 double GetSuffixness();
148 void AddParse(CEdge
*);
149 void AttachComponentToWord(unsigned int piece
, QList
<CStem
*>* word
)
150 { m_MyComponents
->insert(piece
, word
); }
151 void DetachAllPieces();
152 bool RemoveParse(CEdge
*);
153 bool RemoveParse(int i
) { return RemoveParse(GetParse(i
)); }
154 void SetBestParse(int);
155 void SetLexicon(CLexicon
* lex
) { m_pLexicon
= lex
; }
156 void SetParses(Q3PtrList
<CEdge
>*, double*, double*);