Commit 67a0e5b5 authored by Jean-Sébastien Sottet's avatar Jean-Sébastien Sottet
Browse files

Moving old examples

parent 24710cb5
Pipeline #872 passed with stage
in 46 seconds
var JSTL = require('../JSTL_Prototype'); var TransformationModule= JSTL.TransformationModule;
var JSMF = require('../JSMF_Prototype'); var Model = JSMF.Model; var Class = JSMF.Class;
//Load the metamodels (in one file for the example)
var MM = require('./MMABExamples.js');
//Load MMArchi
//Load MMSecurity
//Load the model (in one file for the example)
var M = require('./MABExamples.js');
var inspect = require('eyes').inspector({
maxLength: 9000
});
// <=> to the underscore library.
var _ = require('lodash');
function relationThreatList() {
return [];
}
function relationAList() {
return [];
}
//Simple Rule Definition
var rule = { //ATL <=>
in : function(inputModel) { //ATL <=> from inputModel : MM!C
return inputModel.;
},
out : function(inp) {
var d = MM.D.newInstance('transformed'); //ATL<~>d: MM!D (
d.setnum(inp.id); // ATL <=> num <- inp.id
return [d];
}
}
\ No newline at end of file
/**
* JavaScript Modelling Framework (JSMF)
*
©2015 Luxembourg Institute of Science and Technology All Rights Reserved
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors : J.S. Sottet
*/
var JSTL = require('../../JSTL_Prototype'); var TransformationModule= JSTL.TransformationModule;
var JSMF = require('../../JSMF_Prototype'); var Model = JSMF.Model; var Class = JSMF.Class;
//Load the metamodels (in one file for the example)
var MMI = require('./MMFamily.js');
var MMO = require('./MMPerson.js');
//Load the model (in one file for the example)
var Mi = require('./MFamily.js');
//Create the outputModel
var Mo = new Model('Out');
var inspect = require('eyes').inspector({
maxLength: 9000
});
// <=> to the underscore library.
var _ = require('lodash');
// ************************
//Helper
function isFemale(member) {
//Warning writting the function name... checking empty table
return (member.familyMother.length!=0 || member.familyDaughter.length!=0);
}
//Give the FamilyName the Meta way
/*
function familyName(member) {
var result = '';
var keys = [];
_.each((member.conformsTo().__references), function(n,key){ //should also work chaining select and each
if(n.type.__name=='Family') {
keys.push(key);
}
});
//console.log(keys);
_.each(keys, function(id,el){
if(member[id].length==0) {
// do nothing
} else {
result = member[id][0].lastName;
}
});
return result;
}
*/
function familyName(member) {
var result = '' ;
if(member.familyFather[0] != undefined) {
result = member.familyFather[0].lastName;
}
if(member.familyMother.length!=0) {
result = member.familyMother[0].lastName;
}
if(member.familySon.length!=0) {
result = member.familySon[0].lastName;
}
if(member.familyDaughter.length!=0) {
result = member.familyDaughter[0].lastName;
}
return result;
}
//Rule
var Member2Male = {
in : function(inputModel) {
return _.reject(inputModel.Filter(MMI.Member),
function(elem){
return isFemale(elem);
});
},
out : function(inp) {
var d = MMO.Male.newInstance('');
d.setfullName(inp.firstName+' '+familyName(inp));
return [d];
}
}
var Member2FeMale = {
in : function(inputModel) {
return _.select(inputModel.Filter(MMI.Member),
function(elem){
return isFemale(elem);
});
},
out : function(inp) {
var d = MMO.Female.newInstance('');
console.log(familyName(inp));
familyName(inp);
d.setfullName(inp.firstName+' '+familyName(inp));
return [d];
}
}
// ***********************
var module = new TransformationModule('test', Mi.ma, Mo); //multiple
module.addRule(Member2Male);
module.addRule(Member2FeMale);
//Apply rule by rule...
//module.apply(t);
//module.apply(trule2);
//inspect(Mi.ma.Filter(MMI.Member));
//Apply all rules in the models and resolve references, actual transformation execution
module.applyAllRules();
inspect(Mo.);
//Mo.save();
var JSMF = require('./JSMF_Prototype'); var Model = JSMF.Model; var Class = JSMF.Class;
var _ = require('underscore');
var inspect = require('eyes').inspector({
maxLength: 9000
});
var mma = new Model('MetaA');
var mmb = new Model('MetaB');
var A = Class.newInstance('A');
A.setAttribute('name', String);
var C = Class.newInstance('C');
C.setAttribute('id', Number); //define other primitive types?
A.setReference('toC', C, -1);
var B = Class.newInstance('B');
B.setAttribute('bat', String);
var D = Class.newInstance('D');
D.setAttribute('num', Number);
B.setReference('toD', D, 1);
mma.setModellingElements([A,C]);
mmb.setModellingElements([B,D]); //should check if calling single assignation (setModellingElement to a collection).
//** ********************************
// setting transformation example
//** ********************************
var ma = new Model('a');
var instancea = A.newInstance('a');
instancea.setname('toto');
var instanceaa = A.newInstance('aa');
instanceaa.setname('titi');
var instancec = C.newInstance('c');
instancec.setid(3);
var instancecc = C.newInstance('cc');
instancecc.setid(15);
instancea.settoC(instancec);
instancea.settoC(instancecc);
ma.setReferenceModel(mma); //should check conformance?
ma.setModellingElements([instancea,instanceaa,instancec,instancecc]); //add a dummy creator of modelling elements
//should be created by default in ma model...
var mb = new Model('b');
mb.setReferenceModel(mmb);
var j = ma.modellingElements[A.__name]; //equivalent of metamodel!element.all instances from
//*********************************
// transformation set
// *******************************
//map (source,target(s))
var resolveRef = [];
var resolver = {};
function Rule1 () {
//Rule filter
var i = _(ma.modellingElements[A.__name]).select(
function(elem){
return elem.name!='titi';
}
);
//Rule application (on filtered element)
_.each(i,
function(elem,index){ //hide the _.each within a function
var b = B.newInstance('transformed');
b.setbat(elem.name+'_transfo');
relation = {
source : b,
relationname : 'toD',
target : elem.toC
} //equivalent to ATL <-> targetOutput <- i.targetInput
resolveRef.push(relation); //should be hidden!
resolver[elem]=b; // idem
mb.setModellingElement(b); //should be hidden?
;}
);
}
function Rule2 () {
//from
var i = ma.modellingElements[C.__name];
//to
_.each(i,
function(elem,index){ //hide the _.each within a function
var d = D.newInstance('transformed');
d.setnum(elem.id);
resolver[elem]=d; // should be hidden
mb.setModellingElement(d);
;}
);
}
Rule1(); //req call back? , order independent/not deterministic execution (like ATL);
Rule2();
//Should be tested on multi valued references
_.each(resolveRef,
function(elem, index) {
_.each(elem.target, // get the type of the target(s) of the relation element in the input model in order to...
function(elem2,index2) {
var target = resolver[elem2]; // ... resolve the target of the relation in the output model!
var referenceFunctionName = 'set'+elem.relationname;
elem.source[referenceFunctionName](target);
}
);
});
console.log(mb.modellingElements);
console.log(ma.modellingElements);
console.log(resolver);
//ma.save();
//mb.save();
/************************
** ATL comparison
Rule X { // function Rule1() {
from //maybe replace var i = ma.modellinglement ...
i: mma!A //_.each(ma.modellingElements[A.__name]) (i.name!=titi) //_.select(ma.modellingElements[A.__name], function(elem) {elem.name!='titi')
to
o: mmb!B ( //var o = B.newInstance('');
bat <- i.name+'_transfo' //o.setbat(elem.name+'_transfo')
toD <- i.toC
)
}
*/
\ No newline at end of file
var JSMF = require('../../JSMF_Prototype'); var Model = JSMF.Model; var Class = JSMF.Class;
var MM = require('./MMABExamples.js'); var A = MM.A; var B = MM.B; var C = MM.C; var D = MM.D;
var inspect = require('eyes').inspector({
maxLength: 9000
});
//** ********************************
// setting transformation example
//** ********************************
var ma = new Model('a');
var instancea = MM.A.newInstance('a');
instancea.setname('toto');
var instanceaa = A.newInstance('aa');
instanceaa.setname('titi');
var instancec = C.newInstance('c');
instancec.setid(3);
var instancecc = C.newInstance('cc');
instancecc.setid(15);
instancea.settoC(instancec);
instancea.settoC(instancecc);
ma.setReferenceModel(MM.mma); //should check conformance?
ma.setModellingElements([instancea,instanceaa,instancec,instancecc]); //add a dummy creator of modelling elements
//should be created by default in ma model...
inspect(ma);
//Create an empty model mb
var mb = new Model('b');
mb.setReferenceModel(MM.mmb);
//console.log(MM.mmb.modellingElements);
module.exports = {
ma : ma,
mb : mb
};
var JSMF = require('../../JSMF_Prototype'); var Model = JSMF.Model; var Class = JSMF.Class;
var MM = require('./MMFamily.js');
var inspect = require('eyes').inspector({
maxLength: 9000
});
var ma = new Model('a');
var familyMarch = MM.Family.newInstance('march');
familyMarch.setlastName('March');
var fatherM = MM.Member.newInstance('Jim');
fatherM.setfirstName('Jim');
var motherM = MM.Member.newInstance('Cindy');
motherM.setfirstName('Cindy');
var sonM = MM.Member.newInstance('Brandon');
sonM.setfirstName('Brandon');
var daughterM = MM.Member.newInstance('Brenda');
daughterM.setfirstName('Brenda');
//Should be resolved later with opposite!!!!!!!
//familyMarch.setfather(fatherM);
fatherM.setfamilyFather(familyMarch);
//familyMarch.setmother(motherM);
motherM.setfamilyMother(familyMarch);
//familyMarch.setsons(sonM);
sonM.setfamilySon(familyMarch);
//familyMarch.setdaughters(daughterM);
daughterM.setfamilyDaughter(familyMarch);
var familySailor = MM.Family.newInstance('Sailor');
familySailor.setlastName('Sailor');
var FatherS = MM.Member.newInstance('Peter');
FatherS.setfirstName('Peter');
var MotherS = MM.Member.newInstance('Jackie');
MotherS.setfirstName('Jackie');
var SonS1 = MM.Member.newInstance('David');
SonS1.setfirstName('David');
var SonS2 = MM.Member.newInstance('Dylan');
SonS2.setfirstName('Dylan');
var DaughterS = MM.Member.newInstance('Kelly');
DaughterS.setfirstName('Kelly');
//familySailor.setfather(FatherS);
FatherS.setfamilyFather(familySailor);
//familySailor.setmother(MotherS);
MotherS.setfamilyMother(familySailor);
//familySailor.setsons(SonS1);
SonS1.setfamilySon(familySailor);
//familySailor.setsons(SonS2);
SonS2.setfamilySon(familySailor);
//familySailor.setdaughters(DaughterS);
DaughterS.setfamilyDaughter(familySailor);
//ma.setReferenceModel(MM.mma);
ma.setModellingElements([familyMarch,fatherM,motherM,sonM,daughterM,familySailor,FatherS,MotherS,SonS1,SonS2,DaughterS]);
//ma.setModellingElements([familyMarch,familySailor]);
//ma.save();
module.exports = {
ma : ma
}
\ No newline at end of file
var JSMF = require('../../JSMF_Prototype'); var Model = JSMF.Model; var Class = JSMF.Class; var Enum = JSMF.Enum;
/*****************************************
// context : Model and MetamodeModel
******************************************/
var mma = new Model('MetaA');
var mmb = new Model('MetaB');
var e = new Enum('MyEnum');
e.setLiteral('input',0);
e.setLiteral('output',1);
e.setLiteral('in-output',2);
//console.log('e',e);
var A = Class.newInstance('A');
A.setAttribute('name', String);
//A.setAttribute('value', e);
var C = Class.newInstance('C');
C.setAttribute('id', Number); //define other primitive types?
A.setReference('toC', C, -1);
var B = Class.newInstance('B');
B.setAttribute('nameB', String);
var D = Class.newInstance('D');
D.setAttribute('num', Number);
B.setReference('toD', D, -1);
mma.setModellingElements([A,C]);
mmb.setModellingElements([B,D]);
var a = A.newInstance('');
module.exports = {
mma : mma,
mmb : mmb,
A: A,
B: B,
C: C,
D: D
};
var JSMF = require('../../JSMF_Prototype'); var Model = JSMF.Model; var Class = JSMF.Class; var Enum = JSMF.Enum;
var mma = new Model('Famillies');
var Family = Class.newInstance('Family');
var Member = Class.newInstance('Member');
Family.setAttribute('lastName', String);
Family.setReference('father',Member,1,'familyFather',true);
Family.setReference('mother',Member,1,'familyMother', true);
Family.setReference('sons',Member,-1, 'familySon', true);
Family.setReference('daughters',Member,-1,'familyDaughter', true);
Member.setAttribute('firstName', String);
Member.setReference('familyFather',Family,1, 'father');
Member.setReference('familyMother', Family,1, 'mother');
Member.setReference('familySon', Family,1, 'sons');
Member.setReference('familyDaughter', Family,1, 'daughters');
//console.log(Family.__references['father']);
mma.setModellingElements([Family,Member]);
module.exports = {
mma : mma,
// mmb : mmb,
Family: Family,
Member: Member
};
var JSMF = require('../../JSMF_Prototype'); var Model = JSMF.Model; var Class = JSMF.Class; var Enum = JSMF.Enum;
var mmb = new Model('Person');
var Person = Class.newInstance('Person');
Person.setAttribute('fullName', String);
var Male = Class.newInstance('Male');
var Female = Class.newInstance('Female');
Male.setSuperType(Person);
Female.setSuperType(Person);
mmb.setModellingElements([Person,Male,Female]);
module.exports = {
mmb : mmb,
Person: Person,
Male : Male,
Female : Female
};
var JSMF = require('../JSMF_Prototype'); var Model = JSMF.Model; var Class = JSMF.Class; var Enum = JSMF.Enum;
var inspect = require('eyes').inspector({
maxLength: 9000
});
/*****************************************
// context : Model and MetamodeModel
******************************************/
var mma = new Model('MetaA');
var mmb = new Model('MetaB');
var e = new Enum('MyEnum');
e.setLiteral('input',0);
e.setLiteral('output',1);
e.setLiteral('in-output',2);
//console.log('e',e);
var A = Class.newInstance('A');
A.setAttribute('name', String);
A.setAttribute('type', e);
inspect(A);
var C = Class.newInstance('C');
C.setAttribute('id', Number); //define other primitive types?
A.setReference('toC', C, -1);
var B = Class.newInstance('B');
B.setAttribute('nameB', String);
var D = Class.newInstance('D');
D.setAttribute('num', Number);
B.setReference('toD', D, -1);
mma.setModellingElements([A,C]);
mmb.setModellingElements([B,D]);
module.exports = {
mma : mma,
mmb : mmb,