Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » EMF-IncQuery » UML Incquery pattern : constrain to particular model name(UML Incquery pattern : constrain to particular model name)
UML Incquery pattern : constrain to particular model name [message #1681688] Tue, 17 March 2015 12:19 Go to next message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
Hello,
(1)
I am trying to write the patterns that addresses specifically the UML.ecore models. The pattern suppose to include the classes that are belong to a Particular UML:: Model name. I write some code below , but not seem to work , is there a better way.??

pattern nonEmptyClass(cl : Class) {
	neg find emptyClass(cl);
	find filterToModel(c1);
}

pattern filterToModel(m1: Class){
	Class.^package(m1, pack);
	find getPackage+(pack);
}

pattern getPackage(c1:Package){
	Package.nestingPackage(c1, pack);
	Package.name(pack, "MyProjectName"); 
	find getPackage(pack);
	
}


(2)
Also , I wonder if it is possible to read constant values like : "MyProjectName" in code above from an external file (e.g., property file)


Thanks
Re: UML Incquery pattern : constrain to particular model name [message #1681814 is a reply to message #1681688] Tue, 17 March 2015 13:21 Go to previous messageGo to next message
Eric Lépicier is currently offline Eric LépicierFriend
Messages: 25
Registered: October 2013
Junior Member
Hi,

(1) The use you make of find getPackage+ is not correct.
The getPackage pattern must be written as a transitive pattern to be used in the find...+ transitive closure expression.
Your approach mimics imperative recursivity, and it isn't the right way to express your need.

You may try something like :
pattern filterToModel(m1: Class) {
	Package.name(myProject, "MyProjectName");
	find getPackage+(myProject, pack); // pack is a subpackage of myProject, at any level of subpackages
	Class.^package(m1, pack);
}
pattern getPackage(pack:Package, subpack : Package) { // transitive pattern with two parameters of the same type, allowing recursive calls with find +
	Package.nestingPackage(subpack, pack);
}


(2) I didn't find a way to do it, except adding a parameters model as a complementary resource, and then writing cross-resource patterns, thus querying both your UML model and your parameter model.

Cheers
--Eric
Re: UML Incquery pattern : constrain to particular model name [message #1681932 is a reply to message #1681814] Tue, 17 March 2015 14:21 Go to previous messageGo to next message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
Hi Eric , thanks for the reply,.

I tried your solution but dont seem to work .
the only concern that i have, is that the recursive call has to stop if it finds a package in the high hierarchy with a specific name . That is , if I have the Class c1, its parent package should be inherited from a package with the name "MyProjectName" . Otherwise that class should not be consider as a match .
I am asking for this , because when i display the classes in my UML model , it shows all class that is belong to my project and the external classes related to other java project such as (Thread , HttpRequest, ArrayList) .
I attached the code of the patterns .

Thank you



Re: UML Incquery pattern : constrain to particular model name [message #1682053 is a reply to message #1681932] Tue, 17 March 2015 15:24 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 343
Registered: July 2015
Senior Member
Hi Salwa,

(1) The problem with your getPackage pattern is that you are limiting it to packages named "MyProjectName" (as visible in your eiq file). You should do something similar as Eric proposed:

pattern filterToModel(m1: Class) {
        //There is a package with the name "MyProjectName"
	Package.name(myProject, "MyProjectName");
        // pack is a subpackage (either direct or indirect) of myProject
	find getPackage+(myProject, pack); 
       //m1 is a class in the Package pack
	Class.^package(m1, pack);
}

/** This pattern enumerates all package-subpackage pairs. */
pattern childPackage(pack:Package, subpack : Package) { 
	Package.nestingPackage(subpack, pack);
}


(2) Loading the possible values from a file is possible, but not recommended. The main issue is that EMF-IncQuery addresses incremental queries; and unless the list of elements is fixed during the entire lifecycle it will not be safe to use. If it is fixed, you can use check expressions with corresponding Java functions that determines whether a package name is in your file.

However, I am not recommending to use this approach, as it is very easy to provide something that will not work correctly or performantly (basically, the check expressions are often not called, and there is no guaranteed execution path; and the calculated results are then cached).

On the other hand, if you want to use some packages, you could model them directly: either via corresponding profiles/stereotypes; or by creating an EMF model that refers to the enabled package instances, and use these references for matching.



I hope, this was clear. If not, please try to provide some details, what is not clear, what does it mean "I tried your solution but dont seem to work ." (e.g. what are the expected results, what results do you get, how does the instance model look like).

Cheers,
Zoltán
Re: UML Incquery pattern : constrain to particular model name [message #1683696 is a reply to message #1682053] Wed, 18 March 2015 06:00 Go to previous messageGo to next message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
Hi Zoltan,

thank you for your reply!

(1) I tried Eric solution but the graph is not coming . Both of you suggested to get first the package ("MyProjectName"), and then go down in the sub-packages to get all classes. However, what confusing is hat you are using Package.nestingPackage (Go Up) instead of Package.nestedPackage (Go Down).

I attached both the eiq and sample uml model . The result of my query should return only the classes in the package ("MyProjectName") and the dependency between them. Any dependency with classes in the the package ("External") should not be included. In the nonEmptyClass pattern , I get first all non empty class and then constrain even more the result to include classes belong to specific package by calling find filterToModel(c1); . The dependencyClass pattern will show the dependency between the classes. THe dependencies with classes in package ("External") are suppose to be displayed.


Appreciate your help on this .

Re: UML Incquery pattern : constrain to particular model name [message #1684170 is a reply to message #1683696] Wed, 18 March 2015 10:09 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 343
Registered: July 2015
Senior Member
Hi Salwa,

thanks for the attachments, I have now found different causes while your queries were not working as expected:

1. Your pattern definitions were using derived features (all such usage were reported by warnings in the code), and by default EMF-IncQuery does not allow the usage of derived features, as more often than not they do not provide correct change notifications, making incremental evaluation impossible. We are in the process of making such features available for querying (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=414824), and that feature should work shortly (I hope, they will be available next week). In the meanwhile, I have replaced the usage of these features with different model traversals to make the feature work.
2. "MyProjectName" was not a Package but a Model in UML terminology. This was problematic, because the getPackage pattern expected to have a Package as its first parameter, and would not match when called with a model. I have updated with an extra feature traversal that goes down one level from the Model to its member Packages, and then used these to call the getPackage pattern.
3. In the nonEmptyClass pattern in the filterModel call the name 'cl' was misspelled as 'c1'. The system issued a warning, as this is most likely not what you have wanted to provide, and it did not do correct filtering.

I have attached an updated version of your queries that worked in my incquery instance.

Cheers,
Zoltán
Re: UML Incquery pattern : constrain to particular model name [message #1684841 is a reply to message #1683696] Wed, 18 March 2015 15:51 Go to previous messageGo to next message
Eric Lépicier is currently offline Eric LépicierFriend
Messages: 25
Registered: October 2013
Junior Member
Salwa Alzahmi wrote on Wed, 18 March 2015 07:00
Hi Zoltan,

(1) I tried Eric solution but the graph is not coming . Both of you suggested to get first the package ("MyProjectName"), and then go down in the sub-packages to get all classes. However, what confusing is hat you are using Package.nestingPackage (Go Up) instead of Package.nestedPackage (Go Down).


Hi,

Sorry if my answer was only based on my comprehension of your code snippet ...

I just want to mention that again, in your formulation, you consider incquery as an imperative language whereas it's a declarative one. There is no signification in the constraints order, none is "executed" first, and nobody "goes down" ...
So, one can read the filterToModel pattern either as "give me all classes in subpackages of MyProjectName", or as "is this particular class a member of a subpackage of MyProjectName". The constraint is the same : the existence of a matching path between MyProjectname and a class.

In the same way, there shall be no difference in matching a couple with a feature or its opposite.
pattern childPackage(pack:Package, subpack : Package) { 
	Package.nestingPackage(subpack, pack);
}

and
pattern childPackage(pack:Package, subpack : Package) { 
	Package.nestedPackages(pack, subpack);
}

are equivalent, as long as nestingPackage and nestedPackages are fully opposites.

Cheers,
--Eric

[Updated on: Fri, 20 March 2015 08:24]

Report message to a moderator

Re: UML Incquery pattern : constrain to particular model name [message #1693161 is a reply to message #1684841] Wed, 22 April 2015 07:50 Go to previous messageGo to next message
Denes Harmath is currently offline Denes HarmathFriend
Messages: 9
Registered: August 2014
Junior Member
Hi Salwa,

starting from the 1.0 M2 milestone released yesterday, you can use derived features such as Package.nestingPackage and Type.package. For more details, see the documentation.
Re: UML Incquery pattern : constrain to particular model name [message #1709426 is a reply to message #1693161] Mon, 28 September 2015 11:11 Go to previous messageGo to next message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
From the last time I have the UML File that contain multiple "model" Elements. I was trying to filter out two models 'external' & 'resource references' that I don't need to show in my Zest Viewer Chart. Is there a 'Not' operation that I can add to my query statement to exclude these two models:
Model.name(myProject," external');
Model.name(myProject," resource references);


Regards
Re: UML Incquery pattern : constrain to particular model name [message #1709438 is a reply to message #1709426] Mon, 28 September 2015 12:31 Go to previous messageGo to next message
Gabor Bergmann is currently offline Gabor BergmannFriend
Messages: 28
Registered: July 2009
Junior Member
Hi Salwa,

we have non-equivalence in the language:

Model.name(myProject, modelName);
modelName != " external";

And for expressing more complicated cases, there is also "neg find".

Cheers
Gábor
Re: UML Incquery pattern : constrain to particular model name [message #1710102 is a reply to message #1709438] Sun, 04 October 2015 09:08 Go to previous messageGo to next message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
Hi Gabor
I tried the non-equivalence operation but it dont seem to work. I still get the elements of all model displays in my Graph. This is my pattern methods:
pattern filterToModel(m1: Class) {
         find filtereternalPackage(myProject);
	Model.packagedElement(myProject, topPackage);
	find getPackage+(topPackage, pack); // pack is a subpackage of myProject, at any level of subpackages
	Package.packagedElement(pack, m1);
}
pattern filtereternalPackage(m:Model){
	Model.name(m, modelName); 
	modelName != "externals";
}



can you please check if I am writing in right way

thanks
Re: UML Incquery pattern : constrain to particular model name [message #1710390 is a reply to message #1710102] Tue, 06 October 2015 11:53 Go to previous messageGo to next message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
any help with that please


Re: UML Incquery pattern : constrain to particular model name [message #1710393 is a reply to message #1710390] Tue, 06 October 2015 12:00 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 189
Registered: September 2015
Senior Member
As a first step, check the matches of the filterExternalPackage pattern. The model with name "externals" should not be a match (by the way, earlier you wrote "external" without the "s" at the end).

If the above is ok, then I see no problems with your patterns.

As a workaround, try rewriting the pattern to the following:
pattern externalModel(m:Model){
	Model.name(m, "externals");
}


And use "neg find externalModel(m)" in the other pattern.

Also, you could add a screenshot of your Model Explorer or any treeview of your resourse set.
Re: UML Incquery pattern : constrain to particular model name [message #1710398 is a reply to message #1710393] Tue, 06 October 2015 12:39 Go to previous messageGo to next message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
Hi Abel ,
I tried this approach but it never work. The graph viewer still show all elements in all Models .


pattern filterToModel(m1: Class) {

   find existModel(myProject);
	Model.packagedElement(myProject, topPackage);
	find getPackage+(topPackage, pack); 
	
	Package.packagedElement(pack, m1);
}

pattern existModel(m:Model){
	neg find externalModel(m);
}
pattern externalModel(m:Model){
	Model.name(m, "externals");
}


I attached sample of my UML model structure..

Thanks
  • Attachment: kdm.xmi.uml
    (Size: 252.09KB, Downloaded 102 times)

[Updated on: Tue, 06 October 2015 14:05]

Report message to a moderator

Re: UML Incquery pattern : constrain to particular model name [message #1710399 is a reply to message #1710393] Tue, 06 October 2015 12:39 Go to previous messageGo to next message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
Hi Abel ,
I tried this approach but it never work. The graph viewer still show all elements in all Models .
I attached sample of my UML model structure..

Thanks
Re: UML Incquery pattern : constrain to particular model name [message #1714310 is a reply to message #1710399] Wed, 11 November 2015 16:37 Go to previous message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 189
Registered: September 2015
Senior Member
First of all, sorry for the late answer, my subscription to this thread was lost when my e-mail changed.

I have tried your queries with the example model and found the issue. Your model looks like this:

- root : Model
--- my project : Model
--- externals : Model

However, that way, "externals" is a packaged element of "root". Furthermore, all Classes will match filterToModel, because they are contained by "root" (transitively).

Instead, you should check that a given class is not contained by the externals model, like this:

package uml.queries

import "http://www.eclipse.org/uml2/5.0.0/UML"

pattern getPackage(pack:Package, subpack : Package) { 
    Package.nestedPackage(pack, subpack);
}

pattern filterToModel(m1: Class) {
    neg find containedByExternalModel(m1); 
    Package.packagedElement(_, m1);
}

pattern containedByExternalModel(m1: Class) {
    find externalModel(myProject);
    Model.packagedElement(myProject, topPackage);
    find getPackage+(topPackage, pack); 
    Package.packagedElement(pack, m1);
}

pattern existModel(m:Model){
    neg find externalModel(m);
}
pattern externalModel(m:Model){
    Model.name(m, "externals");
}
Previous Topic:no packages to be imported in query definition wizard?
Next Topic:How to generate java files from inc query definition file (.eiq files)
Goto Forum:
  


Current Time: Sun Nov 18 01:16:12 GMT 2018

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

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

Back to the top