HowManyAreAnalyzed(): use status_user_agent to report progress
[linguistica.git] / Phonology.cpp
blob97dc28e81f253ba3b96733d79ce4342d4b4cb41b
1 // UI actions for discovering phonology
2 // Copyright © 2009 The University of Chicago
3 #include "linguisticamainwindow.h"
5 #include <QMessageBox>
6 #include "corpusviewdialog.h"
7 #include "MiniLexicon.h"
8 #include "Lexicon.h"
9 #include "StateEmitHMM.h"
10 #include "Sequencer.h"
11 #include "Stats.h"
12 #include "cMT.h"
13 #include "WordCollection.h"
15 void LinguisticaMainWindow::GenericPhonologySlot()
17 CMiniLexicon* current_mini = m_lexicon->GetMiniLexicon(m_lexicon->GetActiveMiniIndex());
19 if ( current_mini )
21 current_mini->GetWords()->DoPhonology();
23 // Update tree view
24 emit updateAllViewsSignal();
26 void LinguisticaMainWindow::CreateSkeletonSlot() // Creates CV template
29 CMiniLexicon* current_mini = m_lexicon->GetMiniLexicon(m_lexicon->GetActiveMiniIndex());
30 if ( current_mini )
32 current_mini->GetWords()->CreateCVTemplate();
36 // Update tree view
37 emit updateAllViewsSignal();
40 void LinguisticaMainWindow::PhonologyCalculateInformation()
46 void LinguisticaMainWindow::DropTierLeaveSlot()
48 CMiniLexicon* current_mini = m_lexicon->GetMiniLexicon(m_lexicon->GetActiveMiniIndex());
50 if ( current_mini )
52 current_mini->GetWords()->SplitPhonologyToTiers(
53 CStem::Split_LeaveSlot);
54 current_mini->GetWords()->ComputeZ();
55 current_mini->GetWords()->ComputeZStar();
56 current_mini->GetWords()->ComputeBoltzmannProbabilities();
61 // Update tree view
62 emit updateAllViewsSignal();
65 void LinguisticaMainWindow::DropTierLeaveCopy()
67 CMiniLexicon* current_mini = m_lexicon->GetMiniLexicon(m_lexicon->GetActiveMiniIndex());
68 if ( current_mini)
70 current_mini->GetWords()->SplitPhonologyToTiers(
71 CStem::Split_LeaveCopy);
72 current_mini->GetWords()->ComputeZ();
73 current_mini->GetWords()->ComputeZStar();
74 current_mini->GetWords()->ComputeBoltzmannProbabilities();
78 // Update tree view
79 emit updateAllViewsSignal();
82 void LinguisticaMainWindow::PhonologyComputeGibbsFunction() // currently not used.
84 CMiniLexicon* current_mini = m_lexicon->GetMiniLexicon(m_lexicon->GetActiveMiniIndex());
85 if ( current_mini)
87 //current_mini->GetWords()->ComputeZ();
89 // Update tree view
90 emit updateAllViewsSignal();
93 void LinguisticaMainWindow::sequencerReadCorpusSlot()
95 if (m_Sequencer != 0)
96 m_Sequencer->readCorpus(status_display());
99 void LinguisticaMainWindow::sequenceASentenceSlot()
101 if ( m_Sequencer == NULL)
103 return;
106 int birank;
107 int trirank;
110 //m_Sequencer ->sequenceASentence(birank,trirank);
111 m_Sequencer ->sequenceASentence2(birank,trirank);
116 void LinguisticaMainWindow::sequencerTestAFileSlot()
118 if (m_Sequencer != 0)
119 m_Sequencer->sequencerTestAFile(status_display());
122 void LinguisticaMainWindow::statsReadCorpusSlot()
124 if ( m_Stats == NULL)
126 return;
129 m_Stats->readCorpus();
133 void LinguisticaMainWindow::DCNstressSlot()
135 // combinedWindow *window = new combinedWindow(0, "DCN");
136 // window->show();
139 void LinguisticaMainWindow::DCNsylSlot()
141 // windowsyl* window = new windowsyl(0, "DCN Main Window");
142 // window->show();
145 void LinguisticaMainWindow::fromStemsFindCompoundsSlot()
147 if( m_logging ) OpenLogFile();
148 m_lexicon->FromStemsFindCompounds();
149 if( m_logging ) CloseLogFile();
151 // Update corpus words
152 m_lexicon->DoWordUpdates();
154 // Unsaved work
155 m_projectDirty = true;
157 // Update tree view
158 emit updateAllViewsSignal();
161 void LinguisticaMainWindow::fromStemsFindFlatCompoundsSlot()
163 if( m_logging ) OpenLogFile();
164 m_lexicon->FromStemsFindFlatCompounds();
165 if( m_logging ) CloseLogFile();
167 // Update corpus words
168 m_lexicon->DoWordUpdates();
170 // Unsaved work
171 m_projectDirty = true;
173 // Update tree view
174 emit updateAllViewsSignal();
179 // MT part
180 void LinguisticaMainWindow::mTModel1Slot()
183 int model1Iterations = 10;
184 int model2Iterations = 10;
185 bool inheritTFromModel1 = true;
187 if ( m_MT != NULL)
189 delete m_MT;
192 m_MT = new cMT(this, m_projectDirectory);
194 m_MT ->readTrainingCorpus();
196 m_MT ->trainModel1(model1Iterations);
198 m_MT ->trainModel2Norm(model2Iterations, inheritTFromModel1);
202 // HMM part
203 void LinguisticaMainWindow::testSEMHMMSlot()
206 CWordCollection* dataCorpus;
207 StateEmitHMM* pHMM;
208 bool dataIsRight;
209 int NumberOfIterations(70);
210 int NumberOfStates;
213 NumberOfIterations = m_lexicon ->GetIntParameter ("HMM\\NumberOfIterations", 25);
214 NumberOfStates = m_lexicon ->GetIntParameter ("HMM\\NumberOfStates", 2);
216 if ( !m_lexicon)
218 QMessageBox::information ( this, "Linguistica : Error", "Lexicon is NULL when running HMM!" );
219 return;
222 CMiniLexicon* pMini;
224 pMini = (*(m_lexicon ->m_pMiniLexica))[0];
226 dataCorpus = pMini ->GetWords();
228 pHMM = m_lexicon->CreateNewHMM();
231 dataIsRight = pHMM->preprocessData(PHONE_TIER1, (void*)(dataCorpus));
233 if ( !dataIsRight)
235 delete pHMM;
236 QMessageBox::information ( this, "Linguistica : Error", "Data is not right for HMM!" );
237 return;
240 pHMM->init(NumberOfStates,NumberOfIterations);
241 pHMM->initPiAndAB();
245 pHMM->trainParameters();
246 pHMM->logInfo(-1);
248 // delete oneStateHMM;
250 // Update tree view
251 emit updateAllViewsSignal();
255 void LinguisticaMainWindow::calculateAffixnessSlot()
257 if( m_logging ) OpenLogFile();
258 m_lexicon->CalculateCoefficientsOfAffixness();
259 if( m_logging ) CloseLogFile();
261 // Unsaved work
262 m_projectDirty = true;
264 // Update tree view
265 emit updateAllViewsSignal();
269 void LinguisticaMainWindow::fromAffixnessUpdateSigsAndCompoundsSlot()
271 if( m_logging ) OpenLogFile();
272 m_lexicon->FromAffixnessUpdateSigsAndCompounds();
273 if( m_logging ) CloseLogFile();
275 // Update corpus words
276 m_lexicon->DoWordUpdates();
278 // Unsaved work
279 m_projectDirty = true;
281 // Update tree view
282 emit updateAllViewsSignal();
286 void LinguisticaMainWindow::viewCorpusSlot()
288 CorpusViewDialog *corpusViewDlg = new CorpusViewDialog( m_lexicon, this,
289 Qt::WStyle_Customize |
290 Qt::WStyle_NormalBorder |
291 Qt::WStyle_Title |
292 Qt::WStyle_SysMenu );
293 if( corpusViewDlg->exec() == QDialog::Accepted )
295 // Do nothing
297 else
299 // Do nothing
301 delete corpusViewDlg;
305 void LinguisticaMainWindow::exportProjectSlot()
307 #ifdef _EXPORTWIZARD_ //@@@
308 ExportWizard *exportWiz = new ExportWizard( m_lexicon, this, "exportWizard", FALSE );
309 if( exportWiz->exec() == QDialog::Accepted )
311 // Export
313 exportWiz->exportAll();
315 else
317 // Do nothing
319 delete exportWiz;
320 #endif