当前位置: 首页>>代码示例>>Java>>正文


Java AIRequest类代码示例

本文整理汇总了Java中ai.api.model.AIRequest的典型用法代码示例。如果您正苦于以下问题:Java AIRequest类的具体用法?Java AIRequest怎么用?Java AIRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AIRequest类属于ai.api.model包,在下文中一共展示了AIRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: voiceRequest

import ai.api.model.AIRequest; //导入依赖的package包/类
/**
 * @see AIDataService#voiceRequest(InputStream, RequestExtras, AIServiceContext)
 */
@Override
public AIResponse voiceRequest(InputStream voiceStream, RequestExtras requestExtras,
		AIServiceContext serviceContext) throws AIServiceException {
	
  RecognizeResponse response;
	try {
	    SpeechClient speechClient = SpeechClient.create();
		RecognitionAudio recognitionAudio = createRecognitionAudio(voiceStream);

        response = speechClient.recognize(config.getRecognitionConfig(), recognitionAudio);
	} catch (IOException | StatusRuntimeException e) {
		throw new AIServiceException("Failed to recognize speech", e);
	}
	if ((response.getResultsCount() == 0) || (response.getResults(0).getAlternativesCount() == 0)) {
		throw new AIServiceException("No speech");
	}
	String transcript = response.getResults(0).getAlternatives(0).getTranscript();
	AIRequest request = new AIRequest(transcript);
	return request(request, requestExtras, serviceContext);
}
 
开发者ID:dialogflow,项目名称:dialogflow-java-client,代码行数:24,代码来源:GcpAIDataService.java

示例2: 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());
}
 
开发者ID:dialogflow,项目名称:dialogflow-java-client,代码行数:23,代码来源:V20150204ProtocolTest.java

示例3: 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());

}
 
开发者ID:dialogflow,项目名称:dialogflow-android-client,代码行数:27,代码来源:V20150415ProtocolTest.java

示例4: sendRequest

import ai.api.model.AIRequest; //导入依赖的package包/类
private void sendRequest(Message message, String request) {
    try {
        AIResponse response = service.request(new AIRequest(request));

        String action = response.getResult().getAction();
        AvaIre.getLogger().info(ACTION_OUTPUT
            .replace("%action%", action)
            .replace("%author%", generateUsername(message))
            .replace("%server%", generateServer(message))
            .replace("%channel%", generateChannel(message))
            .replace("%message%", message.getRawContent())
            .replace("%response%", response.getResult().getFulfillment().getSpeech())
        );

        if (response.getStatus().getCode() != 200) {
            MessageFactory.makeError(message, response.getStatus().getErrorDetails()).queue();
            return;
        }

        for (Map.Entry<IntentAction, Intent> entry : INTENTS.entrySet()) {
            if (entry.getKey().isWildcard() && action.startsWith(entry.getKey().getAction())) {
                invokeIntent(message, response, entry.getValue());
                return;
            }

            if (entry.getKey().getAction().equals(action)) {
                invokeIntent(message, response, entry.getValue());
                return;
            }
        }
    } catch (AIServiceException e) {
        e.printStackTrace();
    }
}
 
开发者ID:avaire,项目名称:avaire,代码行数:35,代码来源:IntelligenceManager.java

示例5: 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);
    }
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:34,代码来源:RemoteAPIAI.java

示例6: copyTo

import ai.api.model.AIRequest; //导入依赖的package包/类
public void copyTo(final AIRequest request) {
    if (hasContexts()) {
        request.setContexts(getContexts());
    }

    if (hasEntities()) {
        request.setEntities(getEntities());
    }

    if (getResetContexts() != null) {
        request.setResetContexts(getResetContexts());
    }

}
 
开发者ID:dialogflow,项目名称:dialogflow-java-client,代码行数:15,代码来源:RequestExtras.java

示例7: 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;
  }
}
 
开发者ID:dialogflow,项目名称:dialogflow-java-client,代码行数:20,代码来源:AIDataService.java

示例8: fillRequest

import ai.api.model.AIRequest; //导入依赖的package包/类
private void fillRequest(final AIRequest request, final RequestExtras requestExtras) {
  assert request != null;
  assert requestExtras != null;
  if (requestExtras.hasContexts()) {
    request.setContexts(requestExtras.getContexts());
  }

  if (requestExtras.hasEntities()) {
    request.setEntities(requestExtras.getEntities());
  }

  if (requestExtras.getLocation() != null) {
    request.setLocation(requestExtras.getLocation());
  }
}
 
开发者ID:dialogflow,项目名称:dialogflow-java-client,代码行数:16,代码来源:AIDataService.java

示例9: 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);
    }
}
 
开发者ID:dialogflow,项目名称:dialogflow-java-client,代码行数:40,代码来源:DefaultProtocolTest.java

示例10: testOriginalRequest

import ai.api.model.AIRequest; //导入依赖的package包/类
@Test
public void testOriginalRequest() throws AIServiceException {
  TestableAIDataService dataService = new TestableAIDataService();
  AIRequest request = new AIRequest();
  
  dataService.request(request);
  assertTrue(dataService.requestJsonValue.indexOf("\"originalRequest\":{}") == -1);
  
  request.setOriginalRequest(new AIOriginalRequest());
  dataService.request(request);
  assertTrue(dataService.requestJsonValue.indexOf("\"originalRequest\":{}") > 0);
}
 
开发者ID:dialogflow,项目名称:dialogflow-java-client,代码行数:13,代码来源:AIDataServiceTest.java

示例11: 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();
}
 
开发者ID:dialogflow,项目名称:dialogflow-android-client,代码行数:32,代码来源:GoogleRecognitionServiceImpl.java

示例12: textRequest

import ai.api.model.AIRequest; //导入依赖的package包/类
public AIResponse textRequest(final AIRequest request) throws AIServiceException {
    if (aiService != null) {
        return aiService.textRequest(request);
    } else {
        throw new IllegalStateException("Call initialize method before usage");
    }
}
 
开发者ID:dialogflow,项目名称:dialogflow-android-client,代码行数:8,代码来源:AIButton.java

示例13: prepareRequest

import ai.api.model.AIRequest; //导入依赖的package包/类
private void prepareRequest(final AIRequest request, final AIConfiguration config) {
    request.setLanguage(config.getApiAiLanguage());
    request.setTimezone(Calendar.getInstance().getTimeZone().getID());
}
 
开发者ID:dialogflow,项目名称:dialogflow-java-client,代码行数:5,代码来源:V20150204ProtocolTest.java

示例14: textRequest

import ai.api.model.AIRequest; //导入依赖的package包/类
public AIResponse textRequest(final AIRequest request) throws AIServiceException {
    return aiButton.textRequest(request);
}
 
开发者ID:dialogflow,项目名称:dialogflow-android-client,代码行数:4,代码来源:AIDialog.java

示例15: textRequest

import ai.api.model.AIRequest; //导入依赖的package包/类
public AIResponse textRequest(final AIRequest request) throws AIServiceException {
    return aiDataService.request(request);
}
 
开发者ID:dialogflow,项目名称:dialogflow-android-client,代码行数:4,代码来源:AIService.java


注:本文中的ai.api.model.AIRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。