blob: 39a3b71260992c5706b899e51449545baa21fab2 [file] [log] [blame]
package org.eclipse.papyrus.aiml.gen.keras;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.papyrus.aiml.gen.keras.GenCheck;
import org.eclipse.papyrus.aiml.gen.keras.ModuleInfo;
import org.eclipse.papyrus.aiml.gen.keras.ModuleInfoAttributes;
import org.eclipse.papyrus.aiml.profile.AIML.Module.Model;
import org.eclipse.uml2.uml.DirectedRelationship;
import org.eclipse.uml2.uml.InformationFlow;
import org.eclipse.uml2.uml.Property;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
/**
* Composing each functions needed to compute the model : _init_ and _call_
*/
@SuppressWarnings("all")
public class ModelOps {
public static ModuleInfoAttributes modelAttributesToCollectProperly(final Model mod_val) {
ModuleInfoAttributes mi = new ModuleInfoAttributes();
EList<EAttribute> _eAllAttributes = mod_val.eClass().getEAllAttributes();
for (final EAttribute value : _eAllAttributes) {
{
String attri_name = value.getName();
mi.attributesName.add(attri_name);
Object attri_val = mod_val.eGet(value);
mi.attributesValue.add(attri_val);
EClassifier attri_type = value.getEType();
mi.attributesType.add(value.getEType().getInstanceClassName());
boolean _isAssignableFrom = attri_type.getInstanceClass().isAssignableFrom(Float.class);
if (_isAssignableFrom) {
}
}
}
return mi;
}
/**
* Select model attributes to display for the compilation
*/
public static String modelAttributesToDisplayForCompilationProperly(final Model mod) {
final ModuleInfoAttributes attributes = ModelOps.modelAttributesToCollectProperly(mod);
List<String> name_attrib = IterableExtensions.<String>toList(attributes.attributesName);
List<Object> val_attrib = IterableExtensions.<Object>toList(attributes.attributesValue);
String _firstLower = StringExtensions.toFirstLower(mod.getBase_Class().getName());
String Display = (_firstLower + ".compile(");
int increm = 0;
for (final Object step : val_attrib) {
{
boolean _equals = name_attrib.get(increm).equals("name");
boolean _not = (!_equals);
if (_not) {
if ((step instanceof String)) {
System.out.println("String ok");
if (((!GenCheck.isZeroForString(((String)step))) && (!GenCheck.isNullOrEmptyForString(((String)step))))) {
String DisplayInit = name_attrib.get(increm);
String DisplayStateZero = (((DisplayInit + "=\"") + ((String)step)) + "\",");
Display = (Display + DisplayStateZero);
}
} else {
if ((step instanceof Boolean)) {
System.out.println("Boolean ok");
if (((!GenCheck.isFalseBoolean(((Boolean)step))) && (!GenCheck.isNull(step)))) {
System.out.println("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
String DisplayInit_1 = name_attrib.get(increm);
String DisplayStateZero_1 = (((DisplayInit_1 + "=\"") + step) + "\",");
Display = (Display + DisplayStateZero_1);
}
}
}
}
int _increm = increm;
increm = (_increm + 1);
}
}
int _length = Display.length();
int _minus = (_length - 1);
String _substring = Display.substring(0, _minus);
String _plus = (_substring + ")");
Display = _plus;
return Display;
}
/**
* Collect model attributes for the compilation step
*/
public static String[][] modelAttributesToCollect(final Model mod_val) {
EList<EClass> type = mod_val.eClass().getESuperTypes();
int l = 0;
String[] namelisted = new String[((Object[])Conversions.unwrapArray(mod_val.eClass().getEAllAttributes(), Object.class)).length];
String[] vallisted = new String[((Object[])Conversions.unwrapArray(mod_val.eClass().getEAllAttributes(), Object.class)).length];
String[] typelisted = new String[((Object[])Conversions.unwrapArray(mod_val.eClass().getEAllAttributes(), Object.class)).length];
String[][] shades = new String[((Object[])Conversions.unwrapArray(mod_val.eClass().getEAllAttributes(), Object.class)).length][
((Object[])Conversions.unwrapArray(mod_val.eClass().getEAllAttributes(), Object.class)).length];
EList<EAttribute> _eAllAttributes = mod_val.eClass().getEAllAttributes();
for (final EAttribute valu : _eAllAttributes) {
{
l = (l + 1);
int d = (l - 1);
String attri_name = valu.getName();
namelisted[d] = attri_name;
boolean _isNullOrEmptyForString = GenCheck.isNullOrEmptyForString(String.valueOf(mod_val.eGet(valu)));
boolean _not = (!_isNullOrEmptyForString);
if (_not) {
final String attri_type = mod_val.eGet(valu).getClass().getSimpleName();
typelisted[d] = attri_type;
Object attri_val = mod_val.eGet(valu);
vallisted[d] = String.valueOf(attri_val);
final String[][] shade = { namelisted, vallisted };
shades = shade;
} else {
}
}
}
return shades;
}
/**
* Select model attributes to display for the compilation
*/
public static String modelAttributesToDisplayForCompilation(final Model mod) {
final String[][] attributes = ModelOps.modelAttributesToCollect(mod);
List<String> name_attrib = IterableExtensions.<String>toList(((Iterable<String>)Conversions.doWrapArray(attributes[0])));
List<String> val_attrib = IterableExtensions.<String>toList(((Iterable<String>)Conversions.doWrapArray(attributes[1])));
String _firstLower = StringExtensions.toFirstLower(mod.getBase_Class().getName());
String Display = (_firstLower + ".compile(");
for (final String step : val_attrib) {
if ((((!GenCheck.isZeroForString(step)) || (!GenCheck.isNullOrEmptyForString(step))) || (!name_attrib.get(val_attrib.indexOf(step)).equals("name")))) {
String DisplayInit = name_attrib.get(val_attrib.indexOf(step));
String DisplayStateZero = (((DisplayInit + "=\"") + step) + "\",");
Display = (Display + DisplayStateZero);
}
}
int _length = Display.length();
int _minus = (_length - 1);
String _substring = Display.substring(0, _minus);
String _plus = (_substring + ")");
Display = _plus;
return Display;
}
/**
* Collect information flow as following Input,Output -> [LayerName,Inputs,Outputs]
*/
public static Object genInputOutputLayerArrayWithFlow(final Integer nbr_lay, final Model l) {
final ModuleInfo mi = new ModuleInfo((nbr_lay).intValue());
int i = 0;
EList<Property> _ownedAttributes = l.getBase_Class().getOwnedAttributes();
for (final Property layer : _ownedAttributes) {
{
EList<DirectedRelationship> inputList = layer.getTargetDirectedRelationships();
EList<DirectedRelationship> outputList = layer.getSourceDirectedRelationships();
String _name = layer.getName();
String _plus = ("name Connection : " + _name);
System.err.println(_plus);
int _length = ((Object[])Conversions.unwrapArray(layer.getTargetDirectedRelationships(), Object.class)).length;
String _plus_1 = ("nbr Connection : " + Integer.valueOf(_length));
System.err.println(_plus_1);
mi.layersName[i] = layer.getName();
for (final DirectedRelationship input : inputList) {
{
final InformationFlow inFlow = ((InformationFlow) input);
mi.layersInput[i] = inFlow;
}
}
for (final DirectedRelationship output : outputList) {
{
final InformationFlow outFlow = ((InformationFlow) output);
mi.layersOutput[i] = outFlow;
}
}
i = (i + 1);
}
}
i = 0;
System.err.println(mi);
System.err.println(IterableExtensions.<InformationFlow>toList(((Iterable<InformationFlow>)Conversions.doWrapArray(mi.layersInput))));
if (((GenCheck.findNbrOfInformationFLowMissing(mi) != 0) && (GenCheck.findNbrOfInformationFLowPara(l) != 0))) {
return mi;
} else {
return Integer.valueOf(1);
}
}
/**
* Sort layers according to informations flows
*/
public static ArrayList<String> genFlowOrder(final Integer nbr_lay, final ModuleInfo mi) {
int index_first_layer = ModelOps.genFlowOrderInit(mi);
ArrayList<Integer> sorted_layer_indexs = new ArrayList<Integer>();
ArrayList<String> sorted_layer_names = new ArrayList<String>();
sorted_layer_indexs.add(Integer.valueOf(index_first_layer));
int i = 1;
while ((i < ((Object[])Conversions.unwrapArray(IterableExtensions.<String>toList(((Iterable<String>)Conversions.doWrapArray(mi.layersName))), Object.class)).length)) {
{
index_first_layer = (ModelOps.genFlowOrderNext(mi, Integer.valueOf(index_first_layer))).intValue();
sorted_layer_indexs.add(Integer.valueOf(index_first_layer));
int _i = i;
i = (_i + 1);
}
}
for (final Integer u : sorted_layer_indexs) {
{
sorted_layer_names.add(IterableExtensions.<String>toList(((Iterable<String>)Conversions.doWrapArray(mi.layersName))).get((u).intValue()));
System.out.println(IterableExtensions.<String>toList(((Iterable<String>)Conversions.doWrapArray(mi.layersName))).get((u).intValue()));
}
}
return sorted_layer_names;
}
/**
* Collect the first layer according to the information flow
*/
public static int genFlowOrderInit(final ModuleInfo mi) {
int index_first_layer = 0;
for (final InformationFlow ell : mi.layersInput) {
if ((ell == null)) {
index_first_layer = ((List<InformationFlow>)Conversions.doWrapArray(mi.layersInput)).indexOf(ell);
}
}
return index_first_layer;
}
/**
* Collect following layers according to the information flow
*/
public static Integer genFlowOrderNext(final ModuleInfo mi, final Integer index_first_layer) {
Integer index_next_layer = index_first_layer;
for (final InformationFlow el : mi.layersInput) {
InformationFlow _get = IterableExtensions.<InformationFlow>toList(((Iterable<InformationFlow>)Conversions.doWrapArray(mi.layersOutput))).get((index_next_layer).intValue());
boolean _tripleEquals = (el == _get);
if (_tripleEquals) {
index_next_layer = Integer.valueOf(((List<InformationFlow>)Conversions.doWrapArray(mi.layersInput)).indexOf(IterableExtensions.<InformationFlow>toList(((Iterable<InformationFlow>)Conversions.doWrapArray(mi.layersOutput))).get((index_next_layer).intValue())));
return index_next_layer;
}
}
return null;
}
}