HowManyAreAnalyzed(): use status_user_agent to report progress
[linguistica.git] / linguisticamainwindow.h
blob056dc542586034ff91306f5b7a08a13f90edd8a9
1 // User interface and driver
2 // Copyright © 2009 The University of Chicago
3 #ifndef LINGUISTICAMAINWINDOW_H
4 #define LINGUISTICAMAINWINDOW_H
6 // Doxygen comments defining the index page
7 /** \mainpage Linguistica
9 \section intro_sec What is Linguistica?
11 Linguistica is a program designed to explore the unsupervised learning of natural language, with primary focus on morphology (word-structure). It runs under Windows, Mac OS X and Linux, and is written in C++ within the Qt development framework. Its demands on memory depend on the size of the corpus analyzed.
13 Unsupervised learning refers to the computational task of making inferences (and therefore acquiring knowledge) about the structure that lies behind some set of data, without any direct access to that structure. In the case of unsupervised learning of morphology, Linguistica explores the possibilities of morpheme-combinations for a set of words, based on no internal knowledge of the language from which the words are drawn.
15 Segmentation is the first task of this process; the program figures out where the morpheme boundaries are in the words, and then decides what the stems are, what the suffixes are, and so forth. Most of Linguistica's functionality, at this point, goes into making these decisions.
17 \section creator Creator
18 - John Goldsmith
20 \section engineers Engineers
22 - Jon Cihlar
23 - Yu Hu
24 - Jeremy O'Brien
25 - Colin Sprague
27 \section contributors Contributors
29 - Carl Dolnick
30 - James Kirby
31 - Irina Matveeva
32 - Aris Xanthos
36 #include <QMainWindow>
37 #include "ui_linguisticamainwindowbase.h"
39 #include <memory>
40 #include <Q3ProgressDialog>
41 #include <Q3FileDialog>
42 #include <QInputDialog>
43 #include <QFontDialog>
44 #include <Q3PopupMenu>
45 #include <QStatusBar>
46 #include <Q3TextEdit>
47 #include <QSplitter>
48 #include <Q3ToolBar>
49 #include <QMenuBar>
50 #include <Q3Canvas>
51 #include <Q3VBox>
52 #include <QResizeEvent>
53 #include <QCloseEvent>
54 #include <QMoveEvent>
55 #include <QApplication>
56 #include <QSettings>
57 #include <Q3Process>
58 #include <QLayout>
59 #include <QAction>
60 #include <QLabel>
61 #include <Q3TextStream>
62 #include <Q3PtrList>
63 #include <QString>
64 #include <Qt>
65 #include "LPreferences.h"
66 #include "generaldefinitions.h"
67 #include "AffixLocation.h"
69 #include <QLabel>
71 namespace linguistica { namespace ui {
72 struct status_user_agent;
73 } }
74 class CStem;
75 class CLexicon;
76 class CParse;
77 class CLPreferences;
78 class CTreeViewItem;
79 class CState;
80 class GraphicView;
81 class CTemplate;
82 class CTemplateCollection;
83 class CTemplateListViewItem;
84 class CSequencer;
85 class CStats;
86 class cMT;
87 class CCorpusWord;
88 class CSignature;
89 class GUIWordCollection;
91 enum eDocumentType;
93 //typedef QMap<QString,QString> StringToString;
94 typedef QMap<QString,CTemplate*> QStringToTemplate;
95 typedef Q3PtrList<CStem> CStemList;
96 typedef QMap<QString,CStemList> StringToCStemList;
97 typedef QMap<QString,CStem*> StringToPtrCStem;
98 typedef QMap<QString,CStem> StringToCStem;
99 typedef QMap<QString,CParse*> StringToParse;
100 typedef QMap<QString,CCorpusWord*> StringToPtrCCorpusWord;
101 typedef QMap<int,QString> IntToString;
103 class LinguisticaMainWindow : public QMainWindow,
104 public Ui::LinguisticaMainWindowBase
106 Q_OBJECT
107 protected:
108 // Application
109 QApplication* m_app; ///< memory belongs to caller
110 /// true if running in batch mode
111 bool m_commandLineFlag;
113 // Preferences
114 QSettings m_Settings;
115 CLPreferences m_preferences;
117 // Lexicon
118 CLexicon* m_lexicon;
120 // GUI
121 eDocumentType m_docType;
122 CParse* m_commandParse;
123 int m_commandMini;
124 CSignature* m_pSig1;
125 CSignature* m_pSig2;
126 GUIWordCollection* m_GUIWords;
128 // Token count
129 int m_numberOfTokens;
131 // Logging variables
132 bool m_logging;
133 QString m_logFileName;
134 QFile* m_logFile;
135 QTextStream* m_logFileStream;
137 // Status/Progress Bar
138 std::auto_ptr<linguistica::ui::status_user_agent> m_status;
139 Q3ProgressDialog* m_progressDialog;
140 QString m_progressText1,
141 m_progressText2;
143 // Counter
144 bool m_counterDisplayFlag;
145 int m_counter;
147 // Project information
148 int m_projectIndex;
149 QString m_projectDirectory;
150 QString m_projectName;
151 bool m_projectDirty;
153 // File names
154 QString m_corpusFileName;
155 QString m_goldStdFileName;
156 QString m_goldStdOutputFile;
158 // Encoding
159 QString m_EncodingType;
161 // Fonts
162 // Collection view and command line can have different
163 // font, they are on the east side of the screen
164 QFont m_eastFont; // Collection view and command line font, east side of screen
167 //========== FSA
168 CState* m_CommonState;
170 //========= SED
171 CTemplate* m_CommonTemplate;
172 CTemplateCollection* m_Words_InitialTemplates;
173 CTemplateCollection* m_Words_Templates;
175 //========= Sequencer
176 CSequencer* m_Sequencer;
178 //========= Statistics
179 CStats* m_Stats;
181 //========= MT
182 cMT* m_MT;
184 public:
185 LinguisticaMainWindow( const int argc, char** argv, QApplication* app = 0,
186 QWidget* parent = 0, Qt::WindowFlags f = Qt::WType_TopLevel );
187 ~LinguisticaMainWindow();
189 // disable copy
190 private:
191 LinguisticaMainWindow(const LinguisticaMainWindow& x);
192 LinguisticaMainWindow& operator=(const LinguisticaMainWindow& x);
193 public:
195 void SetNumberOfTokens( int i ) { m_numberOfTokens = i; }
196 int GetNumberOfTokens() { return m_numberOfTokens; }
198 void SetUpNewLexicon ();
200 void setProjectDirectory( QString dir ) { m_projectDirectory = dir; }
201 bool getProjectDirty () { return m_projectDirty; }
203 void setStatusBar1 (QString);
204 void setStatusBar2 (QString);
206 void BeginCountDown ();
207 void EndCountDown ();
208 void CountDownOnStatusBar(int i, int total, int step = 100);
210 linguistica::ui::status_user_agent& status_display()
211 { return *m_status; }
213 QString GetLogFileName () { return m_logFileName; }
214 void AskUserForLogFileName();
216 void SetEastFont ( QFont font ) { m_eastFont = font; }
217 CLPreferences* GetPreferences () { return &m_preferences; }
218 QSettings* GetSettings () { return &m_Settings; }
220 void SetDocType ( eDocumentType dt ) { m_docType = dt; }
221 eDocumentType GetDocType () { return m_docType; }
223 bool autoLayering () { return m_autoLayeringAction->isOn(); }
225 bool isCorrectAffix ( eAffixLocation );
227 void executeCommandLineArgs(int words_count, bool auto_layer,
228 bool prefix, bool suffix);
229 /// true if running in batch mode
230 bool commandLineMode() { return m_commandLineFlag; }
232 QFont GetEastFont () { return m_eastFont; }
234 // Logging
235 void CloseLogFile ();
236 void OpenLogFile ();
237 bool LogFileOn () { return m_logging; }
238 QTextStream* GetLogFileStream() { return m_logFileStream; }
241 Q3Canvas* m_SmallCanvas;
242 GraphicView* m_SmallGraphicDisplay; ///< deleted by m_SmallGraphicDisplayTab
243 Q3VBox* m_SmallGraphicDisplayVBox;
244 QLabel * pImgLabel;
246 CLexicon* GetLexicon(void) { return m_lexicon; }
247 private:
250 Q3ListViewItem* GetMiniLexiconSubTree( Q3ListViewItem*, int );
251 void GetMorphPrecisionRecallByWord( StringToCStemList&,
252 StringToParse&,
253 double&,
254 double&,
255 double&,
256 double& );
258 void GetCutPrecisionRecall( StringToCStemList&,
259 StringToParse&,
260 double&,
261 double&,
262 double&,
263 double& );
265 void GetMorphPrecisionRecall( StringToCStemList&,
266 StringToParse&,
267 double&,
268 double&,
269 double&,
270 double& );
271 private:
272 QFont GetFontPreference(QString key) const
273 { return m_preferences.GetFontPreference(key); }
274 void SetFontPreference(QString key, QFont font)
275 { m_preferences.SetFontPreference(key, font); }
276 QString GetPreference(QString key) const
277 { return m_preferences.GetPreference(key); }
278 void GetStringListPreference(QString key, QStringList* out) const
279 { m_preferences.GetStringListPreference(key, out); }
281 signals:
282 void corpusOKSignal(bool);
283 void updateAllViewsSignal();
284 void updateTreeViewSignal();
285 void updateCommandLineSignal();
286 void tokensRequestedSignal(); // for changing the number of words requested
287 void commandLineClose();
289 public slots:
291 // Slots derived from LinguisticaMainWindowBase
292 void openFileActionSlot();
293 void runAllSuffixActionSlot();
294 void enableLoggingActionSlot( bool );
295 void clearLogFileActionSlot();
296 void newLogFileActionSlot();
297 /// Refresh collection view, for example for a switch in m_docType.
298 void updateCollectionViewSlot();
299 void updateCollectionViewSlot( Q3ListViewItem* );
300 void updateCommandLineSlot( Q3ListViewItem* );
301 void changeFontSlot();
302 void preferencesEditSlot();
303 void saveFileActionSlot();
304 void newFileActionSlot();
305 void saveAsFileActionSlot();
306 void findAllomorphySlot();
307 void showDeleteesSlot( bool );
308 void rereadCorpusSlot();
309 void clearLexiconSlot();
310 void predecessorFreqSlot();
311 void successorFreqSlot();
312 void checkPfxSignaturesSlot();
313 void checkSignaturesSlot();
314 void knownStemsPrefixesSlot();
315 void knownStemsSuffixesSlot();
316 void fromPfxSigsFindStemsSlot();
317 void fromSigsFindStemsSlot();
318 void findPfxSingletonSigsSlot();
319 void findSingletonSigsSlot();
320 void pfxLooseFitSlot();
321 void looseFitSlot();
322 void showToolbarsSlot( bool );
323 void showStatusBarSlot( bool );
324 void saveBrokenCorpusSlot();
325 void helpAboutSlot();
326 void newMiniLexiconActionSlot();
327 void deleteMiniLexiconActionSlot();
328 void autoLayeringActionSlot();
329 void populateWordsActionSlot();
330 void addToBorrowedSigsSlot();
331 void compareGoldStdSlot();
332 void changeGoldStdFileSlot();
333 void runAllPrefixActionSlot();
334 void commandLineCloseSlot();
335 void viewCorpusSlot();
336 void exportProjectSlot();
337 void addContentToCommandLine(QString);
338 void setCommandLineTabStopWidth(int length){m_commandLine->setTabStopWidth(length);};
339 int getCommandLinePointSize(){ return m_commandLine ->pointSize();};
340 void setCommandLineStyle( QString );
341 void xfstExportActionSlot();
343 // Compounds
344 void fromStemsFindCompoundsSlot();
345 void fromStemsFindFlatCompoundsSlot();
346 void calculateAffixnessSlot();
347 void fromAffixnessUpdateSigsAndCompoundsSlot();
348 void compareCompoundsSlot();
350 // Phonology
351 virtual void GenericPhonologySlot();
352 virtual void CreateSkeletonSlot();
353 virtual void fromStemsFindAffixesSlot();
354 virtual void DropTierLeaveSlot();
355 virtual void DropTierLeaveCopy();
356 virtual void PhonologyCalculateInformation();
357 virtual void PhonologyComputeGibbsFunction();
359 void updateSmallGraphicDisplaySlot(); //needed for compound displays
360 // --- new fsa code
361 void fsaTestFuncAction();
363 // Phonogy graphic display
364 void updateSmallGraphicDisplaySlotForPhonogy(CStem*);
367 // Sequencer
368 void sequencerReadCorpusSlot();
369 void sequenceASentenceSlot();
370 void sequencerTestAFileSlot();
372 //======== MT
373 void mTModel1Slot();
375 // ========= HMM
376 void testSEMHMMSlot();
377 void DisplayVideoHMM();
379 // ========= Graphic display of Multidimension data
380 void testMultiDimensionDisplaySlot();
381 void updateSmallGraphicDisplaySlotForMultiDimensionData(int, int, double**, IntToString);
383 // ====== Goldwater Method
384 void goldwaterMethodSlot();
386 void testSignatureDisplaySlot(); //jg july 2006
388 // Statistics
389 void statsReadCorpusSlot();
391 // DCN
392 void DCNstressSlot();
393 void DCNsylSlot();
395 void DCNstressComputeSlot();
396 void DCNstressLearnSlot();
398 void DCNsylFindTrainSlot();
399 void DCNsylFindTestSlot();
400 void DCNsylTrainSlot();
402 // StringEditDistance
403 void RunSedSlot();
404 void FindSlicesSlot();
405 void FindAllEditDistances(CTemplateCollection*);
406 void CheckForConflations(CTemplateCollection* , CTemplateCollection* );
407 void FindAllWordNeighbors(CLexicon*);
409 // Goldstandard
410 // void GetPrecisionRecall(StringToPtrCStem&, StringToParse&, double& , double& , double& , double& );
412 // Machine Translation
413 void editCorpusForMT();
415 // Other slots
416 void jgWebLinksActionSlot();
417 void lxaWebLinksActionSlot();
418 void updateTreeViewSlot();
419 void updateCommandLineSlot();
420 void tokensRequestedDialogSlot();
421 void setProjectDirtySlot( bool b ) { m_projectDirty = b; }
423 void suffixesCollapse_two_signaturesAction_activated();
424 void updateSignatureGraphicDisplaySlot();
427 // User interface items
428 void toggleMultipleSelectionSlot();
431 protected:
432 virtual void closeEvent( QCloseEvent * );
433 virtual void resizeEvent( QResizeEvent * );
434 virtual void moveEvent( QMoveEvent * );
436 public:
437 bool getLogging(){ return m_logging; }
440 #endif // LINGUISTICAMAINWINDOW_H