Add the SDK, Sample Application, LICENSE and CONTRIBUTING files, and modified the README file

This commit is contained in:
Ahmed Elhinidy 2016-09-04 18:34:20 +02:00
Родитель 4d862ce717
Коммит 88913231b0
78 изменённых файлов: 2996 добавлений и 2 удалений

46
CONTRIBUTING.md Normal file
Просмотреть файл

@ -0,0 +1,46 @@
Contributing to Microsoft Cognitive Services Client Libraries & Samples
===============================================
So, you want to contribute on a client library or sample for one of the Microsoft Cognitive Services.
Here's what you need to know.
1. Each SDK should include both a client library and a sample showing the API in
action
2. When working on an SDK, it's important that we are consistent from project to project, so we ask you to follow the coding guidelines below:
- Windows [(Coding guidelines for C#)](https://msdn.microsoft.com/en-us/library/ff926074.aspx) -- also reference our [common Windows code](https://github.com/Microsoft/Cognitive-common-windows) for building samples
- Android [(Coding guidelines for
Java)](<http://source.android.com/source/code-style.html>)
- iOS Objective-C [(Coding guidelines for
Cocoa)](<https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html>)
- Optional: Client Javascript ([Coding guidelines for
npm](<https://docs.npmjs.com/misc/coding-style>))
3. Samples are important for illustrating how to actually call into the API.
Samples should be as visual and reusable as possible.
- Do:
- Create a UI sample when possible.
- Make your sample user friendly. Expect that developers will want to try
different mainline scenarios and key APIs.
- Create code that's easy for other developers to copy/paste into their
own solutions
- Consider:
- Adding UI to allow devs to quickly copy/paste subscription keys, instead
of updating them in the code or using a config file. The
FaceAPI-WPF-Samples.sln provides an example.
- Don't:
- Leave your subscription key in the source of samples. You do not want your key to be abused by others.
Happy coding!

1
ClientLibrary/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
/build

Просмотреть файл

@ -0,0 +1,82 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'signing'
signing {
sign configurations.archives
}
group = "com.microsoft.cognitiveservices"
archivesBaseName = "luis"
version = "0.1.0"
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.loopj.android:android-async-http:1.4.9'
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Microsoft Cognitive Servies LUIS SDK'
packaging 'jar'
description 'This is the LUIS SDK for Android'
url 'githubURL'
// Project URL
url 'https://github.com/Microsoft/ProjectOxford-ClientSDK'
// Github information
scm {
connection 'scm:git:https://github.com/Microsoft/ProjectOxford-ClientSDK'
developerConnection 'scm:git:https://github.com/Microsoft/ProjectOxford-ClientSDK'
url 'scm:git:https://github.com/Microsoft/ProjectOxford-ClientSDK'
}
licenses {
license {
name 'MIT'
url 'https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/LICENSE.md'
}
}
developers {
developer {
id 'projectoxfordSDK'
name 'Project Oxford SDK'
email 'projectoxfordsdk@microsoft.com'
}
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":clientlibrary" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.microsoft.cognitiveservices" external.system.module.version="0.1.0" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":clientlibrary" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
<option name="LIBRARY_PROJECT" value="true" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-23.4.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.4.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="httpclient-4.3.6" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" exported="" name="android-async-http-1.4.9" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.4.0" level="project" />
<orderEntry type="library" exported="" name="android-android-23" level="project" />
</component>
</module>

17
ClientLibrary/proguard-rules.pro поставляемый Normal file
Просмотреть файл

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\t-ahelhi\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

Просмотреть файл

@ -0,0 +1,13 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

Просмотреть файл

@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.microsoft.cognitiveservices.luis.clientlibrary">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
</application>
</manifest>

Просмотреть файл

@ -0,0 +1,49 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* Describes the LUIS Action structure
*/
public class LUISAction {
private boolean triggered;
private String name;
private List<LUISParameter> parameters;
/**
* Constructs a LUIS Action from a JSON object
* @param JSONaction a JSONObject containing the data of an action
*/
public LUISAction(JSONObject JSONaction) {
triggered = JSONaction.optBoolean("triggered");
name = JSONaction.optString("name");
parameters = new ArrayList<>();
JSONArray JSONparameters = JSONaction.optJSONArray("parameters");
for (int i = 0; JSONparameters != null && i < JSONparameters.length(); i++) {
JSONObject JSONparameter = JSONparameters.optJSONObject(i);
if (JSONparameter != null) {
LUISParameter parameter = new LUISParameter(JSONparameter);
parameters.add(parameter);
}
}
}
public boolean getTrigerred() {
return triggered;
}
public String getName() {
return name;
}
public List<LUISParameter> getParams() {
return parameters;
}
}

Просмотреть файл

@ -0,0 +1,252 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import com.loopj.android.http.*;
import cz.msebera.android.httpclient.Header;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.regex.Pattern;
/**
* This is the interface of the LUIS SDK
*/
public class LUISClient {
private final String LUISURL = "https://api.projectoxford.ai/luis/v1/application";
private final String LUISPreviewURL;
private final String LUISPredictMask = "%s%s?id=%s&subscription-key=%s%s&q=%s";
private final String LUISReplyMask = "%s%s?id=%s&subscription-key=%s&contextid=%s%s&q=%s";
private final String LUISVerboseURL;
private String appId;
private String appKey;
private boolean preview;
private boolean verbose;
/**
* Constructs a LUISClient with the corresponding user's App Id and Subscription Keys
* @param appId a String containing the Application Id
* @param appKey a String containing the Subscription Key
* @param preview a boolean to choose whether to use the published or the in preview version
* @param verbose a boolean to choose whether or not to use the verbose version
* @throws NullPointerException
* @throws IllegalArgumentException
*/
public LUISClient(String appId, String appKey, boolean preview, boolean verbose) {
if (appId == null)
throw new NullPointerException("NULL Application Id");
if (appId.isEmpty())
throw new IllegalArgumentException("Empty Application Id");
if (Pattern.compile("\\s").matcher(appId).find())
throw new IllegalArgumentException("Invalid Application Id");
if (appKey == null)
throw new NullPointerException("NULL Subscription Key");
if (appKey.isEmpty())
throw new IllegalArgumentException("Empty Subscription Key");
if (Pattern.compile("\\s").matcher(appKey).find())
throw new IllegalArgumentException("Invalid Subscription Key");
this.appId = appId;
this.appKey = appKey;
this.preview = preview;
this.verbose = verbose;
LUISPreviewURL = preview ? "/preview" : "";
LUISVerboseURL = verbose ? "&verbose=true" : "";
}
/**
* Constructs a LUISClient with the corresponding user's App Id and Subscription Keys
* in non verbose version (if preview version is used)
* @param appId a String containing the Application Id
* @param appKey a String containing the Subscription Key
* @param preview a boolean to choose whether to use the published or the in preview version
* @throws NullPointerException
* @throws IllegalArgumentException
*/
public LUISClient(String appId, String appKey, boolean preview) {
this(appId, appKey, preview, false);
}
/**
* Constructs a LUISClient with the corresponding user's App Id and Subscription Keys
* in non preview version
* in non verbose version (if preview version is used)
* @param appId a String containing the Application Id
* @param appKey a String containing the Subscription Key
* @throws NullPointerException
* @throws IllegalArgumentException
*/
public LUISClient(String appId, String appKey) {
this(appId, appKey, false, false);
}
/**
* Starts the prediction procedure for the user's text
* @param text A String containing the text that needs to be analysed and predicted
* @return A LUISResponse containing the content of the response sent by LUIS API
* @throws NullPointerException
* @throws IllegalArgumentException
* @throws IOException
*/
public LUISResponse predict(String text) throws IOException {
if (text == null)
throw new NullPointerException("NULL text to predict");
text = text.trim();
if (text.isEmpty())
throw new IllegalArgumentException("Empty text to predict");
return LUISUtility.LUISHTTP(predictURLGen(text));
}
/**
* Generates the url for the predict web request
* @param text A String containing the text that needs to be analysed and predicted
* @return A String containing the url for the predict web request
* @throws IOException
*/
public String predictURLGen(String text) throws IOException{
String encodedQuery;
encodedQuery = URLEncoder.encode(text, "UTF-8");
return String.format(LUISPredictMask,LUISURL,LUISPreviewURL, appId, appKey, LUISVerboseURL, encodedQuery);
}
/**
* Starts the replying procedure for the user's dialog, and accepts a LUISResponse object
* which includes the context Id of the dialog
* @param text A String containing the text that needs to be analysed and predicted
* @param response A LUISResponse containing the context Id of the current Dialog
* @returns A LUISResponse containing the reply data sent by LUIS
* @throws RuntimeException
* @throws NullPointerException
* @throws IllegalArgumentException
* @throws IOException
*/
public LUISResponse reply(String text, LUISResponse response) throws IOException {
//TODO: When the reply can be used in the published version:
//TODO: This condition has to be removed
if(!preview)
throw new RuntimeException("Reply can only be used with the preview version");
if (text == null)
throw new NullPointerException("NULL text to predict");
text = text.trim();
if (text.isEmpty())
throw new IllegalArgumentException("Empty text to predict");
if (response == null)
throw new NullPointerException("NULL LUIS response");
return LUISUtility.LUISHTTP(replyURLGen(text,response));
}
/**
* Generates the url for the reply web request
* @param text A String containing the text that needs to be analysed and predicted
* @return A String containing the url for the reply web request
* @throws IOException
*/
String replyURLGen(String text, LUISResponse response) throws IOException {
String encodedQuery;
encodedQuery = URLEncoder.encode(text, "UTF-8");
return String.format(LUISReplyMask, LUISURL, LUISPreviewURL, appId, appKey, response.getDialog().getContextId(), LUISVerboseURL, encodedQuery);
}
/**
* Starts the prediction procedure for the user's text
* @param text A String containing the text that needs to be analysed and predicted
* @param responseHandler A responseHandler object af a class that can contains 2 functions
* onSuccess and onFailure to be executed based on the success or the failure of the prediction
* @throws NullPointerException
* @throws IllegalArgumentException
* @throws IOException
*/
public void predict(String text, final LUISResponseHandler responseHandler) throws IOException {
if (text == null)
throw new NullPointerException("NULL text to predict");
text = text.trim();
if (text.isEmpty())
throw new IllegalArgumentException("Empty text to predict");
if (responseHandler == null)
throw new NullPointerException("Null response handler");
AsyncHttpClient client = new AsyncHttpClient();
client.get(predictURLGen(text), new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
LUISResponse response = null;
try {
String JSONResponse = new String(responseBody);
response = new LUISResponse(JSONResponse);
} catch(Exception e) {
responseHandler.onFailure(e);
}
responseHandler.onSuccess(response);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody,
Throwable error) {
String errorMsg = "";
if (statusCode == 400) {
errorMsg = "Invalid Application Id";
} else if (statusCode == 401) {
errorMsg = "Invalid Subscription Key";
}
responseHandler.onFailure(new IllegalArgumentException(errorMsg));
}
});
}
/**
* Starts the replying procedure for the user's dialog, and accepts a LUISResponse object
* which includes the context Id of the dialog
* @param text A String containing the text that needs to be analysed and predicted
* @param response A LUISResponse containing the context Id of the current Dialog
* @param responseHandler A responseHandler object af a class that can contains 2 functions
* onSuccess and onFailure to be executed based on the success or the failure of the prediction
* @throws RuntimeException
* @throws NullPointerException
* @throws IllegalArgumentException
* @throws IOException
*/
public void reply(String text, LUISResponse response,
final LUISResponseHandler responseHandler) throws IOException {
if(!preview)
throw new RuntimeException("Reply can only be used with the preview version");
if (text == null)
throw new NullPointerException("NULL text to predict");
text = text.trim();
if (text.isEmpty())
throw new IllegalArgumentException("Empty text to predict");
if (response == null)
throw new NullPointerException("NULL LUIS response");
if (responseHandler == null)
throw new NullPointerException("Null response handler");
AsyncHttpClient client = new AsyncHttpClient();
client.get(replyURLGen(text,response), new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
LUISResponse response = null;
try {
String JSONResponse = new String(responseBody);
response = new LUISResponse(JSONResponse);
} catch(Exception e) {
responseHandler.onFailure(e);
}
responseHandler.onSuccess(response);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody,
Throwable error) {
String errorMsg = "";
if (statusCode == 400) {
errorMsg = "Invalid Application Id";
} else if (statusCode == 401) {
errorMsg = "Invalid Subscription Key";
}
responseHandler.onFailure(new IllegalArgumentException(errorMsg));
}
});
}
}

Просмотреть файл

@ -0,0 +1,47 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class LUISCompositeEntity {
private String parentType;
private String value;
private List<LUISCompositeEntityChild> children;
/**
* Constructs a LUIS Composite Entity from a JSON object
*
* @param JSONcompositeEntity a JSONObject containing the composite entity data
*/
public LUISCompositeEntity(JSONObject JSONcompositeEntity) {
parentType = JSONcompositeEntity.optString("parentType");
value = JSONcompositeEntity.optString("value");
children = new ArrayList<>();
JSONArray JSONcompositeEntityChildren = JSONcompositeEntity.optJSONArray("children");
for (int i = 0; JSONcompositeEntityChildren != null
&& i < JSONcompositeEntityChildren.length(); i++) {
JSONObject JSONcompositeEntityChild = JSONcompositeEntityChildren.optJSONObject(i);
if (JSONcompositeEntityChild != null) {
LUISCompositeEntityChild compositeEntityChild =
new LUISCompositeEntityChild(JSONcompositeEntityChild);
children.add(compositeEntityChild);
}
}
}
public String getParentType() {
return parentType;
}
public String getValue() {
return value;
}
public List<LUISCompositeEntityChild> getChildren() {
return children;
}
}

Просмотреть файл

@ -0,0 +1,29 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONObject;
import java.util.List;
public class LUISCompositeEntityChild {
private String type;
private String value;
private List<LUISCompositeEntityChild> children;
/**
* Constructs a LUIS Composite Entity Child from a JSON object
*
* @param JSONcompositeEntityChild a JSONObject containing the composite entity child data
*/
public LUISCompositeEntityChild(JSONObject JSONcompositeEntityChild) {
type = JSONcompositeEntityChild.optString("type");
value = JSONcompositeEntityChild.optString("value");
}
public String getType() {
return type;
}
public String getValue() {
return value;
}
}

Просмотреть файл

@ -0,0 +1,46 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONObject;
/**
* Describes the LUIS Action structure
*/
public class LUISDialog {
private String prompt;
private String parameterName;
private String contextId;
private String status;
private boolean finished;
/**
* Constructs a LUIS Dialog from a JSON object
* @param JSONdialog a JSONObject containing the data of a dialog
*/
public LUISDialog(JSONObject JSONdialog) {
prompt = JSONdialog.optString("prompt");
parameterName = JSONdialog.optString("parameterName");
contextId = JSONdialog.optString("contextId");
status = JSONdialog.optString("status");
finished = status.equals("Finished");
}
public String getPrompt() {
return prompt;
}
public String getParameterName() {
return parameterName;
}
public String getContextId() {
return contextId;
}
public String getStatus() {
return status;
}
public boolean isFinished() {
return finished;
}
}

Просмотреть файл

@ -0,0 +1,56 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONObject;
import java.util.Map;
/**
* Describes the LUIS Entity structure
*/
public class LUISEntity {
private String name;
private String type;
private int startIndex;
private int endIndex;
private double score;
private Map<String, Object> resolution;
/**
* Constructs a LUIS Entity from a JSON object
* @param JSONentity a JSONObject containing the entity data
*/
public LUISEntity(JSONObject JSONentity) {
name = JSONentity.optString("entity");
type = JSONentity.optString("type");
startIndex = JSONentity.optInt("startIndex");
endIndex = JSONentity.optInt("endIndex");
score = JSONentity.optDouble("score");
JSONObject JSONresolution = JSONentity.optJSONObject("resolution");
resolution = JSONresolution != null ? LUISUtility.JSONObjectToMap(JSONresolution) : null;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public int getStartIndex() {
return startIndex;
}
public int getEndIndex() {
return endIndex;
}
public double getScore() {
return score;
}
public Map<String, Object> getResolution() {
return resolution;
}
}

Просмотреть файл

@ -0,0 +1,49 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* Describes the LUIS Intent structure
*/
public class LUISIntent {
private String name;
private double score;
private List<LUISAction> actions;
/**
* Constructs a LUIS Intention from a JSON object
* @param JSONintent a JSONObject containing the intent data
*/
public LUISIntent(JSONObject JSONintent) {
name = JSONintent.optString("intent");
score = JSONintent.optDouble("score");
actions = new ArrayList<>();
JSONArray JSONactions = JSONintent.optJSONArray("actions");
for (int i = 0; JSONactions != null && i < JSONactions.length(); i++) {
JSONObject JSONaction = JSONactions.optJSONObject(i);
if(JSONaction != null) {
LUISAction action = new LUISAction(JSONaction);
actions.add(action);
}
}
}
public String getName() {
return name;
}
public double getScore() {
return score;
}
public List<LUISAction> getActions() {
return actions;
}
}

Просмотреть файл

@ -0,0 +1,49 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* Describes the Parameter structure
*/
public class LUISParameter {
private String name;
private boolean required;
private List<LUISParameterValue> parameterValues;
/**
* Constructs a LUIS Parameter from a JSON object
* @param JSONparameter a JSONObject containing the parameter data
*/
public LUISParameter(JSONObject JSONparameter) {
name = JSONparameter.optString("name");
required = JSONparameter.optBoolean("required");
parameterValues = new ArrayList<>();
JSONArray JSONparameterValues = JSONparameter.optJSONArray("value");
for (int i = 0; JSONparameterValues != null && i < JSONparameterValues.length(); i++) {
JSONObject JSONparameterValue = JSONparameterValues.optJSONObject(i);
if (JSONparameterValue != null) {
LUISParameterValue parameterValue = new LUISParameterValue(JSONparameterValue);
parameterValues.add(parameterValue);
}
}
}
public String getName() {
return name;
}
public boolean getRequired() {
return required;
}
public List<LUISParameterValue> getParameterValues() {
return parameterValues;
}
}

Просмотреть файл

@ -0,0 +1,43 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONObject;
import java.util.Map;
/**
* Describes the Parameter Value structure
*/
public class LUISParameterValue {
private String name;
private String type;
private double score;
private Map<String, Object> resolution;
/**
* Constructs a LUIS Action from a JSON object
* @param JSONparameterValue a JSONObject containing the parameter value data
*/
public LUISParameterValue(JSONObject JSONparameterValue) {
name = JSONparameterValue.optString("entity");
type = JSONparameterValue.optString("type");
score = JSONparameterValue.optDouble("score");
JSONObject JSONresolution = JSONparameterValue.optJSONObject("resolution");
resolution = JSONresolution != null ? LUISUtility.JSONObjectToMap(JSONresolution) : null;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public double getScore() {
return score;
}
public Map<String, Object> getResolution() {
return resolution;
}
}

Просмотреть файл

@ -0,0 +1,107 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* Describes the response structure, and is the main point
* to access the response sent by LUIS after prediction
*/
public class LUISResponse {
private String query;
private List<LUISIntent> intents;
private List<LUISEntity> entities;
private List<LUISCompositeEntity> compositeEntities;
private LUISDialog dialog;
/**
* Constructs a LUIS Response from the JSON sent by LUIS
* @param JSONResponse a String containing the JSON response sent by LUIS
* @throws NullPointerException
* @throws IllegalArgumentException
*/
public LUISResponse(String JSONResponse) throws NullPointerException,IllegalArgumentException {
if (JSONResponse == null)
throw new NullPointerException("NULL JSON response");
if (JSONResponse.isEmpty())
throw new IllegalArgumentException("Invalid Subscription Key");
JSONObject JSONresponse;
//Create an empty JSONObject If there is a problem with the JSON sent by LUIS
try {
JSONresponse = new JSONObject(JSONResponse);
} catch (JSONException e) {
JSONresponse = new JSONObject();
}
query = JSONresponse.optString("query");
intents = new ArrayList<>();
entities = new ArrayList<>();
compositeEntities = new ArrayList<>();
JSONObject JSONdialog = JSONresponse.optJSONObject("dialog");
dialog = JSONdialog != null ? new LUISDialog(JSONdialog) : null;
JSONObject JSONtopIntent = JSONresponse.optJSONObject("topScoringIntent");
if (JSONtopIntent != null) {
intents.add(new LUISIntent(JSONtopIntent));
} else {
JSONArray JSONintents = JSONresponse.optJSONArray("intents");
for (int i = 0; JSONintents != null && i < JSONintents.length(); i++) {
JSONObject JSONintent = JSONintents.optJSONObject(i);
if (JSONintent != null) {
LUISIntent intent = new LUISIntent(JSONintent);
intents.add(intent);
}
}
}
JSONArray JSONentities = JSONresponse.optJSONArray("entities");
for (int i = 0; JSONentities != null && i < JSONentities.length(); i++) {
JSONObject JSONentity = JSONentities.optJSONObject(i);
if(JSONentity != null) {
LUISEntity entity = new LUISEntity(JSONentity);
entities.add(entity);
}
}
JSONArray JSONcompositeEntities = JSONresponse.optJSONArray("compositeEntities");
for (int i = 0; JSONcompositeEntities != null && i < JSONcompositeEntities.length(); i++) {
JSONObject JSONcompositeEntity = JSONcompositeEntities.optJSONObject(i);
if(JSONcompositeEntity != null) {
LUISCompositeEntity compositeEntity = new LUISCompositeEntity(JSONcompositeEntity);
compositeEntities.add(compositeEntity);
}
}
}
public String getQuery() {
return query;
}
public LUISIntent getTopIntent() {
return intents.get(0);
}
public List<LUISIntent> getIntents() {
return intents;
}
public List<LUISEntity> getEntities() {
return entities;
}
public List<LUISCompositeEntity> getCompositeEntities() {
return compositeEntities;
}
public LUISDialog getDialog() {
return dialog;
}
}

Просмотреть файл

@ -0,0 +1,25 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
/**
* An interface to be inherited when predicting text
* in order to encapsulate the developer's logic that
* depeneds on the response sent by LUIS
*/
public interface LUISResponseHandler {
/**
* This functions needs to be implemented by the user in order to
* encapsulate his logic that should be executed if the prediction
* or replying actions succeed
* @param response a LUISResponse object that contains the response data
*/
void onSuccess(LUISResponse response);
/**
* This functions needs to be implemented by the user in order to
* encapsulate his logic that should be executed if the prediction
* or replying actions fail
* @param e an Exception that is thrown while predicting or replying
*/
void onFailure(Exception e);
}

Просмотреть файл

@ -0,0 +1,121 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* A utility class that contains functions needed by LUIS SDK
*/
public class LUISUtility {
/**
* Consumes LUIS API and returns an object containing the parsed LUIS reponse
* @param url A string containing the URL of the LUIS API to be consumed
* @return LUISResponse containing the content of the response sent by LUIS API
* @throws IOException
*/
public static LUISResponse LUISHTTP(String url) throws IOException {
HttpURLConnection urlConnection;
LUISResponse response = null;
URL _url = new URL(url);
urlConnection = (HttpURLConnection) _url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
response = responseToLUISResponse(in);
} finally {
urlConnection.disconnect();
}
return response;
}
/**
* Converts the JSON response into a Java Object
* @param in an InputStream for the JSON response data
* @return LUISResponse containing the content of the response sent by LUIS API
* @throws IOException
*/
public static LUISResponse responseToLUISResponse(InputStream in) throws IOException {
LUISResponse response = null;
String line;
String result = "";
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
while ((line = bufferedReader.readLine()) != null)
result += line;
}finally {
in.close();
}
response = new LUISResponse(result);
return response;
}
/**
* Converts a JSONObject to a Map<String, Object>
*
* @param JSONobject A JSONObject that needs to be converted to a Map<String, Object>
* @return A Map<String, Object> that contains the data of the JSONObject
*/
public static Map<String, Object> JSONObjectToMap(JSONObject JSONobject) {
Map<String, Object> map = new HashMap<>();
Iterator<String> keysItr = JSONobject.keys();
while (keysItr.hasNext()) {
try {
String key = keysItr.next();
Object value = JSONobject.get(key);
if (value instanceof JSONObject) {
value = JSONObjectToMap((JSONObject) value);
} else if (value instanceof JSONArray) {
value = JSONArrayToList((JSONArray) value);
}
map.put(key, value);
} catch (JSONException e) {
Log.e("LUIS Exception", e.getMessage());
break;
}
}
return map;
}
/**
* Converts a JSONArray to a List<Object>
*
* @param JSONarray A JSONArray that needs to be converted to a List<Object>
* @return A List<Object> that contains the data of the JSONArray
*/
public static List<Object> JSONArrayToList(JSONArray JSONarray) {
List<Object> list = new ArrayList<>();
for (int i = 0; i < JSONarray.length(); i++) {
try {
Object value = JSONarray.get(i);
if (value instanceof JSONObject) {
value = JSONObjectToMap((JSONObject) value);
} else if (value instanceof JSONArray) {
value = JSONArrayToList((JSONArray) value);
}
list.add(value);
} catch (JSONException e) {
Log.e("LUIS Exception", e.getMessage());
break;
}
}
return list;
}
}

Просмотреть файл

@ -0,0 +1,3 @@
<resources>
<string name="app_name">ClientLibrary</string>
</resources>

Просмотреть файл

@ -0,0 +1,15 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}

14
LICENSE.md Normal file
Просмотреть файл

@ -0,0 +1,14 @@
Microsoft Cognitive Services SDK
Copyright (c) Microsoft Corporation
All rights reserved.
*This license applies only to the SDK and the sample applications code.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Просмотреть файл

@ -1,2 +1,26 @@
# Microsoft-LUIS-Android
Android (Java) SDK for the Microsoft Language Understanding Intelligent Service API, part of Congitive Services
LUIS
==============
LUIS is a service for language understanding that provides intent classification and entity extraction.
In order to use the SDK you first need to create and publish an app on www.luis.ai where you will get your appID and appKey and input their values when prompted by the sample applications.
The SDK
--------------
The SDK can be used in 2 different ways with a separate sample for each way.
- One way to use it is synchronously by calling the functions "predict" and "reply" that are present in the "LUISClient" and receiving the response as a returned object from the class "LUISResponse".
- Another way is asynchronously by creating 2 callback functions "onSuccess" and "onFailure" and passing them to the "predict" and "reply" functions to be called asynchronously in the cases of the request success or failure.
Sample Application
--------------
The sample application allows you to perform the Predict and Reply operations and to view the following parts of the parsed response:
- Query
- Top Intent
- Entities
- Dialog status and prompt
License
=======
All Microsoft Cognitive Services SDKs and samples are licensed with the MIT License. For more details, see
[LICENSE](</LICENSE.md>).

8
Sample/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures

1
Sample/.idea/.name Normal file
Просмотреть файл

@ -0,0 +1 @@
Sample

22
Sample/.idea/compiler.xml Normal file
Просмотреть файл

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

Просмотреть файл

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="" />
</component>

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

26
Sample/.idea/gradle.xml Normal file
Просмотреть файл

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.10" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/clientlibrary" />
</set>
</option>
<option name="myModules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/clientlibrary" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

Просмотреть файл

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintUselessParent" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

Просмотреть файл

@ -0,0 +1,7 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>

46
Sample/.idea/misc.xml Normal file
Просмотреть файл

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

10
Sample/.idea/modules.xml Normal file
Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Sample.iml" filepath="$PROJECT_DIR$/Sample.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/clientlibrary/clientlibrary.iml" filepath="$PROJECT_DIR$/clientlibrary/clientlibrary.iml" />
</modules>
</component>
</project>

Просмотреть файл

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

6
Sample/.idea/vcs.xml Normal file
Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

1
Sample/app/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
/build

27
Sample/app/build.gradle Normal file
Просмотреть файл

@ -0,0 +1,27 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.microsoft.cognitiveservices.luis.sample"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile project(':clientlibrary')
}

17
Sample/app/proguard-rules.pro поставляемый Normal file
Просмотреть файл

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\t-ahelhi\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

Просмотреть файл

@ -0,0 +1,13 @@
package com.microsoft.cognitiveservices.luis.sample;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

Просмотреть файл

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.microsoft.cognitiveservices.luis.sample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:windowSoftInputMode="adjustNothing">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Просмотреть файл

@ -0,0 +1,129 @@
package com.microsoft.cognitiveservices.luis.sample;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
import com.microsoft.cognitiveservices.luis.clientlibrary.LUISClient;
import com.microsoft.cognitiveservices.luis.clientlibrary.LUISDialog;
import com.microsoft.cognitiveservices.luis.clientlibrary.LUISEntity;
import com.microsoft.cognitiveservices.luis.clientlibrary.LUISIntent;
import com.microsoft.cognitiveservices.luis.clientlibrary.LUISResponse;
import com.microsoft.cognitiveservices.luis.clientlibrary.LUISResponseHandler;
import java.util.List;
public class MainActivity extends AppCompatActivity {
LUISResponse previousResponse = null;
String chatText = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnPredict = (Button) findViewById(R.id.buttonPredict);
Button btnReply = (Button) findViewById(R.id.buttonReply);
final EditText editTextAppId = (EditText) findViewById(R.id.editTextAppId);
final EditText editTextAppKey = (EditText) findViewById(R.id.editTextAppKey);
final EditText editTextPredict = (EditText) findViewById(R.id.editTextPredict);
btnPredict.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String appId = String.valueOf(editTextAppId.getText());
String appKey = String.valueOf(editTextAppKey.getText());
String textPredict = String.valueOf(editTextPredict.getText());
try {
LUISClient client = new LUISClient(appId, appKey, true, true);
client.predict(textPredict, new LUISResponseHandler() {
@Override
public void onSuccess(LUISResponse response) {
processResponse(response);
}
@Override
public void onFailure(Exception e) {
printToResponse(e.getMessage());
}
});
} catch (Exception e) {
printToResponse(e.getMessage());
}
editTextPredict.setText("");
}
});
btnReply.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (previousResponse == null || (previousResponse.getDialog() != null
&& previousResponse.getDialog().isFinished())) {
printToResponse("Nothing to reply to!");
return;
}
String appId = String.valueOf(editTextAppId.getText());
String appKey = String.valueOf(editTextAppKey.getText());
String textPredict = String.valueOf(editTextPredict.getText());
try {
LUISClient client = new LUISClient(appId, appKey, true, true);
client.reply(textPredict, previousResponse, new LUISResponseHandler() {
@Override
public void onSuccess(LUISResponse response) {
processResponse(response);
}
@Override
public void onFailure(Exception e) {
printToResponse(e.getMessage());
}
});
} catch (Exception e) {
printToResponse(e.getMessage());
}
editTextPredict.setText("");
}
});
}
public void processResponse(LUISResponse response) {
printToResponse("-------------------");
previousResponse = response;
printToResponse(response.getQuery());
LUISIntent topIntent = response.getTopIntent();
printToResponse("Top Intent: " + topIntent.getName());
printToResponse("Entities:");
List<LUISEntity> entities = response.getEntities();
for (int i = 0; i < entities.size(); i++) {
printToResponse(String.valueOf(i+1)+ " - " + entities.get(i).getName());
}
LUISDialog dialog = response.getDialog();
if (dialog != null) {
printToResponse("Dialog Status: " + dialog.getStatus());
if (!dialog.isFinished()) {
printToResponse("Dialog prompt: " + dialog.getPrompt());
}
}
}
public void printToResponse(String text) {
TextView textViewResponse = (TextView) findViewById(R.id.textViewResponse);
chatText += "\n" + text;
textViewResponse.setText(chatText);
scrollToBottom();
}
public void scrollToBottom(){
final ScrollView scrollView = (ScrollView) findViewById(R.id.SV);
scrollView.postDelayed(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
}, 100);
}
}

Просмотреть файл

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.microsoft.cognitiveservices.luis.sample.MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="40"
android:orientation="vertical"
android:gravity="center">
<EditText
android:id="@+id/editTextAppId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your App Id"
android:inputType="text" />
<EditText
android:id="@+id/editTextAppKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Subscription Key"
android:inputType="text" />
<EditText
android:id="@+id/editTextPredict"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter text to predict"
android:inputType="text" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/buttonPredict"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Predict" />
<Button
android:id="@+id/buttonReply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reply" />
</LinearLayout>
</LinearLayout>
<ScrollView
android:id="@+id/SV"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="60"
android:fillViewport="true">
<TextView
android:id="@+id/textViewResponse"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
</LinearLayout>
</RelativeLayout>

Двоичные данные
Sample/app/src/main/res/mipmap-hdpi/ic_launcher.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.3 KiB

Двоичные данные
Sample/app/src/main/res/mipmap-mdpi/ic_launcher.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.2 KiB

Двоичные данные
Sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.7 KiB

Двоичные данные
Sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.5 KiB

Двоичные данные
Sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 10 KiB

Просмотреть файл

@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

Просмотреть файл

@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

Просмотреть файл

@ -0,0 +1,3 @@
<resources>
<string name="app_name">Cognitive Services LUIS API Sample</string>
</resources>

Просмотреть файл

@ -0,0 +1,11 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

Просмотреть файл

@ -0,0 +1,15 @@
package com.microsoft.cognitiveservices.luis.sample;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}

23
Sample/build.gradle Normal file
Просмотреть файл

@ -0,0 +1,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

1
Sample/clientlibrary/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
/build

Просмотреть файл

@ -0,0 +1,82 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'signing'
signing {
sign configurations.archives
}
group = "com.microsoft.cognitiveservices"
archivesBaseName = "luis"
version = "0.1.0"
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.loopj.android:android-async-http:1.4.9'
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Microsoft Cognitive Servies LUIS SDK'
packaging 'jar'
description 'This is the LUIS SDK for Android'
url 'githubURL'
// Project URL
url 'https://github.com/Microsoft/ProjectOxford-ClientSDK'
// Github information
scm {
connection 'scm:git:https://github.com/Microsoft/ProjectOxford-ClientSDK'
developerConnection 'scm:git:https://github.com/Microsoft/ProjectOxford-ClientSDK'
url 'scm:git:https://github.com/Microsoft/ProjectOxford-ClientSDK'
}
licenses {
license {
name 'MIT'
url 'https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/LICENSE.md'
}
}
developers {
developer {
id 'projectoxfordSDK'
name 'Project Oxford SDK'
email 'projectoxfordsdk@microsoft.com'
}
}
}
}
}
}

17
Sample/clientlibrary/proguard-rules.pro поставляемый Normal file
Просмотреть файл

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\t-ahelhi\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

Просмотреть файл

@ -0,0 +1,13 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

Просмотреть файл

@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.microsoft.cognitiveservices.luis.clientlibrary">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
</application>
</manifest>

Просмотреть файл

@ -0,0 +1,49 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* Describes the LUIS Action structure
*/
public class LUISAction {
private boolean triggered;
private String name;
private List<LUISParameter> parameters;
/**
* Constructs a LUIS Action from a JSON object
* @param JSONaction a JSONObject containing the data of an action
*/
public LUISAction(JSONObject JSONaction) {
triggered = JSONaction.optBoolean("triggered");
name = JSONaction.optString("name");
parameters = new ArrayList<>();
JSONArray JSONparameters = JSONaction.optJSONArray("parameters");
for (int i = 0; JSONparameters != null && i < JSONparameters.length(); i++) {
JSONObject JSONparameter = JSONparameters.optJSONObject(i);
if (JSONparameter != null) {
LUISParameter parameter = new LUISParameter(JSONparameter);
parameters.add(parameter);
}
}
}
public boolean getTrigerred() {
return triggered;
}
public String getName() {
return name;
}
public List<LUISParameter> getParams() {
return parameters;
}
}

Просмотреть файл

@ -0,0 +1,252 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import com.loopj.android.http.*;
import cz.msebera.android.httpclient.Header;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.regex.Pattern;
/**
* This is the interface of the LUIS SDK
*/
public class LUISClient {
private final String LUISURL = "https://api.projectoxford.ai/luis/v1/application";
private final String LUISPreviewURL;
private final String LUISPredictMask = "%s%s?id=%s&subscription-key=%s%s&q=%s";
private final String LUISReplyMask = "%s%s?id=%s&subscription-key=%s&contextid=%s%s&q=%s";
private final String LUISVerboseURL;
private String appId;
private String appKey;
private boolean preview;
private boolean verbose;
/**
* Constructs a LUISClient with the corresponding user's App Id and Subscription Keys
* @param appId a String containing the Application Id
* @param appKey a String containing the Subscription Key
* @param preview a boolean to choose whether to use the published or the in preview version
* @param verbose a boolean to choose whether or not to use the verbose version
* @throws NullPointerException
* @throws IllegalArgumentException
*/
public LUISClient(String appId, String appKey, boolean preview, boolean verbose) {
if (appId == null)
throw new NullPointerException("NULL Application Id");
if (appId.isEmpty())
throw new IllegalArgumentException("Empty Application Id");
if (Pattern.compile("\\s").matcher(appId).find())
throw new IllegalArgumentException("Invalid Application Id");
if (appKey == null)
throw new NullPointerException("NULL Subscription Key");
if (appKey.isEmpty())
throw new IllegalArgumentException("Empty Subscription Key");
if (Pattern.compile("\\s").matcher(appKey).find())
throw new IllegalArgumentException("Invalid Subscription Key");
this.appId = appId;
this.appKey = appKey;
this.preview = preview;
this.verbose = verbose;
LUISPreviewURL = preview ? "/preview" : "";
LUISVerboseURL = verbose ? "&verbose=true" : "";
}
/**
* Constructs a LUISClient with the corresponding user's App Id and Subscription Keys
* in non verbose version (if preview version is used)
* @param appId a String containing the Application Id
* @param appKey a String containing the Subscription Key
* @param preview a boolean to choose whether to use the published or the in preview version
* @throws NullPointerException
* @throws IllegalArgumentException
*/
public LUISClient(String appId, String appKey, boolean preview) {
this(appId, appKey, preview, false);
}
/**
* Constructs a LUISClient with the corresponding user's App Id and Subscription Keys
* in non preview version
* in non verbose version (if preview version is used)
* @param appId a String containing the Application Id
* @param appKey a String containing the Subscription Key
* @throws NullPointerException
* @throws IllegalArgumentException
*/
public LUISClient(String appId, String appKey) {
this(appId, appKey, false, false);
}
/**
* Starts the prediction procedure for the user's text
* @param text A String containing the text that needs to be analysed and predicted
* @return A LUISResponse containing the content of the response sent by LUIS API
* @throws NullPointerException
* @throws IllegalArgumentException
* @throws IOException
*/
public LUISResponse predict(String text) throws IOException {
if (text == null)
throw new NullPointerException("NULL text to predict");
text = text.trim();
if (text.isEmpty())
throw new IllegalArgumentException("Empty text to predict");
return LUISUtility.LUISHTTP(predictURLGen(text));
}
/**
* Generates the url for the predict web request
* @param text A String containing the text that needs to be analysed and predicted
* @return A String containing the url for the predict web request
* @throws IOException
*/
public String predictURLGen(String text) throws IOException{
String encodedQuery;
encodedQuery = URLEncoder.encode(text, "UTF-8");
return String.format(LUISPredictMask,LUISURL,LUISPreviewURL, appId, appKey, LUISVerboseURL, encodedQuery);
}
/**
* Starts the replying procedure for the user's dialog, and accepts a LUISResponse object
* which includes the context Id of the dialog
* @param text A String containing the text that needs to be analysed and predicted
* @param response A LUISResponse containing the context Id of the current Dialog
* @returns A LUISResponse containing the reply data sent by LUIS
* @throws RuntimeException
* @throws NullPointerException
* @throws IllegalArgumentException
* @throws IOException
*/
public LUISResponse reply(String text, LUISResponse response) throws IOException {
//TODO: When the reply can be used in the published version:
//TODO: This condition has to be removed
if(!preview)
throw new RuntimeException("Reply can only be used with the preview version");
if (text == null)
throw new NullPointerException("NULL text to predict");
text = text.trim();
if (text.isEmpty())
throw new IllegalArgumentException("Empty text to predict");
if (response == null)
throw new NullPointerException("NULL LUIS response");
return LUISUtility.LUISHTTP(replyURLGen(text,response));
}
/**
* Generates the url for the reply web request
* @param text A String containing the text that needs to be analysed and predicted
* @return A String containing the url for the reply web request
* @throws IOException
*/
String replyURLGen(String text, LUISResponse response) throws IOException {
String encodedQuery;
encodedQuery = URLEncoder.encode(text, "UTF-8");
return String.format(LUISReplyMask, LUISURL, LUISPreviewURL, appId, appKey, response.getDialog().getContextId(), LUISVerboseURL, encodedQuery);
}
/**
* Starts the prediction procedure for the user's text
* @param text A String containing the text that needs to be analysed and predicted
* @param responseHandler A responseHandler object af a class that can contains 2 functions
* onSuccess and onFailure to be executed based on the success or the failure of the prediction
* @throws NullPointerException
* @throws IllegalArgumentException
* @throws IOException
*/
public void predict(String text, final LUISResponseHandler responseHandler) throws IOException {
if (text == null)
throw new NullPointerException("NULL text to predict");
text = text.trim();
if (text.isEmpty())
throw new IllegalArgumentException("Empty text to predict");
if (responseHandler == null)
throw new NullPointerException("Null response handler");
AsyncHttpClient client = new AsyncHttpClient();
client.get(predictURLGen(text), new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
LUISResponse response = null;
try {
String JSONResponse = new String(responseBody);
response = new LUISResponse(JSONResponse);
} catch(Exception e) {
responseHandler.onFailure(e);
}
responseHandler.onSuccess(response);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody,
Throwable error) {
String errorMsg = "";
if (statusCode == 400) {
errorMsg = "Invalid Application Id";
} else if (statusCode == 401) {
errorMsg = "Invalid Subscription Key";
}
responseHandler.onFailure(new IllegalArgumentException(errorMsg));
}
});
}
/**
* Starts the replying procedure for the user's dialog, and accepts a LUISResponse object
* which includes the context Id of the dialog
* @param text A String containing the text that needs to be analysed and predicted
* @param response A LUISResponse containing the context Id of the current Dialog
* @param responseHandler A responseHandler object af a class that can contains 2 functions
* onSuccess and onFailure to be executed based on the success or the failure of the prediction
* @throws RuntimeException
* @throws NullPointerException
* @throws IllegalArgumentException
* @throws IOException
*/
public void reply(String text, LUISResponse response,
final LUISResponseHandler responseHandler) throws IOException {
if(!preview)
throw new RuntimeException("Reply can only be used with the preview version");
if (text == null)
throw new NullPointerException("NULL text to predict");
text = text.trim();
if (text.isEmpty())
throw new IllegalArgumentException("Empty text to predict");
if (response == null)
throw new NullPointerException("NULL LUIS response");
if (responseHandler == null)
throw new NullPointerException("Null response handler");
AsyncHttpClient client = new AsyncHttpClient();
client.get(replyURLGen(text,response), new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
LUISResponse response = null;
try {
String JSONResponse = new String(responseBody);
response = new LUISResponse(JSONResponse);
} catch(Exception e) {
responseHandler.onFailure(e);
}
responseHandler.onSuccess(response);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody,
Throwable error) {
String errorMsg = "";
if (statusCode == 400) {
errorMsg = "Invalid Application Id";
} else if (statusCode == 401) {
errorMsg = "Invalid Subscription Key";
}
responseHandler.onFailure(new IllegalArgumentException(errorMsg));
}
});
}
}

Просмотреть файл

@ -0,0 +1,47 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class LUISCompositeEntity {
private String parentType;
private String value;
private List<LUISCompositeEntityChild> children;
/**
* Constructs a LUIS Composite Entity from a JSON object
*
* @param JSONcompositeEntity a JSONObject containing the composite entity data
*/
public LUISCompositeEntity(JSONObject JSONcompositeEntity) {
parentType = JSONcompositeEntity.optString("parentType");
value = JSONcompositeEntity.optString("value");
children = new ArrayList<>();
JSONArray JSONcompositeEntityChildren = JSONcompositeEntity.optJSONArray("children");
for (int i = 0; JSONcompositeEntityChildren != null
&& i < JSONcompositeEntityChildren.length(); i++) {
JSONObject JSONcompositeEntityChild = JSONcompositeEntityChildren.optJSONObject(i);
if (JSONcompositeEntityChild != null) {
LUISCompositeEntityChild compositeEntityChild =
new LUISCompositeEntityChild(JSONcompositeEntityChild);
children.add(compositeEntityChild);
}
}
}
public String getParentType() {
return parentType;
}
public String getValue() {
return value;
}
public List<LUISCompositeEntityChild> getChildren() {
return children;
}
}

Просмотреть файл

@ -0,0 +1,29 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONObject;
import java.util.List;
public class LUISCompositeEntityChild {
private String type;
private String value;
private List<LUISCompositeEntityChild> children;
/**
* Constructs a LUIS Composite Entity Child from a JSON object
*
* @param JSONcompositeEntityChild a JSONObject containing the composite entity child data
*/
public LUISCompositeEntityChild(JSONObject JSONcompositeEntityChild) {
type = JSONcompositeEntityChild.optString("type");
value = JSONcompositeEntityChild.optString("value");
}
public String getType() {
return type;
}
public String getValue() {
return value;
}
}

Просмотреть файл

@ -0,0 +1,46 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONObject;
/**
* Describes the LUIS Action structure
*/
public class LUISDialog {
private String prompt;
private String parameterName;
private String contextId;
private String status;
private boolean finished;
/**
* Constructs a LUIS Dialog from a JSON object
* @param JSONdialog a JSONObject containing the data of a dialog
*/
public LUISDialog(JSONObject JSONdialog) {
prompt = JSONdialog.optString("prompt");
parameterName = JSONdialog.optString("parameterName");
contextId = JSONdialog.optString("contextId");
status = JSONdialog.optString("status");
finished = status.equals("Finished");
}
public String getPrompt() {
return prompt;
}
public String getParameterName() {
return parameterName;
}
public String getContextId() {
return contextId;
}
public String getStatus() {
return status;
}
public boolean isFinished() {
return finished;
}
}

Просмотреть файл

@ -0,0 +1,56 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONObject;
import java.util.Map;
/**
* Describes the LUIS Entity structure
*/
public class LUISEntity {
private String name;
private String type;
private int startIndex;
private int endIndex;
private double score;
private Map<String, Object> resolution;
/**
* Constructs a LUIS Entity from a JSON object
* @param JSONentity a JSONObject containing the entity data
*/
public LUISEntity(JSONObject JSONentity) {
name = JSONentity.optString("entity");
type = JSONentity.optString("type");
startIndex = JSONentity.optInt("startIndex");
endIndex = JSONentity.optInt("endIndex");
score = JSONentity.optDouble("score");
JSONObject JSONresolution = JSONentity.optJSONObject("resolution");
resolution = JSONresolution != null ? LUISUtility.JSONObjectToMap(JSONresolution) : null;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public int getStartIndex() {
return startIndex;
}
public int getEndIndex() {
return endIndex;
}
public double getScore() {
return score;
}
public Map<String, Object> getResolution() {
return resolution;
}
}

Просмотреть файл

@ -0,0 +1,49 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* Describes the LUIS Intent structure
*/
public class LUISIntent {
private String name;
private double score;
private List<LUISAction> actions;
/**
* Constructs a LUIS Intention from a JSON object
* @param JSONintent a JSONObject containing the intent data
*/
public LUISIntent(JSONObject JSONintent) {
name = JSONintent.optString("intent");
score = JSONintent.optDouble("score");
actions = new ArrayList<>();
JSONArray JSONactions = JSONintent.optJSONArray("actions");
for (int i = 0; JSONactions != null && i < JSONactions.length(); i++) {
JSONObject JSONaction = JSONactions.optJSONObject(i);
if(JSONaction != null) {
LUISAction action = new LUISAction(JSONaction);
actions.add(action);
}
}
}
public String getName() {
return name;
}
public double getScore() {
return score;
}
public List<LUISAction> getActions() {
return actions;
}
}

Просмотреть файл

@ -0,0 +1,49 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* Describes the Parameter structure
*/
public class LUISParameter {
private String name;
private boolean required;
private List<LUISParameterValue> parameterValues;
/**
* Constructs a LUIS Parameter from a JSON object
* @param JSONparameter a JSONObject containing the parameter data
*/
public LUISParameter(JSONObject JSONparameter) {
name = JSONparameter.optString("name");
required = JSONparameter.optBoolean("required");
parameterValues = new ArrayList<>();
JSONArray JSONparameterValues = JSONparameter.optJSONArray("value");
for (int i = 0; JSONparameterValues != null && i < JSONparameterValues.length(); i++) {
JSONObject JSONparameterValue = JSONparameterValues.optJSONObject(i);
if (JSONparameterValue != null) {
LUISParameterValue parameterValue = new LUISParameterValue(JSONparameterValue);
parameterValues.add(parameterValue);
}
}
}
public String getName() {
return name;
}
public boolean getRequired() {
return required;
}
public List<LUISParameterValue> getParameterValues() {
return parameterValues;
}
}

Просмотреть файл

@ -0,0 +1,43 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONObject;
import java.util.Map;
/**
* Describes the Parameter Value structure
*/
public class LUISParameterValue {
private String name;
private String type;
private double score;
private Map<String, Object> resolution;
/**
* Constructs a LUIS Action from a JSON object
* @param JSONparameterValue a JSONObject containing the parameter value data
*/
public LUISParameterValue(JSONObject JSONparameterValue) {
name = JSONparameterValue.optString("entity");
type = JSONparameterValue.optString("type");
score = JSONparameterValue.optDouble("score");
JSONObject JSONresolution = JSONparameterValue.optJSONObject("resolution");
resolution = JSONresolution != null ? LUISUtility.JSONObjectToMap(JSONresolution) : null;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public double getScore() {
return score;
}
public Map<String, Object> getResolution() {
return resolution;
}
}

Просмотреть файл

@ -0,0 +1,107 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* Describes the response structure, and is the main point
* to access the response sent by LUIS after prediction
*/
public class LUISResponse {
private String query;
private List<LUISIntent> intents;
private List<LUISEntity> entities;
private List<LUISCompositeEntity> compositeEntities;
private LUISDialog dialog;
/**
* Constructs a LUIS Response from the JSON sent by LUIS
* @param JSONResponse a String containing the JSON response sent by LUIS
* @throws NullPointerException
* @throws IllegalArgumentException
*/
public LUISResponse(String JSONResponse) throws NullPointerException,IllegalArgumentException {
if (JSONResponse == null)
throw new NullPointerException("NULL JSON response");
if (JSONResponse.isEmpty())
throw new IllegalArgumentException("Invalid Subscription Key");
JSONObject JSONresponse;
//Create an empty JSONObject If there is a problem with the JSON sent by LUIS
try {
JSONresponse = new JSONObject(JSONResponse);
} catch (JSONException e) {
JSONresponse = new JSONObject();
}
query = JSONresponse.optString("query");
intents = new ArrayList<>();
entities = new ArrayList<>();
compositeEntities = new ArrayList<>();
JSONObject JSONdialog = JSONresponse.optJSONObject("dialog");
dialog = JSONdialog != null ? new LUISDialog(JSONdialog) : null;
JSONObject JSONtopIntent = JSONresponse.optJSONObject("topScoringIntent");
if (JSONtopIntent != null) {
intents.add(new LUISIntent(JSONtopIntent));
} else {
JSONArray JSONintents = JSONresponse.optJSONArray("intents");
for (int i = 0; JSONintents != null && i < JSONintents.length(); i++) {
JSONObject JSONintent = JSONintents.optJSONObject(i);
if (JSONintent != null) {
LUISIntent intent = new LUISIntent(JSONintent);
intents.add(intent);
}
}
}
JSONArray JSONentities = JSONresponse.optJSONArray("entities");
for (int i = 0; JSONentities != null && i < JSONentities.length(); i++) {
JSONObject JSONentity = JSONentities.optJSONObject(i);
if(JSONentity != null) {
LUISEntity entity = new LUISEntity(JSONentity);
entities.add(entity);
}
}
JSONArray JSONcompositeEntities = JSONresponse.optJSONArray("compositeEntities");
for (int i = 0; JSONcompositeEntities != null && i < JSONcompositeEntities.length(); i++) {
JSONObject JSONcompositeEntity = JSONcompositeEntities.optJSONObject(i);
if(JSONcompositeEntity != null) {
LUISCompositeEntity compositeEntity = new LUISCompositeEntity(JSONcompositeEntity);
compositeEntities.add(compositeEntity);
}
}
}
public String getQuery() {
return query;
}
public LUISIntent getTopIntent() {
return intents.get(0);
}
public List<LUISIntent> getIntents() {
return intents;
}
public List<LUISEntity> getEntities() {
return entities;
}
public List<LUISCompositeEntity> getCompositeEntities() {
return compositeEntities;
}
public LUISDialog getDialog() {
return dialog;
}
}

Просмотреть файл

@ -0,0 +1,25 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
/**
* An interface to be inherited when predicting text
* in order to encapsulate the developer's logic that
* depeneds on the response sent by LUIS
*/
public interface LUISResponseHandler {
/**
* This functions needs to be implemented by the user in order to
* encapsulate his logic that should be executed if the prediction
* or replying actions succeed
* @param response a LUISResponse object that contains the response data
*/
void onSuccess(LUISResponse response);
/**
* This functions needs to be implemented by the user in order to
* encapsulate his logic that should be executed if the prediction
* or replying actions fail
* @param e an Exception that is thrown while predicting or replying
*/
void onFailure(Exception e);
}

Просмотреть файл

@ -0,0 +1,121 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* A utility class that contains functions needed by LUIS SDK
*/
public class LUISUtility {
/**
* Consumes LUIS API and returns an object containing the parsed LUIS reponse
* @param url A string containing the URL of the LUIS API to be consumed
* @return LUISResponse containing the content of the response sent by LUIS API
* @throws IOException
*/
public static LUISResponse LUISHTTP(String url) throws IOException {
HttpURLConnection urlConnection;
LUISResponse response = null;
URL _url = new URL(url);
urlConnection = (HttpURLConnection) _url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
response = responseToLUISResponse(in);
} finally {
urlConnection.disconnect();
}
return response;
}
/**
* Converts the JSON response into a Java Object
* @param in an InputStream for the JSON response data
* @return LUISResponse containing the content of the response sent by LUIS API
* @throws IOException
*/
public static LUISResponse responseToLUISResponse(InputStream in) throws IOException {
LUISResponse response = null;
String line;
String result = "";
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
while ((line = bufferedReader.readLine()) != null)
result += line;
}finally {
in.close();
}
response = new LUISResponse(result);
return response;
}
/**
* Converts a JSONObject to a Map<String, Object>
*
* @param JSONobject A JSONObject that needs to be converted to a Map<String, Object>
* @return A Map<String, Object> that contains the data of the JSONObject
*/
public static Map<String, Object> JSONObjectToMap(JSONObject JSONobject) {
Map<String, Object> map = new HashMap<>();
Iterator<String> keysItr = JSONobject.keys();
while (keysItr.hasNext()) {
try {
String key = keysItr.next();
Object value = JSONobject.get(key);
if (value instanceof JSONObject) {
value = JSONObjectToMap((JSONObject) value);
} else if (value instanceof JSONArray) {
value = JSONArrayToList((JSONArray) value);
}
map.put(key, value);
} catch (JSONException e) {
Log.e("LUIS Exception", e.getMessage());
break;
}
}
return map;
}
/**
* Converts a JSONArray to a List<Object>
*
* @param JSONarray A JSONArray that needs to be converted to a List<Object>
* @return A List<Object> that contains the data of the JSONArray
*/
public static List<Object> JSONArrayToList(JSONArray JSONarray) {
List<Object> list = new ArrayList<>();
for (int i = 0; i < JSONarray.length(); i++) {
try {
Object value = JSONarray.get(i);
if (value instanceof JSONObject) {
value = JSONObjectToMap((JSONObject) value);
} else if (value instanceof JSONArray) {
value = JSONArrayToList((JSONArray) value);
}
list.add(value);
} catch (JSONException e) {
Log.e("LUIS Exception", e.getMessage());
break;
}
}
return list;
}
}

Просмотреть файл

@ -0,0 +1,3 @@
<resources>
<string name="app_name">ClientLibrary</string>
</resources>

Просмотреть файл

@ -0,0 +1,15 @@
package com.microsoft.cognitiveservices.luis.clientlibrary;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}

Двоичные данные
Sample/gradle/wrapper/gradle-wrapper.jar поставляемый Normal file

Двоичный файл не отображается.

6
Sample/gradle/wrapper/gradle-wrapper.properties поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

160
Sample/gradlew поставляемый Normal file
Просмотреть файл

@ -0,0 +1,160 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
Sample/gradlew.bat поставляемый Normal file
Просмотреть файл

@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

1
Sample/settings.gradle Normal file
Просмотреть файл

@ -0,0 +1 @@
include ':app', ':clientlibrary'