Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.sysml.api.mlcontext;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.sysml.runtime.controlprogram.LocalVariableMap;
import org.apache.sysml.runtime.controlprogram.caching.CacheableData;
import org.apache.sysml.runtime.instructions.cp.Data;
import scala.Tuple2;
import scala.Tuple3;
import scala.collection.JavaConversions;
/**
* A Script object encapsulates a DML or PYDML script.
*
*/
public class Script {
/**
* The type of script ({@code ScriptType.DML} or {@code ScriptType.PYDML}).
*/
private ScriptType scriptType;
/**
* The script content.
*/
private String scriptString;
/**
* The optional name of the script.
*/
private String name;
/**
* All inputs (input parameters ($) and input variables).
*/
private Map inputs = new LinkedHashMap<>();
/**
* The input parameters ($).
*/
private Map inputParameters = new LinkedHashMap<>();
/**
* The input variables.
*/
private Set inputVariables = new LinkedHashSet<>();
/**
* The input matrix or frame metadata if present.
*/
private Map inputMetadata = new LinkedHashMap<>();
/**
* The output variables.
*/
private Set outputVariables = new LinkedHashSet<>();
/**
* The symbol table containing the data associated with variables.
*/
private LocalVariableMap symbolTable = new LocalVariableMap();
/**
* The ScriptExecutor which is used to define the execution of the script.
*/
private ScriptExecutor scriptExecutor;
/**
* The results of the execution of the script.
*/
private MLResults results;
/**
* Script constructor, which by default creates a DML script.
*/
public Script() {
scriptType = ScriptType.DML;
}
/**
* Script constructor, specifying the type of script ({@code ScriptType.DML}
* or {@code ScriptType.PYDML}).
*
* @param scriptType
* {@code ScriptType.DML} or {@code ScriptType.PYDML}
*/
public Script(ScriptType scriptType) {
this.scriptType = scriptType;
}
/**
* Script constructor, specifying the script content. By default, the script
* type is DML.
*
* @param scriptString
* the script content as a string
*/
public Script(String scriptString) {
this.scriptString = scriptString;
this.scriptType = ScriptType.DML;
}
/**
* Script constructor, specifying the script content and the type of script
* (DML or PYDML).
*
* @param scriptString
* the script content as a string
* @param scriptType
* {@code ScriptType.DML} or {@code ScriptType.PYDML}
*/
public Script(String scriptString, ScriptType scriptType) {
this.scriptString = scriptString;
this.scriptType = scriptType;
}
/**
* Obtain the script type.
*
* @return {@code ScriptType.DML} or {@code ScriptType.PYDML}
*/
public ScriptType getScriptType() {
return scriptType;
}
/**
* Set the type of script (DML or PYDML).
*
* @param scriptType
* {@code ScriptType.DML} or {@code ScriptType.PYDML}
*/
public void setScriptType(ScriptType scriptType) {
this.scriptType = scriptType;
}
/**
* Obtain the script string.
*
* @return the script string
*/
public String getScriptString() {
return scriptString;
}
/**
* Set the script string.
*
* @param scriptString
* the script string
* @return {@code this} Script object to allow chaining of methods
*/
public Script setScriptString(String scriptString) {
this.scriptString = scriptString;
return this;
}
/**
* Obtain the input variable names as an unmodifiable set of strings.
*
* @return the input variable names
*/
public Set getInputVariables() {
return Collections.unmodifiableSet(inputVariables);
}
/**
* Obtain the output variable names as an unmodifiable set of strings.
*
* @return the output variable names
*/
public Set getOutputVariables() {
return Collections.unmodifiableSet(outputVariables);
}
/**
* Obtain the symbol table, which is essentially a
* {@code HashMap} representing variables and their values.
*
* @return the symbol table
*/
public LocalVariableMap getSymbolTable() {
return symbolTable;
}
/**
* Obtain an unmodifiable map of all inputs (parameters ($) and variables).
*
* @return all inputs to the script
*/
public Map getInputs() {
return Collections.unmodifiableMap(inputs);
}
/**
* Obtain an unmodifiable map of input matrix/frame metadata.
*
* @return input matrix/frame metadata
*/
public Map getInputMetadata() {
return Collections.unmodifiableMap(inputMetadata);
}
/**
* Pass a map of inputs to the script.
*
* @param inputs
* map of inputs (parameters ($) and variables).
* @return {@code this} Script object to allow chaining of methods
*/
public Script in(Map inputs) {
for (Entry input : inputs.entrySet()) {
in(input.getKey(), input.getValue());
}
return this;
}
/**
* Pass a Scala Map of inputs to the script.
*
* Note that the {@code Map} value type is not explicitly specified on this
* method because {@code [String, Any]} can't be recognized on the Java side
* since {@code Any} doesn't have an equivalent in the Java class hierarchy
* ({@code scala.Any} is a superclass of {@code scala.AnyRef}, which is
* equivalent to {@code java.lang.Object}). Therefore, specifying
* {@code scala.collection.Map} as an input parameter to
* this Java method is not encompassing enough and would require types such
* as a {@code scala.Double} to be cast using {@code asInstanceOf[AnyRef]}.
*
* @param inputs
* Scala Map of inputs (parameters ($) and variables).
* @return {@code this} Script object to allow chaining of methods
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public Script in(scala.collection.Map inputs) {
Map javaMap = JavaConversions.mapAsJavaMap(inputs);
in(javaMap);
return this;
}
/**
* Pass a Scala Seq of inputs to the script. The inputs are either two-value
* or three-value tuples, where the first value is the variable name, the
* second value is the variable value, and the third optional value is the
* metadata.
*
* @param inputs
* Scala Seq of inputs (parameters ($) and variables).
* @return {@code this} Script object to allow chaining of methods
*/
public Script in(scala.collection.Seq