Writing your own Matcher in Java with Eclipse
From AgreementMakerWiki
Contents |
Purpose
- This tutorial serves as an introduction to developing ontology matching algorithms for use with the AgreementMaker system. The development is done in the Java language, using Eclipse as the IDE.
- Eclipse is a Java IDE (but it is not limited to Java). I recommend it highly: http://www.eclipse.org/. If you don't already have Eclipse, I recommend downloading the Helios release, since it comes prepackaged with many plugins.
Run AgreementMaker from Eclipse
Download
- Download AgreementMaker and unzip the archive somewhere on your hard drive. I will unzip the archive to my Desktop.
Create Project
- Start up Eclipse. You can use your existing workspace, or you can make a new workspace if you desire. Create a new Java project in your workspace, named whatever you want.
Import AgreementMaker
- Ok, now we need to import AgreementMaker into our project. Right click on the project in the Package view and click Import.
- Then, select "File System" from the General folder in the Import dialog. Click next.
- On the next dialog screen, click "Browse" and browse to the folder where you unzipped AgreementMaker and click ok to select that folder. On the left hand list, check all the subdirectories, and on the right hand list, check AgreementMaker.jar.
Add AgreementMaker to the Buildpath
- Ok, now we have to add AgreementMaker.jar to the buildpath.
- Right click the project in the Package view, and go to Build Path -> Configure Build Path...
- In the Build Path dialog, click the Libraries tab, and then click the "Add JARs..." button.
- Find the AgreementMaker.jar in your current project, and click Ok. Click Ok on the Build Path dialog also.
Run Configuration
- Now that we have the buildpath setup, we have to setup a Run Configuration for AgreementMaker.
- In the top menu bar, click Run -> Run Configurations ..
- In the Run Configurations dialog, right click the "Java Application" item from the left, and click New. This will create a new configuration.
- Rename the configuration to "AgreementMaker", and set the Main class to "am.Main".
- Now, we need to give Java some more memory space. Click the Arguments tab, and in the "VM arguments:" textbox enter "-Xmx2048m" to increase the heap space to 2gb. If your computer does not have enough memory, decrease the "-Xmx2048m" argument. For example, to reserve 1 GB instead of 2 GB, you would use "-Xmx1024m".
- Click the Apply button to save your changes (it is just above the Run button). If you do not click Apply, your Run Configuration will not be created properly.
- Now click Run. AgreementMaker should start up.
Creating your matcher class
Java Packages
- We will create two new Java packages in your project src. Right click "src" and go to New -> Package. The first package we will create will be "am.extension".
- Repeat the package creation and create a second package named "am.app.mappingEngine".
- Now, I have linked the code for a simple matcher here. Use this matcher as a barebones for your matcher: File:MyMatcher.java. Import this file into your project.
- Note that MyMatcher extends AbstractMatcher. Every matcher in AgreementMaker extends the AbstractMatcher class.
Matchers Registry
- AgreementMaker uses a static enum as a list for all the matching algorithms in the program: File:MatchersRegistry.java. You must import this MatchersRegistry.java into your project in order to edit the list and add your matcher and also to override the MatchersRegistry that comes in AgreementMaker.jar. The file I linked here already has "MyMatcher" added. Import this file into your project also.
- Please note that if you are using the Student Edition you must remove the import lines and also references to the matchers that have not been included with your version. I have included the edited file here: File:MatchersRegistry-se.java.
- To double check that your code is working with AgreementMaker, click the Run button
in Eclipse to start AgreementMaker. Then check to see that "My Custom Matcher" is shown as the first entry in the "Matcher:" dropdown box in the "Matchings Control Panel" at the bottom of the AgreementMaker window.
Running your matcher
- Before you can run your matcher, you need to load two ontologies. From the AgreementMaker View menu, select "Show Label" and "Show Localname" (both should be checked). You can load any of the ontologies distributed with AgreementMaker. I loaded the OAEI Anatomy Track Ontologies: the mouse anatomy as the source ontology, and the human anatomy as the target ontology.
- To run your matcher, select your matcher from the dropdown list (it should be already selected) and click the "Match!" button. The matcher will run on the concepts in both ontologies in a double nested loop fashion, calling alignTwoNodes() for every source concept with every target concept.
- Since your matcher does not return any Alignment objects, it finds no alignments.
Conclusion
Thank you for your time, I hope this has been a good introduction to creating your own matching algorithm to work with AgreementMaker.
