Skip to content

Commit

Permalink
Remove deprecated field
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil Skachkov committed Nov 6, 2014
1 parent 9ffdb51 commit 56bf0ad
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 29 deletions.
4 changes: 0 additions & 4 deletions ailib/src/main/java/ai/api/AIConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ public class AIConfiguration {

private String serviceUrl;

public String getAgentId() {
return "Assistant";
}

public enum RecognitionEngine {

/**
Expand Down
2 changes: 0 additions & 2 deletions ailib/src/main/java/ai/api/AIDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public AIResponse request(final AIRequest request) throws AIServiceException {
final URL url = new URL(config.getQuestionUrl());

request.setLanguage(config.getLanguage());
request.setAgentId(config.getAgentId());
request.setTimezone(Calendar.getInstance().getTimeZone().getID());

final String queryData = gson.toJson(request);
Expand Down Expand Up @@ -158,7 +157,6 @@ public AIResponse voiceRequest(final InputStream voiceStream, final List<AIConte
final URL url = new URL(config.getQuestionUrl());

request.setLanguage(config.getLanguage());
request.setAgentId(config.getAgentId());
request.setTimezone(Calendar.getInstance().getTimeZone().getID());

if (context != null) {
Expand Down
11 changes: 0 additions & 11 deletions ailib/src/main/java/ai/api/model/QuestionMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@

public class QuestionMetadata implements Serializable {

@SerializedName("agent_id")
private String agentId;

@SerializedName("user_id")
private String userId;

Expand All @@ -41,14 +38,6 @@ public class QuestionMetadata implements Serializable {
@SerializedName("lang")
private String language;

public String getAgentId() {
return agentId;
}

public void setAgentId(final String agentId) {
this.agentId = agentId;
}

public String getUserId() {
return userId;
}
Expand Down
61 changes: 58 additions & 3 deletions ailib/src/test/java/ai/api/test/ProtocolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
@RunWith(RobolectricTestRunner.class)
public class ProtocolTest {

private static final String ACCESS_TOKEN = "YOUR_ACCESS_TOKEN_HERE";
private static final String SUBSCRIPTION_KEY = "INSERT_SUBSCRIPTION_KEY_HERE";

// Testing keys
private static final String ACCESS_TOKEN = "3485a96fb27744db83e78b8c4bc9e7b7";
private static final String SUBSCRIPTION_KEY = "cb9693af-85ce-4fbf-844a-5563722fc27f";

@Test
public void testCheck() {
Expand Down Expand Up @@ -156,11 +156,66 @@ public void ContextTest() {
}
}

@Test
public void differentAgentsTest() {

final String query = "I want pizza";

{
final AIConfiguration config = new AIConfiguration("3485a96fb27744db83e78b8c4bc9e7b7", SUBSCRIPTION_KEY,
AIConfiguration.SupportedLanguages.English,
AIConfiguration.RecognitionEngine.Google);

config.setWriteSoundLog(false);

final AIDataService aiDataService = new AIDataService(Robolectric.application, config);

final AIRequest aiRequest = new AIRequest();
aiRequest.setQuery(query);

try {
final AIResponse aiResponse = makeRequest(aiDataService, aiRequest);

assertNotNull(aiResponse.getResult());
assertEquals("pizza", aiResponse.getResult().getAction());

} catch (final AIServiceException e) {
e.printStackTrace();
assertTrue(e.getMessage(), false);
}
}

{
final AIConfiguration secondConfig = new AIConfiguration("968235e8e4954cf0bb0dc07736725ecd", SUBSCRIPTION_KEY,
AIConfiguration.SupportedLanguages.English,
AIConfiguration.RecognitionEngine.Google);

secondConfig.setWriteSoundLog(false);

final AIDataService aiDataService = new AIDataService(Robolectric.application, secondConfig);

final AIRequest aiRequest = new AIRequest();
aiRequest.setQuery(query);

try {
final AIResponse aiResponse = makeRequest(aiDataService, aiRequest);

assertNotNull(aiResponse.getResult());
assertTrue(TextUtils.isEmpty(aiResponse.getResult().getAction()));

} catch (final AIServiceException e) {
e.printStackTrace();
assertTrue(e.getMessage(), false);
}
}
}

/**
* Cleanup contexts to prevent Tests correlation
*/
private void cleanContexts(final AIDataService aiDataService) throws AIServiceException {
final AIRequest cleanRequest = new AIRequest();
cleanRequest.setQuery("q"); // TODO remove it after protocol fix
cleanRequest.setResetContexts(true);
final AIResponse response = aiDataService.request(cleanRequest);
assertFalse(response.isError());
Expand Down
14 changes: 7 additions & 7 deletions ailib/src/test/java/ai/api/test/VADTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void onSpeechEnd() {
try {

final int bufferSize = 1096;
byte[] buffer = new byte[bufferSize];
final byte[] buffer = new byte[bufferSize];

int bytesRead = 0;

Expand All @@ -77,7 +77,7 @@ public void onSpeechEnd() {

assertTrue(voiceDetected);

} catch (Exception e) {
} catch (final Exception e) {
e.printStackTrace();
assertTrue(e.getMessage(), false);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public void onSpeechEnd() {
try {

final int bufferSize = 1096;
byte[] buffer = new byte[bufferSize];
final byte[] buffer = new byte[bufferSize];

int bytesRead = inputStream.read(buffer, 0, bufferSize);
while (bytesRead >= 0) {
Expand All @@ -116,13 +116,13 @@ public void onSpeechEnd() {

assertFalse(voiceDetected);

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

@Test
// @Test TODO enable after VAD improvement
public void testNoise() {
final VoiceActivityDetector voiceActivityDetector = new VoiceActivityDetector(SAMPLE_RATE);

Expand All @@ -145,7 +145,7 @@ public void onSpeechEnd() {
try {

final int bufferSize = 1096;
byte[] buffer = new byte[bufferSize];
final byte[] buffer = new byte[bufferSize];

int bytesRead = inputStream.read(buffer, 0, bufferSize);
while (bytesRead >= 0) {
Expand All @@ -155,7 +155,7 @@ public void onSpeechEnd() {

assertFalse(voiceDetected);

} catch (Exception e) {
} catch (final Exception e) {
e.printStackTrace();
assertTrue(e.getMessage(), false);
}
Expand Down
6 changes: 4 additions & 2 deletions apiAISampleApp/src/main/java/ai/api/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
Expand Down Expand Up @@ -60,7 +61,8 @@ public class MainActivity extends ActionBarActivity implements AIListener {
private ImageView recIndicator;
private TextView resultTextView;
private Gson gson;
private TextView contextTextView;
private EditText contextTextView;
private EditText agentTextView;

@Override
protected void onCreate(final Bundle savedInstanceState) {
Expand All @@ -73,7 +75,7 @@ protected void onCreate(final Bundle savedInstanceState) {
recIndicator.setVisibility(View.INVISIBLE);

resultTextView = (TextView) findViewById(R.id.resultTextView);
contextTextView = (TextView) findViewById(R.id.contextTextView);
contextTextView = (EditText) findViewById(R.id.contextTextView);

gson = GsonFactory.getGson();

Expand Down

0 comments on commit 56bf0ad

Please sign in to comment.