Home » Archived » M2M (model-to-model transformation) » [QVTO] first() and If Expression
[QVTO] first() and If Expression [message #91913] |
Thu, 09 October 2008 16:53 |
Eclipse User |
|
|
|
Originally posted by: mahdider.students.uni-mainz.de
Hello again,
I want to count how "deep" the inheritance for a given class is and sum
up all steps for all classes of a given set to finally compute an average.
I have issues with the qvto syntax and after trying for a long time, I
have no idea what else to try.
Here is a snippet:
/*
Recursively computes the amount of steps from the leaf classes to their
roots and sums them up.
*/
query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) : Integer {
return leafClasses->computeSteps()->sum();
}
/*
Computes the needed steps from leaf to root for a single class.
*/
query UmlClass::computeSteps() : Integer {
-- How to select the first element from the bag or set?
var g := self.umlGeneral->any(true);
-- if else not supported?
if (g == null) {
}
return res;
}
In computeSteps(), my idea is to go back the umlGeneral reference and
jump from class to class until this is null, counting the inheritance
path length.
The issue is first, that self.umlgeneral is a set / baf and I want to
access only its first element (language only knows single inheritance).
I saw some method like first() but this seems not to exist?
After this, I need some sort of if, else construct, which is there
according to the QVT specs but it looks like it is not yet in QVTO?
Any help to express this in QVTO is welcome! Maybe I am just trying to
do it the "wrong way"?
Best Regards,
Mahdi D-Manesh
|
|
|
Re: [QVTO] first() and If Expression [message #91945 is a reply to message #91913] |
Fri, 10 October 2008 08:34 |
Sergey Boyko Messages: 171 Registered: July 2009 |
Senior Member |
|
|
Hi Mahdi,
According to spec 'first()' is defined for ordered collections only
(Sequence and OrderedSet). For the other collection types 'any(true)' is
appropriate way to obtain some element. Or you can cast collection to
sequence like 'coll->asSequence()->first()'.
Qvto supports 'if' construction with the following syntax
if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
Use like:
if true then {} endif;
if true then OclVoid endif;
if true then {} else {} endif;
if true then {} else OclVoid endif;
Btw, for counting generals for uml-like class it's possible to use
'while()' expression (supposing single inheritance):
query uml::Class::computeSteps() : Integer {
var gen : uml::Classifier := self;
var count := 0;
while (not gen.generalization->isEmpty()) {
gen := gen.generalization->any(true).general;
count = count + 1;
};
return count;
}
Regards,
Sergey
Mahdi D-Manesh wrote:
> Hello again,
>
> I want to count how "deep" the inheritance for a given class is and sum
> up all steps for all classes of a given set to finally compute an average.
>
> I have issues with the qvto syntax and after trying for a long time, I
> have no idea what else to try.
>
> Here is a snippet:
>
> /*
> Recursively computes the amount of steps from the leaf classes to
> their roots and sums them up.
> */
> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) : Integer {
> return leafClasses->computeSteps()->sum();
> }
>
> /*
> Computes the needed steps from leaf to root for a single class.
> */
> query UmlClass::computeSteps() : Integer {
> -- How to select the first element from the bag or set?
> var g := self.umlGeneral->any(true);
>
> -- if else not supported?
> if (g == null) {
>
> }
>
> return res;
> }
>
> In computeSteps(), my idea is to go back the umlGeneral reference and
> jump from class to class until this is null, counting the inheritance
> path length.
>
> The issue is first, that self.umlgeneral is a set / baf and I want to
> access only its first element (language only knows single inheritance).
> I saw some method like first() but this seems not to exist?
>
> After this, I need some sort of if, else construct, which is there
> according to the QVT specs but it looks like it is not yet in QVTO?
>
> Any help to express this in QVTO is welcome! Maybe I am just trying to
> do it the "wrong way"?
>
> Best Regards,
> Mahdi D-Manesh
|
|
|
Re: [QVTO] first() and If Expression [message #91961 is a reply to message #91945] |
Fri, 10 October 2008 09:19 |
Eclipse User |
|
|
|
Originally posted by: mahdider.students.uni-mainz.de
Hello Sergey,
thanks a lot for the examples!
In the meantime I found the while statement and my Benchmark
transformation runs.
For the ->first() of course it makes sense for ordered collections only,
my bad. I tried it and it works. :)
Same for the if Statement - I just tried the ways from QVT 07-07-07.pdf
specs but they did not look correct there. Yours run like expected.
Is there some (free) Document, which lists such syntax more up to date
and according to the QVTO plugin implementation?
Thanks for the computeSteps() example! My version looks very similar,
just that I didnt know how to initialize the var with a type like this.
Once again, thanks alot for your time!
Mahdi
Sergey Boyko schrieb:
> Hi Mahdi,
>
> According to spec 'first()' is defined for ordered collections only
> (Sequence and OrderedSet). For the other collection types 'any(true)' is
> appropriate way to obtain some element. Or you can cast collection to
> sequence like 'coll->asSequence()->first()'.
>
> Qvto supports 'if' construction with the following syntax
> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>
> Use like:
> if true then {} endif;
> if true then OclVoid endif;
> if true then {} else {} endif;
> if true then {} else OclVoid endif;
>
>
> Btw, for counting generals for uml-like class it's possible to use
> 'while()' expression (supposing single inheritance):
>
> query uml::Class::computeSteps() : Integer {
> var gen : uml::Classifier := self;
> var count := 0;
>
> while (not gen.generalization->isEmpty()) {
> gen := gen.generalization->any(true).general;
> count = count + 1;
> };
> return count;
> }
>
> Regards,
> Sergey
>
>
> Mahdi D-Manesh wrote:
>> Hello again,
>>
>> I want to count how "deep" the inheritance for a given class is and
>> sum up all steps for all classes of a given set to finally compute an
>> average.
>>
>> I have issues with the qvto syntax and after trying for a long time, I
>> have no idea what else to try.
>>
>> Here is a snippet:
>>
>> /*
>> Recursively computes the amount of steps from the leaf classes to
>> their roots and sums them up.
>> */
>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) : Integer {
>> return leafClasses->computeSteps()->sum();
>> }
>>
>> /*
>> Computes the needed steps from leaf to root for a single class.
>> */
>> query UmlClass::computeSteps() : Integer {
>> -- How to select the first element from the bag or set?
>> var g := self.umlGeneral->any(true);
>> -- if else not supported?
>> if (g == null) {
>> }
>> return res;
>> }
>>
>> In computeSteps(), my idea is to go back the umlGeneral reference and
>> jump from class to class until this is null, counting the inheritance
>> path length.
>>
>> The issue is first, that self.umlgeneral is a set / baf and I want to
>> access only its first element (language only knows single
>> inheritance). I saw some method like first() but this seems not to exist?
>>
>> After this, I need some sort of if, else construct, which is there
>> according to the QVT specs but it looks like it is not yet in QVTO?
>>
>> Any help to express this in QVTO is welcome! Maybe I am just trying to
>> do it the "wrong way"?
>>
>> Best Regards,
>> Mahdi D-Manesh
|
|
|
Re: [QVTO] first() and If Expression [message #91976 is a reply to message #91961] |
Fri, 10 October 2008 09:50 |
Sergey Boyko Messages: 171 Registered: July 2009 |
Senior Member |
|
|
Hi Mahdi
Not at all. I like qvto to be used in the field ;)
About spec conformance. It's our goal :)
Section "8.4.7 EBNF" defines the following
<if_exp> ::= 'if' <expression> <then_part>
<elif_part>* <else_part>? 'endif'
<then_part> ::= 'then' <if_body>
<elif_part> ::= 'elif' <if_body>
<else_part> ::= 'else' <if_body>
<if_body> ::= <expression> | <expression_block>
We only missed 'elif' part at present.
Snippets from the spec like
var x:= if (self.name.startsWith("_") "PROTECTED"
elif (self.type.isPrimitive() "NORMAL"
else "UNEXPECTED"
simply don't match grammar defined in the same doc :)
The only addition doc about our implementation I can point is from our
Eclipse corner:
http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
Regards,
Sergey.
Mahdi D-Manesh wrote:
> Hello Sergey,
>
> thanks a lot for the examples!
> In the meantime I found the while statement and my Benchmark
> transformation runs.
>
> For the ->first() of course it makes sense for ordered collections only,
> my bad. I tried it and it works. :)
>
> Same for the if Statement - I just tried the ways from QVT 07-07-07.pdf
> specs but they did not look correct there. Yours run like expected.
> Is there some (free) Document, which lists such syntax more up to date
> and according to the QVTO plugin implementation?
>
> Thanks for the computeSteps() example! My version looks very similar,
> just that I didnt know how to initialize the var with a type like this.
>
> Once again, thanks alot for your time!
> Mahdi
>
>
> Sergey Boyko schrieb:
>> Hi Mahdi,
>>
>> According to spec 'first()' is defined for ordered collections only
>> (Sequence and OrderedSet). For the other collection types 'any(true)'
>> is appropriate way to obtain some element. Or you can cast collection
>> to sequence like 'coll->asSequence()->first()'.
>>
>> Qvto supports 'if' construction with the following syntax
>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>
>> Use like:
>> if true then {} endif;
>> if true then OclVoid endif;
>> if true then {} else {} endif;
>> if true then {} else OclVoid endif;
>>
>>
>> Btw, for counting generals for uml-like class it's possible to use
>> 'while()' expression (supposing single inheritance):
>>
>> query uml::Class::computeSteps() : Integer {
>> var gen : uml::Classifier := self;
>> var count := 0;
>>
>> while (not gen.generalization->isEmpty()) {
>> gen := gen.generalization->any(true).general;
>> count = count + 1;
>> }; return count;
>> }
>>
>> Regards,
>> Sergey
>>
>>
>> Mahdi D-Manesh wrote:
>>> Hello again,
>>>
>>> I want to count how "deep" the inheritance for a given class is and
>>> sum up all steps for all classes of a given set to finally compute an
>>> average.
>>>
>>> I have issues with the qvto syntax and after trying for a long time,
>>> I have no idea what else to try.
>>>
>>> Here is a snippet:
>>>
>>> /*
>>> Recursively computes the amount of steps from the leaf classes to
>>> their roots and sums them up.
>>> */
>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>> Integer {
>>> return leafClasses->computeSteps()->sum();
>>> }
>>>
>>> /*
>>> Computes the needed steps from leaf to root for a single class.
>>> */
>>> query UmlClass::computeSteps() : Integer {
>>> -- How to select the first element from the bag or set?
>>> var g := self.umlGeneral->any(true);
>>> -- if else not supported?
>>> if (g == null) {
>>> }
>>> return res;
>>> }
>>>
>>> In computeSteps(), my idea is to go back the umlGeneral reference and
>>> jump from class to class until this is null, counting the inheritance
>>> path length.
>>>
>>> The issue is first, that self.umlgeneral is a set / baf and I want to
>>> access only its first element (language only knows single
>>> inheritance). I saw some method like first() but this seems not to
>>> exist?
>>>
>>> After this, I need some sort of if, else construct, which is there
>>> according to the QVT specs but it looks like it is not yet in QVTO?
>>>
>>> Any help to express this in QVTO is welcome! Maybe I am just trying
>>> to do it the "wrong way"?
>>>
>>> Best Regards,
>>> Mahdi D-Manesh
|
|
|
Re: [QVTO] first() and If Expression [message #91992 is a reply to message #91976] |
Fri, 10 October 2008 10:50 |
Eclipse User |
|
|
|
Originally posted by: mahdider.students.uni-mainz.de
Hello Sergey,
yes you're right, actually the specs are correct, just the example isn't
wow... I was so close to looking at the EBNF but I usually avoid it when
possible. In this case it would have been good though, I agree! :)
Well missing the elif part is not such a big deal.
Best Regards,
Mahdi
Sergey Boyko schrieb:
> Hi Mahdi
>
> Not at all. I like qvto to be used in the field ;)
>
> About spec conformance. It's our goal :)
> Section "8.4.7 EBNF" defines the following
> <if_exp> ::= 'if' <expression> <then_part>
> <elif_part>* <else_part>? 'endif'
> <then_part> ::= 'then' <if_body>
> <elif_part> ::= 'elif' <if_body>
> <else_part> ::= 'else' <if_body>
> <if_body> ::= <expression> | <expression_block>
>
> We only missed 'elif' part at present.
>
> Snippets from the spec like
> var x:= if (self.name.startsWith("_") "PROTECTED"
> elif (self.type.isPrimitive() "NORMAL"
> else "UNEXPECTED"
> simply don't match grammar defined in the same doc :)
>
> The only addition doc about our implementation I can point is from our
> Eclipse corner:
> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>
>
> Regards,
> Sergey.
>
>
> Mahdi D-Manesh wrote:
>> Hello Sergey,
>>
>> thanks a lot for the examples!
>> In the meantime I found the while statement and my Benchmark
>> transformation runs.
>>
>> For the ->first() of course it makes sense for ordered collections
>> only, my bad. I tried it and it works. :)
>>
>> Same for the if Statement - I just tried the ways from QVT
>> 07-07-07.pdf specs but they did not look correct there. Yours run like
>> expected.
>> Is there some (free) Document, which lists such syntax more up to date
>> and according to the QVTO plugin implementation?
>>
>> Thanks for the computeSteps() example! My version looks very similar,
>> just that I didnt know how to initialize the var with a type like this.
>>
>> Once again, thanks alot for your time!
>> Mahdi
>>
>>
>> Sergey Boyko schrieb:
>>> Hi Mahdi,
>>>
>>> According to spec 'first()' is defined for ordered collections only
>>> (Sequence and OrderedSet). For the other collection types 'any(true)'
>>> is appropriate way to obtain some element. Or you can cast collection
>>> to sequence like 'coll->asSequence()->first()'.
>>>
>>> Qvto supports 'if' construction with the following syntax
>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>
>>> Use like:
>>> if true then {} endif;
>>> if true then OclVoid endif;
>>> if true then {} else {} endif;
>>> if true then {} else OclVoid endif;
>>>
>>>
>>> Btw, for counting generals for uml-like class it's possible to use
>>> 'while()' expression (supposing single inheritance):
>>>
>>> query uml::Class::computeSteps() : Integer {
>>> var gen : uml::Classifier := self;
>>> var count := 0;
>>>
>>> while (not gen.generalization->isEmpty()) {
>>> gen := gen.generalization->any(true).general;
>>> count = count + 1;
>>> }; return count;
>>> }
>>>
>>> Regards,
>>> Sergey
>>>
>>>
>>> Mahdi D-Manesh wrote:
>>>> Hello again,
>>>>
>>>> I want to count how "deep" the inheritance for a given class is and
>>>> sum up all steps for all classes of a given set to finally compute
>>>> an average.
>>>>
>>>> I have issues with the qvto syntax and after trying for a long time,
>>>> I have no idea what else to try.
>>>>
>>>> Here is a snippet:
>>>>
>>>> /*
>>>> Recursively computes the amount of steps from the leaf classes
>>>> to their roots and sums them up.
>>>> */
>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>> Integer {
>>>> return leafClasses->computeSteps()->sum();
>>>> }
>>>>
>>>> /*
>>>> Computes the needed steps from leaf to root for a single class.
>>>> */
>>>> query UmlClass::computeSteps() : Integer {
>>>> -- How to select the first element from the bag or set?
>>>> var g := self.umlGeneral->any(true);
>>>> -- if else not supported?
>>>> if (g == null) {
>>>> }
>>>> return res;
>>>> }
>>>>
>>>> In computeSteps(), my idea is to go back the umlGeneral reference
>>>> and jump from class to class until this is null, counting the
>>>> inheritance path length.
>>>>
>>>> The issue is first, that self.umlgeneral is a set / baf and I want
>>>> to access only its first element (language only knows single
>>>> inheritance). I saw some method like first() but this seems not to
>>>> exist?
>>>>
>>>> After this, I need some sort of if, else construct, which is there
>>>> according to the QVT specs but it looks like it is not yet in QVTO?
>>>>
>>>> Any help to express this in QVTO is welcome! Maybe I am just trying
>>>> to do it the "wrong way"?
>>>>
>>>> Best Regards,
>>>> Mahdi D-Manesh
|
|
|
Re: [QVTO] first() and If Expression [message #92022 is a reply to message #91992] |
Fri, 10 October 2008 11:10 |
Eclipse User |
|
|
|
Originally posted by: Alexander.Igdalov.borland.com
Hi Mahdi,
In addition to Sergey's comment, I would also recommend you to take a
look at our LPG files in the org.eclipse.m2m.qvt.oml.cst.parser to have
the most up-to-date notion of what is already implemented.
QVTO tests and samples are also a good source of code snippets.
Cheers,
Alex.
Mahdi D-Manesh wrote:
> Hello Sergey,
>
> yes you're right, actually the specs are correct, just the example isn't
> wow... I was so close to looking at the EBNF but I usually avoid it when
> possible. In this case it would have been good though, I agree! :)
>
> Well missing the elif part is not such a big deal.
>
> Best Regards,
> Mahdi
>
> Sergey Boyko schrieb:
>> Hi Mahdi
>>
>> Not at all. I like qvto to be used in the field ;)
>>
>> About spec conformance. It's our goal :)
>> Section "8.4.7 EBNF" defines the following
>> <if_exp> ::= 'if' <expression> <then_part>
>> <elif_part>* <else_part>? 'endif'
>> <then_part> ::= 'then' <if_body>
>> <elif_part> ::= 'elif' <if_body>
>> <else_part> ::= 'else' <if_body>
>> <if_body> ::= <expression> | <expression_block>
>>
>> We only missed 'elif' part at present.
>>
>> Snippets from the spec like
>> var x:= if (self.name.startsWith("_") "PROTECTED"
>> elif (self.type.isPrimitive() "NORMAL"
>> else "UNEXPECTED"
>> simply don't match grammar defined in the same doc :)
>>
>> The only addition doc about our implementation I can point is from our
>> Eclipse corner:
>> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>>
>>
>> Regards,
>> Sergey.
>>
>>
>> Mahdi D-Manesh wrote:
>>> Hello Sergey,
>>>
>>> thanks a lot for the examples!
>>> In the meantime I found the while statement and my Benchmark
>>> transformation runs.
>>>
>>> For the ->first() of course it makes sense for ordered collections
>>> only, my bad. I tried it and it works. :)
>>>
>>> Same for the if Statement - I just tried the ways from QVT
>>> 07-07-07.pdf specs but they did not look correct there. Yours run
>>> like expected.
>>> Is there some (free) Document, which lists such syntax more up to
>>> date and according to the QVTO plugin implementation?
>>>
>>> Thanks for the computeSteps() example! My version looks very similar,
>>> just that I didnt know how to initialize the var with a type like this.
>>>
>>> Once again, thanks alot for your time!
>>> Mahdi
>>>
>>>
>>> Sergey Boyko schrieb:
>>>> Hi Mahdi,
>>>>
>>>> According to spec 'first()' is defined for ordered collections only
>>>> (Sequence and OrderedSet). For the other collection types
>>>> 'any(true)' is appropriate way to obtain some element. Or you can
>>>> cast collection to sequence like 'coll->asSequence()->first()'.
>>>>
>>>> Qvto supports 'if' construction with the following syntax
>>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>>
>>>> Use like:
>>>> if true then {} endif;
>>>> if true then OclVoid endif;
>>>> if true then {} else {} endif;
>>>> if true then {} else OclVoid endif;
>>>>
>>>>
>>>> Btw, for counting generals for uml-like class it's possible to use
>>>> 'while()' expression (supposing single inheritance):
>>>>
>>>> query uml::Class::computeSteps() : Integer {
>>>> var gen : uml::Classifier := self;
>>>> var count := 0;
>>>>
>>>> while (not gen.generalization->isEmpty()) {
>>>> gen := gen.generalization->any(true).general;
>>>> count = count + 1;
>>>> }; return count;
>>>> }
>>>>
>>>> Regards,
>>>> Sergey
>>>>
>>>>
>>>> Mahdi D-Manesh wrote:
>>>>> Hello again,
>>>>>
>>>>> I want to count how "deep" the inheritance for a given class is and
>>>>> sum up all steps for all classes of a given set to finally compute
>>>>> an average.
>>>>>
>>>>> I have issues with the qvto syntax and after trying for a long
>>>>> time, I have no idea what else to try.
>>>>>
>>>>> Here is a snippet:
>>>>>
>>>>> /*
>>>>> Recursively computes the amount of steps from the leaf classes
>>>>> to their roots and sums them up.
>>>>> */
>>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>>> Integer {
>>>>> return leafClasses->computeSteps()->sum();
>>>>> }
>>>>>
>>>>> /*
>>>>> Computes the needed steps from leaf to root for a single class.
>>>>> */
>>>>> query UmlClass::computeSteps() : Integer {
>>>>> -- How to select the first element from the bag or set?
>>>>> var g := self.umlGeneral->any(true);
>>>>> -- if else not supported?
>>>>> if (g == null) {
>>>>> }
>>>>> return res;
>>>>> }
>>>>>
>>>>> In computeSteps(), my idea is to go back the umlGeneral reference
>>>>> and jump from class to class until this is null, counting the
>>>>> inheritance path length.
>>>>>
>>>>> The issue is first, that self.umlgeneral is a set / baf and I want
>>>>> to access only its first element (language only knows single
>>>>> inheritance). I saw some method like first() but this seems not to
>>>>> exist?
>>>>>
>>>>> After this, I need some sort of if, else construct, which is there
>>>>> according to the QVT specs but it looks like it is not yet in QVTO?
>>>>>
>>>>> Any help to express this in QVTO is welcome! Maybe I am just trying
>>>>> to do it the "wrong way"?
>>>>>
>>>>> Best Regards,
>>>>> Mahdi D-Manesh
|
|
|
Re: [QVTO] first() and If Expression [message #92037 is a reply to message #92022] |
Fri, 10 October 2008 14:38 |
Eclipse User |
|
|
|
Originally posted by: mahdider.students.uni-mainz.de
Hello,
okay this is a good idea! I should get the files.
Actually I am learning QVT because I will need it for the practical part
of my Bachelor Thesis during the next months. :)
BTW:
Is there any restriction on WHERE if-statements are allowed?
I noticed that they work inside the begin or end section,
but not inbetween or even in an explicit population section.
What would be the reason for this?
Best Regards,
Mahdi
Alexander Igdalov schrieb:
> Hi Mahdi,
>
> In addition to Sergey's comment, I would also recommend you to take a
> look at our LPG files in the org.eclipse.m2m.qvt.oml.cst.parser to have
> the most up-to-date notion of what is already implemented.
> QVTO tests and samples are also a good source of code snippets.
>
> Cheers,
> Alex.
>
>
> Mahdi D-Manesh wrote:
>> Hello Sergey,
>>
>> yes you're right, actually the specs are correct, just the example
>> isn't wow... I was so close to looking at the EBNF but I usually avoid
>> it when possible. In this case it would have been good though, I
>> agree! :)
>>
>> Well missing the elif part is not such a big deal.
>>
>> Best Regards,
>> Mahdi
>>
>> Sergey Boyko schrieb:
>>> Hi Mahdi
>>>
>>> Not at all. I like qvto to be used in the field ;)
>>>
>>> About spec conformance. It's our goal :)
>>> Section "8.4.7 EBNF" defines the following
>>> <if_exp> ::= 'if' <expression> <then_part>
>>> <elif_part>* <else_part>? 'endif'
>>> <then_part> ::= 'then' <if_body>
>>> <elif_part> ::= 'elif' <if_body>
>>> <else_part> ::= 'else' <if_body>
>>> <if_body> ::= <expression> | <expression_block>
>>>
>>> We only missed 'elif' part at present.
>>>
>>> Snippets from the spec like
>>> var x:= if (self.name.startsWith("_") "PROTECTED"
>>> elif (self.type.isPrimitive() "NORMAL"
>>> else "UNEXPECTED"
>>> simply don't match grammar defined in the same doc :)
>>>
>>> The only addition doc about our implementation I can point is from
>>> our Eclipse corner:
>>> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>>>
>>>
>>> Regards,
>>> Sergey.
>>>
>>>
>>> Mahdi D-Manesh wrote:
>>>> Hello Sergey,
>>>>
>>>> thanks a lot for the examples!
>>>> In the meantime I found the while statement and my Benchmark
>>>> transformation runs.
>>>>
>>>> For the ->first() of course it makes sense for ordered collections
>>>> only, my bad. I tried it and it works. :)
>>>>
>>>> Same for the if Statement - I just tried the ways from QVT
>>>> 07-07-07.pdf specs but they did not look correct there. Yours run
>>>> like expected.
>>>> Is there some (free) Document, which lists such syntax more up to
>>>> date and according to the QVTO plugin implementation?
>>>>
>>>> Thanks for the computeSteps() example! My version looks very similar,
>>>> just that I didnt know how to initialize the var with a type like this.
>>>>
>>>> Once again, thanks alot for your time!
>>>> Mahdi
>>>>
>>>>
>>>> Sergey Boyko schrieb:
>>>>> Hi Mahdi,
>>>>>
>>>>> According to spec 'first()' is defined for ordered collections only
>>>>> (Sequence and OrderedSet). For the other collection types
>>>>> 'any(true)' is appropriate way to obtain some element. Or you can
>>>>> cast collection to sequence like 'coll->asSequence()->first()'.
>>>>>
>>>>> Qvto supports 'if' construction with the following syntax
>>>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>>>
>>>>> Use like:
>>>>> if true then {} endif;
>>>>> if true then OclVoid endif;
>>>>> if true then {} else {} endif;
>>>>> if true then {} else OclVoid endif;
>>>>>
>>>>>
>>>>> Btw, for counting generals for uml-like class it's possible to use
>>>>> 'while()' expression (supposing single inheritance):
>>>>>
>>>>> query uml::Class::computeSteps() : Integer {
>>>>> var gen : uml::Classifier := self;
>>>>> var count := 0;
>>>>>
>>>>> while (not gen.generalization->isEmpty()) {
>>>>> gen := gen.generalization->any(true).general;
>>>>> count = count + 1;
>>>>> }; return count;
>>>>> }
>>>>>
>>>>> Regards,
>>>>> Sergey
>>>>>
>>>>>
>>>>> Mahdi D-Manesh wrote:
>>>>>> Hello again,
>>>>>>
>>>>>> I want to count how "deep" the inheritance for a given class is
>>>>>> and sum up all steps for all classes of a given set to finally
>>>>>> compute an average.
>>>>>>
>>>>>> I have issues with the qvto syntax and after trying for a long
>>>>>> time, I have no idea what else to try.
>>>>>>
>>>>>> Here is a snippet:
>>>>>>
>>>>>> /*
>>>>>> Recursively computes the amount of steps from the leaf classes
>>>>>> to their roots and sums them up.
>>>>>> */
>>>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>>>> Integer {
>>>>>> return leafClasses->computeSteps()->sum();
>>>>>> }
>>>>>>
>>>>>> /*
>>>>>> Computes the needed steps from leaf to root for a single class.
>>>>>> */
>>>>>> query UmlClass::computeSteps() : Integer {
>>>>>> -- How to select the first element from the bag or set?
>>>>>> var g := self.umlGeneral->any(true);
>>>>>> -- if else not supported?
>>>>>> if (g == null) {
>>>>>> }
>>>>>> return res;
>>>>>> }
>>>>>>
>>>>>> In computeSteps(), my idea is to go back the umlGeneral reference
>>>>>> and jump from class to class until this is null, counting the
>>>>>> inheritance path length.
>>>>>>
>>>>>> The issue is first, that self.umlgeneral is a set / baf and I want
>>>>>> to access only its first element (language only knows single
>>>>>> inheritance). I saw some method like first() but this seems not to
>>>>>> exist?
>>>>>>
>>>>>> After this, I need some sort of if, else construct, which is there
>>>>>> according to the QVT specs but it looks like it is not yet in QVTO?
>>>>>>
>>>>>> Any help to express this in QVTO is welcome! Maybe I am just
>>>>>> trying to do it the "wrong way"?
>>>>>>
>>>>>> Best Regards,
>>>>>> Mahdi D-Manesh
|
|
|
Re: [QVTO] first() and If Expression [message #92106 is a reply to message #92022] |
Sun, 12 October 2008 16:59 |
Alfons Laarman Messages: 71 Registered: July 2009 |
Member |
|
|
Hi Alex,
I was following your advice and took a look at the files. I could only find
the generated LPG java files. Where can we find the source lpg files?
Isn;t some kind of changelist from previous builds?
Cheers,
Alfons
"Alexander Igdalov" <Alexander.Igdalov@borland.com> schreef in bericht
news:gcnd7t$kgn$1@build.eclipse.org...
> Hi Mahdi,
>
> In addition to Sergey's comment, I would also recommend you to take a look
> at our LPG files in the org.eclipse.m2m.qvt.oml.cst.parser to have the
> most up-to-date notion of what is already implemented.
> QVTO tests and samples are also a good source of code snippets.
>
> Cheers,
> Alex.
>
>
> Mahdi D-Manesh wrote:
>> Hello Sergey,
>>
>> yes you're right, actually the specs are correct, just the example isn't
>> wow... I was so close to looking at the EBNF but I usually avoid it when
>> possible. In this case it would have been good though, I agree! :)
>>
>> Well missing the elif part is not such a big deal.
>>
>> Best Regards,
>> Mahdi
>>
>> Sergey Boyko schrieb:
>>> Hi Mahdi
>>>
>>> Not at all. I like qvto to be used in the field ;)
>>>
>>> About spec conformance. It's our goal :)
>>> Section "8.4.7 EBNF" defines the following
>>> <if_exp> ::= 'if' <expression> <then_part>
>>> <elif_part>* <else_part>? 'endif'
>>> <then_part> ::= 'then' <if_body>
>>> <elif_part> ::= 'elif' <if_body>
>>> <else_part> ::= 'else' <if_body>
>>> <if_body> ::= <expression> | <expression_block>
>>>
>>> We only missed 'elif' part at present.
>>>
>>> Snippets from the spec like
>>> var x:= if (self.name.startsWith("_") "PROTECTED"
>>> elif (self.type.isPrimitive() "NORMAL"
>>> else "UNEXPECTED"
>>> simply don't match grammar defined in the same doc :)
>>>
>>> The only addition doc about our implementation I can point is from our
>>> Eclipse corner:
>>> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>>>
>>>
>>> Regards,
>>> Sergey.
>>>
>>>
>>> Mahdi D-Manesh wrote:
>>>> Hello Sergey,
>>>>
>>>> thanks a lot for the examples!
>>>> In the meantime I found the while statement and my Benchmark
>>>> transformation runs.
>>>>
>>>> For the ->first() of course it makes sense for ordered collections
>>>> only, my bad. I tried it and it works. :)
>>>>
>>>> Same for the if Statement - I just tried the ways from QVT 07-07-07.pdf
>>>> specs but they did not look correct there. Yours run like expected.
>>>> Is there some (free) Document, which lists such syntax more up to date
>>>> and according to the QVTO plugin implementation?
>>>>
>>>> Thanks for the computeSteps() example! My version looks very similar,
>>>> just that I didnt know how to initialize the var with a type like this.
>>>>
>>>> Once again, thanks alot for your time!
>>>> Mahdi
>>>>
>>>>
>>>> Sergey Boyko schrieb:
>>>>> Hi Mahdi,
>>>>>
>>>>> According to spec 'first()' is defined for ordered collections only
>>>>> (Sequence and OrderedSet). For the other collection types 'any(true)'
>>>>> is appropriate way to obtain some element. Or you can cast collection
>>>>> to sequence like 'coll->asSequence()->first()'.
>>>>>
>>>>> Qvto supports 'if' construction with the following syntax
>>>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>>>
>>>>> Use like:
>>>>> if true then {} endif;
>>>>> if true then OclVoid endif;
>>>>> if true then {} else {} endif;
>>>>> if true then {} else OclVoid endif;
>>>>>
>>>>>
>>>>> Btw, for counting generals for uml-like class it's possible to use
>>>>> 'while()' expression (supposing single inheritance):
>>>>>
>>>>> query uml::Class::computeSteps() : Integer {
>>>>> var gen : uml::Classifier := self;
>>>>> var count := 0;
>>>>>
>>>>> while (not gen.generalization->isEmpty()) {
>>>>> gen := gen.generalization->any(true).general;
>>>>> count = count + 1;
>>>>> }; return count;
>>>>> }
>>>>>
>>>>> Regards,
>>>>> Sergey
>>>>>
>>>>>
>>>>> Mahdi D-Manesh wrote:
>>>>>> Hello again,
>>>>>>
>>>>>> I want to count how "deep" the inheritance for a given class is and
>>>>>> sum up all steps for all classes of a given set to finally compute an
>>>>>> average.
>>>>>>
>>>>>> I have issues with the qvto syntax and after trying for a long time,
>>>>>> I have no idea what else to try.
>>>>>>
>>>>>> Here is a snippet:
>>>>>>
>>>>>> /*
>>>>>> Recursively computes the amount of steps from the leaf classes to
>>>>>> their roots and sums them up.
>>>>>> */
>>>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>>>> Integer {
>>>>>> return leafClasses->computeSteps()->sum();
>>>>>> }
>>>>>>
>>>>>> /*
>>>>>> Computes the needed steps from leaf to root for a single class.
>>>>>> */
>>>>>> query UmlClass::computeSteps() : Integer {
>>>>>> -- How to select the first element from the bag or set?
>>>>>> var g := self.umlGeneral->any(true);
>>>>>> -- if else not supported?
>>>>>> if (g == null) {
>>>>>> }
>>>>>> return res;
>>>>>> }
>>>>>>
>>>>>> In computeSteps(), my idea is to go back the umlGeneral reference and
>>>>>> jump from class to class until this is null, counting the inheritance
>>>>>> path length.
>>>>>>
>>>>>> The issue is first, that self.umlgeneral is a set / baf and I want to
>>>>>> access only its first element (language only knows single
>>>>>> inheritance). I saw some method like first() but this seems not to
>>>>>> exist?
>>>>>>
>>>>>> After this, I need some sort of if, else construct, which is there
>>>>>> according to the QVT specs but it looks like it is not yet in QVTO?
>>>>>>
>>>>>> Any help to express this in QVTO is welcome! Maybe I am just trying
>>>>>> to do it the "wrong way"?
>>>>>>
>>>>>> Best Regards,
>>>>>> Mahdi D-Manesh
|
|
|
Re: [QVTO] first() and If Expression [message #92249 is a reply to message #92037] |
Mon, 13 October 2008 10:05 |
Radomil Dvorak Messages: 249 Registered: July 2009 |
Senior Member |
|
|
Hi Mahdi,
Thanks for pointing this out!
Right, the spec does not say explicitly that the constructor body of
implicit ObjectExp
is restricted to contain only assignment expressions, though the notation
examples in the spec
might give such impression.
It's a limitation of our implementation at the moment, which should
disappear soon as we are
currently working on the grammar alignment with the OMG spec.
As for the explicit population section, I think it's questionable if it
should contain other
expressions than object expressions. If yes, the 'population' keyword gets
redundant.
Regards,
/Radek
On Fri, 10 Oct 2008 16:38:31 +0200, Mahdi D-Manesh
<mahdider@students.uni-mainz.de> wrote:
> Hello,
>
> okay this is a good idea! I should get the files.
> Actually I am learning QVT because I will need it for the practical part
> of my Bachelor Thesis during the next months. :)
>
> BTW:
> Is there any restriction on WHERE if-statements are allowed?
> I noticed that they work inside the begin or end section,
> but not inbetween or even in an explicit population section.
>
> What would be the reason for this?
>
> Best Regards,
> Mahdi
>
>
> Alexander Igdalov schrieb:
>> Hi Mahdi,
>> In addition to Sergey's comment, I would also recommend you to take a
>> look at our LPG files in the org.eclipse.m2m.qvt.oml.cst.parser to have
>> the most up-to-date notion of what is already implemented.
>> QVTO tests and samples are also a good source of code snippets.
>> Cheers,
>> Alex.
>> Mahdi D-Manesh wrote:
>>> Hello Sergey,
>>>
>>> yes you're right, actually the specs are correct, just the example
>>> isn't wow... I was so close to looking at the EBNF but I usually avoid
>>> it when possible. In this case it would have been good though, I
>>> agree! :)
>>>
>>> Well missing the elif part is not such a big deal.
>>>
>>> Best Regards,
>>> Mahdi
>>>
>>> Sergey Boyko schrieb:
>>>> Hi Mahdi
>>>>
>>>> Not at all. I like qvto to be used in the field ;)
>>>>
>>>> About spec conformance. It's our goal :)
>>>> Section "8.4.7 EBNF" defines the following
>>>> <if_exp> ::= 'if' <expression> <then_part>
>>>> <elif_part>* <else_part>? 'endif'
>>>> <then_part> ::= 'then' <if_body>
>>>> <elif_part> ::= 'elif' <if_body>
>>>> <else_part> ::= 'else' <if_body>
>>>> <if_body> ::= <expression> | <expression_block>
>>>>
>>>> We only missed 'elif' part at present.
>>>>
>>>> Snippets from the spec like
>>>> var x:= if (self.name.startsWith("_") "PROTECTED"
>>>> elif (self.type.isPrimitive() "NORMAL"
>>>> else "UNEXPECTED"
>>>> simply don't match grammar defined in the same doc :)
>>>>
>>>> The only addition doc about our implementation I can point is from
>>>> our Eclipse corner:
>>>> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>>>>
>>>>
>>>> Regards,
>>>> Sergey.
>>>>
>>>>
>>>> Mahdi D-Manesh wrote:
>>>>> Hello Sergey,
>>>>>
>>>>> thanks a lot for the examples!
>>>>> In the meantime I found the while statement and my Benchmark
>>>>> transformation runs.
>>>>>
>>>>> For the ->first() of course it makes sense for ordered collections
>>>>> only, my bad. I tried it and it works. :)
>>>>>
>>>>> Same for the if Statement - I just tried the ways from QVT
>>>>> 07-07-07.pdf specs but they did not look correct there. Yours run
>>>>> like expected.
>>>>> Is there some (free) Document, which lists such syntax more up to
>>>>> date and according to the QVTO plugin implementation?
>>>>>
>>>>> Thanks for the computeSteps() example! My version looks very similar,
>>>>> just that I didnt know how to initialize the var with a type like
>>>>> this.
>>>>>
>>>>> Once again, thanks alot for your time!
>>>>> Mahdi
>>>>>
>>>>>
>>>>> Sergey Boyko schrieb:
>>>>>> Hi Mahdi,
>>>>>>
>>>>>> According to spec 'first()' is defined for ordered collections only
>>>>>> (Sequence and OrderedSet). For the other collection types
>>>>>> 'any(true)' is appropriate way to obtain some element. Or you can
>>>>>> cast collection to sequence like 'coll->asSequence()->first()'.
>>>>>>
>>>>>> Qvto supports 'if' construction with the following syntax
>>>>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>>>>
>>>>>> Use like:
>>>>>> if true then {} endif;
>>>>>> if true then OclVoid endif;
>>>>>> if true then {} else {} endif;
>>>>>> if true then {} else OclVoid endif;
>>>>>>
>>>>>>
>>>>>> Btw, for counting generals for uml-like class it's possible to use
>>>>>> 'while()' expression (supposing single inheritance):
>>>>>>
>>>>>> query uml::Class::computeSteps() : Integer {
>>>>>> var gen : uml::Classifier := self;
>>>>>> var count := 0;
>>>>>>
>>>>>> while (not gen.generalization->isEmpty()) {
>>>>>> gen := gen.generalization->any(true).general;
>>>>>> count = count + 1;
>>>>>> }; return count;
>>>>>> }
>>>>>>
>>>>>> Regards,
>>>>>> Sergey
>>>>>>
>>>>>>
>>>>>> Mahdi D-Manesh wrote:
>>>>>>> Hello again,
>>>>>>>
>>>>>>> I want to count how "deep" the inheritance for a given class is
>>>>>>> and sum up all steps for all classes of a given set to finally
>>>>>>> compute an average.
>>>>>>>
>>>>>>> I have issues with the qvto syntax and after trying for a long
>>>>>>> time, I have no idea what else to try.
>>>>>>>
>>>>>>> Here is a snippet:
>>>>>>>
>>>>>>> /*
>>>>>>> Recursively computes the amount of steps from the leaf classes
>>>>>>> to their roots and sums them up.
>>>>>>> */
>>>>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>>>>> Integer {
>>>>>>> return leafClasses->computeSteps()->sum();
>>>>>>> }
>>>>>>>
>>>>>>> /*
>>>>>>> Computes the needed steps from leaf to root for a single class.
>>>>>>> */
>>>>>>> query UmlClass::computeSteps() : Integer {
>>>>>>> -- How to select the first element from the bag or set?
>>>>>>> var g := self.umlGeneral->any(true);
>>>>>>> -- if else not supported?
>>>>>>> if (g == null) {
>>>>>>> }
>>>>>>> return res;
>>>>>>> }
>>>>>>>
>>>>>>> In computeSteps(), my idea is to go back the umlGeneral reference
>>>>>>> and jump from class to class until this is null, counting the
>>>>>>> inheritance path length.
>>>>>>>
>>>>>>> The issue is first, that self.umlgeneral is a set / baf and I want
>>>>>>> to access only its first element (language only knows single
>>>>>>> inheritance). I saw some method like first() but this seems not to
>>>>>>> exist?
>>>>>>>
>>>>>>> After this, I need some sort of if, else construct, which is there
>>>>>>> according to the QVT specs but it looks like it is not yet in QVTO?
>>>>>>>
>>>>>>> Any help to express this in QVTO is welcome! Maybe I am just
>>>>>>> trying to do it the "wrong way"?
>>>>>>>
>>>>>>> Best Regards,
>>>>>>> Mahdi D-Manesh
|
|
|
Re: [QVTO] first() and If Expression [message #92376 is a reply to message #92106] |
Mon, 13 October 2008 13:42 |
Eclipse User |
|
|
|
Originally posted by: Alexander.Igdalov.borland.com
Hi Alfons,
Currently they are not included into the build, however, you can get
them from CVS. Meanwhile, the idea of adding them to the build seems good.
HTH,
Alex.
Alfons Laarman wrote:
> Hi Alex,
>
> I was following your advice and took a look at the files. I could only find
> the generated LPG java files. Where can we find the source lpg files?
> Isn;t some kind of changelist from previous builds?
>
> Cheers,
>
> Alfons
>
> "Alexander Igdalov" <Alexander.Igdalov@borland.com> schreef in bericht
> news:gcnd7t$kgn$1@build.eclipse.org...
>> Hi Mahdi,
>>
>> In addition to Sergey's comment, I would also recommend you to take a look
>> at our LPG files in the org.eclipse.m2m.qvt.oml.cst.parser to have the
>> most up-to-date notion of what is already implemented.
>> QVTO tests and samples are also a good source of code snippets.
>>
>> Cheers,
>> Alex.
>>
>>
>> Mahdi D-Manesh wrote:
>>> Hello Sergey,
>>>
>>> yes you're right, actually the specs are correct, just the example isn't
>>> wow... I was so close to looking at the EBNF but I usually avoid it when
>>> possible. In this case it would have been good though, I agree! :)
>>>
>>> Well missing the elif part is not such a big deal.
>>>
>>> Best Regards,
>>> Mahdi
>>>
>>> Sergey Boyko schrieb:
>>>> Hi Mahdi
>>>>
>>>> Not at all. I like qvto to be used in the field ;)
>>>>
>>>> About spec conformance. It's our goal :)
>>>> Section "8.4.7 EBNF" defines the following
>>>> <if_exp> ::= 'if' <expression> <then_part>
>>>> <elif_part>* <else_part>? 'endif'
>>>> <then_part> ::= 'then' <if_body>
>>>> <elif_part> ::= 'elif' <if_body>
>>>> <else_part> ::= 'else' <if_body>
>>>> <if_body> ::= <expression> | <expression_block>
>>>>
>>>> We only missed 'elif' part at present.
>>>>
>>>> Snippets from the spec like
>>>> var x:= if (self.name.startsWith("_") "PROTECTED"
>>>> elif (self.type.isPrimitive() "NORMAL"
>>>> else "UNEXPECTED"
>>>> simply don't match grammar defined in the same doc :)
>>>>
>>>> The only addition doc about our implementation I can point is from our
>>>> Eclipse corner:
>>>> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>>>>
>>>>
>>>> Regards,
>>>> Sergey.
>>>>
>>>>
>>>> Mahdi D-Manesh wrote:
>>>>> Hello Sergey,
>>>>>
>>>>> thanks a lot for the examples!
>>>>> In the meantime I found the while statement and my Benchmark
>>>>> transformation runs.
>>>>>
>>>>> For the ->first() of course it makes sense for ordered collections
>>>>> only, my bad. I tried it and it works. :)
>>>>>
>>>>> Same for the if Statement - I just tried the ways from QVT 07-07-07.pdf
>>>>> specs but they did not look correct there. Yours run like expected.
>>>>> Is there some (free) Document, which lists such syntax more up to date
>>>>> and according to the QVTO plugin implementation?
>>>>>
>>>>> Thanks for the computeSteps() example! My version looks very similar,
>>>>> just that I didnt know how to initialize the var with a type like this.
>>>>>
>>>>> Once again, thanks alot for your time!
>>>>> Mahdi
>>>>>
>>>>>
>>>>> Sergey Boyko schrieb:
>>>>>> Hi Mahdi,
>>>>>>
>>>>>> According to spec 'first()' is defined for ordered collections only
>>>>>> (Sequence and OrderedSet). For the other collection types 'any(true)'
>>>>>> is appropriate way to obtain some element. Or you can cast collection
>>>>>> to sequence like 'coll->asSequence()->first()'.
>>>>>>
>>>>>> Qvto supports 'if' construction with the following syntax
>>>>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>>>>
>>>>>> Use like:
>>>>>> if true then {} endif;
>>>>>> if true then OclVoid endif;
>>>>>> if true then {} else {} endif;
>>>>>> if true then {} else OclVoid endif;
>>>>>>
>>>>>>
>>>>>> Btw, for counting generals for uml-like class it's possible to use
>>>>>> 'while()' expression (supposing single inheritance):
>>>>>>
>>>>>> query uml::Class::computeSteps() : Integer {
>>>>>> var gen : uml::Classifier := self;
>>>>>> var count := 0;
>>>>>>
>>>>>> while (not gen.generalization->isEmpty()) {
>>>>>> gen := gen.generalization->any(true).general;
>>>>>> count = count + 1;
>>>>>> }; return count;
>>>>>> }
>>>>>>
>>>>>> Regards,
>>>>>> Sergey
>>>>>>
>>>>>>
>>>>>> Mahdi D-Manesh wrote:
>>>>>>> Hello again,
>>>>>>>
>>>>>>> I want to count how "deep" the inheritance for a given class is and
>>>>>>> sum up all steps for all classes of a given set to finally compute an
>>>>>>> average.
>>>>>>>
>>>>>>> I have issues with the qvto syntax and after trying for a long time,
>>>>>>> I have no idea what else to try.
>>>>>>>
>>>>>>> Here is a snippet:
>>>>>>>
>>>>>>> /*
>>>>>>> Recursively computes the amount of steps from the leaf classes to
>>>>>>> their roots and sums them up.
>>>>>>> */
>>>>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>>>>> Integer {
>>>>>>> return leafClasses->computeSteps()->sum();
>>>>>>> }
>>>>>>>
>>>>>>> /*
>>>>>>> Computes the needed steps from leaf to root for a single class.
>>>>>>> */
>>>>>>> query UmlClass::computeSteps() : Integer {
>>>>>>> -- How to select the first element from the bag or set?
>>>>>>> var g := self.umlGeneral->any(true);
>>>>>>> -- if else not supported?
>>>>>>> if (g == null) {
>>>>>>> }
>>>>>>> return res;
>>>>>>> }
>>>>>>>
>>>>>>> In computeSteps(), my idea is to go back the umlGeneral reference and
>>>>>>> jump from class to class until this is null, counting the inheritance
>>>>>>> path length.
>>>>>>>
>>>>>>> The issue is first, that self.umlgeneral is a set / baf and I want to
>>>>>>> access only its first element (language only knows single
>>>>>>> inheritance). I saw some method like first() but this seems not to
>>>>>>> exist?
>>>>>>>
>>>>>>> After this, I need some sort of if, else construct, which is there
>>>>>>> according to the QVT specs but it looks like it is not yet in QVTO?
>>>>>>>
>>>>>>> Any help to express this in QVTO is welcome! Maybe I am just trying
>>>>>>> to do it the "wrong way"?
>>>>>>>
>>>>>>> Best Regards,
>>>>>>> Mahdi D-Manesh
>
>
|
|
|
Re: [QVTO] first() and If Expression [message #92391 is a reply to message #92376] |
Mon, 13 October 2008 14:59 |
Alfons Laarman Messages: 71 Registered: July 2009 |
Member |
|
|
I helps, a bit, whats left for me is to find them in this vast space called
CVS...
Do you have a hint?
Thanks,
Alfons
"Alexander Igdalov" <Alexander.Igdalov@borland.com> schreef in bericht
news:gcvj93$9oe$1@build.eclipse.org...
> Hi Alfons,
>
> Currently they are not included into the build, however, you can get them
> from CVS. Meanwhile, the idea of adding them to the build seems good.
>
> HTH,
> Alex.
>
> Alfons Laarman wrote:
>> Hi Alex,
>>
>> I was following your advice and took a look at the files. I could only
>> find the generated LPG java files. Where can we find the source lpg
>> files?
>> Isn;t some kind of changelist from previous builds?
>>
>> Cheers,
>>
>> Alfons
>>
>> "Alexander Igdalov" <Alexander.Igdalov@borland.com> schreef in bericht
>> news:gcnd7t$kgn$1@build.eclipse.org...
>>> Hi Mahdi,
>>>
>>> In addition to Sergey's comment, I would also recommend you to take a
>>> look at our LPG files in the org.eclipse.m2m.qvt.oml.cst.parser to have
>>> the most up-to-date notion of what is already implemented.
>>> QVTO tests and samples are also a good source of code snippets.
>>>
>>> Cheers,
>>> Alex.
>>>
>>>
>>> Mahdi D-Manesh wrote:
>>>> Hello Sergey,
>>>>
>>>> yes you're right, actually the specs are correct, just the example
>>>> isn't wow... I was so close to looking at the EBNF but I usually avoid
>>>> it when possible. In this case it would have been good though, I agree!
>>>> :)
>>>>
>>>> Well missing the elif part is not such a big deal.
>>>>
>>>> Best Regards,
>>>> Mahdi
>>>>
>>>> Sergey Boyko schrieb:
>>>>> Hi Mahdi
>>>>>
>>>>> Not at all. I like qvto to be used in the field ;)
>>>>>
>>>>> About spec conformance. It's our goal :)
>>>>> Section "8.4.7 EBNF" defines the following
>>>>> <if_exp> ::= 'if' <expression> <then_part>
>>>>> <elif_part>* <else_part>? 'endif'
>>>>> <then_part> ::= 'then' <if_body>
>>>>> <elif_part> ::= 'elif' <if_body>
>>>>> <else_part> ::= 'else' <if_body>
>>>>> <if_body> ::= <expression> | <expression_block>
>>>>>
>>>>> We only missed 'elif' part at present.
>>>>>
>>>>> Snippets from the spec like
>>>>> var x:= if (self.name.startsWith("_") "PROTECTED"
>>>>> elif (self.type.isPrimitive() "NORMAL"
>>>>> else "UNEXPECTED"
>>>>> simply don't match grammar defined in the same doc :)
>>>>>
>>>>> The only addition doc about our implementation I can point is from our
>>>>> Eclipse corner:
>>>>> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>>>>>
>>>>>
>>>>> Regards,
>>>>> Sergey.
>>>>>
>>>>>
>>>>> Mahdi D-Manesh wrote:
>>>>>> Hello Sergey,
>>>>>>
>>>>>> thanks a lot for the examples!
>>>>>> In the meantime I found the while statement and my Benchmark
>>>>>> transformation runs.
>>>>>>
>>>>>> For the ->first() of course it makes sense for ordered collections
>>>>>> only, my bad. I tried it and it works. :)
>>>>>>
>>>>>> Same for the if Statement - I just tried the ways from QVT
>>>>>> 07-07-07.pdf specs but they did not look correct there. Yours run
>>>>>> like expected.
>>>>>> Is there some (free) Document, which lists such syntax more up to
>>>>>> date and according to the QVTO plugin implementation?
>>>>>>
>>>>>> Thanks for the computeSteps() example! My version looks very similar,
>>>>>> just that I didnt know how to initialize the var with a type like
>>>>>> this.
>>>>>>
>>>>>> Once again, thanks alot for your time!
>>>>>> Mahdi
>>>>>>
>>>>>>
>>>>>> Sergey Boyko schrieb:
>>>>>>> Hi Mahdi,
>>>>>>>
>>>>>>> According to spec 'first()' is defined for ordered collections only
>>>>>>> (Sequence and OrderedSet). For the other collection types
>>>>>>> 'any(true)' is appropriate way to obtain some element. Or you can
>>>>>>> cast collection to sequence like 'coll->asSequence()->first()'.
>>>>>>>
>>>>>>> Qvto supports 'if' construction with the following syntax
>>>>>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>>>>>
>>>>>>> Use like:
>>>>>>> if true then {} endif;
>>>>>>> if true then OclVoid endif;
>>>>>>> if true then {} else {} endif;
>>>>>>> if true then {} else OclVoid endif;
>>>>>>>
>>>>>>>
>>>>>>> Btw, for counting generals for uml-like class it's possible to use
>>>>>>> 'while()' expression (supposing single inheritance):
>>>>>>>
>>>>>>> query uml::Class::computeSteps() : Integer {
>>>>>>> var gen : uml::Classifier := self;
>>>>>>> var count := 0;
>>>>>>>
>>>>>>> while (not gen.generalization->isEmpty()) {
>>>>>>> gen := gen.generalization->any(true).general;
>>>>>>> count = count + 1;
>>>>>>> }; return count;
>>>>>>> }
>>>>>>>
>>>>>>> Regards,
>>>>>>> Sergey
>>>>>>>
>>>>>>>
>>>>>>> Mahdi D-Manesh wrote:
>>>>>>>> Hello again,
>>>>>>>>
>>>>>>>> I want to count how "deep" the inheritance for a given class is and
>>>>>>>> sum up all steps for all classes of a given set to finally compute
>>>>>>>> an average.
>>>>>>>>
>>>>>>>> I have issues with the qvto syntax and after trying for a long
>>>>>>>> time, I have no idea what else to try.
>>>>>>>>
>>>>>>>> Here is a snippet:
>>>>>>>>
>>>>>>>> /*
>>>>>>>> Recursively computes the amount of steps from the leaf classes
>>>>>>>> to their roots and sums them up.
>>>>>>>> */
>>>>>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>>>>>> Integer {
>>>>>>>> return leafClasses->computeSteps()->sum();
>>>>>>>> }
>>>>>>>>
>>>>>>>> /*
>>>>>>>> Computes the needed steps from leaf to root for a single class.
>>>>>>>> */
>>>>>>>> query UmlClass::computeSteps() : Integer {
>>>>>>>> -- How to select the first element from the bag or set?
>>>>>>>> var g := self.umlGeneral->any(true);
>>>>>>>> -- if else not supported?
>>>>>>>> if (g == null) {
>>>>>>>> }
>>>>>>>> return res;
>>>>>>>> }
>>>>>>>>
>>>>>>>> In computeSteps(), my idea is to go back the umlGeneral reference
>>>>>>>> and jump from class to class until this is null, counting the
>>>>>>>> inheritance path length.
>>>>>>>>
>>>>>>>> The issue is first, that self.umlgeneral is a set / baf and I want
>>>>>>>> to access only its first element (language only knows single
>>>>>>>> inheritance). I saw some method like first() but this seems not to
>>>>>>>> exist?
>>>>>>>>
>>>>>>>> After this, I need some sort of if, else construct, which is there
>>>>>>>> according to the QVT specs but it looks like it is not yet in QVTO?
>>>>>>>>
>>>>>>>> Any help to express this in QVTO is welcome! Maybe I am just trying
>>>>>>>> to do it the "wrong way"?
>>>>>>>>
>>>>>>>> Best Regards,
>>>>>>>> Mahdi D-Manesh
>>
|
|
|
Re: [QVTO] first() and If Expression [message #92406 is a reply to message #92391] |
Mon, 13 October 2008 20:14 |
Sergey Boyko Messages: 171 Registered: July 2009 |
Senior Member |
|
|
Look at
dev.eclipse.org:/cvsroot/modeling,
/org.eclipse.m2m/org.eclipse.m2m.qvt.oml/plugins/org.eclipse .m2m.qvt.oml.cst.parser
Wbr,
Sergey
Alfons Laarman wrote:
> I helps, a bit, whats left for me is to find them in this vast space called
> CVS...
> Do you have a hint?
>
>
> Thanks,
>
> Alfons
>
> "Alexander Igdalov" <Alexander.Igdalov@borland.com> schreef in bericht
> news:gcvj93$9oe$1@build.eclipse.org...
>> Hi Alfons,
>>
>> Currently they are not included into the build, however, you can get them
>> from CVS. Meanwhile, the idea of adding them to the build seems good.
>>
>> HTH,
>> Alex.
>>
>> Alfons Laarman wrote:
>>> Hi Alex,
>>>
>>> I was following your advice and took a look at the files. I could only
>>> find the generated LPG java files. Where can we find the source lpg
>>> files?
>>> Isn;t some kind of changelist from previous builds?
>>>
>>> Cheers,
>>>
>>> Alfons
>>>
>>> "Alexander Igdalov" <Alexander.Igdalov@borland.com> schreef in bericht
>>> news:gcnd7t$kgn$1@build.eclipse.org...
>>>> Hi Mahdi,
>>>>
>>>> In addition to Sergey's comment, I would also recommend you to take a
>>>> look at our LPG files in the org.eclipse.m2m.qvt.oml.cst.parser to have
>>>> the most up-to-date notion of what is already implemented.
>>>> QVTO tests and samples are also a good source of code snippets.
>>>>
>>>> Cheers,
>>>> Alex.
>>>>
>>>>
>>>> Mahdi D-Manesh wrote:
>>>>> Hello Sergey,
>>>>>
>>>>> yes you're right, actually the specs are correct, just the example
>>>>> isn't wow... I was so close to looking at the EBNF but I usually avoid
>>>>> it when possible. In this case it would have been good though, I agree!
>>>>> :)
>>>>>
>>>>> Well missing the elif part is not such a big deal.
>>>>>
>>>>> Best Regards,
>>>>> Mahdi
>>>>>
>>>>> Sergey Boyko schrieb:
>>>>>> Hi Mahdi
>>>>>>
>>>>>> Not at all. I like qvto to be used in the field ;)
>>>>>>
>>>>>> About spec conformance. It's our goal :)
>>>>>> Section "8.4.7 EBNF" defines the following
>>>>>> <if_exp> ::= 'if' <expression> <then_part>
>>>>>> <elif_part>* <else_part>? 'endif'
>>>>>> <then_part> ::= 'then' <if_body>
>>>>>> <elif_part> ::= 'elif' <if_body>
>>>>>> <else_part> ::= 'else' <if_body>
>>>>>> <if_body> ::= <expression> | <expression_block>
>>>>>>
>>>>>> We only missed 'elif' part at present.
>>>>>>
>>>>>> Snippets from the spec like
>>>>>> var x:= if (self.name.startsWith("_") "PROTECTED"
>>>>>> elif (self.type.isPrimitive() "NORMAL"
>>>>>> else "UNEXPECTED"
>>>>>> simply don't match grammar defined in the same doc :)
>>>>>>
>>>>>> The only addition doc about our implementation I can point is from our
>>>>>> Eclipse corner:
>>>>>> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Sergey.
>>>>>>
>>>>>>
>>>>>> Mahdi D-Manesh wrote:
>>>>>>> Hello Sergey,
>>>>>>>
>>>>>>> thanks a lot for the examples!
>>>>>>> In the meantime I found the while statement and my Benchmark
>>>>>>> transformation runs.
>>>>>>>
>>>>>>> For the ->first() of course it makes sense for ordered collections
>>>>>>> only, my bad. I tried it and it works. :)
>>>>>>>
>>>>>>> Same for the if Statement - I just tried the ways from QVT
>>>>>>> 07-07-07.pdf specs but they did not look correct there. Yours run
>>>>>>> like expected.
>>>>>>> Is there some (free) Document, which lists such syntax more up to
>>>>>>> date and according to the QVTO plugin implementation?
>>>>>>>
>>>>>>> Thanks for the computeSteps() example! My version looks very similar,
>>>>>>> just that I didnt know how to initialize the var with a type like
>>>>>>> this.
>>>>>>>
>>>>>>> Once again, thanks alot for your time!
>>>>>>> Mahdi
>>>>>>>
>>>>>>>
>>>>>>> Sergey Boyko schrieb:
>>>>>>>> Hi Mahdi,
>>>>>>>>
>>>>>>>> According to spec 'first()' is defined for ordered collections only
>>>>>>>> (Sequence and OrderedSet). For the other collection types
>>>>>>>> 'any(true)' is appropriate way to obtain some element. Or you can
>>>>>>>> cast collection to sequence like 'coll->asSequence()->first()'.
>>>>>>>>
>>>>>>>> Qvto supports 'if' construction with the following syntax
>>>>>>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>>>>>>
>>>>>>>> Use like:
>>>>>>>> if true then {} endif;
>>>>>>>> if true then OclVoid endif;
>>>>>>>> if true then {} else {} endif;
>>>>>>>> if true then {} else OclVoid endif;
>>>>>>>>
>>>>>>>>
>>>>>>>> Btw, for counting generals for uml-like class it's possible to use
>>>>>>>> 'while()' expression (supposing single inheritance):
>>>>>>>>
>>>>>>>> query uml::Class::computeSteps() : Integer {
>>>>>>>> var gen : uml::Classifier := self;
>>>>>>>> var count := 0;
>>>>>>>>
>>>>>>>> while (not gen.generalization->isEmpty()) {
>>>>>>>> gen := gen.generalization->any(true).general;
>>>>>>>> count = count + 1;
>>>>>>>> }; return count;
>>>>>>>> }
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Sergey
>>>>>>>>
>>>>>>>>
>>>>>>>> Mahdi D-Manesh wrote:
>>>>>>>>> Hello again,
>>>>>>>>>
>>>>>>>>> I want to count how "deep" the inheritance for a given class is and
>>>>>>>>> sum up all steps for all classes of a given set to finally compute
>>>>>>>>> an average.
>>>>>>>>>
>>>>>>>>> I have issues with the qvto syntax and after trying for a long
>>>>>>>>> time, I have no idea what else to try.
>>>>>>>>>
>>>>>>>>> Here is a snippet:
>>>>>>>>>
>>>>>>>>> /*
>>>>>>>>> Recursively computes the amount of steps from the leaf classes
>>>>>>>>> to their roots and sums them up.
>>>>>>>>> */
>>>>>>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>>>>>>> Integer {
>>>>>>>>> return leafClasses->computeSteps()->sum();
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> /*
>>>>>>>>> Computes the needed steps from leaf to root for a single class.
>>>>>>>>> */
>>>>>>>>> query UmlClass::computeSteps() : Integer {
>>>>>>>>> -- How to select the first element from the bag or set?
>>>>>>>>> var g := self.umlGeneral->any(true);
>>>>>>>>> -- if else not supported?
>>>>>>>>> if (g == null) {
>>>>>>>>> }
>>>>>>>>> return res;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> In computeSteps(), my idea is to go back the umlGeneral reference
>>>>>>>>> and jump from class to class until this is null, counting the
>>>>>>>>> inheritance path length.
>>>>>>>>>
>>>>>>>>> The issue is first, that self.umlgeneral is a set / baf and I want
>>>>>>>>> to access only its first element (language only knows single
>>>>>>>>> inheritance). I saw some method like first() but this seems not to
>>>>>>>>> exist?
>>>>>>>>>
>>>>>>>>> After this, I need some sort of if, else construct, which is there
>>>>>>>>> according to the QVT specs but it looks like it is not yet in QVTO?
>>>>>>>>>
>>>>>>>>> Any help to express this in QVTO is welcome! Maybe I am just trying
>>>>>>>>> to do it the "wrong way"?
>>>>>>>>>
>>>>>>>>> Best Regards,
>>>>>>>>> Mahdi D-Manesh
>
|
|
|
Re: [QVTO] first() and If Expression [message #92421 is a reply to message #92249] |
Mon, 13 October 2008 20:52 |
Eclipse User |
|
|
|
Originally posted by: mahdider.students.uni-mainz.de
Hi Radek,
comments below...
> Hi Mahdi,
>
> Thanks for pointing this out!
Sure, I just noticed it. :)
>
> Right, the spec does not say explicitly that the constructor body of
> implicit ObjectExp
> is restricted to contain only assignment expressions, though the
> notation examples in the spec
> might give such impression.
>
> It's a limitation of our implementation at the moment, which should
> disappear soon as we are
> currently working on the grammar alignment with the OMG spec.
I understand that it takes time to align all this work and I must say
that I really like the QVTO tool so far! What I actually really like is
conformance to the OMG Specs. When I started a week ago, I could mostly
start learning QVT with the specs, which is really nice (and of course
one of the reasons for having a standard in the first place). Great job
so far!
>
> As for the explicit population section, I think it's questionable if it
> should contain other
> expressions than object expressions. If yes, the 'population' keyword
> gets redundant.
Agreed! If the population section is really just for assignments, then
conditional assignments should be kept out of them to keep simple things
simple. I must admit, that I did not dig deeper into the reasons for the
subdevision of a mapping into the three parts.
Best Regards,
Mahdi
>
> Regards,
> /Radek
>
>
> On Fri, 10 Oct 2008 16:38:31 +0200, Mahdi D-Manesh
> <mahdider@students.uni-mainz.de> wrote:
>
>> Hello,
>>
>> okay this is a good idea! I should get the files.
>> Actually I am learning QVT because I will need it for the practical
>> part of my Bachelor Thesis during the next months. :)
>>
>> BTW:
>> Is there any restriction on WHERE if-statements are allowed?
>> I noticed that they work inside the begin or end section,
>> but not inbetween or even in an explicit population section.
>>
>> What would be the reason for this?
>>
>> Best Regards,
>> Mahdi
>>
>>
>> Alexander Igdalov schrieb:
>>> Hi Mahdi,
>>> In addition to Sergey's comment, I would also recommend you to take
>>> a look at our LPG files in the org.eclipse.m2m.qvt.oml.cst.parser to
>>> have the most up-to-date notion of what is already implemented.
>>> QVTO tests and samples are also a good source of code snippets.
>>> Cheers,
>>> Alex.
>>> Mahdi D-Manesh wrote:
>>>> Hello Sergey,
>>>>
>>>> yes you're right, actually the specs are correct, just the example
>>>> isn't wow... I was so close to looking at the EBNF but I usually
>>>> avoid it when possible. In this case it would have been good though,
>>>> I agree! :)
>>>>
>>>> Well missing the elif part is not such a big deal.
>>>>
>>>> Best Regards,
>>>> Mahdi
>>>>
>>>> Sergey Boyko schrieb:
>>>>> Hi Mahdi
>>>>>
>>>>> Not at all. I like qvto to be used in the field ;)
>>>>>
>>>>> About spec conformance. It's our goal :)
>>>>> Section "8.4.7 EBNF" defines the following
>>>>> <if_exp> ::= 'if' <expression> <then_part>
>>>>> <elif_part>* <else_part>? 'endif'
>>>>> <then_part> ::= 'then' <if_body>
>>>>> <elif_part> ::= 'elif' <if_body>
>>>>> <else_part> ::= 'else' <if_body>
>>>>> <if_body> ::= <expression> | <expression_block>
>>>>>
>>>>> We only missed 'elif' part at present.
>>>>>
>>>>> Snippets from the spec like
>>>>> var x:= if (self.name.startsWith("_") "PROTECTED"
>>>>> elif (self.type.isPrimitive() "NORMAL"
>>>>> else "UNEXPECTED"
>>>>> simply don't match grammar defined in the same doc :)
>>>>>
>>>>> The only addition doc about our implementation I can point is from
>>>>> our Eclipse corner:
>>>>> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>>>>>
>>>>>
>>>>> Regards,
>>>>> Sergey.
>>>>>
>>>>>
>>>>> Mahdi D-Manesh wrote:
>>>>>> Hello Sergey,
>>>>>>
>>>>>> thanks a lot for the examples!
>>>>>> In the meantime I found the while statement and my Benchmark
>>>>>> transformation runs.
>>>>>>
>>>>>> For the ->first() of course it makes sense for ordered collections
>>>>>> only, my bad. I tried it and it works. :)
>>>>>>
>>>>>> Same for the if Statement - I just tried the ways from QVT
>>>>>> 07-07-07.pdf specs but they did not look correct there. Yours run
>>>>>> like expected.
>>>>>> Is there some (free) Document, which lists such syntax more up to
>>>>>> date and according to the QVTO plugin implementation?
>>>>>>
>>>>>> Thanks for the computeSteps() example! My version looks very similar,
>>>>>> just that I didnt know how to initialize the var with a type like
>>>>>> this.
>>>>>>
>>>>>> Once again, thanks alot for your time!
>>>>>> Mahdi
>>>>>>
>>>>>>
>>>>>> Sergey Boyko schrieb:
>>>>>>> Hi Mahdi,
>>>>>>>
>>>>>>> According to spec 'first()' is defined for ordered collections
>>>>>>> only (Sequence and OrderedSet). For the other collection types
>>>>>>> 'any(true)' is appropriate way to obtain some element. Or you can
>>>>>>> cast collection to sequence like 'coll->asSequence()->first()'.
>>>>>>>
>>>>>>> Qvto supports 'if' construction with the following syntax
>>>>>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>>>>>
>>>>>>> Use like:
>>>>>>> if true then {} endif;
>>>>>>> if true then OclVoid endif;
>>>>>>> if true then {} else {} endif;
>>>>>>> if true then {} else OclVoid endif;
>>>>>>>
>>>>>>>
>>>>>>> Btw, for counting generals for uml-like class it's possible to
>>>>>>> use 'while()' expression (supposing single inheritance):
>>>>>>>
>>>>>>> query uml::Class::computeSteps() : Integer {
>>>>>>> var gen : uml::Classifier := self;
>>>>>>> var count := 0;
>>>>>>>
>>>>>>> while (not gen.generalization->isEmpty()) {
>>>>>>> gen := gen.generalization->any(true).general;
>>>>>>> count = count + 1;
>>>>>>> }; return count;
>>>>>>> }
>>>>>>>
>>>>>>> Regards,
>>>>>>> Sergey
>>>>>>>
>>>>>>>
>>>>>>> Mahdi D-Manesh wrote:
>>>>>>>> Hello again,
>>>>>>>>
>>>>>>>> I want to count how "deep" the inheritance for a given class is
>>>>>>>> and sum up all steps for all classes of a given set to finally
>>>>>>>> compute an average.
>>>>>>>>
>>>>>>>> I have issues with the qvto syntax and after trying for a long
>>>>>>>> time, I have no idea what else to try.
>>>>>>>>
>>>>>>>> Here is a snippet:
>>>>>>>>
>>>>>>>> /*
>>>>>>>> Recursively computes the amount of steps from the leaf
>>>>>>>> classes to their roots and sums them up.
>>>>>>>> */
>>>>>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>>>>>> Integer {
>>>>>>>> return leafClasses->computeSteps()->sum();
>>>>>>>> }
>>>>>>>>
>>>>>>>> /*
>>>>>>>> Computes the needed steps from leaf to root for a single class.
>>>>>>>> */
>>>>>>>> query UmlClass::computeSteps() : Integer {
>>>>>>>> -- How to select the first element from the bag or set?
>>>>>>>> var g := self.umlGeneral->any(true);
>>>>>>>> -- if else not supported?
>>>>>>>> if (g == null) {
>>>>>>>> }
>>>>>>>> return res;
>>>>>>>> }
>>>>>>>>
>>>>>>>> In computeSteps(), my idea is to go back the umlGeneral
>>>>>>>> reference and jump from class to class until this is null,
>>>>>>>> counting the inheritance path length.
>>>>>>>>
>>>>>>>> The issue is first, that self.umlgeneral is a set / baf and I
>>>>>>>> want to access only its first element (language only knows
>>>>>>>> single inheritance). I saw some method like first() but this
>>>>>>>> seems not to exist?
>>>>>>>>
>>>>>>>> After this, I need some sort of if, else construct, which is
>>>>>>>> there according to the QVT specs but it looks like it is not yet
>>>>>>>> in QVTO?
>>>>>>>>
>>>>>>>> Any help to express this in QVTO is welcome! Maybe I am just
>>>>>>>> trying to do it the "wrong way"?
>>>>>>>>
>>>>>>>> Best Regards,
>>>>>>>> Mahdi D-Manesh
>
|
|
|
Re: [QVTO] first() and If Expression [message #92436 is a reply to message #92421] |
Tue, 14 October 2008 10:24 |
Alfons Laarman Messages: 71 Registered: July 2009 |
Member |
|
|
Hi Mahdi,
If you check out SmartQVT, you will see it conforms better to the spec.
And - last time I checked - is more complete. I hope to see M2M QVT OML
reach te same state.
Regards,
Alfons
"Mahdi D-Manesh" <mahdider@students.uni-mainz.de> schreef in bericht
news:gd0ce4$o0p$1@build.eclipse.org...
> Hi Radek,
>
> comments below...
>
>> Hi Mahdi,
>>
>> Thanks for pointing this out!
>
> Sure, I just noticed it. :)
>
>>
>> Right, the spec does not say explicitly that the constructor body of
>> implicit ObjectExp
>> is restricted to contain only assignment expressions, though the
>> notation examples in the spec
>> might give such impression.
>>
>> It's a limitation of our implementation at the moment, which should
>> disappear soon as we are
>> currently working on the grammar alignment with the OMG spec.
>
> I understand that it takes time to align all this work and I must say
> that I really like the QVTO tool so far! What I actually really like is
> conformance to the OMG Specs. When I started a week ago, I could mostly
> start learning QVT with the specs, which is really nice (and of course
> one of the reasons for having a standard in the first place). Great job
> so far!
>
>>
>> As for the explicit population section, I think it's questionable if it
>> should contain other
>> expressions than object expressions. If yes, the 'population' keyword
>> gets redundant.
>
> Agreed! If the population section is really just for assignments, then
> conditional assignments should be kept out of them to keep simple things
> simple. I must admit, that I did not dig deeper into the reasons for the
> subdevision of a mapping into the three parts.
>
> Best Regards,
> Mahdi
>
>>
>> Regards,
>> /Radek
>>
>>
>> On Fri, 10 Oct 2008 16:38:31 +0200, Mahdi D-Manesh
>> <mahdider@students.uni-mainz.de> wrote:
>>
>>> Hello,
>>>
>>> okay this is a good idea! I should get the files.
>>> Actually I am learning QVT because I will need it for the practical
>>> part of my Bachelor Thesis during the next months. :)
>>>
>>> BTW:
>>> Is there any restriction on WHERE if-statements are allowed?
>>> I noticed that they work inside the begin or end section,
>>> but not inbetween or even in an explicit population section.
>>>
>>> What would be the reason for this?
>>>
>>> Best Regards,
>>> Mahdi
>>>
>>>
>>> Alexander Igdalov schrieb:
>>>> Hi Mahdi,
>>>> In addition to Sergey's comment, I would also recommend you to take
>>>> a look at our LPG files in the org.eclipse.m2m.qvt.oml.cst.parser to
>>>> have the most up-to-date notion of what is already implemented.
>>>> QVTO tests and samples are also a good source of code snippets.
>>>> Cheers,
>>>> Alex.
>>>> Mahdi D-Manesh wrote:
>>>>> Hello Sergey,
>>>>>
>>>>> yes you're right, actually the specs are correct, just the example
>>>>> isn't wow... I was so close to looking at the EBNF but I usually
>>>>> avoid it when possible. In this case it would have been good though,
>>>>> I agree! :)
>>>>>
>>>>> Well missing the elif part is not such a big deal.
>>>>>
>>>>> Best Regards,
>>>>> Mahdi
>>>>>
>>>>> Sergey Boyko schrieb:
>>>>>> Hi Mahdi
>>>>>>
>>>>>> Not at all. I like qvto to be used in the field ;)
>>>>>>
>>>>>> About spec conformance. It's our goal :)
>>>>>> Section "8.4.7 EBNF" defines the following
>>>>>> <if_exp> ::= 'if' <expression> <then_part>
>>>>>> <elif_part>* <else_part>? 'endif'
>>>>>> <then_part> ::= 'then' <if_body>
>>>>>> <elif_part> ::= 'elif' <if_body>
>>>>>> <else_part> ::= 'else' <if_body>
>>>>>> <if_body> ::= <expression> | <expression_block>
>>>>>>
>>>>>> We only missed 'elif' part at present.
>>>>>>
>>>>>> Snippets from the spec like
>>>>>> var x:= if (self.name.startsWith("_") "PROTECTED"
>>>>>> elif (self.type.isPrimitive() "NORMAL"
>>>>>> else "UNEXPECTED"
>>>>>> simply don't match grammar defined in the same doc :)
>>>>>>
>>>>>> The only addition doc about our implementation I can point is from
>>>>>> our Eclipse corner:
>>>>>> http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Sergey.
>>>>>>
>>>>>>
>>>>>> Mahdi D-Manesh wrote:
>>>>>>> Hello Sergey,
>>>>>>>
>>>>>>> thanks a lot for the examples!
>>>>>>> In the meantime I found the while statement and my Benchmark
>>>>>>> transformation runs.
>>>>>>>
>>>>>>> For the ->first() of course it makes sense for ordered collections
>>>>>>> only, my bad. I tried it and it works. :)
>>>>>>>
>>>>>>> Same for the if Statement - I just tried the ways from QVT
>>>>>>> 07-07-07.pdf specs but they did not look correct there. Yours run
>>>>>>> like expected.
>>>>>>> Is there some (free) Document, which lists such syntax more up to
>>>>>>> date and according to the QVTO plugin implementation?
>>>>>>>
>>>>>>> Thanks for the computeSteps() example! My version looks very
>>>>>>> similar,
>>>>>>> just that I didnt know how to initialize the var with a type like
>>>>>>> this.
>>>>>>>
>>>>>>> Once again, thanks alot for your time!
>>>>>>> Mahdi
>>>>>>>
>>>>>>>
>>>>>>> Sergey Boyko schrieb:
>>>>>>>> Hi Mahdi,
>>>>>>>>
>>>>>>>> According to spec 'first()' is defined for ordered collections
>>>>>>>> only (Sequence and OrderedSet). For the other collection types
>>>>>>>> 'any(true)' is appropriate way to obtain some element. Or you can
>>>>>>>> cast collection to sequence like 'coll->asSequence()->first()'.
>>>>>>>>
>>>>>>>> Qvto supports 'if' construction with the following syntax
>>>>>>>> if <oclExperssion> then <ifExpBody> [else <ifExpBody>] endif
>>>>>>>>
>>>>>>>> Use like:
>>>>>>>> if true then {} endif;
>>>>>>>> if true then OclVoid endif;
>>>>>>>> if true then {} else {} endif;
>>>>>>>> if true then {} else OclVoid endif;
>>>>>>>>
>>>>>>>>
>>>>>>>> Btw, for counting generals for uml-like class it's possible to
>>>>>>>> use 'while()' expression (supposing single inheritance):
>>>>>>>>
>>>>>>>> query uml::Class::computeSteps() : Integer {
>>>>>>>> var gen : uml::Classifier := self;
>>>>>>>> var count := 0;
>>>>>>>>
>>>>>>>> while (not gen.generalization->isEmpty()) {
>>>>>>>> gen := gen.generalization->any(true).general;
>>>>>>>> count = count + 1;
>>>>>>>> }; return count;
>>>>>>>> }
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Sergey
>>>>>>>>
>>>>>>>>
>>>>>>>> Mahdi D-Manesh wrote:
>>>>>>>>> Hello again,
>>>>>>>>>
>>>>>>>>> I want to count how "deep" the inheritance for a given class is
>>>>>>>>> and sum up all steps for all classes of a given set to finally
>>>>>>>>> compute an average.
>>>>>>>>>
>>>>>>>>> I have issues with the qvto syntax and after trying for a long
>>>>>>>>> time, I have no idea what else to try.
>>>>>>>>>
>>>>>>>>> Here is a snippet:
>>>>>>>>>
>>>>>>>>> /*
>>>>>>>>> Recursively computes the amount of steps from the leaf
>>>>>>>>> classes to their roots and sums them up.
>>>>>>>>> */
>>>>>>>>> query computeInheritanceSteps(in leafClasses : Bag(UmlClass)) :
>>>>>>>>> Integer {
>>>>>>>>> return leafClasses->computeSteps()->sum();
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> /*
>>>>>>>>> Computes the needed steps from leaf to root for a single
>>>>>>>>> class.
>>>>>>>>> */
>>>>>>>>> query UmlClass::computeSteps() : Integer {
>>>>>>>>> -- How to select the first element from the bag or set?
>>>>>>>>> var g := self.umlGeneral->any(true);
>>>>>>>>> -- if else not supported?
>>>>>>>>> if (g == null) {
>>>>>>>>> }
>>>>>>>>> return res;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> In computeSteps(), my idea is to go back the umlGeneral
>>>>>>>>> reference and jump from class to class until this is null,
>>>>>>>>> counting the inheritance path length.
>>>>>>>>>
>>>>>>>>> The issue is first, that self.umlgeneral is a set / baf and I
>>>>>>>>> want to access only its first element (language only knows
>>>>>>>>> single inheritance). I saw some method like first() but this
>>>>>>>>> seems not to exist?
>>>>>>>>>
>>>>>>>>> After this, I need some sort of if, else construct, which is
>>>>>>>>> there according to the QVT specs but it looks like it is not yet
>>>>>>>>> in QVTO?
>>>>>>>>>
>>>>>>>>> Any help to express this in QVTO is welcome! Maybe I am just
>>>>>>>>> trying to do it the "wrong way"?
>>>>>>>>>
>>>>>>>>> Best Regards,
>>>>>>>>> Mahdi D-Manesh
>>
|
|
|
Goto Forum:
Current Time: Thu Nov 21 15:09:53 GMT 2024
Powered by FUDForum. Page generated in 0.04923 seconds
|