本文整理汇总了Java中ai.api.model.AIRequest.setQuery方法的典型用法代码示例。如果您正苦于以下问题:Java AIRequest.setQuery方法的具体用法?Java AIRequest.setQuery怎么用?Java AIRequest.setQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ai.api.model.AIRequest
的用法示例。
在下文中一共展示了AIRequest.setQuery方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: legacySpeechTest
import ai.api.model.AIRequest; //导入方法依赖的package包/类
@Test
public void legacySpeechTest() throws MalformedURLException, AIServiceException {
final AIConfiguration config = new AIConfiguration(
"3485a96fb27744db83e78b8c4bc9e7b7",
AIConfiguration.SupportedLanguages.English);
config.setProtocolVersion(PROTOCOL_VERSION);
final SimpleProtocolTestingService aiService = new SimpleProtocolTestingService(config);
final AIRequest aiRequest = new AIRequest();
aiRequest.setQuery("hello");
prepareRequest(aiRequest, config);
final String textRequest = gson.toJson(aiRequest);
final String textResponse = aiService.doDefaultProtocolTextRequest(textRequest);
final AIResponseV20150204 aiResponse = gson.fromJson(textResponse, AIResponseV20150204.class);
assertNotNull(aiResponse);
assertEquals("Hi! How are you?", aiResponse.getResult().getSpeech());
}
示例2: legacyContextsWithoutParametersTest
import ai.api.model.AIRequest; //导入方法依赖的package包/类
@Test
public void legacyContextsWithoutParametersTest() throws AIServiceException {
final AIConfiguration config = new AIConfiguration(
"3485a96fb27744db83e78b8c4bc9e7b7",
AIConfiguration.SupportedLanguages.English,
AIConfiguration.RecognitionEngine.System);
config.setProtocolVersion(PROTOCOL_VERSION);
final AIDataService aiDataService = new AIDataService(RuntimeEnvironment.application, config);
final AIContext weatherContext = new AIContext("weather");
weatherContext.setParameters(Collections.singletonMap("location", "London"));
final List<AIContext> contexts = Collections.singletonList(weatherContext);
final AIRequest aiRequest = new AIRequest();
aiRequest.setQuery("and for tomorrow");
aiRequest.setContexts(contexts);
final AIResponse aiResponse = aiDataService.request(aiRequest);
// Old protocol doesn't support parameters, so response will not contains city name
assertEquals("Weather in for tomorrow", aiResponse.getResult().getFulfillment().getSpeech());
}
示例3: fetch
import ai.api.model.AIRequest; //导入方法依赖的package包/类
public Pair<Boolean, String> fetch() {
final AIRequest aiRequest = new AIRequest();
aiRequest.setQuery(utterance);
try {
final AIResponse response = aiDataService.request(aiRequest);
if (response != null) {
final String gsonString = new GsonBuilder().disableHtmlEscaping().create().toJson(response);
if (DEBUG) {
MyLog.i(CLS_NAME, "gsonString: " + response.toString());
}
return new Pair<>(true, gsonString);
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "response null");
}
}
} catch (final AIServiceException e) {
if (DEBUG) {
MyLog.e(CLS_NAME, "AIResponse AIServiceException");
e.printStackTrace();
}
}
return new Pair<>(false, null);
}
示例4: resetContexts
import ai.api.model.AIRequest; //导入方法依赖的package包/类
/**
* Forget all old contexts
*
* @return true if operation succeed, false otherwise
*/
@Deprecated
public boolean resetContexts() {
final AIRequest cleanRequest = new AIRequest();
cleanRequest.setQuery("empty_query_for_resetting_contexts"); // TODO remove it after protocol
// fix
cleanRequest.setResetContexts(true);
try {
final AIResponse response = request(cleanRequest);
return !response.isError();
} catch (final AIServiceException e) {
logger.error("Exception while contexts clean.", e);
return false;
}
}
示例5: legacyContextsTest
import ai.api.model.AIRequest; //导入方法依赖的package包/类
@Test
public void legacyContextsTest() {
final AIConfiguration config = new AIConfiguration(
"3485a96fb27744db83e78b8c4bc9e7b7",
AIConfiguration.SupportedLanguages.English);
config.setProtocolVersion(null);
final SimpleProtocolTestingService aiDataService = new SimpleProtocolTestingService(config);
try {
final AIRequest aiRequest = new AIRequest();
aiRequest.setQuery("weather");
prepareRequest(aiRequest, config);
final String textRequest = gson.toJson(aiRequest);
final String textResponse = aiDataService.doDefaultProtocolTextRequest(textRequest);
final AIResponseDefault aiResponse = gson.fromJson(textResponse, AIResponseDefault.class);
assertFalse(StringUtils.isEmpty(aiResponse.getResult().getResolvedQuery()));
assertEquals("showWeather", aiResponse.getResult().getAction());
final String[] contexts = aiResponse.getResult().getMetadata().getContexts();
assertNotNull(contexts);
boolean contextLoaded = false;
for (int i = 0; i < contexts.length; i++) {
if ("weather".equalsIgnoreCase(contexts[i])) {
contextLoaded = true;
}
}
assertTrue(contextLoaded);
} catch (final AIServiceException | MalformedURLException e) {
e.printStackTrace();
assertTrue(e.getMessage(), false);
}
}
示例6: onResults
import ai.api.model.AIRequest; //导入方法依赖的package包/类
@TargetApi(14)
@Override
public void onResults(final Bundle results) {
if (recognitionActive) {
final ArrayList<String> recognitionResults = results
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
float[] rates = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
rates = results.getFloatArray(SpeechRecognizer.CONFIDENCE_SCORES);
}
if (recognitionResults == null || recognitionResults.isEmpty()) {
// empty response
GoogleRecognitionServiceImpl.this.onResult(new AIResponse());
} else {
final AIRequest aiRequest = new AIRequest();
if (rates != null) {
aiRequest.setQuery(recognitionResults.toArray(new String[recognitionResults.size()]), rates);
} else {
aiRequest.setQuery(recognitionResults.get(0));
}
// notify listeners about the last recogntion result for more accurate user feedback
GoogleRecognitionServiceImpl.this.onPartialResults(recognitionResults);
GoogleRecognitionServiceImpl.this.sendRequest(aiRequest, requestExtras);
}
}
stopInternal();
}