1 // User interface for Dynamic Computational Network computations
2 // Copyright © 2009 The University of Chicago
3 #include "linguisticamainwindow.h"
7 #include "DCNlearningsyl.h"
8 #include "DCNcorpussyl.h"
9 #include "DCNlearning.h"
10 #include "DCNsnetwork.h"
11 #include "DCNgrammar.h"
15 This file contains all the GUI slots for the DCN tabs, namely
16 DCN Stress and DCN Syllabification
19 // DCN STRESS FUNCTIONS:
21 // sets up a grammar, snetwork, and then computes the dcn from the
22 // data given by the user (alpha through max)
23 void LinguisticaMainWindow::DCNstressComputeSlot()
25 float alpha
= alphaLine
->text().toFloat();
26 float beta
= betaLine
->text().toFloat();
27 float I
= initialLine
->text().toFloat();
28 float F
= finalLine
->text().toFloat();
29 int min
= 2; //minLine->text().toInt();
30 int max
= 15; //maxLine->text().toInt();
32 grammar
*theGrammar
= new grammar();
33 theGrammar
->setValues(alpha
, beta
, I
, F
, 0, 0);
34 snetwork
*theSnetwork
= new snetwork(min
, max
);
35 theSnetwork
->setGrammar(theGrammar
);
36 theSnetwork
->equilibrium();
37 theSnetwork
->print(corpusTextEdit
);
42 // sets up a learning system, reads in the corpus, and runs the learning
44 void LinguisticaMainWindow::DCNstressLearnSlot()
48 DCNlearn
.TfromUser
= TLine
->text().toFloat();
49 DCNlearn
.increaseWhenWrong
= iwwLine
->text().toFloat();
50 DCNlearn
.decreaseWhenRight
= dwrLine
->text().toFloat();
51 DCNlearn
.numberOfTries
= trialsLine
->text().toInt();
52 DCNlearn
.cutoffFromUser
= cutoffLine
->text().toInt();
54 DCNlearn
.startingAlpha
= sAlphaLine
->text().toFloat();
55 DCNlearn
.startingBeta
= sBetaLine
->text().toFloat();
56 DCNlearn
.startingI
= sInitialLine
->text().toFloat();
57 DCNlearn
.startingF
= sFinalLine
->text().toFloat();
59 int maxCorpusIndex
= corpusTextEdit
->lines() - 1;
61 QString theWindow
= corpusTextEdit
->text();
62 QString
* corpus
= new QString
[maxCorpusIndex
];
64 for (int i
= 0; i
< maxCorpusIndex
; i
++)
66 QString word
= corpusTextEdit
->text(i
);
67 int length
= word
.length();
69 word
.truncate(length
);
73 DCNlearn
.setCorpus(corpus
, maxCorpusIndex
);
74 DCNlearn
.run(status_display());
76 grammar
* theGrammar
= DCNlearn
.returnGrammar();
77 snetwork
theSnetwork(2, 15);
78 theSnetwork
.setGrammar(theGrammar
);
79 theSnetwork
.equilibrium();
81 float alpha
= theGrammar
->getAlpha();
82 float beta
= theGrammar
->getBeta();
83 float I
= theGrammar
->getI();
84 float F
= theGrammar
->getF();
86 if (DCNlearn
.isSuccessful())
88 QMessageBox::information( this, "DCN Stress Learning Algorithm",
89 "The learning algorithm was successful!" );
92 string
.setNum(alpha
); alphaLine
->setText(string
);
93 string
.setNum(beta
); betaLine
->setText(string
);
94 string
.setNum(I
); initialLine
->setText(string
);
95 string
.setNum(F
); finalLine
->setText(string
);
100 QMessageBox::warning( this, "dcn syl",
101 "Sorry, the learning algorithm was unsuccessful." );
109 // DCN SYLLABIFICATION FUNCTIONS:
111 // opens the training corpus
112 void LinguisticaMainWindow::DCNsylFindTrainSlot()
114 QString trainFileName
;
116 trainFileName
= Q3FileDialog::getOpenFileName( trainFileName
,
120 "Choose a training file to open" );
121 if ( trainFileName
.isEmpty() )
124 QFile
trainFile(trainFileName
);
126 m_lexicon
->DCNsylTrainCorpus
= new corpussyl
;
127 m_lexicon
->DCNsylTrainCorpus
->readInput(trainFile
);
128 m_lexicon
->isDCNtrainRead
= true;
132 // opens the testing corpus
133 void LinguisticaMainWindow::DCNsylFindTestSlot()
135 QString testFileName
;
137 testFileName
= Q3FileDialog::getOpenFileName( testFileName
,
141 "Choose a test file to open" );
142 if ( testFileName
.isEmpty() )
145 QFile
testFile(testFileName
);
147 m_lexicon
->DCNsylTestCorpus
= new corpussyl
;
148 m_lexicon
->DCNsylTestCorpus
->readInput(testFile
); // testFile
149 m_lexicon
->isDCNtestRead
= true;
152 // trains the network.
153 void LinguisticaMainWindow::DCNsylTrainSlot()
155 if (!(m_lexicon
->isDCNtrainRead
&& m_lexicon
->isDCNtestRead
))
157 QMessageBox::information( this, "Linguistica DCN Syllabification",
158 "Unable to access the Training and Test corpera.\n"
159 "Please select the corresponding corpera with the \"Find Training Corpus\" and "
160 "\"Find Testing Corpus\" buttons." );
163 learningsyl DCNlearn
;
164 DCNlearn
.setCorpus(*m_lexicon
->DCNsylTrainCorpus
);
167 DCNlearn
.TfromUser
= TLineS
->text().toFloat();
168 DCNlearn
.increaseWhenWrong
= iwwLineS
->text().toFloat();
169 DCNlearn
.decreaseWhenRight
= dwrLineS
->text().toFloat();
170 DCNlearn
.numberOfTries
= trialsLineS
->text().toInt();
171 DCNlearn
.cutoffFromUser
= cutoffLineS
->text().toInt();
173 DCNlearn
.startingAlpha
= sAlphaLineS
->text().toFloat();
174 DCNlearn
.startingBeta
= sBetaLineS
->text().toFloat();
176 DCNlearn
.run(status_display());
179 if (!DCNlearn
.isSuccessful())
181 QMessageBox::warning( this, "Linguistica DCN Syllabification",
182 "Sorry, the training algorithm was unsuccessful." );
186 QMessageBox::information( this, "Linguistica DCN Syllabification",
187 "The training algorithm was successful!" );
189 grammarsyl
* gram
= DCNlearn
.returnGrammar();
190 grammarOutputS
->setText(gram
->print());
191 corpusOutputS
->setText(m_lexicon
->DCNsylTestCorpus
->printCorpus(gram
));