Skip to content

Commit

Permalink
SDK Release 1.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil Skachkov committed Mar 20, 2015
1 parent 1190183 commit 05aeebb
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 30 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ Two permissions are required to use the API.AI Android SDK:
* **android.permission.INTERNET** for internet access
* **android.permission.RECORD_AUDIO** for microphone access

Add this dependencies to your project to use SDK

```
compile 'ai.api:sdk:1.4.5@aar'
// api.ai SDK dependencies
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.code.gson:gson:2.3'
compile 'commons-io:commons-io:2.4'
```

Currently, speech recognition is performed using Google's Android SDK, either on the client device or in the cloud. Recognized text is passed to the API.AI through HTTP requests. Also you can try Speaktoit recognition engine (Use [AIConfiguration.RecognitionEngine.Speaktoit](https://github.com/api-ai/api-ai-android-sdk/blob/master/ailib/src/main/java/ai/api/AIConfiguration.java#L37)).

Authentication is accomplished through setting the client access token when initializing an **AIConfiguration** object. The client access token specifies which agent will be used for natural language processing.
Expand Down Expand Up @@ -54,7 +64,7 @@ To create your own app, you must first add the API.AI SDK library to your projec
* Add a dependency to your *build.gradle* file. Add the following line to your **build.gradle** file. (In the sample app, the **apiAISampleApp/build.gradle** is an example of how to do this.)

```
compile 'ai.api:sdk:1.3.0@aar'
compile 'ai.api:sdk:1.4.5@aar'
// api.ai SDK dependencies
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.code.gson:gson:2.3'
Expand Down
74 changes: 49 additions & 25 deletions ailib/src/test/java/ai/api/test/ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,52 @@

import com.google.gson.Gson;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.text.ParseException;
import java.util.Date;

import ai.api.GsonFactory;
import ai.api.model.AIResponse;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@Config(emulateSdk = 18, manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class ModelTest {

@Test
public void testTrimParameters() {
final Gson gson = GsonFactory.getGson();
final String testJson = "{\n" +
" \"id\": \"d872e7d9-d2ee-4ebd-aaff-655bfc8fbf33\",\n" +
" \"timestamp\": \"2015-03-18T09:54:36.216Z\",\n" +
" \"result\": {\n" +
" \"resolvedQuery\": \"remind feed cat tomorrow 7 am\",\n" +
" \"action\": \"task_create\",\n" +
" \"parameters\": {\n" +
" \"date\": \"\",\n" +
" \"date-time\": \"2015-03-19T07:00:00+06:00\",\n" +
" \"time\": \"\",\n" +
" \"text\": \"feed cat\",\n" +
" \"priority\": \"\",\n" +
" \"remind\": \"remind\"\n" +
" }\n" +
" },\n" +
" \"status\": {\n" +
" \"code\": 200,\n" +
" \"errorType\": \"success\"\n" +
" }\n" +
"}";

final AIResponse aiResponse = gson.fromJson(testJson, AIResponse.class);
public static final String TEST_JSON = "{\n" +
" \"id\": \"d872e7d9-d2ee-4ebd-aaff-655bfc8fbf33\",\n" +
" \"timestamp\": \"2015-03-18T09:54:36.216Z\",\n" +
" \"result\": {\n" +
" \"resolvedQuery\": \"remind feed cat tomorrow 7 am\",\n" +
" \"action\": \"task_create\",\n" +
" \"parameters\": {\n" +
" \"date\": \"\",\n" +
" \"date-time\": \"2015-03-19T07:00:00+06:00\",\n" +
" \"time\": \"\",\n" +
" \"text\": \"feed cat\",\n" +
" \"priority\": \"\",\n" +
" \"remind\": \"remind\"\n" +
" }\n" +
" },\n" +
" \"status\": {\n" +
" \"code\": 200,\n" +
" \"errorType\": \"success\"\n" +
" }\n" +
"}";

final Gson gson = GsonFactory.getGson();

@Test
public void trimParametersTest() {
final AIResponse aiResponse = gson.fromJson(TEST_JSON, AIResponse.class);
aiResponse.cleanup();

assertFalse(aiResponse.getResult().getParameters().containsKey("date"));
Expand All @@ -54,4 +59,23 @@ public void testTrimParameters() {
assertTrue(aiResponse.getResult().getParameters().containsKey("remind"));

}

@Test
@Ignore
public void getDateParameterTest() {
final AIResponse aiResponse = gson.fromJson(TEST_JSON, AIResponse.class);

try {
final Date dateTimeParameter = aiResponse.getResult().getDateTimeParameter("date-time");

assertEquals(2015, dateTimeParameter.getYear());
assertEquals(3 - 1 /* month is zero-based */, dateTimeParameter.getMonth());
assertEquals(19, dateTimeParameter.getDate());
assertEquals(7, dateTimeParameter.getHours());
assertEquals(0, dateTimeParameter.getMinutes());

} catch (final Exception e) {
assertTrue(e.getMessage(), false);
}
}
}
22 changes: 20 additions & 2 deletions ailib/src/test/java/ai/api/test/ParametersConverterTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ai.api.test;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.text.ParseException;
import java.util.Date;

import ai.api.util.ParametersConverter;
Expand All @@ -31,7 +31,25 @@ public void parseTimeTest() {
assertEquals(17, date.getMinutes());
assertEquals(50, date.getSeconds());

} catch (final ParseException e) {
} catch (final Exception e) {
assertTrue(e.getMessage(), false);
}
}

@Test
@Ignore
public void parseDateTimeTest() {
final String input = "2015-03-21T07:00:00+06:00";
try {
final Date date = ParametersConverter.parseTime(input);

assertEquals(2015, date.getYear());
assertEquals(3 - 1 /* month is zero-based */, date.getMonth());
assertEquals(21, date.getDate());
assertEquals(7, date.getHours());
assertEquals(0, date.getMinutes());

} catch (final Exception e) {
assertTrue(e.getMessage(), false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

VERSION_NAME=1.3.2
VERSION_CODE=9
VERSION_NAME=1.4.5
VERSION_CODE=15
GROUP=ai.api

POM_DESCRIPTION=API.AI Android SDK allows using voice commands and integration with dialog scenarios defined for a particular agent in API.AI.
Expand Down

0 comments on commit 05aeebb

Please sign in to comment.