Skip to content

Repository files navigation

Wit-Java

Wit-Java Is A Java Library For Wit.ai

Current Version: 1.0.0

Build StatusJavadocs

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=appidherewit_access_token=accesstokenherelogging_level=tarceordebugorinfoorwarningorerrorlogging_file_path=src/main/java/resources/
logging_file_format=current_dateorapplogging_log_type=fileorconsoleorbothlogging_current_date_format=yyyy-MM-ddlogging_append=trueorfalselogging_buffered=trueorfalse

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

Configconfig = newConfig();
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.

importcom.clivern.wit.api.App;
importcom.clivern.wit.api.endpoint.AppEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
AppgetApp = newApp(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.App;
importcom.clivern.wit.api.endpoint.AppEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
AppgetApp = newApp(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Update an app with the given attributes.

importcom.clivern.wit.api.App;
importcom.clivern.wit.api.endpoint.AppEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
AppupdateApp = newApp(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.App;
importcom.clivern.wit.api.endpoint.AppEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
AppupdateApp = newApp(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Permanently delete the app.

importcom.clivern.wit.api.App;
importcom.clivern.wit.api.endpoint.AppEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
AppdeleteApp = newApp(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.App;
importcom.clivern.wit.api.endpoint.AppEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
AppdeleteApp = newApp(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Create a new app for an existing user.

importcom.clivern.wit.api.App;
importcom.clivern.wit.api.endpoint.AppEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
AppcreateApp = newApp(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.App;
importcom.clivern.wit.api.endpoint.AppEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
AppcreateApp = newApp(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

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

importcom.clivern.wit.api.Message;
importcom.clivern.wit.api.endpoint.MessageEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Messagemessage = newMessage(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Message;
importcom.clivern.wit.api.endpoint.MessageEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Messagemessage = newMessage(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To get a list of available entities for the app.

importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Create a new entity with the given attributes.

importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(EntityEndpoint.CREATE_ENTITY);
entity.setId("favorite_city"); // requiredentity.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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(EntityEndpoint.CREATE_ENTITY);
entity.setId("favorite_city"); // requiredentity.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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To get entity data and values.

importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Update an entity with the given attributes.

importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(EntityEndpoint.UPDATE_ENTITY);
entity.setEntityId("favorite_land");
entity.setId("favorite_city");
entity.setDoc("These are lands worth going to");
entity.setValues(newString[]{
"{\"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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(EntityEndpoint.UPDATE_ENTITY);
entity.setEntityId("favorite_land");
entity.setId("favorite_city");
entity.setDoc("These are lands worth going to");
entity.setValues(newString[]{
"{\"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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Permanently delete an entity.

importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Add new values to a keyword entity.

importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(EntityEndpoint.CREATE_ENTITY_VALUE);
entity.setEntityId("favorite_city");
entity.setValue("London");
entity.setExpressions(newString[]{"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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(EntityEndpoint.CREATE_ENTITY_VALUE);
entity.setEntityId("favorite_city");
entity.setValue("London");
entity.setExpressions(newString[]{"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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Remove a given value from an entity.

importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Create a new expression for a keyword entity.

importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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) ){
returnwit.getResponse();
}else{
returnwit.getError();
}
}
}
}

To Remove an expression from an entity.

importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
//....Configconfig = newConfig();
config.loadPropertiesFile("config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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");Stringresult = "";
Stringerror = "";
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:

packagecom.clivern.test;
importstaticspark.Spark.*;
importcom.clivern.wit.api.Entity;
importcom.clivern.wit.api.endpoint.EntityEndpoint;
importcom.clivern.wit.util.Config;
importcom.clivern.wit.Wit;
/** * Main Class * * @since 1.0.0 */publicclassMain {
publicstaticvoidmain(String[] args)
{
get("/", (request, response) -> {
Configconfig = newConfig();
config.loadPropertiesFile("src/main/java/resources/config.properties");
config.configLogger();
Witwit = newWit(config);
Entityentity = newEntity(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) ){
returnwit.getResponse();
}else{
returnwit.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.

Releases

Sponsor this project

Packages

Used by

Contributors

Languages