From de5f278bb64167646cbf8d235f8302b1dde7ee9e Mon Sep 17 00:00:00 2001 From: Amin F Date: Thu, 28 Dec 2017 13:37:23 +0100 Subject: [PATCH] Final touches --- README.md | 47 ++++++++++++++++++- build/makefile | 4 +- .../java/de/upb/pasestub/PaseInstance.java | 2 +- .../de/upb/pasestub/PaseInstanceTest.java | 5 -- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7da853a..d904797 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,47 @@ # PaseStub -Java client stub for a PASE server. + +Java client stub for a [PASE](https://github.com/aminfa/Pase) server. + +## Code Example + +Take a look at the code example section of the [PASE repository](https://github.com/aminfa/Pase). +The same operations can execute using a `PaseInstance`: + +```java + PaseInstance instance = new PaseInstance("localhost:5000"); // specify host + + Map parameters = new HashMap(); + parameters.put("normalize", true); + instance.create("sklearn.linear_model.LinearRegression", parameters); + + parameters.clear(); + double[][] X = {{0,0}, {1,1}, {2,2}}; + parameters.put("X", X); + double [] y = {0,1,2}; + parameters.put("y", y); + instance.callFunction("fit", parameters); + + // You will have to know the structure of the return value: + Map returnedMap = (Map) instance.getAttribute("coef_"); + ArrayList coef_ = (ArrayList) returnedMap.get("values"); + System.out.println("coef_: " + coef_); // coef_: [0.5, 0.5] + + parameters.clear(); + double[][] X2 = {{0.5, 1}, {1, 0.5}}; + parameters.put("X", X2); + Map returnedMap2 = (Map) instance.callFunction("predict", parameters); + ArrayList predictions = (ArrayList) returnedMap2.get("values"); + System.out.println("predictions: " + predictions); // predictions: [0.75, 0.75] +``` + +## Installation + +Clone this repository. Use the `makefile` in the `build/` folder to build this project: + +```bash +cd build/ +make +``` + +`pasestub.jar` will afterwards lie in the root folder and the `resources` folder will contain all the dependecies needed to use this stub. +You can alternatively then use maven to build this project too. \ No newline at end of file diff --git a/build/makefile b/build/makefile index 2f95b31..a8622b3 100644 --- a/build/makefile +++ b/build/makefile @@ -32,7 +32,7 @@ CLASSES := $(shell find $(PROJECT_SRC_DIR) -type f -name '*.java') TESTS := $(shell find $(TEST_DIR) -type f -name '*.java') -DEPLOY_DIR = $(ROOT_DIR)/deploy +DEPLOY_DIR = $(ROOT_DIR) JAR_NAME = pase.jar @@ -61,6 +61,7 @@ test: java -classpath "$(RESOURCE_DIR)/*:$(RESOURCE_TEST_DIR)/*:$(TESTBIN_DIR):$(BIN_DIR)" org.junit.runner.JUnitCore $(PACKAGES_TEST) pack: + $(REMOVE) $(DEPLOY_DIR)/$(JAR_NAME) make clean @echo "Compiling classes..." make compile @@ -74,7 +75,6 @@ pack: clean: $(REMOVE) $(BIN_DIR) $(REMOVE) $(TESTBIN_DIR) - $(REMOVE) $(DEPLOY_DIR) reset: make clean diff --git a/src/main/java/de/upb/pasestub/PaseInstance.java b/src/main/java/de/upb/pasestub/PaseInstance.java index 93de668..78595b6 100644 --- a/src/main/java/de/upb/pasestub/PaseInstance.java +++ b/src/main/java/de/upb/pasestub/PaseInstance.java @@ -176,7 +176,7 @@ private Response httpGet(String url) throws IOException{ } - //TODO: constum json parser if there are any problems parsing objects. + //TODO: custom json parser if there are any problems parsing objects. /** * JSON-Serializes the given map. */ diff --git a/src/test/java/de/upb/pasestub/PaseInstanceTest.java b/src/test/java/de/upb/pasestub/PaseInstanceTest.java index 33f0e98..7ac1bcb 100644 --- a/src/test/java/de/upb/pasestub/PaseInstanceTest.java +++ b/src/test/java/de/upb/pasestub/PaseInstanceTest.java @@ -6,11 +6,6 @@ import java.util.HashMap; import java.util.Map; import com.github.tomakehurst.wiremock.junit.WireMockRule; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; import org.junit.Assert; import org.junit.Rule;