xatkit-bot-platform / xatkit

The simplest way to build all types of smart chatbots and digital assistants
https://xatkit.com
Eclipse Public License 2.0
176 stars 23 forks source link

Error while using "mvn clean compile" #32

Closed smishy05 closed 4 years ago

smishy05 commented 4 years ago

Hi there,

I downloaded the template provided for the project and placed it in the xatkit-examples directory. I made tweaks to the bot and here is the GreetingsBot.java:

package com.xatkit.example;

import com.xatkit.core.XatkitCore;
import com.xatkit.plugins.react.platform.ReactPlatform;
import com.xatkit.plugins.react.platform.io.ReactEventProvider;
import com.xatkit.plugins.react.platform.io.ReactIntentProvider;
import lombok.val;
import org.apache.commons.configuration2.BaseConfiguration;
import org.apache.commons.configuration2.Configuration;

import static com.xatkit.dsl.DSL.eventIs;
import static com.xatkit.dsl.DSL.fallbackState;
import static com.xatkit.dsl.DSL.intent;
import static com.xatkit.dsl.DSL.intentIs;
import static com.xatkit.dsl.DSL.model;
import static com.xatkit.dsl.DSL.state;

/**
 * This is an example greetings bot designed with Xatkit.
 * <p>
 * You can check our <a href="https://github.com/xatkit-bot-platform/xatkit/wiki">wiki</a>
 * to learn more about bot creation, supported platforms, and advanced usage.
 */
public class GreetingsBot {

    /*
     * Your bot is a plain Java application: you need to define a main method to make the created jar executable.
     */
    public static void main(String[] args) {

        /*
         * Define the intents our bot will react to.
         * <p>
         * In this example we want our bot to answer greetings inputs and "how are you" questions, so we create an
         * intent for each, and we give a few example training sentences to configure the underlying NLP engine.
         * <p>
         * Note that we recommend the usage of Lombok's val when using the Xatkit DSL: the fluent API defines many
         * interfaces that are not useful for bot designers. If you don't want to use val you can use our own
         * interface IntentVar instead.
         */
        val contractName = intent("ContractName")
                .trainingSentence("C = CONTRACT")
                .trainingSentence("Contract is CONTRACT")
                .trainingSentence("Name of the contract is CONTRACT")
                .context("contract")
                .parameter("cName").fromFragment("CONTRACT").entity(contract());

        val participantName = intent("ParticipantName")
                .trainingSentence("P = PART")
                .trainingSentence("Participant is PART")
                .trainingSentence("Name of the participant is PART")
                .context("participant")
                .parameter("pName").fromFragment("PART").entity(part());

        val assetName = intent("AssetName")
                .trainingSentence("A = AS")
                .trainingSentence("Asset is AS")
                .trainingSentence("Name of the asset is AS")
                .context("asset")
                .parameter("aName").fromFragment("AS").entity(as());

        val functionName = intent("FunctionName")
                .trainingSentence("F = FUNCTION")
                .trainingSentence("Function is FUNCTION")
                .trainingSentence("Name of the function is FUNCTION")
                .context("function")
                .parameter("fName").fromFragment("FUNCTION").entity(function());

        /*
         * Instantiate the platforms we will use in the bot definition.
         */
        ReactPlatform reactPlatform = new ReactPlatform();
        RestPlatform restPlatform = new RestPlatform();
        /*
         * Similarly, instantiate the intent/event providers we want to use.
         */
        ReactEventProvider reactEventProvider = new ReactEventProvider(reactPlatform);
        ReactIntentProvider reactIntentProvider = new ReactIntentProvider(reactPlatform);

        /*
         * Create the states we want to use in our bot.
         */
        val init = state("Init");
        val awaitingInput = state("AwaitingInput");
        val handleContract = state("HandleContract");
        val handleParticipant = state("HandleParticipant");
        val handleAsset = state("HandleAsset");
        val handleFunction = state("HandleFunction");

        /*
         * Specify the content of the bot states (i.e. the behavior of the bot).
         */
        init
                .next()
                /*
                 * We check that the received event matches the ClientReady event defined in the
                 * ReactEventProvider. The list of events defined in a provider is available in the provider's
                 * wiki page.
                 */
                .when(eventIs(ReactEventProvider.ClientReady)).moveTo(awaitingInput);

        awaitingInput
                .next()
                /*
                 * The Xatkit DSL offers dedicated predicates (intentIs(IntentDefinition) and eventIs
                 * (EventDefinition) to check received intents/events.
                 * <p>
                 * You can also check a condition over the underlying bot state using the following syntax:
                 * <pre>
                 * {@code
                 * .when(context -> [condition manipulating the context]).moveTo(state);
                 * }
                 * </pre>
                 */
                .when(intentIs(contractName)).moveTo(handleContract);

        handleContract
                .body(context -> {
                    String contractname = (String) context.getNlpContext().get("contract").get("cName");
                    reactPlatform.reply(contractname);

                })
                .next()
                .when(intentIs(participantName)).moveTo(handleParticipant);

        handleParticipant
                .body(context -> {
                    String participantname = (String) context.getNlpContext().get("participant").get("pName");
                    reactPlatform.reply(participantname);
                })
                .next()
                .when(intentIs(assetName)).moveTo(handleAsset);

        handleAsset
                .body(context -> {
                    String assetname = (String) context.getNlpContext().get("asset").get("aName");
                    reactPlatform.reply(assetname);
                })
                .next()
                .when(intentIs(functionName)).moveTo(handleFunction);

        handleFunction
                .body(context -> {
                    String functionname = (String) context.getNlpContext().get("function").get("fName");
                    reactPlatform.reply(functionname);
                })
                .next()
                .moveTo(awaitingInput);

        /*
         * The state that is executed if the engine doesn't find any navigable transition in a state and the state
         * doesn't contain a fallback.
         */
        val defaultFallback = fallbackState()
                .body(context -> reactPlatform.reply(context, "Sorry, I didn't, get it"));

        /*
         * Creates the bot model that will be executed by the Xatkit engine.
         * <p>
         * A bot model contains:
         * - A list of intents/events (or libraries) used by the bot. This allows to register the events/intents to
         * the NLP
         * service.
         * - A list of platforms used by the bot. Xatkit will take care of starting and initializing the platforms
         * when starting the bot.
         * - A list of providers the bot should listen to for events/intents. As for the platforms Xatkit will take
         * care of initializing the provider when starting the bot.
         * - The list of states the compose the bot (this list can contain the init/fallback state, but it is optional)
         * - The entry point of the bot (a.k.a init state)
         * - The default fallback state: the state that is executed if the engine doesn't find any navigable
         * transition in a state and the state doesn't contain a fallback.
         */
        val botModel = model()
                .useIntent(contractName)
                .useIntent(participantName)
                .useIntent(assetName)
                .useIntent(functionName)
                .usePlatform(reactPlatform)
                .usePlatform(restPlatform)
                .listenTo(reactEventProvider)
                .listenTo(reactIntentProvider)
                .state(awaitingInput)
                .state(handleContract)
                .state(handleParticipant)
                .state(handleAsset)
                .state(handleFunction)
                .initState(init)
                .defaultFallbackState(defaultFallback);

        Configuration botConfiguration = new BaseConfiguration();
        /*
         * Add configuration properties (e.g. authentication tokens, platform tuning, intent provider to use).
         * Check the corresponding platform's wiki page for further information on optional/mandatory parameters and
         * their values.
         */

        XatkitCore xatkitCore = new XatkitCore(botModel, botConfiguration);
        xatkitCore.run();
        /*
         * The bot is now started, you can check http://localhost:5000/admin to test it.
         * The logs of the bot are stored in the logs folder at the root of this project.
         */
    }
}

The pom.xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xatkit</groupId>
    <artifactId>xatkit-bot-template</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven-assembly-plugin.version>3.1.0</maven-assembly-plugin.version>
        <maven-help-plugin.version>3.2.0</maven-help-plugin.version>

        <junit.version>4.12</junit.version>
        <assertj.version>3.14.0</assertj.version>
        <mockito-version>3.3.3</mockito-version>
        <lombok.version>1.18.12</lombok.version>
    </properties>

    <dependencies>

        <!-- Xatkit Internal -->

        <dependency>
            <groupId>com.xatkit</groupId>
            <artifactId>core</artifactId>
            <version>5.0.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.xatkit</groupId>
            <artifactId>chat-platform-runtime</artifactId>
            <version>3.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.xatkit</groupId>
            <artifactId>react-platform-runtime</artifactId>
            <version>4.0.1-SNAPSHOT</version>
        </dependency>

        <!-- Utils -->

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <!-- Tests -->

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>

        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>

            <!-- Utils -->

            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <scope>provided</scope>
            </dependency>

            <!-- Tests -->

            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-core</artifactId>
                <scope>test</scope>
                <version>${assertj.version}</version>
            </dependency>

            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>${mockito-version}</version>
                <scope>test</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>${maven-assembly-plugin.version}</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>com.xatkit.example.GreetingsBot</mainClass>
                            </manifest>
                        </archive>
                        <finalName>greetings-bot</finalName>
                    </configuration>
                </plugin>

            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

When I type in the command - mvn clean compile

I get this:

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------< com.xatkit:xatkit-bot-template >-------------------
[INFO] Building xatkit-bot-template 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ xatkit-bot-template ---
[INFO] Deleting /home/shailesh1998/xatkit/xatkit-examples/xatkit-bot-template/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xatkit-bot-template ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ xatkit-bot-template ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/shailesh1998/xatkit/xatkit-examples/xatkit-bot-template/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/shailesh1998/xatkit/xatkit-examples/xatkit-bot-template/src/main/java/com/xatkit/example/GreetingsBot.java:[176,13] Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.248 s
[INFO] Finished at: 2020-08-11T12:04:11+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project xatkit-bot-template: Compilation failure
[ERROR] /home/shailesh1998/xatkit/xatkit-examples/xatkit-bot-template/src/main/java/com/xatkit/example/GreetingsBot.java:[176,13] Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I found that it is a issue with lombok. What should I do then?

Thanks in advance!

hamzaed commented 4 years ago

Hi,

Did you try compiling the original GreetingsBot? The bot definition above is not complete. You're using entities that are not defined and the REST platform is not added to the Maven dependencies.

smishy05 commented 4 years ago

Thanks for the reply.

Yes, the original GreetingsBot worked absolutely fine. But I have printed the entities that I just extracted right? I removed the REST platform too. It's still giving the same error.

hamzaed commented 4 years ago

The entities contract(), part(), as() and function() are not defined. We have some built-in entities that you can use (e.g., any() from com.xatkit.dsl.DSL.any for any String). If you need to define your own entities you should do it as follows:

        val contract = mapping("Contract")
                .entry()
                .value("value 1")
                .synonym("synonym 1 of value 1")
                .synonym("synonym 2 of value 1")
                ...
                .synonym("synonym n of value 1")
                .value("value 2")
                .synonym("synonym 1 of value 2")
                .synonym("synonym 2 of value 2")
                ...
                .synonym("synonym n of value 2")
                ...;

then use it in your intent: .context("contract").parameter("cName").fromFragment("CONTRACT").entity(contract);

smishy05 commented 4 years ago

Thanks a lot! Using any() worked like a charm. I messed up with the parameter inside the entity().

Also, defining my own entities also proved to be very helpful! Thanks a lot for the help.

hamzaed commented 4 years ago

You're welcome.

Please find the the DSL constructs here.