HowManyAreAnalyzed(): use status_user_agent to report progress
[linguistica.git] / Prefix.cpp
blobb8f95990822d236af5faba816d366d78ed0d09b3
1 // Implementation of CPrefix methods
2 // Copyright © 2009 The University of Chicago
3 #include "Prefix.h"
5 #include <Q3TextStream>
6 #include "MiniLexicon.h"
7 #include "Stem.h"
8 #include "PrefixCollection.h"
9 #include "WordCollection.h"
10 #include "log2.h"
12 // construction/destruction.
14 /**
15 Constructs an empty prefix. <kbd>mini</kbd> is the mini-lexicon
16 which will contain this prefix.
18 CPrefix::CPrefix( CMiniLexicon* mini ) : CAffix( mini )
21 CPrefix::CPrefix(const QString Prefix) : CAffix(Prefix)
25 /**
26 Constructs a prefix copy of a CStringSurrogate. <kbd>ssPrefix</kbd> is a
27 surrogate of the prefix. <kbd>mini</kbd> is the mini-lexicon which will
28 contain this prefix.
30 CPrefix::CPrefix (const CStringSurrogate& ssPrefix, CMiniLexicon* mini ) : CAffix (ssPrefix, mini)
33 /**
34 Destroys this prefix.
36 CPrefix::~CPrefix()
40 // Prepare a list item for this prefix to be displayed
41 // in the triscreen interface
43 // Parameters:
44 // List - the list item to be prepared
45 // Line - what line to display on
47 /**
48 Prepares a list view item for this prefix to be displayed in provided list view.
49 <kbd>List</kbd> is the list view which will contain the new list view item. <kbd>filter</kbd>
50 is an out filter for preparing strings for display. <kbd>char_count</kbd> is the number
51 of characters in the lexicon, used for calculating description length.
53 void CPrefix::ListDisplay(Q3ListView* List,
54 QMap<QString, QString>* filter, int char_count)
56 static_cast<void>(new CPrefixListViewItem(
57 List, Display(QChar(), filter),
58 this, filter, char_count));
61 /**
62 Returns a CParse copy of this prefix that expresses any allomorphy.
63 <kbd>Output</kbd> is where the expressed prefix will be stored, it is
64 also returned. The <kbd>DisplayDeletees</kbd> flag tells the function
65 whether deleted portions of the morpheme should also be displayed, if
66 they exist.
71 CParse& CPrefix::Express( CParse& Output, bool DisplayDeletees )
73 Output.ClearParse();
74 QString lt = "<", rt = ">";
76 if ( DisplayDeletees && m_Deletees.GetKeyLength() > 0 )
78 Output.Append( lt );
79 Output.Append ( m_Deletees.Display() );
80 Output.Append( rt );
82 Output.Append ( GetKey() );
83 return Output;
89 // Remerge all words that use this prefix into a
90 // single piece
92 // Parameters:
93 // Lexicon - holds stem-->prefix relationship
94 // information
96 /**
97 Merges the prefix with all associated stems. This is
98 the way the Lexicon destroys this prefix analysis. The
99 prefix must be remerged with its stems. They become just
100 a word with no morphology. <kbd>Lexicon</kbd> is the mini
101 lexicon that contains this prefix and its associated stems.
103 void CPrefix::MergeMeWithMyStems ( CMiniLexicon* Lexicon )
105 CStringSurrogate ssPrefix = GetKey(),
106 ssStem;
107 CParse Word;
108 CStem* pWord = NULL;
111 for (int j = 1; j <= (int)GetStemString()->Size(); j++)
113 ssStem = GetStemString()->GetPiece(j);
114 Word = ssStem + ssPrefix;
115 pWord = *Lexicon->GetWords() ^= Word;
116 if (pWord)
118 pWord->ClearPrefixStemSplit();
124 Outputs the prefix to a text stream. This is useful when
125 saving the Linguistica data to a file. <kbd>outf</kbd> is a
126 text stream handle.
128 void CPrefix::OutputPrefix( Q3TextStream& outf )
130 QString key;
132 if( m_KeyLength == 0 ) key = "NULL";
133 else key = Display( QChar(0), m_pMyMini->GetOutFilter() );
135 outf.width(2);
136 outf << " ";
137 outf.setf(2);
138 outf.width(12);
139 outf << key;
140 outf << " ";
142 outf.unsetf(2);
143 outf.width(9);
144 outf << m_UseCount;
145 outf << " ";
146 outf.width(12);
147 outf << GetCorpusCount();
148 outf << " ";
149 outf.width(5);
150 outf << m_Index;
151 outf << " " << endl;
154 double CPrefix::GetLengthOfPointerToMe()
157 if (m_LengthOfPointerToMe == 0)
159 m_LengthOfPointerToMe = base2log ( m_pMyMini->GetPrefixes()->GetCorpusCount () / GetCorpusCount() );
161 return m_LengthOfPointerToMe;
167 #include "affix_list_view_item.tcc"
168 template class linguistica::affix_list_view_item<CPrefix>;