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


Java Intent类代码示例

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


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

示例1: handleProgress

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
private SpeechletResponse handleProgress(IntentRequest request, Session session) {
  checkCalendarName(request, session);

  if(allSlotsFilled(request)) {
    final String title = collectSummary(request);
    final DateTime from = DateTime.parse(
        sv(request, SLOT_DATE_FROM) + "T" + sv(request, SLOT_TIME_FROM));
    final DateTime to = getTimeTo(request, from);

    final String dateFormat = messageService.de("event.new.card.content.time.format");
    session.setAttribute(SESSION_DATE_FORMAT, dateFormat);
    session.setAttribute(SESSION_FROM, from.toString(dateFormat));
    session.setAttribute(SESSION_TO, to.toString(dateFormat));

    final OutputSpeech speech = speechService.confirmNewEvent(title, from, to, request.getLocale());
    return SpeechletResponse.newDialogConfirmIntentResponse(speech);
  }

  //normally we want to delegate because we have defined the dialog into the model on alexa
  if( request.getDialogState() != DialogState.COMPLETED) {
    Intent updatedIntent = updateIntent(request.getIntent());
    return SpeechletResponse.newDialogDelegateResponse(updatedIntent);
  }

  return SpeechletResponse.newTellResponse(speechService.speechCancelNewEvent(request.getLocale()));
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:27,代码来源:NewEventSpeechlet.java

示例2: getVariable

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
private static final String getVariable(String key, Intent intent, Session session, String fallbackValue) {
    LOGGER.debug("Getting variable: [" + key + "], from slots:["
            + join(intent.getSlots().keySet(), " ")
            + "] and session: ["
            + join(session.getAttributes().keySet(), " ") + "].");

    String result = null;
    if (intent.getSlots().containsKey(key)) {
        result = intent.getSlot(key).getValue();
    } else if (session.getAttributes().containsKey(key)) {
        result = String.valueOf(session.getAttribute(key));
    }

    if (Utils.isNullOrEmpty(result)) {
        result = fallbackValue;
    }
    return result;
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:19,代码来源:IntentContext.java

示例3: onIntent

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
public SpeechletResponse onIntent(IntentRequest request, Session session) throws SpeechletException {
    LOGGER.info("onRequest requestId={}, sessionId={}", request.getRequestId(), session.getSessionId());
    // Get intent from the request object.
    Intent intent = request.getIntent();
    String intentName = (intent != null) ? intent.getName() : null;

    RequestHandlerFactory factory = GetRequestHandlerFactory.FUNCTION.apply(intentName);

    if (factory != null) {
        return factory.create(context).onRequest(request, session);
    } else {
        return new SpeechletResponseBuilder()
                .withNewPlainTextOutputSpeechOutputSpeech()
                    .withText("I don't know how to do that.")
                .endPlainTextOutputSpeechOutputSpeech()
                .build();
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:19,代码来源:RequestDispatcher.java

示例4: onIntent

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) {
    LOGGER.info("onIntent()");

    Intent intent = requestEnvelope.getRequest().getIntent();
    switch (intent.getName()) {
        case "QueryInventory":
            return handleQueryInventory(requestEnvelope);
        case "OrderWare":
            return handleOrderWare(requestEnvelope);
        case "LocateWare":
            return handleLocateWare(requestEnvelope);
        case "Quit":
            return handleQuit();
        default:
            throw new IllegalArgumentException("Unknown intent: " + intent.getName());
    }
}
 
开发者ID:qaware,项目名称:iot-hessen-amazon-echo,代码行数:19,代码来源:WarehouseSpeechlet.java

示例5: setDevice

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
private SpeechletResponse setDevice(final Intent intent, boolean enable) {
  Slot deviceSlot = intent.getSlot(DEVICE_SLOT);
  if (deviceSlot == null || deviceSlot.getValue() == null) {
    return newResponse("Gerät nicht erkannt");
  }

  try {
    Optional<SwitchDevice> dev = findDevice(deviceSlot.getValue());
    if (!dev.isPresent()) {
      return newResponse(String.format("Das Gerät %s ist mir nicht bekannt", deviceSlot.getValue()));
    }
    SwitchDevice device = dev.get();
    if (!device.isSwitch()) {
      return newResponse(String.format("%s %s ist kein Schaltgerät", toGroupName(device), deviceSlot.getValue()));
    }
    if (!device.isPresent()) {
      return newResponse(String.format("%s %s ist nicht verbunden", toGroupName(device), deviceSlot.getValue()));
    }
    service.setDeviceState(device, enable);
    boolean succeed = device.getState() == (enable ? State.ON : State.OFF);
    return newResponse("Fritz Home Switch", succeed ? "Ok" : String.format("Das Gerät %s konnte nicht geschaltet werden", deviceSlot.getValue()));
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
  }
  return newResponse("Es ist ein Fehler beim Schalten des Gerätes aufgetreten");
}
 
开发者ID:comtel2000,项目名称:fritz-home-skill,代码行数:27,代码来源:FritzHomeSpeechlet.java

示例6: getDeviceTemp

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
private SpeechletResponse getDeviceTemp(final Intent intent, final Locale locale) {
  Slot deviceSlot = intent.getSlot(DEVICE_SLOT);
  if (deviceSlot == null || deviceSlot.getValue() == null) {
    return newResponse("Gerät nicht erkannt");
  }

  try {
    Optional<SwitchDevice> dev = findDevice(deviceSlot.getValue());
    if (!dev.isPresent()) {
      return newResponse(String.format("Das Gerät %s ist mir nicht bekannt", deviceSlot.getValue()));
    }
    SwitchDevice device = dev.get();
    if (!device.isPresent()) {
      return newResponse(String.format("%s %s ist aktuell nicht verfügbar", toGroupName(device), deviceSlot.getValue()));
    }
    if (!device.isTemperature()) {
      return newResponse(String.format("%s %s hat keinen Temperatursensor", toGroupName(device), deviceSlot.getValue()));
    }
    return newResponse("Fritz Home Temperatur",
        String.format("Die Temperatur an Gerät %s beträgt %s", deviceSlot.getValue(), FritzUtils.getTemperature(locale, device.getTemperature())));
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
  }
  return newResponse("Es ist ein Fehler beim Lesen der Gerätetemperatur aufgetreten");
}
 
开发者ID:comtel2000,项目名称:fritz-home-skill,代码行数:26,代码来源:FritzHomeSpeechlet.java

示例7: updateIntent

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
private Intent updateIntent(Intent intent) {
  Map<String, Slot> slots = new HashMap<>(intent.getSlots());

  if(sv(intent, SLOT_DATE_TO) != null || sv(intent, SLOT_TIME_TO) != null) {
    if(sv(intent, SLOT_DURATION) == null) {
      Slot updatedSlot = Slot.builder()
          .withName(SLOT_DURATION)
          .withConfirmationStatus(ConfirmationStatus.NONE)
          .withValue("<placeholder>")
          .build();
      slots.put(SLOT_DURATION, updatedSlot);
    }
  }

  return Intent.builder()
      .withName(intent.getName())
      .withConfirmationStatus(intent.getConfirmationStatus())
      .withSlots(slots)
      .build();
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:21,代码来源:NewEventSpeechlet.java

示例8: inProgress_NotAllSlotsAreFilled

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
@Test
public void inProgress_NotAllSlotsAreFilled() throws CalendarWriteException {
  //given
  final Session session = Session.builder()
      .withSessionId("<session-id>")
      .build();
  final Intent intent = Intent.builder()
      .withName("<intent>")
      .withSlots(slots(
        slot("day", null)
      ))
      .build();
  final IntentRequest request = IntentRequest.builder()
      .withRequestId("<requestId>")
      .withIntent(intent)
      .withDialogState(DialogState.IN_PROGRESS)
      .build();

  //when
  final SpeechletResponse response = toTest.handleDialogAction(request, session);

  //then
  assertEquals(
      json(SpeechletResponse.newDialogDelegateResponse(intent)),
      json(response));
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:27,代码来源:NewEventSpeechletTest.java

示例9: checkCalendarName

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
private void checkCalendarName(final String calendarSlot, final String expectedCalendar) throws CalendarWriteException {
  final Intent intent = Intent.builder()
      .withName("<intent>")
      .withSlots(slots(
          slot("calendar", calendarSlot)
      ))
      .build();
  final IntentRequest request = IntentRequest.builder()
      .withRequestId("<requestId>")
      .withIntent(intent)
      .withDialogState(DialogState.IN_PROGRESS)
      .build();
  final Session session = Session.builder()
      .withSessionId("<sessionId>")
      .build();
  doReturn(new HashSet<>(Arrays.asList("Geburtstage", "Termine", "Haushalt"))).when(toTest).getCalendarNames();

  toTest.handleDialogAction(request, session);

  //then
  assertEquals(expectedCalendar, session.getAttribute(SESSION_CALENDAR));
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:23,代码来源:NewEventSpeechletTest.java

示例10: respondToIntentRequest

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
@Override
public SpeechletResponse respondToIntentRequest(IntentRequest intentReq, Session session) {
	Intent intent = intentReq.getIntent();
	String intentName = (intent != null) ? intent.getName() : null;
	SpeechletResponse response = null;
	
	if (INTENT_START.equals(intentName)) {
		response = handleStartJokeIntent(intentReq, session);
       }
	else if (INTENT_WHO_DER.equals(intentName)) {
		response = handleWhoThereIntent(intentReq, session);
       }
	else if (INTENT_DR_WHO.equals(intentName)) {
		response = handleDrWhoIntent(intentReq, session);
       }
	else {
		response = newTellResponse("Whatchu talkin' bout!", false);
	}
	
	return response;
}
 
开发者ID:jneong,项目名称:CS370_Echo_Demo,代码行数:22,代码来源:KnockKnockConversation.java

示例11: onIntent

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
@Override
public SpeechletResponse onIntent(final IntentRequest request, final Session session)
        throws SpeechletException {
    log.info("onIntent requestId={}, sessionId={}", request.getRequestId(),
            session.getSessionId());

    SpeechletResponse response = null;
    Intent intent = request.getIntent();
    String intentName = (intent != null) ? intent.getName() : null;
    
    //Check for convo handling
    Conversation convo = getConvoForIntent(intentName);
    if(convo != null) {
    	response = convo.respondToIntentRequest(request, session);
    }
    else {
        throw new SpeechletException("Invalid Intent");
    }
    
    return response;
}
 
开发者ID:jneong,项目名称:CS370_Echo_Demo,代码行数:22,代码来源:TemplateBaseSkillSpeechlet.java

示例12: onIntent

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
@Override
public SpeechletResponse onIntent(IntentRequest request, Session session) throws SpeechletException {
	Intent intent = request.getIntent();
	
	if (Constants.INTENT_QUERY_TRAIN_STATUS.equals(intent.getName())) {
		return responseShortStatus(intent, session);
	} else if ("AMAZON.YesIntent".equals(intent.getName())) {
		return responseYes(intent, session);
	} else if ("AMAZON.NoIntent".equals(intent.getName())) {
		return responseNo(intent, session);
	} else if ("AMAZON.HelpIntent".equals(intent.getName())) {
		return help(intent, session);
	} else if ("AMAZON.CancelIntent".equals(intent.getName()) || 
		"AMAZON.StopIntent".equals(intent.getName())) {
		return responseText("See you!");
	} else {
		return responseText("Sorry, I didn't get that. Please try again now. Like: What is the status of seven?", false);
	}
}
 
开发者ID:speedyllama,项目名称:nyctransit,代码行数:20,代码来源:MTAStatusSpeechlet.java

示例13: handleIntentRequest

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
@Override
public SpeechletResponse handleIntentRequest(Intent intent, Session session) {
    Object sessionQuestion = session.getAttribute(SkillConfig.SessionAttributeYesNoQuestion);

    SpeechletResponse response = SkillLogic.isAnswerToAnotherEncode(intent, session) ?
                    SkillResponses.getEncodeAskResponse(intent, session) :
                SkillLogic.isAnswerToAnotherSpell(intent, session) ?
                        SkillResponses.getSpellAskResponse(intent, session) :
                    SkillLogic.isAnswerToAnotherExercise(intent, session) ?
                            SkillResponses.getExerciseAskResponse(intent, session) :
                        SkillLogic.isAnswerToAnotherTry(intent, session) ?
                                SkillResponses.getExerciseRepeatResponse(intent, session) :
                                    SkillLogic.hasExercisePending(intent, session) ?
                                        SkillResponses.getHelpDuringExercise(intent, session) :
                                            SkillResponses.getHelpAboutAll(intent, session);

    // reset session attribute if unchanged
    if (sessionQuestion != null && sessionQuestion.toString().equals(session.getAttribute(SkillConfig.SessionAttributeYesNoQuestion)))
        session.removeAttribute(SkillConfig.SessionAttributeYesNoQuestion);
    return response;
}
 
开发者ID:KayLerch,项目名称:alexa-morser-coder-skill,代码行数:22,代码来源:YesIntentHandler.java

示例14: getExerciseAskResponse

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
/**
 * This one handles the user's request for a new exercise word
 *  @param intent the intent given by the user
 * @param session current session with some exercise data
 * @return corresponding speechlet response to an exercise request (including the playback of morse code of a randomly picked word)
 */
public static SpeechletResponse getExerciseAskResponse(Intent intent, Session session) {
    String word = getRandomExerciseWord(SkillLogic.getExerciseLevel(session));
    // keep this word in mind in order to evaluate it against the users answer
    session.setAttribute(SkillConfig.SessionAttributeExercisedWord, word);
    // increment exercise counter
    SkillLogic.incrementExercisesTotal(session);

    OutputSpeech outputSpeech = SkillResponses.getExerciseAskSpeech(word);
    Reprompt reprompt = SkillResponses.getExerciseAskReprompt(word);
    Card card = SkillResponses.getExerciseCard(word, true);

    SpeechletResponse response = SpeechletResponse.newTellResponse(outputSpeech, card);
    response.setShouldEndSession(false);
    response.setReprompt(reprompt);
    return response;
}
 
开发者ID:KayLerch,项目名称:alexa-morser-coder-skill,代码行数:23,代码来源:SkillResponses.java

示例15: getExerciseCorrectResponse

import com.amazon.speech.slu.Intent; //导入依赖的package包/类
/**
 * This one reacts on a user given a correct answer in an exercise
 * @param intent the intent given by the user
 * @param session the current session with some exercise data
 * @return the corresponding speechlet response to the given answer
 */
public static SpeechletResponse getExerciseCorrectResponse(Intent intent, Session session) {
    String sessionWord = session.getAttributes().containsKey(SkillConfig.SessionAttributeExercisedWord) ? session.getAttribute(SkillConfig.SessionAttributeExercisedWord).toString() : null;
    SkillLogic.incrementExercisesCorrect(session);
    SkillLogic.getExercisesRetries(session);
    // add score depending on length of the word
    SkillLogic.increaseScore(session, sessionWord.length());
    // increase length of exercise word
    SkillLogic.increaseExercisesLevel(session);

    String strContent = ResponsePhrases.getSuperlative() + "! " +
            ResponsePhrases.getAnswerCorrect() + "." +
            "<p>" + ResponsePhrases.getScoreIs() + SkillLogic.getScore(session) + "</p>" +
            "<p>" + ResponsePhrases.getWantAnotherCode() + "</p>";

    SsmlOutputSpeech outputSpeech = new SsmlOutputSpeech();
    outputSpeech.setSsml("<speak>" + strContent + "</speak>");
    Card card = getExerciseCard(sessionWord, false);
    SpeechletResponse response = SpeechletResponse.newTellResponse(outputSpeech, card);
    response.setShouldEndSession(false);

    session.removeAttribute(SkillConfig.SessionAttributeExercisedWord);
    session.setAttribute(SkillConfig.SessionAttributeYesNoQuestion, SkillConfig.YesNoQuestions.WantAnotherExercise);
    return response;
}
 
开发者ID:KayLerch,项目名称:alexa-morser-coder-skill,代码行数:31,代码来源:SkillResponses.java


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