修订版 | 64 (tree) |
---|---|
时间 | 2011-05-21 10:55:09 |
作者 | (del#42492) |
#25205
認識結果でプロパティが取得できない問題を解消した。
問題は、SAPIEngine にて文法設定時にプロパティを設定していないことだった。
@@ -8,8 +8,6 @@ | ||
8 | 8 | #ifndef _SPEECH_CONTROLLER_FRAMEWORK_SAPI_PHRASE_HPP_ |
9 | 9 | #define _SPEECH_CONTROLLER_FRAMEWORK_SAPI_PHRASE_HPP_ |
10 | 10 | |
11 | -#include "spcf/sapi/utils/PhraseProperty.hpp" | |
12 | - | |
13 | 11 | #include <atlbase.h> |
14 | 12 | #include <sphelper.h> |
15 | 13 |
@@ -18,9 +16,16 @@ | ||
18 | 16 | #include <vector> |
19 | 17 | |
20 | 18 | #include <boost/noncopyable.hpp> |
19 | +#include <boost/shared_ptr.hpp> | |
21 | 20 | |
22 | 21 | namespace spcf { |
23 | 22 | |
23 | + class GrammarPhrase; | |
24 | + typedef boost::shared_ptr<GrammarPhrase> GrammarPhrasePtr; | |
25 | + | |
26 | + class PhraseProperty; | |
27 | + typedef boost::shared_ptr<PhraseProperty> PhrasePropertyPtr; | |
28 | + | |
24 | 29 | class Phrase_i; |
25 | 30 | |
26 | 31 | /** |
@@ -34,14 +39,9 @@ | ||
34 | 39 | /** |
35 | 40 | * フレーズを構築します。 |
36 | 41 | */ |
37 | - Phrase(const std::string& phrase); | |
42 | + Phrase(const GrammarPhrasePtr& phrase); | |
38 | 43 | |
39 | 44 | /** |
40 | - * フレーズを構築します。 | |
41 | - */ | |
42 | - Phrase(const std::string& phrase, const PhraseProperty& property); | |
43 | - | |
44 | - /** | |
45 | 45 | * フレーズを破棄します。 |
46 | 46 | */ |
47 | 47 | ~Phrase(); |
@@ -55,7 +55,7 @@ | ||
55 | 55 | /** |
56 | 56 | * プロパティを取得します。 |
57 | 57 | */ |
58 | - const PhraseProperty& getProperty() const; | |
58 | + const PhrasePropertyPtr& getProperty() const; | |
59 | 59 | |
60 | 60 | public: |
61 | 61 | /** |
@@ -12,6 +12,8 @@ | ||
12 | 12 | |
13 | 13 | #include <string> |
14 | 14 | |
15 | +#include <boost/noncopyable.hpp> | |
16 | + | |
15 | 17 | namespace spcf { |
16 | 18 | |
17 | 19 | class PhraseProperty_i; |
@@ -19,7 +21,7 @@ | ||
19 | 21 | /** |
20 | 22 | * プロパティです。 |
21 | 23 | */ |
22 | - class PhraseProperty { | |
24 | + class PhraseProperty : public boost::noncopyable { | |
23 | 25 | private: |
24 | 26 | PhraseProperty_i* impl; |
25 | 27 |
@@ -32,11 +34,6 @@ | ||
32 | 34 | /** |
33 | 35 | * プロパティを構築します。 |
34 | 36 | */ |
35 | - PhraseProperty(const SPPHRASEPROPERTY* property); | |
36 | - | |
37 | - /** | |
38 | - * プロパティを構築します。 | |
39 | - */ | |
40 | 37 | PhraseProperty(const std::string& name); |
41 | 38 | |
42 | 39 | /** |
@@ -11,10 +11,13 @@ | ||
11 | 11 | |
12 | 12 | #include "spcf/sapi/utils/Phrase.hpp" |
13 | 13 | |
14 | +#include "spcf/core/GrammarPhrase.hpp" | |
14 | 15 | #include "spcf/sapi/utils/Char2WChar.hpp" |
16 | +#include "spcf/sapi/utils/PhraseProperty.hpp" | |
15 | 17 | |
16 | 18 | #include <cstring> |
17 | 19 | |
20 | +using namespace boost; | |
18 | 21 | using namespace std; |
19 | 22 | |
20 | 23 | namespace spcf { |
@@ -22,24 +25,15 @@ | ||
22 | 25 | class Phrase_i { |
23 | 26 | public: |
24 | 27 | string phrase_; |
25 | - PhraseProperty property_; | |
28 | + PhrasePropertyPtr property_; | |
26 | 29 | |
27 | 30 | public: |
28 | - Phrase_i(const string& phrase) : | |
29 | - phrase_(phrase) { | |
30 | - } | |
31 | - | |
32 | - Phrase_i(const string& phrase, const PhraseProperty& property) : | |
33 | - phrase_(phrase), property_(property) { | |
34 | - } | |
31 | + Phrase_i(const GrammarPhrasePtr& phrase); | |
35 | 32 | }; |
36 | 33 | |
37 | - Phrase::Phrase(const string& phrase) : impl(new Phrase_i(phrase)) { | |
34 | + Phrase::Phrase(const GrammarPhrasePtr& phrase) : impl(new Phrase_i(phrase)) { | |
38 | 35 | } |
39 | 36 | |
40 | - Phrase::Phrase(const string& phrase, const PhraseProperty& property) : impl(new Phrase_i(phrase, property)) { | |
41 | - } | |
42 | - | |
43 | 37 | Phrase::~Phrase() { |
44 | 38 | delete impl; |
45 | 39 | } |
@@ -48,7 +42,7 @@ | ||
48 | 42 | return impl->phrase_; |
49 | 43 | } |
50 | 44 | |
51 | - const PhraseProperty& Phrase::getProperty() const { | |
45 | + const PhrasePropertyPtr& Phrase::getProperty() const { | |
52 | 46 | return impl->property_; |
53 | 47 | } |
54 | 48 |
@@ -63,18 +57,18 @@ | ||
63 | 57 | VARIANT valBuffer; |
64 | 58 | Char2WChar valstrBuffer; |
65 | 59 | if (impl->property_) { |
66 | - nameBuffer = impl->property_.getName(); | |
60 | + nameBuffer = impl->property_->getName(); | |
67 | 61 | property.pszName = nameBuffer; |
68 | 62 | |
69 | - if (impl->property_.hasVal()) { | |
63 | + if (impl->property_->hasVal()) { | |
70 | 64 | VariantInit(&valBuffer); |
71 | 65 | V_VT(&valBuffer) = VT_I4; |
72 | - V_I4(&valBuffer) = impl->property_.getVal(); | |
66 | + V_I4(&valBuffer) = impl->property_->getVal(); | |
73 | 67 | property.vValue = valBuffer; |
74 | 68 | } |
75 | 69 | |
76 | - if (impl->property_.hasValStr()) { | |
77 | - valstrBuffer = impl->property_.getValStr(); | |
70 | + if (impl->property_->hasValStr()) { | |
71 | + valstrBuffer = impl->property_->getValStr(); | |
78 | 72 | property.pszValue = valstrBuffer; |
79 | 73 | } |
80 | 74 | } |
@@ -85,7 +79,7 @@ | ||
85 | 79 | return result; |
86 | 80 | } |
87 | 81 | |
88 | - if (impl->property_ && impl->property_.hasVal()) { | |
82 | + if (impl->property_ && impl->property_->hasVal()) { | |
89 | 83 | VariantClear(&valBuffer); |
90 | 84 | } |
91 | 85 |
@@ -92,4 +86,21 @@ | ||
92 | 86 | return S_OK; |
93 | 87 | } |
94 | 88 | |
89 | + | |
90 | + | |
91 | + Phrase_i::Phrase_i(const GrammarPhrasePtr& phrase) : | |
92 | + phrase_(phrase->getPhrase()) { | |
93 | + if (phrase->hasProperty()) { | |
94 | + if (phrase->hasPropertyInt() && phrase->hasPropertyString()) { | |
95 | + property_ = PhrasePropertyPtr(new PhraseProperty(phrase->getPhrase(), phrase->getPropertyInt(), phrase->getPropertyString())); | |
96 | + } else if (phrase->hasPropertyInt()) { | |
97 | + property_ = PhrasePropertyPtr(new PhraseProperty(phrase->getPhrase(), phrase->getPropertyInt())); | |
98 | + } else if (phrase->hasPropertyString()) { | |
99 | + property_ = PhrasePropertyPtr(new PhraseProperty(phrase->getPhrase(), phrase->getPropertyString())); | |
100 | + } else { | |
101 | + property_ = PhrasePropertyPtr(new PhraseProperty(phrase->getPhrase())); | |
102 | + } | |
103 | + } | |
104 | + } | |
105 | + | |
95 | 106 | } // namespace spcf |
@@ -164,7 +164,7 @@ | ||
164 | 164 | const GrammarTransitionPtr& transition = *i; |
165 | 165 | impl->insertStateMap(stateMap, topState, transition->getStartState()); |
166 | 166 | impl->insertStateMap(stateMap, topState, transition->getEndState()); |
167 | - Phrase(transition->getPhrase()->getPhrase()).addTransition( | |
167 | + Phrase(transition->getPhrase()).addTransition( | |
168 | 168 | impl->grammar_, stateMap.find(transition->getStartState())->second, stateMap.find(transition->getEndState())->second); |
169 | 169 | } |
170 | 170 |