Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » ECL comparision on collections(Comparing OrderedSet or Bag give the same result)
ECL comparision on collections [message #1795560] Tue, 25 September 2018 09:45 Go to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Hi Dimitris,
I'm working with ECL on the comparisions of two xml files based on the same xsd that differs only in the order of a TDOI type element contained in a LN0Type element.
In one xml file I have:
<LN0 desc="General">
<DOI name="Beh">
</DOI>
<DOI name="Mod">
</DOI>
<DOI name="Health">
</DOI>
</LN0>
and in the second one I have;
<LN0 desc="General">
<DOI name="Mod">
</DOI>
<DOI name="Beh">
</DOI>
<DOI name="Health">
</DOI>
</LN0>

I expected that transforming in Bag the collections in input to matches() the result was a true matching, instead I get False as reported in the attached image
index.php/fa/33945/0/

I also try to put true in the TDOI rule compare in order to watch how many times this rules was called with Bag, and I get only 3 times as reported in this picture
index.php/fa/33946/0/

A second starnge behviour is related to getting differents results after calling very similar instructions against two identical xml files :
l.dOI.asBag().matches(r.dOI.asBag());
r.dOI.asBag().matches(l.dOI.asBag());
index.php/fa/33949/0/
One instruction give 1 false the other 3 True matching, shouldn't give the same matching results ?

Could you give some help on this ?
Thanks,
Gianluigi


  • Attachment: ecl-1.png
    (Size: 60.22KB, Downloaded 501 times)
  • Attachment: ecl-2.png
    (Size: 86.43KB, Downloaded 520 times)
  • Attachment: ecl-3.png
    (Size: 81.11KB, Downloaded 532 times)

[Updated on: Tue, 25 September 2018 14:09]

Report message to a moderator

Re: ECL comparision on collections [message #1795589 is a reply to message #1795560] Tue, 25 September 2018 20:34 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

It would be helpful if you could upload your ECL script as a text file rather than an image so that we can debug it. Also if you are using the Interim version of Epsilon, please try it with the stable release (v1.5.0).

Thanks,
Sina
Re: ECL comparision on collections [message #1795653 is a reply to message #1795589] Wed, 26 September 2018 12:20 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

I was unable to reproduce the problem based on the screenshots provided. Please see [1] for guidance on reporting issues/bugs.

Thanks,
Sina

[1] https://www.eclipse.org/epsilon/doc/articles/minimal-examples/
Re: ECL comparision on collections [message #1795655 is a reply to message #1795653] Wed, 26 September 2018 12:43 Go to previous messageGo to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Hi Sina,
thank you for your answers.
I'll provide a minimal example asap.
Gianluigi
Re: ECL comparision on collections [message #1795701 is a reply to message #1795655] Thu, 27 September 2018 05:51 Go to previous messageGo to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Hi Sina,
I'm loading a minimal example that I hope could help to better identify my problem.

-Epsilon version is Epsilon Core 1.6.0.201809191410
- In the attached project I create a "mymodel.model" based on "mymetamodel.ecore" (generate from .emf) by "createInstance.eol".
- The resulting "mymodel.model" was then copied in both "Righ.model" and "Left.model," so we have two identical models both containing 1 instance of TLN class that contains 3 instance of DOI class
- Comparing these two models by "CompareInstance.ecl", give me different result enabling one of the two instructions:
-l.dOI.matches(r.dOI);
-r.dOI.matches(l.dOI);

With l.dOI.matches(r.dOI); I get
# TDOI-l:tdoi-1 <-> TDOI-r:tdoi-1 # TDOI-l:tdoi-2 <-> TDOI-r:tdoi-2 # TDOI-l:tdoi-3 <-> TDOI-r:tdoi-3
Match:true - TLN [any=[], anyAttribute=[], desc=, text=text, text1=text1] <-> TLN [any=[], anyAttribute=[], desc=, text=text, text1=text1]

With r.dOI.matches(l.dOI); I get
Match:false - TDOI [any=[], anyAttribute=[], desc=, group=[], accessControl=tdoi-1, ix=0] <-> TDOI [any=[], anyAttribute=[], desc=, group=[], accessControl=tdoi-1, ix=0]
Match:true - TLN [any=[], anyAttribute=[], desc=, text=text, text1=text1] <-> TLN [any=[], anyAttribute=[], desc=, text=text, text1=text1]

I never get a true matching on TDOI instances as I'm excpeting because the two models are identical.

Let me know if you need more details.
Thanks,
Gianluigi

  • Attachment: test-ecl.zip
    (Size: 5.80KB, Downloaded 112 times)
Re: ECL comparision on collections [message #1795824 is a reply to message #1795701] Sun, 30 September 2018 10:37 Go to previous messageGo to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Hi Sina,
did you have the opportunity to test the example I uploaded ?
Thanks,
Gianluigi
Re: ECL comparision on collections [message #1795825 is a reply to message #1795824] Sun, 30 September 2018 10:57 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

Thank you for your efforts in providing the minimal example. I have been investigating this and still have not found an explanation for the issue. It is indeed an obscure bug! I will update you as soon as we have found the cause and rectified it.

Thanks,
Sina
Re: ECL comparision on collections [message #1795826 is a reply to message #1795825] Sun, 30 September 2018 11:34 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

I believe I have found the cause, and it turns out to be a misunderstanding of the specification of ECL in your script. The problem is tat your TDOI rule is declared such that it matches elements of the Left model with elements of the Right model, hence why
l.dOI.matches(r.dOI)
succeeds whereas
r.dOI.matches(l.dOI)
does not - because the former has a rule defined and the latter does not! Consequently, the latter never invokes the TDOI rule because no matching rule exists. One workaround is to copy-paste the rule such that it is symmetrical for both the left and right model, as demonstrated in the attached script.

Thanks,
Sina
Re: ECL comparision on collections [message #1795833 is a reply to message #1795826] Sun, 30 September 2018 16:10 Go to previous messageGo to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Hi Sina,
you are right, I haven't thought about this aspect. Thanks !

I'm now coming back to my initial question related to the possibility to detect differences between two collections (e-g- our TDOI) not considering the order of the collection.

I've exchanged the order of two model elements in "Left.model" that now differs from "Right.model" only for the order but not for the content as a whole.
Changing the instruction
l.dOI.matches(r.dOI).println();
to
l.dOI.asBag().matches(r.dOI.asBag()).println();
I expexted that the two models as Bags continue to matching, instead I get false.
I'm attaching a new project version.

More in general I'd like to compare two xml files and detect the additional elements that the right model have respect to Left and the opposite, without considering the order.
May be what I'm trying isn't the best, could you suggest a way for this objective ?

Many thanks,
Gianluigi
  • Attachment: test-ecl.zip
    (Size: 8.55KB, Downloaded 126 times)
Re: ECL comparision on collections [message #1795854 is a reply to message #1795833] Mon, 01 October 2018 12:04 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

I understand your problem now and I cannot think of any way to do this currently. Perhaps we may need to implement an unordered variant of the "matches" operation to make this easier, unless someone else has an alternative suggestion.

Thanks,
Sina
Re: ECL comparision on collections [message #1795858 is a reply to message #1795854] Mon, 01 October 2018 12:31 Go to previous messageGo to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Hi Sina,
thanks for your answer.
If I correctly interpret the below section of the epsilon book (page 128), it seems that this functionality should be already available:
In addition to objects, the matches operations can also be invoked to match pairs of collections of the same type (e.g. a Sequence against a Sequence). When invoked on ordered collections (i.e. Sequence and OrderedSet), it examines if the collections have the same size and each item of the source collection matches with the item of the same index in the target collection. Finally, when invoked on unordered collections (i.e. Bag and Set), it examines if for each item in the source collection, there is a matching item in the target collection irrespective of its index.

I've also search for someone that already implement this approach but without any result.
Thanks,
Gianluigi
Re: ECL comparision on collections [message #1795868 is a reply to message #1795858] Mon, 01 October 2018 13:55 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

Thank you for finding this in the book. Looking at the source code (and judging by the results of the example you provided), it appears that such semantics are not implemented correctly, or are not behaving according to your expectations in this particular example. If Dimitris also agrees, we can report this as a bug and fix it.

Thanks,
Sina
Re: ECL comparision on collections [message #1796690 is a reply to message #1795868] Wed, 17 October 2018 16:15 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

Just to let you know that this problem (Bug 539740) has (probably) been resolved now. Thanks for reminding us of this, it appears that this problem was also reported in 2014 in Bug 431620. If you update your Epsilon to the latest interim, it should now be working. However there is a performance hit because the algorithm is O(n^2) for unoredered collections rather than O(n). I will be working on improving this soon.


Thanks,
Sina
Re: ECL comparision on collections [message #1796718 is a reply to message #1796690] Thu, 18 October 2018 05:52 Go to previous messageGo to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Hi Sina,
with the updated interim version things work correctly.
Thank you very much for your support.
Gianluigi
Re: ECL comparision on collections [message #1796922 is a reply to message #1796718] Mon, 22 October 2018 10:18 Go to previous messageGo to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Hi Sina,
In the attached modified "test-ECL-1" example I added in the compare section of "rule TAnyLN"
"and l.dOI.asBag().matches(r.dOI.asBag())" in order to consider for the TLN matching also the TDOI instances value.
Now if I change one the value of the "access" attribute in a DOI instance of the Right.model, I corretly get a no match condition for TLN, but isn't easy to find the TDOI instance that cause it.
The only way I see is to remove the @lazy from "rule TDOI_lr", but for large models this could cause long execution time.
Have you any suggestion about it ?
Thanks
Gianluigi
Re: ECL comparision on collections [message #1797056 is a reply to message #1796922] Wed, 24 October 2018 14:34 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

I'm not sure if I understand the problem. Both matching and non-matching rules should be in the match trace. You could perhaps do the following:
System.context.matchTrace.getMatches().reject(m | m.isMatching()).println();
if that would help.

Thanks,
Sina
Re: ECL comparision on collections [message #1797142 is a reply to message #1797056] Fri, 26 October 2018 08:37 Go to previous messageGo to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Hi Sina,
I'll try to better explain my question.

The "post" section in the example print only 1 match that is related to "the rule TLN"
Match:true - TLN [any=[], anyAttribute=[], desc=, text=text, text1=text1] <-> TLN [any=[], anyAttribute=[], desc=, text=text, text1=text1]
and I haven't any information about the matches of TDOI objects taht are implicitly evaluated for the validation of TLN object (by the "TAnyLN rule").

So it seems that if I didn't remove the @lazy from the "rule TDOI_lr" I haven't any match related to the TDOI class to analyze.
But if I remove the lazy option, I need to analyze all the TDOI instances and not only the ones that TLN refers to.

Thanks,
Gianluigi
Re: ECL comparision on collections [message #1797187 is a reply to message #1797142] Sat, 27 October 2018 10:38 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

The simplest solutions would be to place the "matchInstances" call in your "compare" of TAnyLN instead of the do block. Failing that, you could create a Map in your pre block and add the TLN elements for which the matchInstances on TDOI return false.

Thanks,
Sina
Re: ECL comparision on collections [message #1797188 is a reply to message #1797187] Sat, 27 October 2018 13:03 Go to previous messageGo to next message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
Thanks Sina,
if I well understand the first option suggest to substitute in "rule TAnyLN " the current:
and l.dOI.asBag().matches(r.dOI.asBag())
with
and l.dOI.matches(r.dOI)
This change the matching result of "rule TAnlyLN" from true to false because it evaluates TDOI as an orderedSet instead of a Bag (I have an xml file to analyze where the order shoudn't be considered).
The second option is based on the false TDOI matching result, but I'm able to get them only if I delete the lazy option in "rule TDOI_lr".
Is there any other way to get TDOI false matches if called from other rules ?

Could an "else" option, called when match is false, be added as an alternative to the "do" command ?

Gianluigi
Re: ECL comparision on collections [message #1797189 is a reply to message #1797188] Sat, 27 October 2018 13:07 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Gianluigi,

I believe what you may be looking for is a "nomatch" block, as is present in some other Epsilon languages like EPL. We could look into adding this (might be worth opening an enhancement request on Bugzilla).

Thanks,
Sina
Re: ECL comparision on collections [message #1797192 is a reply to message #1797189] Sat, 27 October 2018 13:28 Go to previous message
Gianluigi Proserpio is currently offline Gianluigi ProserpioFriend
Messages: 30
Registered: November 2015
Member
I've submitted it.
Many thanks,
Gianluigi
Previous Topic:Dealing with Ecore eAnnotation
Next Topic:ETL
Goto Forum:
  


Current Time: Fri Apr 26 11:52:08 GMT 2024

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

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

Back to the top