Giter Club home page Giter Club logo

wit-java's Introduction

Wit-Java

Wit-Java Is A Java Library For Wit.ai

Current Version: 1.0.0

Build Status Javadocs

Installation

To add a dependency using Maven, use the following:

<dependency>
  <groupId>com.clivern</groupId>
  <artifactId>wit-java</artifactId>
  <version>1.0.0</version>
</dependency>

To add a dependency using Gradle, use the following:

dependencies {
  compile 'com.clivern:wit-java:1.0.0'
}

To add a dependency using Scala SBT, use the following:

libraryDependencies += "com.clivern" % "wit-java" % "1.0.0"

Usage

After adding the package as a dependency, Please read the following steps:

Basic Configurations

In order to cofigure the package create config.properties file with the following data

wit_api_id=app id here
wit_access_token=access token here

logging_level=tarce or debug or info or warning or error
logging_file_path=src/main/java/resources/
logging_file_format=current_date or app
logging_log_type=file or console or both
logging_current_date_format=yyyy-MM-dd
logging_append=true or false
logging_buffered=true or false

Please Note That You can put configs manually using set method of config class like the following:

Config config = new Config();
config.set("wit_api_id", "app id here");
config.set("wit_access_token", "access token here");
config.put("logging_level", "tarce or debug or info or warning or error");
config.put("logging_file_path", "src/main/java/resources/");
config.put("logging_file_format", "current_date or app");
config.put("logging_log_type", "file or console or both");
config.put("logging_current_date_format", "yyyy-MM-dd");
config.put("logging_append", "true or false");
config.put("logging_buffered", "true or false");
config.configLogger();

Both wit_api_id and wit_access_token can be changed with each request with setAppId and setAccessToken methods. I will let you know within the docs whenever you can override them.

To get an array of all apps that you own.

import com.clivern.wit.api.App;
import com.clivern.wit.api.endpoint.AppEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

App getApp = new App(AppEndpoint.GET);
// To Use another App Id different from the one on your properties file
// getApp.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// getApp.setAccessToken("Your Custom Access Token Here");
String result = "";
String error = "";

if( wit.send(getApp) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.App;
import com.clivern.wit.api.endpoint.AppEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            App getApp = new App(AppEndpoint.GET);
            // To Use another App Id different from the one on your properties file
            // getApp.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // getApp.setAccessToken("Your Custom Access Token Here");

            if( wit.send(getApp) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To Update an app with the given attributes.

import com.clivern.wit.api.App;
import com.clivern.wit.api.endpoint.AppEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

App updateApp = new App(AppEndpoint.UPDATE);
updateApp.setName("Clark");
updateApp.setLang("English");
updateApp.setPrivate("false");
updateApp.setDesc("Hello World");
updateApp.setTimezone("America/Los_Angeles");
// To Use another App Id different from the one on your properties file
// updateApp.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// updateApp.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(updateApp) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.App;
import com.clivern.wit.api.endpoint.AppEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            App updateApp = new App(AppEndpoint.UPDATE);
            updateApp.setName("Clark");
            updateApp.setLang("English");
            updateApp.setPrivate("false");
            updateApp.setDesc("Hello World");
            updateApp.setTimezone("America/Los_Angeles");
            // To Use another App Id different from the one on your properties file
            // updateApp.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // updateApp.setAccessToken("Your Custom Access Token Here");

            if( wit.send(updateApp) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To Permanently delete the app.

import com.clivern.wit.api.App;
import com.clivern.wit.api.endpoint.AppEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

App deleteApp = new App(AppEndpoint.DELETE);
// To Use another App Id different from the one on your properties file
// deleteApp.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// deleteApp.setAccessToken("Your Custom Access Token Here");
String result = "";
String error = "";

if( wit.send(deleteApp) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.App;
import com.clivern.wit.api.endpoint.AppEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            App deleteApp = new App(AppEndpoint.DELETE);
            // To Use another App Id different from the one on your properties file
            // deleteApp.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // deleteApp.setAccessToken("Your Custom Access Token Here");
            if( wit.send(deleteApp) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To Create a new app for an existing user.

import com.clivern.wit.api.App;
import com.clivern.wit.api.endpoint.AppEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

App createApp = new App(AppEndpoint.CREATE);
createApp.setName("Clark");
createApp.setLang("English");
createApp.setPrivate("false");
createApp.setDesc("Hello World");
// To Use another App Id different from the one on your properties file
// createApp.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// createApp.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(createApp) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.App;
import com.clivern.wit.api.endpoint.AppEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            App createApp = new App(AppEndpoint.CREATE);
            createApp.setName("Clark");
            createApp.setLang("English");
            createApp.setPrivate("false");
            createApp.setDesc("Hello World");
            // To Use another App Id different from the one on your properties file
            // createApp.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // createApp.setAccessToken("Your Custom Access Token Here");

            if( wit.send(createApp) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To extract the meaning from a sentence, based on the app data:

import com.clivern.wit.api.Message;
import com.clivern.wit.api.endpoint.MessageEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Message message = new Message(MessageEndpoint.GET);
message.setQ("Good Morning");
//message.setContext("");
//message.setMsgId("789");
//message.setThreadId("fb_th");
//message.setN(6);
//message.setVerbose(true);

// To Use another App Id different from the one on your properties file
// message.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// message.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(message) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Message;
import com.clivern.wit.api.endpoint.MessageEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Message message = new Message(MessageEndpoint.GET);
            message.setQ("Good Morning");
            //message.setContext("");
            //message.setMsgId("789");
            //message.setThreadId("fb_th");
            //message.setN(6);
            //message.setVerbose(true);

            // To Use another App Id different from the one on your properties file
            // message.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // message.setAccessToken("Your Custom Access Token Here");

            if( wit.send(message) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To get a list of available entities for the app.

import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Entity entity = new Entity(EntityEndpoint.GET_ENTITIES);

// To Use another App Id different from the one on your properties file
// entity.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// entity.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(entity) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Entity entity = new Entity(EntityEndpoint.GET_ENTITIES);

            // To Use another App Id different from the one on your properties file
            // entity.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // entity.setAccessToken("Your Custom Access Token Here");

            if( wit.send(entity) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }

        }
    }
}

To Create a new entity with the given attributes.

import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Entity entity = new Entity(EntityEndpoint.CREATE_ENTITY);
entity.setId("favorite_city"); // required
entity.setDoc("A city that I like"); //optional

// To Use another App Id different from the one on your properties file
// entity.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// entity.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(entity) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Entity entity = new Entity(EntityEndpoint.CREATE_ENTITY);
            entity.setId("favorite_city"); // required
            entity.setDoc("A city that I like"); //optional

            // To Use another App Id different from the one on your properties file
            // entity.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // entity.setAccessToken("Your Custom Access Token Here");

            if( wit.send(entity) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To get entity data and values.

import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Entity entity = new Entity(EntityEndpoint.GET_ENTITY);
entity.setEntityId("favorite_city");

// To Use another App Id different from the one on your properties file
// entity.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// entity.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(entity) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Entity entity = new Entity(EntityEndpoint.GET_ENTITY);
            entity.setEntityId("favorite_city");

            // To Use another App Id different from the one on your properties file
            // entity.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // entity.setAccessToken("Your Custom Access Token Here");

            if( wit.send(entity) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To Update an entity with the given attributes.

import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Entity entity = new Entity(EntityEndpoint.UPDATE_ENTITY);
entity.setEntityId("favorite_land");
entity.setId("favorite_city");
entity.setDoc("These are lands worth going to");
entity.setValues(new String[]{
    "{\"value\": \"Paris\",\"expressions\": [\"Paris\", \"City of Light\", \"Capital of FR\"]}",
    "{\"value\": \"London\",\"expressions\": [\"London\", \"City of Dreams\", \"Capital of UK\"]}",
    "{\"value\": \"Amsterdam\",\"expressions\": [\"Amsterdam\", \"City of Love\", \"Capital of NL\"]}"
});

// To Use another App Id different from the one on your properties file
// entity.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// entity.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(entity) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Entity entity = new Entity(EntityEndpoint.UPDATE_ENTITY);
            entity.setEntityId("favorite_land");
            entity.setId("favorite_city");
            entity.setDoc("These are lands worth going to");
            entity.setValues(new String[]{
                "{\"value\": \"Paris\",\"expressions\": [\"Paris\", \"City of Light\", \"Capital of FR\"]}",
                "{\"value\": \"London\",\"expressions\": [\"London\", \"City of Dreams\", \"Capital of UK\"]}",
                "{\"value\": \"Amsterdam\",\"expressions\": [\"Amsterdam\", \"City of Love\", \"Capital of NL\"]}"
            });

            // To Use another App Id different from the one on your properties file
            // entity.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // entity.setAccessToken("Your Custom Access Token Here");

            if( wit.send(entity) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To Permanently delete an entity.

import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Entity entity = new Entity(EntityEndpoint.DELETE_ENTITY);
entity.setEntityId("favorite_land");

// To Use another App Id different from the one on your properties file
// entity.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// entity.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(entity) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Entity entity = new Entity(EntityEndpoint.DELETE_ENTITY);
            entity.setEntityId("favorite_land");

            // To Use another App Id different from the one on your properties file
            // entity.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // entity.setAccessToken("Your Custom Access Token Here");

            if( wit.send(entity) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To Add new values to a keyword entity.

import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Entity entity = new Entity(EntityEndpoint.CREATE_ENTITY_VALUE);
entity.setEntityId("favorite_city");
entity.setValue("London");
entity.setExpressions(new String[]{"London", "Big Ben City"});
entity.setMetadata("CITY_1234");

// To Use another App Id different from the one on your properties file
// entity.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// entity.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(entity) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Entity entity = new Entity(EntityEndpoint.CREATE_ENTITY_VALUE);
            entity.setEntityId("favorite_city");
            entity.setValue("London");
            entity.setExpressions(new String[]{"London", "Big Ben City"});
            entity.setMetadata("CITY_1234");

            // To Use another App Id different from the one on your properties file
            // entity.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // entity.setAccessToken("Your Custom Access Token Here");

            if( wit.send(entity) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To Remove a given value from an entity.

import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Entity entity = new Entity(EntityEndpoint.DELETE_ENTITY_VALUE);
entity.setEntityId("favorite_city");
entity.setEntityValue("London");

// To Use another App Id different from the one on your properties file
// entity.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// entity.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(entity) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Entity entity = new Entity(EntityEndpoint.DELETE_ENTITY_VALUE);
            entity.setEntityId("favorite_city");
            entity.setEntityValue("London");

            // To Use another App Id different from the one on your properties file
            // entity.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // entity.setAccessToken("Your Custom Access Token Here");

            if( wit.send(entity) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To Create a new expression for a keyword entity.

import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Entity entity = new Entity(EntityEndpoint.CREATE_ENTITY_VALUE_EXPRESSION);
entity.setEntityId("favorite_city");
entity.setEntityValue("London");
entity.setExpression("Britain Capital");

// To Use another App Id different from the one on your properties file
// entity.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// entity.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(entity) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Entity entity = new Entity(EntityEndpoint.CREATE_ENTITY_VALUE_EXPRESSION);
            entity.setEntityId("favorite_city");
            entity.setEntityValue("London");
            entity.setExpression("Britain Capital");

            // To Use another App Id different from the one on your properties file
            // entity.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // entity.setAccessToken("Your Custom Access Token Here");

            if( wit.send(entity) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

To Remove an expression from an entity.

import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

//....


Config config = new Config();
config.loadPropertiesFile("config.properties");
config.configLogger();

Wit wit = new Wit(config);

Entity entity = new Entity(EntityEndpoint.DELETE_ENTITY_VALUE_EXPRESSION);
entity.setEntityId("favorite_city");
entity.setEntityValue("London");
entity.setExpressionValue("Britain Capital");

// To Use another App Id different from the one on your properties file
// entity.setAppId("Your Custom App ID Here");
// To Use Another Access Token Different From The one on your properties file
// entity.setAccessToken("Your Custom Access Token Here");

String result = "";
String error = "";

if( wit.send(entity) ){
    result = wit.getResponse();
}else{
    error = wit.getError();
}

So in case we use spark java framework, Our code can be look like the following:

package com.clivern.test;

import static spark.Spark.*;
import com.clivern.wit.api.Entity;
import com.clivern.wit.api.endpoint.EntityEndpoint;
import com.clivern.wit.util.Config;
import com.clivern.wit.Wit;

/**
 * Main Class
 *
 * @since 1.0.0
 */
public class Main {

    public static void main(String[] args)
    {
        get("/", (request, response) -> {

            Config config = new Config();
            config.loadPropertiesFile("src/main/java/resources/config.properties");
            config.configLogger();

            Wit wit = new Wit(config);

            Entity entity = new Entity(EntityEndpoint.DELETE_ENTITY_VALUE_EXPRESSION);
            entity.setEntityId("favorite_city");
            entity.setEntityValue("London");
            entity.setExpressionValue("Britain Capital");

            // To Use another App Id different from the one on your properties file
            // entity.setAppId("Your Custom App ID Here");
            // To Use Another Access Token Different From The one on your properties file
            // entity.setAccessToken("Your Custom Access Token Here");

            if( wit.send(entity) ){
                return wit.getResponse();
            }else{
                return wit.getError();
            }
        }
    }
}

Misc

Changelog

Version 1.0.0:

Initial Release.

Acknowledgements

© 2018, Clivern. Released under The Apache Software License, Version 2.0.

Wit-Java is authored and maintained by @clivern.

wit-java's People

Contributors

clivern avatar ienoobong avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ks228 weidaolong

wit-java's Issues

Unable To Call Methods From their class

Describe the bug
Whenever i try to call any method after instantiating its class. It doesn't work.
To Reproduce
Steps to reproduce the behavior:
NOTE: When adding the gradle dependency, i have use implementation 'com.clivern:wit-java:1.0.0' instead of compile 'com.clivern:wit-java:1.0.0'

  1. Create a new class, try instantiate Config like so Config config = new Config(); ''
  2. Now call config.loadPropertiesFile("config.properties"); or config.configLogger();
  3. The loadPropertiesFile or configLogger method is unresolved. Same is applied to wit.send(getApp)
  4. See error

Expected behavior
This methods should be callable once instanciated

Screenshots
Here you'd see that my editor has highligted those method with red as they are unresolveable.
Screenshot 2022-05-03 at 01 56 14

I'm not sure this issue is from my end, any sort of help would be appreciated

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

error with keyword "error"

wit.send() returns false with text "I get this error message in epsxe: "Missing render texture extension!""
however this is totally fine "I get this problem in epsxe: "Missing render texture extension!"" (replacing "error" with "problem")
it's not a wit.ai issue, sentence is understood fine on their page and through curl.

It even fails when just writing a single word "error" ("err", "erro", "errror" <- all of them are fine, no issue here)

renamed the Entity from "errors" to "problems" - same issue.

my current dirty workaround: String messageRaw = event.getMessage().getContent().replaceAll("(?i)error", "errror");

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/setup-java v1
gradle
maven-push.gradle
settings.gradle
build.gradle
  • com.diffplug.gradle.spotless 4.5.1
  • org.tinylog:tinylog 1.3.6
  • com.squareup.okhttp3:okhttp 4.10.0
  • com.squareup.okhttp3:okhttp 4.10.0
  • junit:junit 4.13.2
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 6.9.3

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.