Repository: incubator-systemml Updated Branches: refs/heads/master 2137a7e4a -> 96d021930
[SYSTEMML-836] ScriptFactory classpath resource convenience methods Closes #207. Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/96d02193 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/96d02193 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/96d02193 Branch: refs/heads/master Commit: 96d021930eabe11984dbf3bebf27816fa373ddaa Parents: 2137a7e Author: Deron Eriksson <[email protected]> Authored: Thu Aug 11 12:39:13 2016 -0700 Committer: Deron Eriksson <[email protected]> Committed: Thu Aug 11 12:39:13 2016 -0700 ---------------------------------------------------------------------- docs/spark-mlcontext-programming-guide.md | 11 ++++++ .../sysml/api/mlcontext/ScriptFactory.java | 36 ++++++++++++++++++++ 2 files changed, 47 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/96d02193/docs/spark-mlcontext-programming-guide.md ---------------------------------------------------------------------- diff --git a/docs/spark-mlcontext-programming-guide.md b/docs/spark-mlcontext-programming-guide.md index 6c2d2af..2f77347 100644 --- a/docs/spark-mlcontext-programming-guide.md +++ b/docs/spark-mlcontext-programming-guide.md @@ -1150,6 +1150,17 @@ val s5 = ScriptFactory.dmlFromInputStream(inputStream) {% endhighlight %} +**Script from Resource:** + +As mentioned, the SystemML jar file contains all the primary algorithm script files. For convenience, we can +read these script files or other script files on the classpath using ScriptFactory's `dmlFromResource` and `pydmlFromResource` +methods. + +{% highlight scala %} +val s6 = ScriptFactory.dmlFromResource("/scripts/algorithms/Univar-Stats.dml"); +{% endhighlight %} + + ## ScriptExecutor A Script is executed by a ScriptExecutor. If no ScriptExecutor is specified, a default ScriptExecutor will http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/96d02193/src/main/java/org/apache/sysml/api/mlcontext/ScriptFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/mlcontext/ScriptFactory.java b/src/main/java/org/apache/sysml/api/mlcontext/ScriptFactory.java index 5f0e56b..3fc797a 100644 --- a/src/main/java/org/apache/sysml/api/mlcontext/ScriptFactory.java +++ b/src/main/java/org/apache/sysml/api/mlcontext/ScriptFactory.java @@ -109,6 +109,17 @@ public class ScriptFactory { } /** + * Create a DML Script object based on a resource path. + * + * @param resourcePath + * path to a resource on the classpath + * @return DML Script object + */ + public static Script dmlFromResource(String resourcePath) { + return scriptFromResource(resourcePath, ScriptType.DML); + } + + /** * Create a PYDML Script object based on a string path to a file. * * @param scriptFilePath @@ -177,6 +188,17 @@ public class ScriptFactory { } /** + * Create a PYDML Script object based on a resource path. + * + * @param resourcePath + * path to a resource on the classpath + * @return PYDML Script object + */ + public static Script pydmlFromResource(String resourcePath) { + return scriptFromResource(resourcePath, ScriptType.PYDML); + } + + /** * Create a DML or PYDML Script object based on a string path to a file. * * @param scriptFilePath @@ -263,6 +285,20 @@ public class ScriptFactory { } /** + * Create a DML or PYDML Script object based on a resource path. + * + * @param resourcePath + * path to a resource on the classpath + * @param scriptType + * {@code ScriptType.DML} or {@code ScriptType.PYDML} + * @return DML or PYDML Script object + */ + private static Script scriptFromResource(String resourcePath, ScriptType scriptType) { + InputStream inputStream = ScriptFactory.class.getResourceAsStream(resourcePath); + return scriptFromInputStream(inputStream, scriptType).setName(resourcePath); + } + + /** * Create a DML Script object based on a string. * * @param scriptString
