IGNITE-7567: Fixed bug with datasest in examples
authorzaleslaw <zaleslaw.sin@gmail.com>
Tue, 30 Jan 2018 14:25:08 +0000 (17:25 +0300)
committerYury Babak <ybabak@gridgain.com>
Tue, 30 Jan 2018 14:25:08 +0000 (17:25 +0300)
this closes #3453

examples/src/main/java/org/apache/ignite/examples/ml/knn/classification/KNNClassificationExample.java
examples/src/main/java/org/apache/ignite/examples/ml/knn/regression/KNNRegressionExample.java
examples/src/main/resources/datasets/README.md [moved from examples/src/main/java/org/apache/ignite/examples/ml/knn/datasets/README.md with 100% similarity]
examples/src/main/resources/datasets/cleared_machines.txt [moved from examples/src/main/java/org/apache/ignite/examples/ml/knn/datasets/cleared_machines.txt with 100% similarity]
examples/src/main/resources/datasets/iris.txt [moved from examples/src/main/java/org/apache/ignite/examples/ml/knn/datasets/iris.txt with 100% similarity]
parent/pom.xml

index 0e1a52f..6532ac5 100644 (file)
 
 package org.apache.ignite.examples.ml.knn.classification;
 
+import java.io.File;
 import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.Arrays;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.examples.ExampleNodeStartup;
+import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.ml.knn.models.KNNModel;
 import org.apache.ignite.ml.knn.models.KNNStrategy;
 import org.apache.ignite.ml.math.distances.EuclideanDistance;
@@ -53,7 +52,7 @@ public class KNNClassificationExample {
     private static final String SEPARATOR = "\t";
 
     /** Path to the Iris dataset. */
-    private static final String KNN_IRIS_TXT = "../datasets/iris.txt";
+    private static final String KNN_IRIS_TXT = "examples/src/main/resources/datasets/iris.txt";
 
     /**
      * Executes example.
@@ -71,11 +70,11 @@ public class KNNClassificationExample {
 
                 try {
                     // Prepare path to read
-                    URL url = KNNClassificationExample.class.getResource(KNN_IRIS_TXT);
-                    if (url == null)
-                        throw new RuntimeException("Can't get URL for: " + KNN_IRIS_TXT);
+                    File file = IgniteUtils.resolveIgnitePath(KNN_IRIS_TXT);
+                    if (file == null)
+                        throw new RuntimeException("Can't find file: " + KNN_IRIS_TXT);
 
-                    Path path = Paths.get(url.toURI());
+                    Path path = file.toPath();
 
                     // Read dataset from file
                     LabeledDataset dataset = LabeledDatasetLoader.loadFromTxtFile(path, SEPARATOR, true, false);
@@ -138,7 +137,7 @@ public class KNNClassificationExample {
                     }
 
                 }
-                catch (URISyntaxException | IOException e) {
+                catch (IOException e) {
                     e.printStackTrace();
                     System.out.println("\n>>> Unexpected exception, check resources: " + e);
                 }
index b52613a..ba079cc 100644 (file)
 
 package org.apache.ignite.examples.ml.knn.regression;
 
+import java.io.File;
 import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.examples.ml.knn.classification.KNNClassificationExample;
+import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.ml.knn.models.KNNStrategy;
 import org.apache.ignite.ml.knn.regression.KNNMultipleLinearRegression;
 import org.apache.ignite.ml.math.distances.ManhattanDistance;
@@ -54,7 +52,7 @@ public class KNNRegressionExample {
     private static final String SEPARATOR = ",";
 
     /** */
-    private static final String KNN_CLEARED_MACHINES_TXT = "../datasets/cleared_machines.txt";
+    private static final String KNN_CLEARED_MACHINES_TXT = "examples/src/main/resources/datasets/cleared_machines.txt";
 
     /**
      * Executes example.
@@ -72,11 +70,11 @@ public class KNNRegressionExample {
 
                 try {
                     // Prepare path to read
-                    URL url = KNNClassificationExample.class.getResource(KNN_CLEARED_MACHINES_TXT);
-                    if (url == null)
-                        throw new RuntimeException("Can't get URL for: " + KNN_CLEARED_MACHINES_TXT);
+                    File file = IgniteUtils.resolveIgnitePath(KNN_CLEARED_MACHINES_TXT);
+                    if (file == null)
+                        throw new RuntimeException("Can't find file: " + KNN_CLEARED_MACHINES_TXT);
 
-                    Path path = Paths.get(url.toURI());
+                    Path path = file.toPath();
 
                     // Read dataset from file
                     LabeledDataset dataset = LabeledDatasetLoader.loadFromTxtFile(path, SEPARATOR, false, false);
@@ -141,7 +139,7 @@ public class KNNRegressionExample {
 
                     System.out.println("\n>>> R^2 " + detCf);
                 }
-                catch (URISyntaxException | IOException e) {
+                catch (IOException e) {
                     e.printStackTrace();
                     System.out.println("\n>>> Unexpected exception, check resources: " + e);
                 }
index c937227..0d6729e 100644 (file)
                                         <exclude>src/main/java/org/apache/ignite/examples/streaming/wordcount/*.txt</exclude><!--books examples-->
                                         <exclude>examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/*.txt</exclude><!--books examples-->
                                         <exclude>src/main/resources/person.csv</exclude><!--CacheLoadOnlyStoreExample csv-->
-                                        <exclude>**/resources/datasets/knn/*</exclude><!--Dataset examples in ml module-->
-                                        <exclude>**/resources/datasets/regression/*</exclude><!--Dataset examples in ml module-->
-                                        <exclude>**/ml/knn/datasets/*</exclude><!--Datasets for ML KNN in examples module-->
+                                        <exclude>**/resources/datasets/**/*</exclude><!--KNN Datasets in ml module-->
                                         <exclude>examples/src/main/resources/person.csv</exclude><!--CacheLoadOnlyStoreExample csv-->
                                         <exclude>src/main/java/org/jetbrains/annotations/*.java</exclude><!--copyright-->
                                         <exclude>dev-tools/IGNITE-*.patch</exclude>