1 // Implementation of networksyl methods
2 // Copyright © 2009 The University of Chicago
3 #include "DCNnetworksyl.h"
9 //////////////////////////////////////////////////////////////////////
10 // Construction/Destruction
11 //////////////////////////////////////////////////////////////////////
13 networksyl::networksyl()
18 networksyl::~networksyl()
25 void networksyl::setGrammar(grammarsyl
* theGrammar
)
27 this->theGrammar
= theGrammar
;
30 void networksyl::setWord(QString word
)
36 void networksyl::equilibrium()
38 //definitions of network values
39 float alpha
= theGrammar
->getAlpha();
40 float beta
= theGrammar
->getBeta();
44 // the following is the meat of DCNs
46 // oldIteration lets us know when we've converged
47 // also initialize node[] and sonority[]
48 float* oldIteration
= new float[syl
];
49 node
= new float[syl
];
50 sonority
= new float[syl
];
51 for (int i
= 0; i
< syl
; i
++)
53 oldIteration
[i
] = -2.0;
55 sonority
[i
] = theGrammar
->getSonority(word
.at(i
));
59 // the DCN goes for 255 cylces before giving up
60 for (int cycle
= 0; cycle
< 256; cycle
++)
63 for (int s
= 0; s
< syl
; s
++)
66 node
[s
] = alpha
* node
[s
+1] + sonority
[s
];
68 node
[s
] = beta
* node
[s
-1] + sonority
[s
];
70 node
[s
] = beta
* node
[s
-1] + alpha
* node
[s
+1] + sonority
[s
];
73 //calculate the distance
75 for (int i
= 0; i
< syl
; i
++)
76 distance
+= ((node
[i
] - oldIteration
[i
]) * (node
[i
] - oldIteration
[i
]));
78 //has the network converged?
79 float DELTA
= 0.0001f
;
86 //store this iteration as old iteration
87 for (int j
= 0; j
< syl
; j
++)
88 oldIteration
[j
] = node
[j
];
90 //last cycle, the network has failed to converge
95 delete[] oldIteration
;
99 void networksyl::print(QLabel
* label
)
101 //definitions of network values
102 float alpha
= theGrammar
->getAlpha();
103 float beta
= theGrammar
->getBeta();
104 int syl
= syllable();
107 QTextStream
s(&totalString
, QIODevice::Append
);
109 s
<< "The values of the grammar:\n";
110 s
<< "\talpha:\t\t" << alpha
<< '\n';
111 s
<< "\tbeta:\t\t" << beta
<< '\n';
113 s
<< "The value of the nodes:\n";
114 s
<< "\tletter\t\tinherant sonority\t\tderived sonority\n";
116 for (int i
= 0; i
< syl
; i
++) {
117 s
<< "\t" << word
.at(i
) << "\t\t";
118 s
<< sonority
[i
] << " \t\t\t";
119 s
<< node
[i
] << "\n";
124 s
<< "The syllabification of the word is:\t\t";
128 s
<< "not converged!";
130 label
->setText(totalString
);
133 // a complicated printing function
134 QString
networksyl::sylPrintout() {
136 QTextStream
out(&output
, QIODevice::Append
);
140 int syl
= syllable();
144 for (int r
= 1; r
< syl
; ++r
) {
145 if (node
[r
-1] < node
[r
]) {
153 out
<< word
.at(word
.length()-1) << "\t\n\n";
155 out
<< "phonemes:\t\t";
157 for (int w
= 1; w
< syl
; ++w
)
158 out
<< word
.at(w
-1) << "\t";
160 out
<< word
.at(word
.length()-1) << "\t\n\n";
162 out
<< "min/max/other:\t\t";
164 for (int s
= 0; s
< syl
; ++s
) {
166 if (node
[s
] > node
[s
+1])
168 else if (node
[s
] < node
[s
+1])
172 } else if (s
== syl
-1) {
173 if (node
[s
] > node
[s
-1])
175 else if (node
[s
] < node
[s
-1])
180 if ((node
[s
] > node
[s
-1]) && (node
[s
] > node
[s
+1]))
182 else if ((node
[s
] < node
[s
-1]) && (node
[s
] < node
[s
+1]))
190 out
<< "upward/downward:\t";
192 for (int t
= 1; t
< syl
; ++t
) {
193 if (node
[t
-1] < node
[t
])
200 out
<< "onset/nucleus/coda:\t";
203 for (int q
= 0; q
< syl
; ++q
) {
205 if (node
[q
] > node
[q
+1]) {
208 } else /* if (node[q] < node[q+1])*/
210 } else if (q
== syl
-1) {
211 if (node
[q
] > node
[q
-1]) {
214 } else /* if (node[q] < node[q-1])*/
217 if ((node
[q
] > node
[q
-1]) && (node
[q
] > node
[q
+1])) {
220 } else if ((node
[q
] < node
[q
-1]) && (node
[q
] < node
[q
+1])) {
236 QString
networksyl::getMaxima() const
239 QTextStream
out(&output
, QIODevice::Append
);
242 for (int s
= 0; s
< syllable(); ++s
) {
244 if (node
[s
] > node
[s
+1])
246 else if (node
[s
] < node
[s
+1])
250 } else if (s
== syllable()-1) {
251 if (node
[s
] > node
[s
-1])
253 else if (node
[s
] < node
[s
-1])
258 if ((node
[s
] > node
[s
-1]) && (node
[s
] > node
[s
+1]))
260 else if ((node
[s
] < node
[s
-1]) && (node
[s
] < node
[s
+1]))
270 QString
networksyl::getSyllabifiedWord() const
273 QTextStream
out(&output
, QIODevice::Append
);
277 for (int r
= 1; r
< syllable(); r
++) {
278 if (node
[r
-1] < node
[r
]) {
286 out
<< word
.at(word
.length()-1);