This commit is contained in:
Gianpaolo Coro 2012-08-29 10:48:38 +00:00
parent 500677a435
commit e0388081ea
4 changed files with 156 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import org.gcube.dataanalysis.ecoengine.configuration.ALG_PROPS;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.configuration.INFRASTRUCTURE;
import org.gcube.dataanalysis.ecoengine.datatypes.DatabaseType;
import org.gcube.dataanalysis.ecoengine.datatypes.InputTable;
import org.gcube.dataanalysis.ecoengine.datatypes.OutputTable;
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType;
import org.gcube.dataanalysis.ecoengine.datatypes.ServiceType;
@ -229,7 +230,14 @@ public class DBScan implements Clusterer{
Object[] rowArr = (Object[]) row;
int ic=0;
for (Object elem:rowArr){
Double feature = Double.parseDouble(""+elem);
Double feature = null;
try{
feature = Double.parseDouble(""+elem);
}
catch(Exception e){
//transform a string into a number
feature = Transformations.indexString(""+elem);
}
samplesVector[ir][ic] = feature;
ic++;
}
@ -368,7 +376,10 @@ public class DBScan implements Clusterer{
@Override
public List<StatisticalType> getInputParameters() {
List<StatisticalType> parameters = new ArrayList<StatisticalType>();
PrimitiveType p1 = new PrimitiveType(String.class.getName(), null, PrimitiveTypes.STRING, "OccurrencePointsTable","Occurrence Points Table","occurrences");
List<TableTemplates> templateOccs = new ArrayList<TableTemplates>();
templateOccs.add(TableTemplates.GENERIC);
InputTable p1 = new InputTable(templateOccs,"OccurrencePointsTable","Occurrence Points Table","occurrences");
PrimitiveType p2 = new PrimitiveType(String.class.getName(), null, PrimitiveTypes.STRING, "FeaturesColumnNames","Column Names for the features comma separated","x,y");
ServiceType p3 = new ServiceType(ServiceParameters.RANDOMSTRING, "OccurrencePointsClusterTable","Table name of the distribution","occCluster_");
PrimitiveType p4 = new PrimitiveType(String.class.getName(), null, PrimitiveTypes.STRING, "epsilon","DBScan epsilon parameter","10");

View File

@ -9,5 +9,6 @@ public enum TableTemplates {
MINMAXLAT,
TRAININGSET,
TESTSET,
GENERIC,
CLUSTER
}

View File

@ -0,0 +1,110 @@
package org.gcube.dataanalysis.ecoengine.utils;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import com.sun.org.apache.regexp.internal.RE;
public class Sha1
{
static String fixedCachePrefix = "cache_";
private static String convertToHex(byte[] data)
{
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++)
{
int halfbyte = (data[i] >>> 4) & 0x0F;
int two_halfs = 0;
do
{
if ((0 <= halfbyte) && (halfbyte <= 9))
buf.append((char) ('0' + halfbyte));
else
buf.append((char) ('a' + (halfbyte - 10)));
halfbyte = data[i] & 0x0F;
} while (two_halfs++ < 1);
}
return buf.toString();
}
public static String SHA1(String text)
throws NoSuchAlgorithmException, UnsupportedEncodingException
{
MessageDigest md;
md = MessageDigest.getInstance("SHA-1");
byte[] sha1hash = new byte[40];
md.update(text.getBytes("iso-8859-1"), 0, text.length());
sha1hash = md.digest();
return convertToHex(sha1hash);
}
public static String calcFilePrefix(String filestring)
{
try
{
// prendo i primi 3 caratteri del file
int len = filestring.length();
int counter = 0;
String cacheDir = "";
RE regex = new RE("[a-z]");
for (int i = 0; i < len; i++)
{
String chars = "" + filestring.charAt(i);
boolean optioned = regex.match(chars);
if (optioned)
{
counter++;
cacheDir += chars;
}
if (counter > 2)
break;
}
return cacheDir + "/";
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static String calculateDigestMD5(String plainText)
{
String hashText = "";
try
{
MessageDigest m = MessageDigest.getInstance("MD5");
m.reset();
m.update(plainText.getBytes("UTF-8"));
byte[] digestBytes = m.digest();
BigInteger digestValue = new BigInteger(1, digestBytes);
hashText = digestValue.toString(16);
// filling
int remain = 32 - hashText.length();
for (int i = 0; i < remain; i++)
hashText = "0" + hashText;
}
catch (Exception e)
{
// TTSLogger.getLogger().debug("Exception: " + e.getMessage());
}
return hashText;
}
}

View File

@ -148,4 +148,36 @@ public class Transformations {
}
public static double indexString(String string) {
// string = Sha1.SHA1(string);
StringBuffer sb = new StringBuffer();
if ((string==null) ||(string.length()==0))
return -1;
int m= string.length();
for (int i=0;i<m;i++){
sb.append((int)string.charAt(i));
}
double d = Double.MAX_VALUE;
try{
d = Double.valueOf(sb.toString());
}catch(Exception e){
}
return d;
}
public static void main(String[] args) throws Exception{
String s = "un'estate al mare";
System.out.println("index: "+indexString(s));
System.out.println("sha1: "+Sha1.SHA1(s));
String s1 = "un'estate al mari";
System.out.println("index: "+indexString(s1));
System.out.println("sha1: "+Sha1.SHA1(s1));
String s2 = "ciao amico mio come stai oggi? fa caldo o sono io che mi scotto?";
System.out.println("index: "+indexString(s2));
System.out.println("sha1: "+Sha1.SHA1(s2));
}
}