• R/O
  • SSH
  • HTTPS

hands-free: 提交


Commit MetaInfo

修订版66 (tree)
时间2011-05-22 14:51:17
作者(del#42492)

Log Message

計算機のサンプルを簡単にした。
段階を踏むことにした。

更改概述

差异

--- trunk/main/app/sample/calculator/main.cpp (revision 65)
+++ trunk/main/app/sample/calculator/main.cpp (nonexistent)
@@ -1,76 +0,0 @@
1-#include <spcf/core/Controller.hpp>
2-#include <spcf/core/Engine.hpp>
3-#include <spcf/core/GrammarPhrase.hpp>
4-#include <spcf/core/GrammarTransition.hpp>
5-#include <spcf/engine-factory/EngineFactory.hpp>
6-#include <spcf/grammar/GrammarCommonImpl.hpp>
7-#include <spcf/grammar/NumericalGrammar.hpp>
8-#include <spcf/processor/DefaultProcessor.hpp>
9-#include <spcf/view/StdoutView.hpp>
10-
11-using namespace spcf;
12-using namespace std;
13-
14-class OperatorGrammar : public GrammarCommonImpl {
15-public:
16- OperatorGrammar(const string& name = "operator") : GrammarCommonImpl(name) {
17- addGrammarTransition("たす", "operator", "+", Grammar::START_STATE_NAME, Grammar::FINISH_STATE_NAME);
18- addGrammarTransition("ひく", "operator", "-", Grammar::START_STATE_NAME, Grammar::FINISH_STATE_NAME);
19- addGrammarTransition("かける", "operator", "*", Grammar::START_STATE_NAME, Grammar::FINISH_STATE_NAME);
20- addGrammarTransition("わる", "operator", "/", Grammar::START_STATE_NAME, Grammar::FINISH_STATE_NAME);
21- }
22-};
23-
24-class CalculatorGrammar : public GrammarCommonImpl {
25-public:
26- CalculatorGrammar() : GrammarCommonImpl("calculator") {
27- Grammar::State s1("s1");
28- Grammar::State s2("s2");
29- Grammar::State s3("s3");
30- Grammar::State s4("s4");
31- NumericalGrammar n1("n1");
32- NumericalGrammar n2("n2");
33- NumericalGrammar n3("n3");
34- NumericalGrammar n4("n4");
35- NumericalGrammar n5("n5");
36- OperatorGrammar o1("o1");
37- OperatorGrammar o2("o2");
38-
39- addGrammarTransition("かっこ", "parentesis", "open", Grammar::START_STATE_NAME, s1);
40- addGrammarTransition("かっこ", "parentesis", "open", s3, s1);
41-
42- addGrammarTransition(n1, Grammar::START_STATE_NAME, s2);
43- addGrammarTransition(n2, Grammar::START_STATE_NAME, Grammar::FINISH_STATE_NAME);
44- addGrammarTransition(n3, s1, s2);
45- addGrammarTransition(n4, s3, s2);
46- addGrammarTransition(n5, s3, s2);
47-
48- addGrammarTransition(o1, s2, s3);
49- addGrammarTransition(o2, s4, s3);
50-
51- addGrammarTransition("かっこ閉じ", "parentesis", "close", s2, s4);
52- addGrammarTransition("かっこ閉じ", "parentesis", "close", s4, s4);
53- addGrammarTransition("かっこ閉じ", "parentesis", "close", s2, Grammar::FINISH_STATE_NAME);
54- }
55-};
56-
57-class CalculatorProcessor : public DefaultProcessor {
58-public:
59- void start(Context& context) {
60- getController().getEngine()->addGrammar(GrammarPtr(new CalculatorGrammar()));
61- }
62-
63- void recognized(Context& context, Recognition& recognition) {
64- getController().stop();
65- }
66-};
67-
68-int main() {
69- Controller controller;
70- controller.setEngine(EngineFactory::getEngine(EngineFactory::SAPI_ENGINE));
71- controller.setProcessor(ProcessorPtr(new CalculatorProcessor()));
72- controller.setView(ViewPtr(new StdoutView()));
73- controller.start();
74-
75- return 0;
76-}
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
--- trunk/main/app/sample/calculator1/main.cpp (nonexistent)
+++ trunk/main/app/sample/calculator1/main.cpp (revision 66)
@@ -0,0 +1,106 @@
1+#include <spcf/core/Controller.hpp>
2+#include <spcf/core/Engine.hpp>
3+#include <spcf/core/GrammarPhrase.hpp>
4+#include <spcf/core/GrammarTransition.hpp>
5+#include <spcf/core/Recognition.hpp>
6+#include <spcf/core/RecognitionProperty.hpp>
7+#include <spcf/engine-factory/EngineFactory.hpp>
8+#include <spcf/grammar/GrammarCommonImpl.hpp>
9+#include <spcf/grammar/NumeralGrammar.hpp>
10+#include <spcf/processor/DefaultProcessor.hpp>
11+#include <spcf/view/DefaultView.hpp>
12+
13+#include <iostream>
14+#include <string>
15+
16+using namespace spcf;
17+using namespace std;
18+
19+class CalculatorGrammar : public GrammarCommonImpl {
20+public:
21+ CalculatorGrammar() : GrammarCommonImpl("calculator") {
22+ Grammar::State s1("s1");
23+ Grammar::State s2("s2");
24+
25+ addGrammarTransition("いち", "number1", 1, Grammar::START_STATE_NAME, s1);
26+ addGrammarTransition("に", "number1", 2, Grammar::START_STATE_NAME, s1);
27+ addGrammarTransition("さん", "number1", 3, Grammar::START_STATE_NAME, s1);
28+ addGrammarTransition("よん", "number1", 4, Grammar::START_STATE_NAME, s1);
29+ addGrammarTransition("しー", "number1", 4, Grammar::START_STATE_NAME, s1);
30+ addGrammarTransition("ごー", "number1", 5, Grammar::START_STATE_NAME, s1);
31+ addGrammarTransition("ろく", "number1", 6, Grammar::START_STATE_NAME, s1);
32+ addGrammarTransition("なな", "number1", 7, Grammar::START_STATE_NAME, s1);
33+ addGrammarTransition("しち", "number1", 7, Grammar::START_STATE_NAME, s1);
34+ addGrammarTransition("はち", "number1", 8, Grammar::START_STATE_NAME, s1);
35+ addGrammarTransition("きゅう", "number1",9, Grammar::START_STATE_NAME, s1);
36+
37+ addGrammarTransition("たす", "operator", "+", s1, s2);
38+ addGrammarTransition("ひく", "operator", "-", s1, s2);
39+ addGrammarTransition("かける", "operator", "*", s1, s2);
40+ addGrammarTransition("わる", "operator", "/", s1, s2);
41+
42+ addGrammarTransition("いち", "number2", 1, s2, Grammar::FINISH_STATE_NAME);
43+ addGrammarTransition("に", "number2", 2, s2, Grammar::FINISH_STATE_NAME);
44+ addGrammarTransition("さん", "number2", 3, s2, Grammar::FINISH_STATE_NAME);
45+ addGrammarTransition("よん", "number2", 4, s2, Grammar::FINISH_STATE_NAME);
46+ addGrammarTransition("しー", "number2", 4, s2, Grammar::FINISH_STATE_NAME);
47+ addGrammarTransition("ごー", "number2", 5, s2, Grammar::FINISH_STATE_NAME);
48+ addGrammarTransition("ろく", "number2", 6, s2, Grammar::FINISH_STATE_NAME);
49+ addGrammarTransition("なな", "number2", 7, s2, Grammar::FINISH_STATE_NAME);
50+ addGrammarTransition("しち", "number2", 7, s2, Grammar::FINISH_STATE_NAME);
51+ addGrammarTransition("はち", "number2", 8, s2, Grammar::FINISH_STATE_NAME);
52+ addGrammarTransition("きゅう", "number2",9, s2, Grammar::FINISH_STATE_NAME);
53+ }
54+};
55+
56+class CalculatorProcessor : public DefaultProcessor {
57+public:
58+ void start(Context& context) {
59+ getController().getEngine()->addGrammar(GrammarPtr(new CalculatorGrammar()));
60+ }
61+
62+ void recognized(Context& context, Recognition& recognition) {
63+ getController().stop();
64+ }
65+};
66+
67+class CalculatorView : public DefaultView {
68+ void start(Context& context) {
69+ cout << "start";
70+ }
71+
72+ void soundStarted(Context& context) {
73+ cout << "soundStarted";
74+ }
75+
76+ void soundStoped(Context& context) {
77+ cout << "soundStoped";
78+ }
79+
80+ void recognized(Context& context, Recognition& recognition) {
81+ int number1 = recognition.getProperty("number1")->getInt();
82+ string op = recognition.getProperty("operator")->getString();
83+ int number2 = recognition.getProperty("number2")->getInt();
84+
85+ cout << number1 << op << number2 << "=";
86+ if (op== "+") {
87+ cout << number1 + number2;
88+ } else if (op == "-") {
89+ cout << number1 - number2;
90+ } else if (op == "*") {
91+ cout << number1 * number2;
92+ } else if (op == "/") {
93+ cout << (double(number1) / double(number2));
94+ }
95+ }
96+};
97+
98+int main() {
99+ Controller controller;
100+ controller.setEngine(EngineFactory::getEngine(EngineFactory::SAPI_ENGINE));
101+ controller.setProcessor(ProcessorPtr(new CalculatorProcessor()));
102+ controller.setView(ViewPtr(new CalculatorView()));
103+ controller.start();
104+
105+ return 0;
106+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Show on old repository browser