[ATL] Problem with an atl rule [message #55751] |
Thu, 02 August 2007 06:46  |
Eclipse User |
|
|
|
Originally posted by: NewsgroupSPAM.iKupp.de
Hi,
ive got another problem ;-(
ive got a xml file like
<children xsi:type="Element" name="Document" value="">
<children xsi:type="Element" name="Entity" value="">
<children xsi:type="Element" name="id" value="123"/>
<children xsi:type="Element" name="name" value="my name"/>
<children xsi:type="Element" name="is_a" value="345"/>
</children>
<children xsi:type="Element" name="Entity" value="">
<children xsi:type="Element" name="id" value="345"/>
<children xsi:type="Element" name="name" value="my other name"/>
<children xsi:type="Element" name="is_a" value="789"/>
</children>
....
</children>
and a target file like
<relation from_id="123" to_id="345" from_name="my name" to_name="my
other name">
....
but how do i get the to_name value from the other element?
i ve got a rule like:
rule entity{
from i : XML!Element (
i.name='Entity'
)outr0 : relation!relation(
from_id <-i.getvalue('id'),
to_id <-i.getvalue('is_a'),
from_name <-i.getvalue('name'),
to_name <-?????????????
),
with the helper
helper context XML!Element def : getvalue(finder : String) : String =
if self.children->select(c | c.oclIsKindOf(XML!Element) and
c.name=finder)->size()=0 then '' else self.children->select(c |
c.oclIsKindOf(XML!Element) and c.name=finder)->first().value endif;
Many thanks
Ina
|
|
|
|
|
Re: [ATL] Problem with an atl rule [message #55963 is a reply to message #55805] |
Fri, 03 August 2007 09:03   |
Eclipse User |
|
|
|
Originally posted by: NewsgroupSPAM.iKupp.de
Hi,
Hugo Bruneliere schrieb:
> Hugo Bruneliere a écrit :
>> Ina Kupp a écrit :
>>> Hi,
>>
>> Hi Ina,
>>
>>> ive got another problem ;-(
>>> ive got a xml file like
>>> <children xsi:type="Element" name="Document" value="">
>>> <children xsi:type="Element" name="Entity" value="">
>>> <children xsi:type="Element" name="id" value="123"/>
>>> <children xsi:type="Element" name="name" value="my name"/>
>>> <children xsi:type="Element" name="is_a" value="345"/>
>>> </children>
>>>
>>> <children xsi:type="Element" name="Entity" value="">
>>> <children xsi:type="Element" name="id" value="345"/>
>>> <children xsi:type="Element" name="name" value="my other name"/>
>>> <children xsi:type="Element" name="is_a" value="789"/>
>>> </children>
>>> ...
>>> </children>
>>> and a target file like
>>> <relation from_id="123" to_id="345" from_name="my name" to_name="my
>>> other name">
>>> ...
>>>
>>> but how do i get the to_name value from the other element?
>>> i ve got a rule like:
>>> rule entity{
>>> from i : XML!Element (
>>> i.name='Entity'
>>> )outr0 : relation!relation(
>>> from_id <-i.getvalue('id'),
>>> to_id <-i.getvalue('is_a'),
>>> from_name <-i.getvalue('name'),
>>> to_name <-?????????????
>>> ),
>>>
>>> with the helper
>>> helper context XML!Element def : getvalue(finder : String) : String =
>>> if self.children->select(c | c.oclIsKindOf(XML!Element) and
>>> c.name=finder)->size()=0 then '' else self.children->select(c |
>>> c.oclIsKindOf(XML!Element) and c.name=finder)->first().value endif;
>>
>> You can define this helper:
>>
>> helper def: getEntityNameFromId(entityId : String) : String =
>> XML!Element.allInstances()->select(e | e.name = 'Entity'
>> and e.children->select(c | c.name='id' and c.value=
>> entityId)->notEmpty())
>> ->first().children->select(c | c.name='name')->first().value;
>>
>> And call it like this:
>>
>> to_name <- getEntityNameFromId(i.getvalue('is_a'))
>
> Sorry:
>
> to_name <- thisModule.getEntityNameFromId(i.getvalue('is_a'))
>
> :-)
with this helper i get an error if the id isnt found, so i added an if
clause to the helper:
now it works but it isnt very fast.
helper def: getEntityNameFromId(entityId : String) : String =
if XML!Element.allInstances()->select(e | e.name = 'Entity' and
e.children->select(c | c.name='id' and c.value=
entityId)->notEmpty())->notEmpty()
then XML!Element.allInstances()->select(e | e.name = 'Entity' and
e.children->select(c | c.name='id' and c.value= entityId)->notEmpty())
->first().children->select(c | c.name='name')->first().value
else ''endif;
many thanks for your contemporary help, this helper saved my day ;-)
Ina
|
|
|
|
Re: [ATL] Problem with an atl rule (solved) [message #56347 is a reply to message #55963] |
Mon, 06 August 2007 04:56  |
Eclipse User |
|
|
|
Originally posted by: NewsgroupSPAM.iKupp.de
Ina Kupp schrieb:
> Hi,
> Hugo Bruneliere schrieb:
>> Hugo Bruneliere a écrit :
>>> Ina Kupp a écrit :
>>>> Hi,
>>>
>>> Hi Ina,
>>>
>>>> ive got another problem ;-(
>>>> ive got a xml file like
>>>> <children xsi:type="Element" name="Document" value="">
>>>> <children xsi:type="Element" name="Entity" value="">
>>>> <children xsi:type="Element" name="id" value="123"/>
>>>> <children xsi:type="Element" name="name" value="my name"/>
>>>> <children xsi:type="Element" name="is_a" value="345"/>
>>>> </children>
>>>>
>>>> <children xsi:type="Element" name="Entity" value="">
>>>> <children xsi:type="Element" name="id" value="345"/>
>>>> <children xsi:type="Element" name="name" value="my other name"/>
>>>> <children xsi:type="Element" name="is_a" value="789"/>
>>>> </children>
>>>> ...
>>>> </children>
>>>> and a target file like
>>>> <relation from_id="123" to_id="345" from_name="my name" to_name="my
>>>> other name">
>>>> ...
>>>>
>>>> but how do i get the to_name value from the other element?
>>>> i ve got a rule like:
>>>> rule entity{
>>>> from i : XML!Element (
>>>> i.name='Entity'
>>>> )outr0 : relation!relation(
>>>> from_id <-i.getvalue('id'),
>>>> to_id <-i.getvalue('is_a'),
>>>> from_name <-i.getvalue('name'),
>>>> to_name <-?????????????
>>>> ),
>>>>
>>>> with the helper
>>>> helper context XML!Element def : getvalue(finder : String) : String =
>>>> if self.children->select(c | c.oclIsKindOf(XML!Element) and
>>>> c.name=finder)->size()=0 then '' else self.children->select(c |
>>>> c.oclIsKindOf(XML!Element) and c.name=finder)->first().value endif;
>>>
>>> You can define this helper:
>>>
>>> helper def: getEntityNameFromId(entityId : String) : String =
>>> XML!Element.allInstances()->select(e | e.name = 'Entity'
>>> and e.children->select(c | c.name='id' and c.value=
>>> entityId)->notEmpty())
>>> ->first().children->select(c | c.name='name')->first().value;
>>>
>>> And call it like this:
>>>
>>> to_name <- getEntityNameFromId(i.getvalue('is_a'))
>>
>> Sorry:
>>
>> to_name <- thisModule.getEntityNameFromId(i.getvalue('is_a'))
>>
>> :-)
> with this helper i get an error if the id isnt found, so i added an if
> clause to the helper:
> now it works but it isnt very fast.
>
> helper def: getEntityNameFromId(entityId : String) : String =
> if XML!Element.allInstances()->select(e | e.name = 'Entity' and
> e.children->select(c | c.name='id' and c.value=
> entityId)->notEmpty())->notEmpty()
> then XML!Element.allInstances()->select(e | e.name = 'Entity' and
> e.children->select(c | c.name='id' and c.value= entityId)->notEmpty())
> ->first().children->select(c | c.name='name')->first().value
> else ''endif;
>
> many thanks for your contemporary help, this helper saved my day ;-)
> Ina
fyi:
i changed it to this:
helper def: getEntityNameFromId(entityId : String, outname : String,
inname : String) : String =
XML!Element.allInstances()->select(e | e.name = 'Entity' and
e.children->select(c | if c.oclIsUndefined() then false else
c.name=inname and c.value= entityId endif)->notEmpty())
->first().children->select(c | if c.oclIsUndefinded() then false
else c.name=outname endif )->first().value;
(the outname and inname are only for being more flexible)
this changed the speed from over 25h (i canceld it after 10h and after
that it needed another 15h to end the process (it seems like it did the
transformation till the end) to 2h. (the input file is only 276KB big)
;-)
many thanks for your help
Ina
|
|
|
Powered by
FUDForum. Page generated in 0.05796 seconds