Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » [SOLVED] [ECL] how to call lazy rules
[SOLVED] [ECL] how to call lazy rules [message #1113767] Sat, 21 September 2013 17:50 Go to next message
giovi disanto is currently offline giovi disanto
Messages: 58
Registered: September 2011
Member
Hi,
I have a problem with lazy rules.... i didn't understand how to call them! Basing on the book they are called only in an indirect way with the matches built-in operation. Is there a way to call them by passing the involved elements or something like that?

[Updated on: Tue, 24 September 2013 09:28]

Report message to a moderator

Re: [ECL] how to call lazy rules [message #1113814 is a reply to message #1113767] Sat, 21 September 2013 19:37 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris Kolovos
Messages: 880
Registered: July 2009
Senior Member
Hi,

To invoke a lazy rule in ECL for a model element you need to call its matches() operation (e.g. x.matches()).

Cheers,
Dimitris
Re: [ECL] how to call lazy rules [message #1114195 is a reply to message #1113814] Sun, 22 September 2013 10:26 Go to previous messageGo to next message
giovi disanto is currently offline giovi disanto
Messages: 58
Registered: September 2011
Member
Hi,
Thank you for the answer. I've tried with matches operation but it seems to not work properly. Probably i made some mistakes by declaring the lazy rule. I'm comparing a model conforms to java metamodel (provided by modisco framework) and a model conform to a ecore metametamodel.
Here a piece of my code:

rule MatchEClassWithClassDeclaration
	match c : CustomModel!EClass
	with a : ApiModel!ClassDeclaration {
	
	compare {
		if (a.name.isSubstringOf(c.name) or c.name.isSubstringOf(a.name)){
			return true;
		} else {
			if(a.name.simComparison(c.name) or a.name.ws4jComparison(c.name))
				return true;
			else
				return false;
		}
	}
	
	do {
		var md : OrderedSet = a.bodyDeclarations.select(a : MethodDeclaration | true);
		var ea : OrderedSet = c.eAttributes;
		md.matches();
		ea.matches();
		
		for(m : MethodDeclaration in md ){
			m.matches();
		}
		
		for(e : MethodDeclaration in ea ){
				e.matches();
		}
		matchInfo.put("type","EClass-ClassDeclaration");
	}
}


@lazy
rule MatchEAttributeWithMethodDeclaration
	match c: CustomModel!EAttribute
	with a : ApiModel!MethodDeclaration{
	
	compare {
		return true;		
	}
	
	do {
		'test'.println();
		matchInfo.put("type","EAttribute-MethodDeclaration");
	}
	

}


As you can see i called the lazy rule multiple times without success. Model elements held by the two ordered set are MethodDeclarations and EAttributes elements respectively.
Re: [ECL] how to call lazy rules [message #1114198 is a reply to message #1114195] Sun, 22 September 2013 10:31 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris Kolovos
Messages: 880
Registered: July 2009
Senior Member
Hi,

matches() needs a parameter - e.g. x.matches(y). In your case, x should be an instance of EAttribute and y and instance of MethodDeclaration.

Cheers,
Dimitris
Re: [ECL] how to call lazy rules [message #1114243 is a reply to message #1114198] Sun, 22 September 2013 12:18 Go to previous messageGo to next message
giovi disanto is currently offline giovi disanto
Messages: 58
Registered: September 2011
Member
Unfortunately i tried a similar solution before posting my previous answer without success, but i had forgotten to insert it inside my code.
The extra code placed inside the do block is:

for(m : MethodDeclaration in md ){
			for(e : MethodDeclaration in ea ){
				m.matches(e);
			}
		}


I think there is a mistake related with the instance references... i can't figure out what it's..
Re: [ECL] how to call lazy rules [message #1114246 is a reply to message #1114243] Sun, 22 September 2013 12:23 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris Kolovos
Messages: 880
Registered: July 2009
Senior Member
Hi,

ea appears to be a collection of EAttributes so the following loop

for(e : MethodDeclaration in ea ){ ... }

should look like

for(e : EAttribute in ea ){ ... }

instead.

Cheers,
Dimitris
Re: [ECL] how to call lazy rules [message #1114347 is a reply to message #1114246] Sun, 22 September 2013 15:55 Go to previous messageGo to next message
giovi disanto is currently offline giovi disanto
Messages: 58
Registered: September 2011
Member
Thank you!
It was a terrible mistake by me! Now the lazy rule mechanism seems to works. Only another two questions: Are matchings provided by lazy rules inserted inside the matchtrace? When for example is invoked m.matches(e) m matches the element in the "match" and e the element in the "with", right?
Re: [ECL] how to call lazy rules [message #1114357 is a reply to message #1114347] Sun, 22 September 2013 16:12 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris Kolovos
Messages: 880
Registered: July 2009
Senior Member
No worries. Yes, this sounds correct.

Cheers,
Dimitris
Re: [ECL] how to call lazy rules [message #1114390 is a reply to message #1114357] Sun, 22 September 2013 17:24 Go to previous messageGo to next message
giovi disanto is currently offline giovi disanto
Messages: 58
Registered: September 2011
Member
ok everything seems to work fine accept matchtrace... matchings provided by lazy rules seem to not be included inside my matchtrace. Here it is my full code:

pre {
	var sim = new Native("org.ossmeter.repository.plugin.simmetrics.Simmetrics");
	var ws4j = new Native("org.ossmeter.repository.plugin.ws4j.Ws4j");
	 
}

operation String simComparison(other: String ) : Boolean {
	return sim.getSimilarity(self,other) > 0.8;
}

operation String ws4jComparison(other: String) : Boolean {
	return ws4j.getSimilarity(self,other) > 0.8; 
}


rule MatchEClassWithClassDeclaration
	match c : CustomModel!EClass
	with a : ApiModel!ClassDeclaration {
	
	compare {
		if (a.name.isSubstringOf(c.name) or c.name.isSubstringOf(a.name)){
			return true;
		} else {
			if(a.name.simComparison(c.name) or a.name.ws4jComparison(c.name))
				return true;
			else
				return false;
		}
	}
	
	do {
		var md : OrderedSet = a.bodyDeclarations.select(a : MethodDeclaration | true);
		var ea : OrderedSet = c.eAttributes;
		
		for(m : ApiModel!MethodDeclaration in md ){
			for(e : CustomModel!EAttribute in ea ){
				m.matches(e);
			}
		}
		matchInfo.put("type","EClass-ClassDeclaration");
	}
}


@lazy
rule MatchEAttributeWithMethodDeclaration
	match a : ApiModel!MethodDeclaration
	with c : CustomModel!EAttribute {
	
	compare {
		return true;	
	}
	
	do {
		c.eContainer.name.print();
		':'.print();
		c.name.print();
		'---'.print();
		a.eContainer.name.print();
		':'.print();
		a.name.println();
		matchInfo.put("type","EAttribute-MethodDeclaration");
	}
	

}


post{
	var count : Integer = 0;
	var size : Integer = matchTrace.matches.size();
	while(count < size){
		var current = matchTrace.matches[count];
		if(current.matching){
			current.info.get('type').print();
			' : '.print();
			current.left.name.print();
			' <--> '.print();
			current.right.name.println();
		}	
		count = count + 1;
	}
}
Re: [ECL] how to call lazy rules [message #1114437 is a reply to message #1114390] Sun, 22 September 2013 18:51 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris Kolovos
Messages: 880
Registered: July 2009
Senior Member
Hi,

You're right - this is a bug [1]. It's been now fixed in the SVN and in the latest interim release [2].

Cheers,
Dimitris

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=417774
[2] http://download.eclipse.org/epsilon/interim/
Re: [ECL] how to call lazy rules [message #1114822 is a reply to message #1114437] Mon, 23 September 2013 08:55 Go to previous message
giovi disanto is currently offline giovi disanto
Messages: 58
Registered: September 2011
Member
Yes now it works!

Thanks!
Previous Topic:[SOLVED][EUGENIA] generate EMFText model
Next Topic:Eclipse Epsilon 64bit
Goto Forum:
  


Current Time: Tue Oct 21 10:33:56 GMT 2014

Powered by FUDForum. Page generated in 0.11668 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software