adjustements to the csv parser method

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngine@82436 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Gianpaolo Coro 2013-10-04 10:34:57 +00:00
parent 1b156b62d8
commit 71847c3b20
7 changed files with 2287 additions and 97 deletions

View File

@ -1,10 +0,0 @@
5.1,3.5
4.9,3.0
4.7,3.2
4.6,3.1
5.0,3.6
5.4,3.9
4.6,3.4
5.0,3.4
4.4,2.9
4.9,3.1
1 5.1 3.5
2 4.9 3.0
3 4.7 3.2
4 4.6 3.1
5 5.0 3.6
6 5.4 3.9
7 4.6 3.4
8 5.0 3.4
9 4.4 2.9
10 4.9 3.1

2166
ph.asc Normal file

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@
</parent> </parent>
<groupId>org.gcube.dataanalysis</groupId> <groupId>org.gcube.dataanalysis</groupId>
<artifactId>ecological-engine</artifactId> <artifactId>ecological-engine</artifactId>
<version>1.7.0-SNAPSHOT</version> <version>1.7.1-SNAPSHOT</version>
<name>ecological-engine</name> <name>ecological-engine</name>
<description>ecological-engine library</description> <description>ecological-engine library</description>
<properties> <properties>

View File

@ -65,12 +65,10 @@ public class Transformations {
} }
return columns; return columns;
} } else
else
return null; return null;
} }
// gets a column from a matrix // gets a column from a matrix
public static double[] getColumn(int index, double[][] matrix) { public static double[] getColumn(int index, double[][] matrix) {
int colulen = matrix.length; int colulen = matrix.length;
@ -90,7 +88,6 @@ public class Transformations {
} }
// merge matrixes: puts the rows of a matrix under another matrix // merge matrixes: puts the rows of a matrix under another matrix
public static double[][] mergeMatrixes(double[][] matrix1, double[][] matrix2) { public static double[][] mergeMatrixes(double[][] matrix1, double[][] matrix2) {
@ -125,13 +122,10 @@ public class Transformations {
return out; return out;
} }
public static Object getObjectFromFile(String file) throws Exception { public static Object getObjectFromFile(String file) throws Exception {
/* /*
FileInputStream fis = new FileInputStream(file); * FileInputStream fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); return ois.readObject();
ObjectInputStream ois = new ObjectInputStream(fis);
return ois.readObject();
*/ */
XStream xstream = new XStream(); XStream xstream = new XStream();
return xstream.fromXML(new FileInputStream(file)); return xstream.fromXML(new FileInputStream(file));
@ -145,9 +139,7 @@ public class Transformations {
bw.write(xstream.toXML(toWrite)); bw.write(xstream.toXML(toWrite));
bw.close(); bw.close();
/* /*
FileOutputStream fos = new FileOutputStream(file); * FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream ois = new ObjectOutputStream(fos); ois.writeObject(toWrite);
ObjectOutputStream ois = new ObjectOutputStream(fos);
ois.writeObject(toWrite);
*/ */
} }
@ -185,10 +177,12 @@ public class Transformations {
return d; return d;
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String in = "h,t,,,,k,";
in = "Salmo lucidus (Richardson 1836)\",\"Salmo lucidus\",\"Richardson 1836\",\"SIMPLE\",0.6547619047619048,\"ASFIS\",\"APL\",\"Plantae aquaticae\",\"\",\"\",\"PLANTAE AQUATICAE MISCELLANEA\",\"Aquatic plants nei\",\"Plantes aquatiques nca\",\"Plantas acuáticas nep\"";
List<String> ll = Transformations.parseCVSString(in, ",");
List<String> ll = Transformations.parseCVSString("h,t,,,,k,", ",");
for (String l : ll) { for (String l : ll) {
System.out.println(l); System.out.println(l);
} }
@ -215,26 +209,36 @@ public class Transformations {
quot = phrase.startsWith("\""); quot = phrase.startsWith("\"");
if (quot) { if (quot) {
phrase = phrase.substring(1); phrase = phrase.substring(1);
String quoted = "";
if (phrase.startsWith("\""))
phrase = phrase.substring(1);
else{
RE regexp = new RE("[^\\\\]\""); RE regexp = new RE("[^\\\\]\"");
boolean matching = regexp.match(phrase); boolean matching = regexp.match(phrase);
String quoted = "";
if (matching) { if (matching) {
int i0 = regexp.getParenStart(0); int i0 = regexp.getParenStart(0);
quoted = phrase.substring(0, i0 + 1).trim(); quoted = phrase.substring(0, i0 + 1).trim();
phrase = phrase.substring(i0 + 2).trim(); phrase = phrase.substring(i0 + 2).trim();
} }
}
if (phrase.startsWith(delimiter)) if (phrase.startsWith(delimiter))
phrase = phrase.substring(1); phrase = phrase.substring(1);
elements.add(quoted); elements.add(quoted);
} } else {
else{
elements.add(phrase.substring(0, idxdelim)); elements.add(phrase.substring(0, idxdelim));
phrase = phrase.substring(idxdelim + 1).trim(); phrase = phrase.substring(idxdelim + 1).trim();
} }
} }
if (phrase.startsWith("\""))
phrase = phrase.substring(1);
if (phrase.endsWith("\""))
phrase = phrase.substring(0, phrase.length() - 1);
elements.add(phrase); elements.add(phrase);
return elements; return elements;

Binary file not shown.

View File

@ -0,0 +1,5 @@
#Generated by Maven
#Thu Oct 03 09:52:55 CEST 2013
version=1.7.1-SNAPSHOT
groupId=org.gcube.dataanalysis
artifactId=ecological-engine

25
target/profile.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>Ecological Engine Library</Description>
<Class>EcologicalEngine</Class>
<Name>ecological-engine</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>ecological-engine</Name>
<Version>1.7.1-SNAPSHOT</Version>
<MavenCoordinates>
<groupId>org.gcube.dataanalysis</groupId>
<artifactId>ecological-engine</artifactId>
<version>1.7.1-SNAPSHOT</version>
</MavenCoordinates>
<Files>
<File>ecological-engine-1.7.1-SNAPSHOT.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>