Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Set MatchEngine ?(Extending GenericMatchEngine)
Set MatchEngine ? [message #671614] Wed, 18 May 2011 13:39 Go to next message
js Missing name is currently offline js Missing name
Messages: 73
Registered: July 2009
Member
I am trying to create my own MatchEngine and use that instead of the default (GenericMatchEngine). I am following this example:

http://pastebin.com/WGKynS3m

So now I have a type:

MyMatchEngine extends GenericMatchEngine {

...

}


But how do I use it? I have tried:

  static boolean isDifferent(EObject left, EObject right) {
    DiffModel diff = null;
    MatchModel match = null;
    Map<String, Object> options = new HashMap<String, Object>();
    // options.put(MatchOptions.OPTION_IGNORE_XMI_ID, new Boolean(true));
    try {

      // MatchEngineRegistry.INSTANCE. blabla

      // Reguires a List<MatchEngineDescriptor> engines..
      IMatchEngineSelector selector = somehow...;
      selector.selectMatchEngine(engines);
      MatchService.setMatchEngineSelector(selector);


      // doContentMatch from current model and down
      match = MatchService.doContentMatch(left, right, options);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
...


any ideas or examples?
Re: Set MatchEngine ? [message #671616 is a reply to message #671614] Wed, 18 May 2011 13:43 Go to previous messageGo to next message
js Missing name is currently offline js Missing name
Messages: 73
Registered: July 2009
Member
Ah looks like I should just call the contentMatch method inherited from the GenricMatcherEngine:

      MyMatcherEngine myEngine = new MyMatcherEngine();
      myEngine.contentMatch(leftObject, rightObject, optionMap)


here is an example if others decide to mess around with this:

http://model-compare-match-engine-playground.eclipselabs.org .codespot.com/svn-history/r85/trunk/org.eclipse.emf.compare. match.playground.tests/src/org/eclipse/emf/compare/match/ind ex/EMFSimilarityMetric.java

[Updated on: Wed, 18 May 2011 13:44]

Report message to a moderator

Re: Set MatchEngine ? [message #671637 is a reply to message #671616] Wed, 18 May 2011 14:35 Go to previous messageGo to next message
js Missing name is currently offline js Missing name
Messages: 73
Registered: July 2009
Member
I now have:

    DiffModel diff = null;
    MatchModel match = null;
    Map<String, Object> options = new HashMap<String, Object>();
    // my own impl. that overrides the isSimilar method.
    MyMatcherEngine myEngine = new MyMatcherEngine();
    match = myEngine.contentMatch(left, right, options);
    diff = DiffService.doDiff(match, false);
    List<DiffElement> differences1 = new ArrayList<DiffElement>(diff.getOwnedElements());
    System.out.println(differences1.size());


Even though I pass two identical EObjects the List<DiffElement> differences1 is not empty (my overridden isSimilar method returns true). Maybe it would be better to write my own DiffEngine instead and override the doDiff method:

public class MyDiffEngine extends GenericDiffEngine {

        @Override
	public DiffModel doDiff(MatchModel match, boolean threeWay) {
              
          

        }
}


Default implementation:

	public DiffModel doDiff(MatchModel match, boolean threeWay) {
		matchCrossReferencer = new EcoreUtil.CrossReferencer(match) {
			private static final long serialVersionUID = 1L;

			/** initializer. */
			{
				crossReference();
			}
		};
		final DiffModel result = DiffFactory.eINSTANCE.createDiffModel();
		result.getLeftRoots().addAll(match.getLeftRoots());
		result.getRightRoots().addAll(match.getRightRoots());
		result.getAncestorRoots().addAll(match.getAncestorRoots());
		DiffGroup diffRoot = null;

		if (threeWay) {
			diffRoot = doDiffThreeWay(match);
		} else {
			diffRoot = doDiffTwoWay(match);
		}
		result.getOwnedElements().add(diffRoot);

		return result;
	}


But whats the point of using emf-compare when I need to write all (override default methods) the match/diff logic myself? Of course I would be able to do something like this:

    MyMatcherEngine myEngine = new MyMatcherEngine();
    match = myEngine.contentMatch(left, right, options);
    
    MyDiffEngine diffEngine = new MyDiffEngine();
    diff  = diffEngine.doDiff(match, false);
    List<DiffElement> differences1 = new ArrayList<DiffElement>(diff.getOwnedElements());
    System.out.println(differences1.size());
   


but I could do that as easily without introducing a dependency on emf-compare.
Re: Set MatchEngine ? [message #671935 is a reply to message #671637] Thu, 19 May 2011 11:54 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Hi,

EMF Compare provides you with a framework that provide generic comparison engines, model loading help, integration with team repositories, the GUI integrated with the "classic" "compare with" actions of Eclipse... Many of these generic algorithms can be extended. Whether you wish to re-use some of the provided generic algorithms for your own comparison engine really is your call.

As for "how to provide your own engine", it depends on whether you call your code from and Eclipse plugin or from standalone code. If you call it from an Eclipse plugin, use the extension point org.eclipse.emf.compare.match.engine (and similarly for the diff engine, org.eclipse.emf.compare.diff.engine). If you call it from standalone code, then indeed calling the engines themselves like you did here is the way.

Laurent Goubet
Obeo
Previous Topic:[EMF4Net] Proposal
Next Topic:[EEF] Custom Toolkit Widgets
Goto Forum:
  


Current Time: Sat Oct 25 04:21:27 GMT 2014

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

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