Calling AgreementMaker Matchers from your own code
From AgreementMakerWiki
Contents |
Purpose
- This tutorial is meant for integrating AgreementMaker matching algorithms into your own Java code.
Overview
- Every matching algorithm in AgreementMaker (called a matcher) extends the AbstractMatcher class.
- Every matching algorithm is listed in the MatchersRegistry enumeration.
- In order to instantiate a matcher, you need to call the static getMatcherInstance method of the MatcherFactory class, passing in one of the values of the MatchersRegistry enumeration.
- After instantiating a matcher, you have to set the parameters of that matcher. The matcher parameters are represented by the AbstractParameters class, and every matcher extends this class in order to add matcher specific parameter fields.
- Parameters to set include source and target ontologies, source and target cardinality, selection threshold, and any other matcher specific parameters.
- To set the source and target ontologies, they must be read in via the OntoTreeBuilder class (only for OWL ontologies), which returns an Ontology object.
Example Code
This example code will load two ontologies, instantiate the Advanced Similarity Matcher (ASM), set the ASM parameters, match the two ontologies, and finally output the alignment in OAEI format.
package am.extension;
import am.GlobalStaticVariables;
import am.app.mappingEngine.AbstractMatcher;
import am.app.mappingEngine.MatcherFactory;
import am.app.mappingEngine.MatchersRegistry;
import am.app.mappingEngine.baseSimilarity.advancedSimilarity.AdvancedSimilarityParameters;
import am.app.ontology.Ontology;
import am.app.ontology.ontologyParser.OntoTreeBuilder;
import am.output.AlignmentOutput;
public class MyMain {
public static void main(String args[]) {
// Step 1. Load my ontologies.
String sourceOntFile = "/home/cosmin/Desktop/Ontologies/SourceOntology.owl";
String targetOntFile = "/home/cosmin/Desktop/Ontologies/TargetOntology.owl";
Ontology sourceOntology = readOntology(sourceOntFile);
Ontology targetOntology = readOntology(targetOntFile);
// Step 2. Instantiate the Advanced Similarity Matcher.
MatchersRegistry mrASM = MatchersRegistry.AdvancedSimilarity;
AbstractMatcher asm = MatcherFactory.getMatcherInstance(mrASM, 0);
// Step 3. Set the parameters for the matcher.
AdvancedSimilarityParameters asmp = new AdvancedSimilarityParameters();
asmp.threshold = 0.75; // set the threshold
asmp.maxSourceAlign = 1; // set the source cardinality
asmp.maxTargetAlign = 1; // set the target cardinality
asm.setParam(asmp); // set the matcher parameters
asm.setSourceOntology(sourceOntology); // set the source ontology for the matcher
asm.setTargetOntology(targetOntology); // set the target ontology for the matcher
// Step 4. Align the ontologies.
try {
asm.match();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
// Step 5. Save the alignment.
try {
String alignmentFilename = "/home/cosmin/Desktop/Ontologies/source-target-alignment.rdf";
AlignmentOutput output = new AlignmentOutput(asm.getAlignment(), alignmentFilename);
String sourceUri = sourceOntology.getURI();
String targetUri = targetOntology.getURI();
output.write(sourceUri, targetUri, sourceUri, targetUri, asm.getName());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
/**
* Method to read in an OWL ontology.
* @param sourceOntFile Path of the OWL ontology file.
* @return Ontology data structure.
*/
private static Ontology readOntology(String sourceOntFile) {
OntoTreeBuilder ontoBuilder = new OntoTreeBuilder( sourceOntFile,
Ontology.SOURCE, GlobalStaticVariables.LANG_OWL,
GlobalStaticVariables.SYNTAX_RDFXML,
false, false);
ontoBuilder.build(OntoTreeBuilder.Profile.noReasoner); // read in the ontology file, create the Ontology object.
return ontoBuilder.getOntology();
}
}
Matchers and their classes
In general, looking at the classes extending AbstractMatcher will show all the matchers available in AgreementMaker, and looking at the classes extending AbstractParameters will show their parameters class.
Below are two of the matchers in AgreementMaker and their related classes.
| Matcher | Matcher Class | Matcher Registry | Parameters Class | Parameters Panel |
| Advanced Similarity Matcher | AdvancedSimilarityMatcher | AdvancedSimilarity | AdvancedSimilarityParameters | AdvancedSimilarityMatcherParametersPanel |
| Parametric String Matcher | ParametricStringMatcher | ParametricString | ParametricStringParameters | ParametricStringParametersPanel |