Skip to content

Commit

Permalink
Merge pull request #17 from Augugrumi/dev
Browse files Browse the repository at this point in the history
Version 2.0.0 ready
  • Loading branch information
mzanella authored May 19, 2017
2 parents 1e75e5b + ad88192 commit 89daeaf
Show file tree
Hide file tree
Showing 25 changed files with 915 additions and 14 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ jdk:
- openjdk7
sudo: false
env:
matrix:
secure: QJnMTnzyn+VpT4cvu+kw3dTdzj17j2FsRxz6HXm9MrAn4HfjOhoKkLBX8pNDKmvPnG4SwQc3OjQLksbKeB/36caou9iXYmR5ByzarSH8BTMtMzMk6l13lYLtJchoh7ZqN8PPbOxXB/DnQM1qX4Ig09zORsHMGj5hDloWe7QOLTIc4buuJz8RrP4Sg5lJg8fKjmj0CAmRmB40yFWWW16Cg4OYO1Qq3rBGHV58CxBiyl6Z4AqZjqhJbpPHP4VSZ2dfnBPQ1iwaKZ4ojmUPUdyMD5GJkuBEki504aEg14MFP0YZeVPLId9LK549la9AkMQSrdehap5eWD4naPRu5AKQwoyzsIPKZtehj4/rkUhW0UCH6Yb/AfmmJS75gonrsUHxfNw5VPSe7O4plbyoEOmlSwv2GJ31vk4N2C8oKsciZltfowfRs7CHJ2M6Zc5FLGj2EEGeL2pvAVST3YTVQ2SHaWHHj6cvDg0duh055RoETtkasADEcTx4ECKbgSZjR9fNFbLtxE1Tqs5He/Dz7cSqpFiVMBdtKNCEX+AZJw6K4PEElwmsl7rQ+mBJsdvLOcsBPyfkVxOHHInlH13ysRCg4yKnge1/rVNDZr+KUKmp0jiHfIo0GG3KajBSiyXRAktKMjF/VeEAm1AOwi+pzmeMQ2bhxfiJNRGgudQVtQeQxDs=
global:
- secure: QJnMTnzyn+VpT4cvu+kw3dTdzj17j2FsRxz6HXm9MrAn4HfjOhoKkLBX8pNDKmvPnG4SwQc3OjQLksbKeB/36caou9iXYmR5ByzarSH8BTMtMzMk6l13lYLtJchoh7ZqN8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YV9zIB5BYivha0GJXwJYxNVdFXhMWtkNW4d02oplJUWWZeleXAECqfN1CXtmprMqnzelMeWJWq+lfyaH9lw1LPqNAS5yf9fAiZ4xUJpWBDU0pns1xybPsJtCMxz5sPSm91Nm/1x/UhGCIi+72Z9/bTtG8KK2Wcu6j684tEANEfTVcXAdhDvlmkwJ1ZGb53TWikd+tWnj2xSDoxHd94tpepKvE0aTC1W2cH2j1j9f3A+wlPA6KTLlutC16APIG0PaJWZPFOKD9NKioz5zxifZTJB8t30nj9x9crj2kviFksf/vGFwRng/SS+NBY7/kvSWQkJ13WsPvzrWz9XiGNl/8hVBjZgh6DyeUQf8SuIb2XCiAb+Fp1NaVfpBRuXwC/0kUnIN5+1Z3T/ov3qNcHwPLrYrKOE4jjdZ5g/UTZXjPVlG4zRN4ZbjrqJqPPkwyjo=
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@
<version>2.8.0</version>
</dependency>

<dependency>
<groupId>com.ibm.watson.developer_cloud</groupId>
<artifactId>java-sdk</artifactId>
<version>3.8.0</version>

</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.5</version>
</dependency>

</dependencies>
</project>
12 changes: 12 additions & 0 deletions src/main/java/it/polpetta/libris/image/ReverseImageSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import it.polpetta.libris.image.azure.contract.IAbstractAzureImageFactoryReverseSearchProvider;
import it.polpetta.libris.image.google.GoogleAbstractFactory;
import it.polpetta.libris.image.google.contract.IAbstractGoogleImageFactoryReverseSearchProvider;
import it.polpetta.libris.image.ibm.IBMAbstractFactory;
import it.polpetta.libris.image.ibm.contract.IAbstractIBMImageFactoryReverseSearchProvider;
import it.polpetta.libris.image.imagga.ImaggaAbstractFactory;
import it.polpetta.libris.image.imagga.contract.IAbstractImaggaImageFactoryReverseSearchProvider;

/**
* Created by davide on 28/04/17.
Expand All @@ -22,4 +26,12 @@ public static IAbstractFactoryReverseSearchProvider getClarifaiServices() {
public static IAbstractAzureImageFactoryReverseSearchProvider getAzureServices(String subscriptionKey) {
return new AzureAbstractFactory(subscriptionKey);
}

public static IAbstractIBMImageFactoryReverseSearchProvider getIBMServices(String subscriptionKey) {
return new IBMAbstractFactory(subscriptionKey);
}

public static IAbstractImaggaImageFactoryReverseSearchProvider getImaggaServices(String subscriptionKey) {
return new ImaggaAbstractFactory(subscriptionKey);
}
}
24 changes: 24 additions & 0 deletions src/main/java/it/polpetta/libris/image/ibm/IBMAbstractFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package it.polpetta.libris.image.ibm;

import it.polpetta.libris.contract.IQueryBuilder;
import it.polpetta.libris.image.ibm.contract.IAbstractIBMImageFactoryReverseSearchProvider;
import it.polpetta.libris.image.ibm.visualRecognition.URLIBMImageSearcher;

/**
* Created by dpolonio on 17/05/17.
*/
public class IBMAbstractFactory implements IAbstractIBMImageFactoryReverseSearchProvider {

private String subscriptionKey = null;

public IBMAbstractFactory(String subscriptionKey) {

this.subscriptionKey = subscriptionKey;
}

@Override
public URLIBMImageSearcher.Builder imageSearchBuildQuery() {
URLIBMImageSearcher.setSubscriptionKey(subscriptionKey);
return new URLIBMImageSearcher.Builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.polpetta.libris.image.ibm.contract;

import it.polpetta.libris.image.contract.IAbstractImageFactoryReverseSearchProvider;
import it.polpetta.libris.image.ibm.visualRecognition.URLIBMImageSearcher;

/**
* Created by dpolonio on 17/05/17.
*/
public interface IAbstractIBMImageFactoryReverseSearchProvider extends IAbstractImageFactoryReverseSearchProvider {

URLIBMImageSearcher.Builder imageSearchBuildQuery();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.polpetta.libris.image.ibm.contract;


import it.polpetta.libris.image.contract.IImageSearchResult;

import java.util.ArrayList;

/**
* Created by dpolonio on 17/05/17.
*/
public interface IIBMImageSearchResult extends IImageSearchResult {
ArrayList<String> getTags();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.polpetta.libris.image.ibm.contract;

import it.polpetta.libris.contract.ISearcher;

import java.io.IOException;

/**
* Created by dpolonio on 17/05/17.
*/
public interface IIBMImageSearcher extends ISearcher {

IIBMImageSearchResult search() throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package it.polpetta.libris.image.ibm.visualRecognition;

import it.polpetta.libris.image.azure.contract.IAzureImageSearchResult;
import it.polpetta.libris.image.ibm.contract.IIBMImageSearchResult;

import java.util.ArrayList;

/**
* Created by dpolonio on 10/05/17.
*/
public class IBMImageSearchResult implements IIBMImageSearchResult {

private String bestGuess;
private ArrayList<String> tags;

private IBMImageSearchResult(
String bestGuess,
ArrayList<String> tags
) {
this.bestGuess = bestGuess;
this.tags = tags;
}

// TODO evaluate the possibility to introduce constants instead of using explicitly strings
@Override
public String toJSONString() {
StringBuilder builder = new StringBuilder();
builder.append("{")
.append("\"best_guess\":\"")
.append(bestGuess)
.append("\",")
.append("\"tags\":[")
.append(arrayListToString(tags))
.append("]}");
return builder.toString();
}

private String arrayListToString(ArrayList<String> arrayList) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < arrayList.size(); i++) {
sb.append("\"");
sb.append(arrayList.get(i));
sb.append("\"");
if (i != arrayList.size() - 1)
sb.append(",");
}
return sb.toString();
}

@Override
public String getBestGuess() {
return bestGuess;
}

@Override
public ArrayList<String> getTags() {
return tags;
}


public static class Builder {

private String bestGuess;
private ArrayList<String> tags;

public Builder () {
this.bestGuess = "";
this.tags = new ArrayList<>();
}

public IBMImageSearchResult.Builder addBestGuess(String bestGuess) {
this.bestGuess = bestGuess;
return this;
}

public IBMImageSearchResult.Builder addTags(ArrayList<String> tags) {
this.tags = tags;
return this;
}

public IBMImageSearchResult build() {
return new IBMImageSearchResult(
bestGuess,
tags
);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package it.polpetta.libris.image.ibm.visualRecognition;

import com.ibm.watson.developer_cloud.visual_recognition.v3.VisualRecognition;
import com.ibm.watson.developer_cloud.visual_recognition.v3.model.*;
import it.polpetta.libris.contract.AbstractURLSearcher;
import it.polpetta.libris.contract.IQueryBuilder;
import it.polpetta.libris.image.azure.contract.IAzureImageSearcher;
import it.polpetta.libris.image.azure.imageRecognition.URLAzureImageSearcher;
import it.polpetta.libris.image.ibm.contract.IIBMImageSearcher;
import it.polpetta.libris.image.ibm.contract.IIBMImageSearchResult;
import it.polpetta.libris.util.Coordinates;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;

/**
* Created by dpolonio on 17/05/17.
*/
public class URLIBMImageSearcher extends AbstractURLSearcher implements IIBMImageSearcher {

private static String subscriptionKey = null;

private VisualClassification response;

public URLIBMImageSearcher (URL link) {
super(link);

}

public static void setSubscriptionKey(String key) {
subscriptionKey = key;
}

@Override
protected URLConnection setConnectionParameters() {
return null;
}

@Override
protected IIBMImageSearchResult parseResult(String nullString) {
String bestGuess = null;
ArrayList<String> tags = new ArrayList<>();

double score;
double bestScore = 0;
for (VisualClassifier classifier :
this.response.getImages().get(0).getClassifiers()) {
for (VisualClassifier.VisualClass visualClass : classifier.getClasses()) {
score = visualClass.getScore();
if (score > bestScore) {
if (bestGuess != null)
tags.add(bestGuess);
bestGuess = visualClass.getName();
bestScore = score;
} else
tags.add(visualClass.getName());
}
}

return new IBMImageSearchResult.Builder()
.addBestGuess(bestGuess)
.addTags(tags)
.build();
}

@Override
public IIBMImageSearchResult search() throws IOException {
VisualRecognition service =
new VisualRecognition(VisualRecognition.VERSION_DATE_2016_05_20, subscriptionKey);

ClassifyImagesOptions options1 = new ClassifyImagesOptions.Builder()
.url(link.toString())
.build();
response = service.classify(options1).execute();

return parseResult("");
}

public static class Builder implements IQueryBuilder {

private File photo = null;
private URL link = null;
private Coordinates location = null;

public Builder(){}

public URLIBMImageSearcher.Builder setLocation(float x, float y) {
location = new Coordinates(x, y);
return this;
}

@Override
public URLIBMImageSearcher.Builder setImage(File file) {
photo = file;
return this;
}

@Override
public URLIBMImageSearcher.Builder setImage(URL linkToImage) {
link = linkToImage;
return this;
}

@Override
public URLIBMImageSearcher build() {
return new URLIBMImageSearcher(link);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package it.polpetta.libris.image.imagga;

import it.polpetta.libris.image.imagga.contract.IAbstractImaggaImageFactoryReverseSearchProvider;
import it.polpetta.libris.image.imagga.imageRecognition.URLImaggaImageSearcher;

/**
* Created by federico on 17/05/17.
*/
public class ImaggaAbstractFactory implements IAbstractImaggaImageFactoryReverseSearchProvider {
private String subscriptionKey = null;

public ImaggaAbstractFactory(String subscriptionKey) {

this.subscriptionKey = subscriptionKey;
}

public URLImaggaImageSearcher.Builder imageSearchBuildQuery() {
URLImaggaImageSearcher.setSubscriptionKey(subscriptionKey);
return new URLImaggaImageSearcher.Builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package it.polpetta.libris.image.imagga.contract;

import it.polpetta.libris.image.contract.IAbstractImageFactoryReverseSearchProvider;
import it.polpetta.libris.image.imagga.imageRecognition.URLImaggaImageSearcher;

/**
* Created by federico on 17/05/17.
*/
public interface IAbstractImaggaImageFactoryReverseSearchProvider extends IAbstractImageFactoryReverseSearchProvider {
URLImaggaImageSearcher.Builder imageSearchBuildQuery();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.polpetta.libris.image.imagga.contract;

import it.polpetta.libris.image.contract.IImageSearchResult;

import java.util.ArrayList;

/**
* Created by federico on 17/05/17.
*/
public interface IImaggaImageSearchResult extends IImageSearchResult {
ArrayList<String> getOtherTags();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.polpetta.libris.image.imagga.contract;

import it.polpetta.libris.contract.ISearcher;

import java.io.IOException;

/**
* Created by federico on 17/05/17.
*/
public interface IImaggaImageSearcher extends ISearcher {
IImaggaImageSearchResult search() throws IOException;
}
Loading

0 comments on commit 89daeaf

Please sign in to comment.