Commit bebdbd89 authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Add initial phoneme parsing support

parent ae7229a6
......@@ -193,6 +193,9 @@ Phrase * CourseParser::parsePhrase(QXmlStreamReader &xml, const QUrl &path, bool
path.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path()
+ '/' + parseElement(xml, elementOk)));
ok &= elementOk;
} else if (xml.name() == "phonemes") {
parsePhonemeIds(xml, elementOk); //TODO register language phonemes at phrase
ok &= elementOk;
} else if (xml.name() == "type") {
const QString type = parseElement(xml, elementOk);
if (type == "word") {
......@@ -227,6 +230,39 @@ Phrase * CourseParser::parsePhrase(QXmlStreamReader &xml, const QUrl &path, bool
return phrase;
}
QStringList CourseParser::parsePhonemeIds(QXmlStreamReader &xml, bool &ok)
{
QStringList ids;
ok = true;
if (xml.tokenType() != QXmlStreamReader::StartElement
&& xml.name() == "phonemes") {
qCWarning(ARTIKULATE_PARSER()) << "Expected to parse 'phonemes' element, aborting here";
ok = false;
return ids;
}
xml.readNext();
while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "phonemes")) {
xml.readNext();
if (xml.name() == "phoneme") {
while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "phoneme")) {
if (xml.tokenType() == QXmlStreamReader::StartElement) {
bool elementOk{ false };
if (xml.name() == "phonemeID") {
ids.append(parseElement(xml, elementOk));
ok &= elementOk;
} else {
qCWarning(ARTIKULATE_PARSER()) << "Skipping unknown token" << xml.name();
}
}
xml.readNext();
}
}
}
return ids;
}
QString CourseParser::parseElement(QXmlStreamReader& xml, bool &ok)
{
ok = true;
......
......@@ -28,6 +28,7 @@
class ICourse;
class Unit;
class Phrase;
class Phoneme;
class QXmlSchema;
class QJSonDocument;
class QDomDocument;
......@@ -67,6 +68,7 @@ public:
private:
static std::unique_ptr<Unit> parseUnit(QXmlStreamReader &xml, const QUrl &path, bool &ok);
static Phrase * parsePhrase(QXmlStreamReader &xml, const QUrl &path, bool &ok);
static QStringList parsePhonemeIds(QXmlStreamReader &xml, bool &ok);
static QString parseElement(QXmlStreamReader &xml, bool &ok);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment