From 25e59e3885af4a342878351ece3ddd8a753918d5 Mon Sep 17 00:00:00 2001 From: Matthias Schoepfer <mschoepf@techfak.uni-bielefeld.de> Date: Wed, 12 Jun 2013 15:20:10 +0200 Subject: [PATCH] ongoing work --- .../nbproject/private/configurations.xml | 39 ++++++++++++++ pocketsphinxAdapter/src/JsgfParser.cpp | 6 +-- pocketsphinxAdapter/src/JsgfParser.h | 53 +++++++++++++++---- pocketsphinxAdapter/src/dynamicParser.h | 12 +++++ pocketsphinxAdapter/src/simple.jsgf | 5 +- 5 files changed, 100 insertions(+), 15 deletions(-) diff --git a/pocketsphinxAdapter/nbproject/private/configurations.xml b/pocketsphinxAdapter/nbproject/private/configurations.xml index 37f2755f..c07ff778 100644 --- a/pocketsphinxAdapter/nbproject/private/configurations.xml +++ b/pocketsphinxAdapter/nbproject/private/configurations.xml @@ -25,7 +25,45 @@ <in>moc_measureDb.cxx</in> </df> </df> + <df name="cmake"> + <df name="Modules"> + </df> + </df> + <df name="CMakeFiles"> + <df name="2.8.10.2"> + <df name="CompilerIdC"> + <in>CMakeCCompilerId.c</in> + </df> + <df name="CompilerIdCXX"> + <in>CMakeCXXCompilerId.cpp</in> + </df> + </df> + <df name="CMakeTmp"> + </df> + <df name="CompilerIdC"> + <in>CMakeCCompilerId.c</in> + </df> + <df name="CompilerIdCXX"> + <in>CMakeCXXCompilerId.cpp</in> + </df> + <df name="Progress"> + </df> + </df> <df name="src"> + <df name="CMakeFiles"> + <df name="jsgfParser.dir"> + </df> + <df name="jsgfParserTest.dir"> + </df> + <df name="measureAlsaDb.dir"> + </df> + <df name="measureDb.dir"> + </df> + <df name="parserToyExample.dir"> + </df> + <df name="pocketsphinxAdapter.dir"> + </df> + </df> <in>AlsaMicGrabber.cpp</in> <in>AlsaMicGrabber.h</in> <in>EqualizerColorWidget.cpp</in> @@ -61,6 +99,7 @@ <in>moc_SimpleDoubleThresholdSegmenter.cxx</in> <in>moc_SimpleTextAddField.cxx</in> <in>moc_measureDb.cxx</in> + <in>moc_pocketsphinxAdapter.cxx</in> </df> <in>pocketsphinxAdapterConfig.h</in> </df> diff --git a/pocketsphinxAdapter/src/JsgfParser.cpp b/pocketsphinxAdapter/src/JsgfParser.cpp index 217fe1b9..852fdc37 100644 --- a/pocketsphinxAdapter/src/JsgfParser.cpp +++ b/pocketsphinxAdapter/src/JsgfParser.cpp @@ -103,15 +103,15 @@ main(int argc, char** argv) { while (0 != st.compare("")) { getline(std::cin,st); - std::vector<std::string> attr; + std::string attr; //std::cin >> st; bool dynSucc = boost::spirit::qi::phrase_parse(st.begin(),st.end(), myDynamicParser, boost::spirit::qi::ascii::space,attr); if (dynSucc) { - std::cout << "'" << st << "' parsed successfully (" << attr.at(0) << ")" << std::endl; + std::cout << "'" << st << "' parsed successfully (" << attr << ")" << std::endl; } else - std::cout << "'" << st << "' not part of the grammar (" << attr.at(0) << ")" << std::endl; + std::cout << "'" << st << "' not part of the grammar (" << attr << ")" << std::endl; } return 0; } \ No newline at end of file diff --git a/pocketsphinxAdapter/src/JsgfParser.h b/pocketsphinxAdapter/src/JsgfParser.h index 48f5bef6..804b377c 100644 --- a/pocketsphinxAdapter/src/JsgfParser.h +++ b/pocketsphinxAdapter/src/JsgfParser.h @@ -101,6 +101,15 @@ BOOST_FUSION_ADAPT_STRUCT( namespace jsgfParserTypes { + /*void addLastNRules (std::vector<ruleTPtr> &rules, std::vector<ruleTPtr>::size_type diff) + { + std::vector<ruleTPtr>::size_type size = rules.size(); + switch (diff) + { + case 1: if (rules.at(size-1).) + } + }*/ + void fun() { std::cout << "fun called" << std::endl; } @@ -261,16 +270,10 @@ namespace jsgfParserTypes { std::vector<ruleTPtr> temp = myRules; TermTRuleGenerator myGenerator (myRules,myNamesToRules, myNonterminal); myGenerator(t); - std::vector<ruleTPtr>::size_type sizeDiff = myRules.size() - temp.size(); - - switch (sizeDiff) { - case 0: std::cout << "sizeDiff 0 " << std::endl;break; - case 1: std::cout << "sizeDiff 1 " << std::endl;break; - case 2: std::cout << "sizeDiff 2 " << std::endl;myRules.push_back(new ruleT ((*myRules.at(myRules.size()-1)) | (*myRules.at(myRules.size()-2)))); - } + } void operator()(TermLeafT & tl) const - { + { for (std::vector<jsgfParserTypes::SymbolT>::size_type i=0; i < tl.symbols.size(); i++) { if (0 == tl.symbols.at(i).type) @@ -293,6 +296,34 @@ namespace jsgfParserTypes { } } } + std::vector<ruleTPtr>::size_type lastElement = myRules.size()-1; + switch (tl.symbols.size()) + { + case 0: break; + case 1: if (tl.optional) + myRules.push_back(new ruleT ((*myRules.at(lastElement)) | qi::eps)); + break; + case 2: + if (tl.optional) + myRules.push_back(new ruleT (((*myRules.at(lastElement-1)) > (*myRules.at(lastElement)))[qi::_val = px::val('[') + qi::_1 + px::val('>') + qi::_2 + px::val(']')]| qi::eps)); + else + myRules.push_back(new ruleT (((*myRules.at(lastElement-1)) > (*myRules.at(lastElement)))[qi::_val = qi::_1 + px::val('>') + qi::_2])); + break; + case 3: + if (tl.optional) + myRules.push_back(new ruleT (((*myRules.at(lastElement-2)) >(*myRules.at(lastElement-1)) > (*myRules.at(lastElement)))[qi::_val = px::val('[') + qi::_1 + px::val('>') + qi::_2 +px::val('>') + qi::_3 + px::val(']')] | qi::eps)); + else + myRules.push_back(new ruleT (((*myRules.at(lastElement-2)) > (*myRules.at(lastElement-1)) > (*myRules.at(lastElement)))[qi::_val = qi::_1 + px::val('>') + qi::_2 + px::val('>') + qi::_3 ])); + break; + case 4: + if (tl.optional) + myRules.push_back(new ruleT (((*myRules.at(lastElement-3)) > (*myRules.at(lastElement-2)) >(*myRules.at(lastElement-1)) > (*myRules.at(lastElement)))[qi::_val = px::val(myNonterminal)+ px::val('+') + qi::_1] | qi::eps)); + else + myRules.push_back(new ruleT (((*myRules.at(lastElement-3)) >(*myRules.at(lastElement-2)) > (*myRules.at(lastElement-1)) > (*myRules.at(lastElement)))[qi::_val = px::val(myNonterminal)+ px::val('+') + qi::_1])); + break; + default: + std::cout << "PLEASE EXTEND ME RIGHT HERE" << std::endl; + } } std::vector<ruleTPtr> &myRules; nameToRuleT &myNamesToRules; @@ -437,16 +468,18 @@ public: for (std::vector<jsgfParserTypes::TermT>::size_type j=0;j < grammar.rules.at(i-1).RHS.size();j++) { myRuleGenerator(grammar.rules.at(i-1).RHS.at(j)); } - std::vector<jsgfParserTypes::ruleTPtr>::size_type sizeDiff = myRuleVector.size() - tempRuleVector.size(); - switch (sizeDiff) + //std::vector<jsgfParserTypes::ruleTPtr>::size_type sizeDiff = myRuleVector.size() - tempRuleVector.size(); + switch (grammar.rules.at(i-1).RHS.size()) { case 0: std::cout << "Empty Rule?!" << std::endl;break; case 1: std::cout << "Adding 1 Rule to " << grammar.rules.at(i-1).name << std::endl; myRuleVector.at(increment) = new jsgfParserTypes::ruleT ( *myRuleVector.at(myRuleVector.size()-1));break; case 2: std::cout << "Adding 2 Rules to " << grammar.rules.at(i-1).name << std::endl; myRuleVector.at(increment) = new jsgfParserTypes::ruleT ( *myRuleVector.at(myRuleVector.size()-1) | *myRuleVector.at(myRuleVector.size()-2)); + break; case 3: std::cout << "Adding 3 Rules to " << grammar.rules.at(i-1).name << std::endl; myRuleVector.at(increment) = new jsgfParserTypes::ruleT ( *myRuleVector.at(myRuleVector.size()-1) | *myRuleVector.at(myRuleVector.size()-2) | *myRuleVector.at(myRuleVector.size()-3)); + break; } myRuleVector.at(increment)->name(grammar.rules.at(i-1).name); increment--; diff --git a/pocketsphinxAdapter/src/dynamicParser.h b/pocketsphinxAdapter/src/dynamicParser.h index 48538929..3f8652b6 100644 --- a/pocketsphinxAdapter/src/dynamicParser.h +++ b/pocketsphinxAdapter/src/dynamicParser.h @@ -23,9 +23,21 @@ struct dynamicParser : qi::grammar<Iterator,std::string(), boost::spirit::ascii: rulestack = rules; startRule = *(rulestack.at(0)); std::cout << "Startrule name: " << startRule.name() << std::endl; + qi::on_error<qi::fail> + ( + startRule + , std::cout + << px::val("Error! Expecting ") + << qi::_4 // what failed? + << px::val(" here: \"") + << px::construct<std::string>(qi::_3, qi::_2) // iterators to error-pos, end + << px::val("\"") + << std::endl + ); } std::vector<qi::rule<Iterator,std::string(),qi::ascii::space_type>* > rulestack; qi::rule<Iterator,std::string(), qi::ascii::space_type> startRule; + }; diff --git a/pocketsphinxAdapter/src/simple.jsgf b/pocketsphinxAdapter/src/simple.jsgf index c4f3611f..2efbf37a 100644 --- a/pocketsphinxAdapter/src/simple.jsgf +++ b/pocketsphinxAdapter/src/simple.jsgf @@ -1,5 +1,6 @@ #JSGF V1.0; grammar ToBI_GPR; -public <task> = this is a task | this is not a task | <huhu>; +public <task> = [bitte] (hello <world> | <nochwas> | bla <huhu>); <huhu> = random | <nochwas>; -<nochwas> = nochwas; \ No newline at end of file +<nochwas> = nochwas; +<world> = world | bielefeld; \ No newline at end of file -- GitLab