Skip to content

Commit

Permalink
Final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
aminfa committed Dec 28, 2017
1 parent fdf5181 commit de5f278
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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<String, Object> parameters = new HashMap<String, Object>();
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<String, Object> returnedMap = (Map<String,Object>) instance.getAttribute("coef_");
ArrayList<Double> coef_ = (ArrayList<Double>) 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<String, Object> returnedMap2 = (Map<String,Object>) instance.callFunction("predict", parameters);
ArrayList<Double> predictions = (ArrayList<Double>) 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.
4 changes: 2 additions & 2 deletions build/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -74,7 +75,6 @@ pack:
clean:
$(REMOVE) $(BIN_DIR)
$(REMOVE) $(TESTBIN_DIR)
$(REMOVE) $(DEPLOY_DIR)

reset:
make clean
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/upb/pasestub/PaseInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/de/upb/pasestub/PaseInstanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit de5f278

Please sign in to comment.