Repository: incubator-systemml
Updated Branches:
  refs/heads/master 400a0d822 -> 4d3987e60


[SYSTEMML-209] Including the algorithms in the jar for wrappers/demo

As discussed in our mailing list, including our existing DML algorithms
in SystemML.jar will improve usability of our MLPipeline wrappers as
well as our Notebook examples. Also, added a convenience function,
getDMLScript which can be used by our MLPipeline wrappers as well as in
demos to print the DML script.

Example usage of the utility function: val dmlScriptForGLM =
getDMLScript("GLM")

Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/4d3987e6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/4d3987e6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/4d3987e6

Branch: refs/heads/master
Commit: 4d3987e60b36695764d7bf1f73ac0cd09178c647
Parents: 400a0d8
Author: Niketan Pansare <npan...@us.ibm.com>
Authored: Wed Apr 20 07:45:29 2016 -0700
Committer: Niketan Pansare <npan...@us.ibm.com>
Committed: Wed Apr 20 10:29:56 2016 -0700

----------------------------------------------------------------------
 pom.xml                                         |  9 ++++++
 .../sysml/api/ml/scala/ScriptsUtils.scala       | 30 ++++++++++++++++++++
 2 files changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/4d3987e6/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 6ba66d7..336a075 100644
--- a/pom.xml
+++ b/pom.xml
@@ -73,6 +73,15 @@
        </properties>
 
        <build>
+       
+               <resources>
+               <resource>
+                       <directory>scripts/algorithms</directory>
+                       <includes>
+                         <include>**/*.dml</include>
+                       </includes>
+               </resource>
+       </resources>
                <plugins>
 
                        <plugin>

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/4d3987e6/src/main/scala/org/apache/sysml/api/ml/scala/ScriptsUtils.scala
----------------------------------------------------------------------
diff --git a/src/main/scala/org/apache/sysml/api/ml/scala/ScriptsUtils.scala 
b/src/main/scala/org/apache/sysml/api/ml/scala/ScriptsUtils.scala
index 3f8e4d4..a3a58f8 100644
--- a/src/main/scala/org/apache/sysml/api/ml/scala/ScriptsUtils.scala
+++ b/src/main/scala/org/apache/sysml/api/ml/scala/ScriptsUtils.scala
@@ -20,6 +20,9 @@
 package org.apache.sysml.api.ml.scala
 
 import java.io.File
+import java.io.BufferedReader
+import java.io.InputStreamReader
+import org.apache.sysml.runtime.DMLRuntimeException
 
 object ScriptsUtils {
   var systemmlHome = System.getenv("SYSTEMML_HOME")
@@ -30,4 +33,31 @@ object ScriptsUtils {
   def setSystemmlHome(path:String) {
     systemmlHome = path
   }
+  
+  // Example usage: val dmlScriptForGLM = getDMLScript("GLM")
+  def getDMLScript(algorithmName:String): String = {
+    var reader:BufferedReader = null
+    val out = new StringBuilder()
+    
+    try {
+      val in = 
classOf[LogisticRegression].getClassLoader().getResourceAsStream(algorithmName 
+ ".dml")
+               reader = new BufferedReader(new InputStreamReader(in))
+      var line = reader.readLine()
+      while (line != null) {
+          out.append(line);
+          out.append(System.getProperty("line.separator"));
+          line = reader.readLine()
+      }
+    }
+    catch {
+      case ex: Exception =>
+        throw new DMLRuntimeException("Cannot read the algorithm " + 
algorithmName, ex)
+    }
+    finally {
+      if(reader != null)
+        reader.close();
+    }
+    System.out.println(out.toString());   //Prints the string content read 
from input stream
+    return out.toString()
+  }
 }
\ No newline at end of file

Reply via email to