Changes between Initial Version and Version 1 of howto_code_basic


Ignore:
Timestamp:
05/22/06 12:09:53 (18 years ago)
Author:
endres
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • howto_code_basic

    v1 v1  
     1= Code Examples = 
     2The following snippet demonstrates the simple use of the the PhaseLibs by performing the three main tasks 
     3 * Instantiate two OntologyAdapters to access ontology data 
     4 * Create a SimilarityMeasure object, capable of measuring distances between the elements of the ontologies. 
     5 * Create an AlignmentGenerator object that will perform an ontology alignment on the given two ontologies. 
     6 
     7The snippet's purpose is to demonstrate the general usage of the PhaseLibs, but it should, nevertheless, be executable. 
     8 
     9{{{ 
     10// We want to align two ontologies 
     11Ontology o1, o2; 
     12 
     13// Please note, that the constructors are adapter dependent 
     14         
     15// first: instantiate o1, the dublin core metadata types ontology  
     16o1 = new de.dfki.km.phaselib.adapters.rdfsJena.RDFSJenaOntology(DCT_URI, DCT_URI.toURL().openStream()); 
     17 
     18// second: a custom OWL-ontology 
     19o2 = new de.dfki.km.phaselib.adapters.owl.OntologyAdapter(MYFILE_URI); 
     20 
     21// now we need a measure. in this case we use a simple 3-gram measure 
     22SimilarityMeasure measure = new StringBasedSimilarity(); 
     23 
     24// we can now either use the measure to calculate the distance between some classes: 
     25SimilarityMatrix distances = measure.calcSimilarities(o1.getAllClasses(), o2.getAllClasses()); 
     26System.out.println(distances.getSortedNonzeroEntries()); 
     27 
     28 
     29// ... or we can use an AlignmentGenerator to calculate an alignment between the ontologies. 
     30AlignmentGenerator generator; 
     31 
     32// in this case a simple generator using the measure above will do: 
     33generator = new de.dfki.km.phaselib.impl.alignments.SimpleEvidenceAlignment(new StringBasedSimilarity()); 
     34//  (We could have used the measure instatiated above, but to show that these two tasks are  
     35//     completely independet, we have created a new measure instance.) 
     36 
     37// since AlignmentGenerators can only augment existing alignments, we have 
     38//  to create an empty alignment 
     39Alignment emptyAlignment = new AlignmentImpl(o1, o2); 
     40 
     41// we might also set some options 
     42HashMap<String, Object> options = new HashMap<String, Object>(); 
     43options.put(SimpleEvidenceAlignment.PARAM_THRESHOLD, 0.3d); 
     44         
     45// now we can let it generate an alignment 
     46Alignment generatedAlignment = generator.generateAlignment(emptyAlignment, options); 
     47System.out.println(generatedAlignment); 
     48}}}