Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有一种方法可以指定培训短语中的哪些单词是通过JavaSDK在Dialogflow中使用的_Java_Spring Boot_Google Cloud Platform_Dialogflow Es - Fatal编程技术网

有没有一种方法可以指定培训短语中的哪些单词是通过JavaSDK在Dialogflow中使用的

有没有一种方法可以指定培训短语中的哪些单词是通过JavaSDK在Dialogflow中使用的,java,spring-boot,google-cloud-platform,dialogflow-es,Java,Spring Boot,Google Cloud Platform,Dialogflow Es,我想使用Dialogflow java sdk创建一个意图。问题是我能够创建训练短语和槽,但我不能像在dialogflow控制台中那样将特定单词与训练短语分开 我已经检查过了,Dialogflow本身也不这样做。 下面我已经写出了我目前使用的代码和我使用过的函数。这可能没有帮助,但可能有助于向我正在使用的当前方法提供信息 dialogflow java api中是否有任何函数可以帮助我实现这一点 public OutputResponseDTO createIntent(CreateInten

我想使用Dialogflow java sdk创建一个意图。问题是我能够创建训练短语和槽,但我不能像在dialogflow控制台中那样将特定单词与训练短语分开

我已经检查过了,Dialogflow本身也不这样做。 下面我已经写出了我目前使用的代码和我使用过的函数。这可能没有帮助,但可能有助于向我正在使用的当前方法提供信息

dialogflow java api中是否有任何函数可以帮助我实现这一点

public  OutputResponseDTO createIntent(CreateIntentInputDTO createIntentInputDTO)
{
    // Instantiates a client
    try (IntentsClient intentsClient = IntentsClient.create()) {

        // Set the project agent name using the projectID (my-project-id)
        ProjectAgentName parent = ProjectAgentName.of(createIntentInputDTO.getProjectId());

        //first check if intent already exists
        for (Intent intent : intentsClient.listIntents(parent).iterateAll()) {
            //logger.error(intent.getDisplayName()+"Inside delete!!!!!!"+createIntentInputDTO.getIntentName());
            if (intent.getDisplayName().equals(createIntentInputDTO.getDisplayName())) {
                logger.error("Inside delete!!!!!!");
                deleteIntent(createIntentInputDTO.getIntentName(),createIntentInputDTO.getProjectId());
            }
        }

        List<String> trainingPhrasesIP=new ArrayList<String>();
        for(int l=0;l<createIntentInputDTO.getTrainingPhrasesParts().size();l++)
        {
            trainingPhrasesIP.add(createIntentInputDTO.getTrainingPhrasesParts().get(l).getPhraseName());
        }
        // Build the trainingPhrases from the trainingPhrasesParts
        List<TrainingPhrase> trainingPhrases = new ArrayList<>();
        for (String trainingPhrase : trainingPhrasesIP) {
            trainingPhrases.add(
                    TrainingPhrase.newBuilder().addParts(
                            Part.newBuilder().setText(trainingPhrase).build())
                    .build());
        }

        // Build the message texts for the agent's response
        Message messages = Message.newBuilder()
                .setText(
                        Text.newBuilder()
                        .addAllText(createIntentInputDTO.getMessageTexts()).build()
                        ).build();



        List<Parameter> parameters=new ArrayList<Intent.Parameter>();

        for(int j=0;j<createIntentInputDTO.getSlotsInputDTOs().size();j++)
        {

            //String firstFourChars = createIntentInputDTO.getSlotsInputDTOs().get(j).getEntityDisplayName().substring(0, 5);
            //System.out.println(firstFourChars);

            String paraNameWithoutAtTwo;
            String paraNameWithoutAtOne;
            String paraNameWithoutAtAndWithDollar;
            String paraNameWithAt;

            try
            {
                paraNameWithoutAtOne=createIntentInputDTO.getSlotsInputDTOs().get(j).getEntityDisplayName().replace("@sys.", "");
             paraNameWithoutAtTwo=paraNameWithoutAtOne.replace("@", "");
            }
            catch(Exception e)
            {
                paraNameWithoutAtTwo=createIntentInputDTO.getSlotsInputDTOs().get(j).getEntityDisplayName();
                logger.info("Something happended when removing stuff");
            }

            paraNameWithoutAtAndWithDollar="$"+paraNameWithoutAtTwo;
            paraNameWithAt="@"+paraNameWithoutAtTwo;
            paraNameWithoutAt=createIntentInputDTO.getSlotsInputDTOs().get(j).getEntityDisplayName();



            Parameter parameter=Parameter.newBuilder()
                .setValue(createIntentInputDTO.getSlotsInputDTOs().get(j).getValue())
                    .setDisplayName(paraNameWithoutAtTwo)
                    .setValue(paraNameWithoutAtAndWithDollar)


                    .setEntityTypeDisplayName(createIntentInputDTO.getSlotsInputDTOs().get(j).getEntityDisplayName())
                    .build();
            parameters.add(parameter);
        }




        // Build the intent
        Intent intent = Intent.newBuilder()
                .setDisplayName(createIntentInputDTO.getDisplayName())
                .addMessages(messages)
                //                  .addParameters(p)
                                    .addAllParameters(parameters)
                .addAllTrainingPhrases(trainingPhrases)
                .build();




        // Performs the create intent request
        Intent response = intentsClient.createIntent(parent, intent);

    //  System.out.format("Intent created: %s\n", response);


        try
        {
            IntentMasterCollection intentMasterCollection=new IntentMasterCollection();
            intentMasterCollection.setName(createIntentInputDTO.getDisplayName());
            intentActionMaster.save(intentMasterCollection);
        }
        catch(Exception e)
        {
            logger.error("Error adding in DB intent master");
        }

        try
        {
            //we gonna put the data again!(Training phrases only)
            String[] splitName = response.getName().split("/");
            //              intentIds.add(splitName[splitName.length - 1]);



            //finally setting all the values

            updateIntent(splitName[splitName.length - 1]);

        }
        catch(Exception e)
        {
            logger.error("Error in writing to intent");
        }
        return new OutputResponseDTO(true, message.getStatusCode("success.message.createIntent.id"),
                message.get("success.message.createIntent"), null,  null,requestBean.getTraceId());
    }
    catch(Exception e)
    {
        logger.error("Error Creating Intent:"+e.getMessage());
        return new OutputResponseDTO(false, message.getStatusCode("error.message.generalError.id"),
                message.get("error.message.generalError"), null,  e.getMessage(),requestBean.getTraceId());
    }
}
公共输出响应到createIntent(CreateIntentInput到CreateIntentInput)
{
//实例化客户机
try(intentclient intentclient=intentclient.create()){
//使用projectID(我的项目id)设置项目代理名称
ProjectAgentName父项=ProjectAgentName.of(createIntentInputTo.getProjectId());
//首先检查意图是否已经存在
for(Intent-Intent:intentclient.listIntents(parent.iterateAll()){
//logger.error(intent.getDisplayName()+“内部删除”!!!!!“+CreateIntentInputTo.getIntentName());
if(intent.getDisplayName().equals(CreateIntentInputTo.getDisplayName())){
logger.error(“内部删除!!!!!!!”);
deleteIntent(CreateIntentInputTo.getIntentName(),CreateIntentInputTo.getProjectId());
}
}
List trainingPhrasesIP=new ArrayList();

对于(int l=0;l我认为您遇到的问题与零件定义有关。 每个培训短语都分为几个部分,对于每个部分,您可以定义它是文本还是包含实体:

        Part part1 = Part.newBuilder().setText("I want to cancel a card ended in  ").build();
        Part part2 = Part.newBuilder().setText("5123").setEntityType("@cardNumber").setAlias("cardNumber")
                .setUserDefined(true).build();
        List<Part> parts = new ArrayList<Part>();
        parts.add(part1);
        parts.add(part2);

当尝试添加多个训练短语时,IsList选项自动检查可向我建议如何避免该检查?
    TrainingPhrase tp = TrainingPhrase.newBuilder().setType(Type.EXAMPLE).addAllParts(parts).build();