diff --git a/src/fr/inrialpes/exmo/align/gen/ArbitraryTest.java b/src/fr/inrialpes/exmo/align/gen/ArbitraryTest.java index d4d10cf1fc7cbab740f0376bdd3535423397e314..bcb870d0d23fd64a4cf0af666f3179b2dfa11ddd 100644 --- a/src/fr/inrialpes/exmo/align/gen/ArbitraryTest.java +++ b/src/fr/inrialpes/exmo/align/gen/ArbitraryTest.java @@ -1,5 +1,5 @@ /* - * $Id: ArbitraryTest.java$ + * $Id$ * * Copyright (C) 2011, INRIA * @@ -21,6 +21,8 @@ /* * Generates an arbitrary test. + * The days of this class are counted: it is highly redundant with the first part of + * GenerateBenchmark and should be merged with TestGenerator. */ package fr.inrialpes.exmo.align.gen; @@ -28,6 +30,14 @@ package fr.inrialpes.exmo.align.gen; //Java classes import java.io.FileOutputStream; import java.io.InputStream; +import java.io.File; +import java.io.OutputStreamWriter; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.nio.charset.Charset; +import java.util.Properties; //Jena API classes import com.hp.hpl.jena.ontology.OntModel; @@ -38,97 +48,44 @@ import com.hp.hpl.jena.util.FileManager; // Alignment API implementation classes import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; -import java.io.File; -import java.io.OutputStreamWriter; -import java.nio.charset.Charset; -import java.util.Properties; import fr.inrialpes.exmo.ontowrap.jena25.JENAOntology; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; + import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentVisitor; public class ArbitraryTest { - private String fileName; //the initial file - private String testNumber; //the test number - private String [] params; //vector to build the parameters - private Properties parameters; //the parameters + //private String fileName; //the initial file + //private String testNumber; //the test number + //private Properties parameters; //the parameters public final String namespace = "http://oaei.ontologymatching.org/2011/gen/"; //constructor - public ArbitraryTest(String fileName, String testNumber, String [] params) { - this.fileName = fileName; - this.testNumber = testNumber; - this.params = params; - } - - //build the parameters - public void buildParameters() { - parameters = new Properties(); //initialize the parameters - - for ( int i=0; i<params.length; i+=2 ) { - if ( params[i].equals("addClasses") ) /* add percentage classes */ - parameters.setProperty(ParametersIds.ADD_CLASSES, params[i+1]); - - if ( params[i].equals("addProperties") ) /* add percentage properties */ - parameters.setProperty(ParametersIds.ADD_PROPERTIES, params[i+1]); - - //add c classes beginning from level l -> the value of this parameters should be: - //beginning_level.number_of_classes_to_add - if ( params[i].equals("addClassesLevel") ) /* add c classes beginning from level l */ - parameters.setProperty(ParametersIds.ADD_CLASSES, params[i+1]); - - if ( params[i].equals("removeClasses") ) /* remove percentage classes */ - parameters.setProperty(ParametersIds.REMOVE_CLASSES, params[i+1]); - - if ( params[i].equals("removeProperties") ) /* remove percentage properties */ - parameters.setProperty(ParametersIds.REMOVE_PROPERTIES, params[i+1]); - - if ( params[i].equals("removeComments") ) /* remove percentage comments */ - parameters.setProperty(ParametersIds.REMOVE_COMMENTS, params[i+1]); - - if ( params[i].equals("removeRestrictions") ) /* remove percentage restrictions */ - parameters.setProperty(ParametersIds.REMOVE_RESTRICTIONS, params[i+1]); - - if ( params[i].equals("removeIndividuals") ) /* remove percentage individuals */ - parameters.setProperty(ParametersIds.REMOVE_INDIVIDUALS, params[i+1]); - - if ( params[i].equals("renameClasses") ) /* rename percentage classes */ - parameters.setProperty(ParametersIds.RENAME_CLASSES, params[i+1]); - - if ( params[i].equals("renameProperties") ) /* rename percentage properties */ - parameters.setProperty(ParametersIds.RENAME_PROPERTIES, params[i+1]); - - if ( params[i].equals("levelFlattened") ) /* flattened level */ - parameters.setProperty(ParametersIds.LEVEL_FLATTENED, params[i+1]); - - if ( params[i].equals( ("noHierarchy")) ) /* no hierarchy */ - parameters.setProperty( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY); - } + public ArbitraryTest() { + //this.fileName = fileName; + //this.testNumber = testNumber; + //parameters = params; } //get the prefix to build the namespace - public String getPrefix(String fileName) { + public String getPrefix( String fileName ) { return fileName.substring(0, fileName.lastIndexOf(".")); } //get the uri - public String getURI(String fileName, String testNumber) { - return this.namespace + this.getPrefix(fileName) + "/" + testNumber + "/" + fileName + "#"; + public String getURI( String fileName, String testNumber ) { + return this.namespace + getPrefix(fileName) + "/" + testNumber + "/" + fileName + "#"; } //load ontology - public OntModel loadOntology (String fileName) { + public OntModel loadOntology ( String fileName ) { InputStream in = FileManager.get().open( fileName ); OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); - model.read(in, null); + model.read( in, null ); return model; } //write ontology - public static void writeOntology(OntModel model, String destFile, String ns) { + public static void writeOntology( OntModel model, String destFile, String ns ) { try { File f = new File(destFile); FileOutputStream fout = new FileOutputStream(f); @@ -143,28 +100,29 @@ public class ArbitraryTest { writer.write(model.getBaseModel(), new OutputStreamWriter(fout, defaultCharset), ""); fout.close(); } catch (Exception ex) { - System.out.println("Exception " + ex.getMessage()); + System.err.println("Exception " + ex.getMessage()); } } + // JE: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> THE REAL STUFF + + // JE: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> WE SHOULD HAVE INCREMENTAL HERE IN THE SAME WAY! //modify ontology - public void modifyOntology(){ - //build the list of parameters - this.buildParameters(); + public void modifyOntology( String fileName, String testNumber, Properties params ) { //modify the model try { OntModel model = loadOntology(fileName); //load the initial ontology - TestGenerator t = new TestGenerator(); //build an instance of TestGenerator JENAOntology onto = new JENAOntology(); //cast the model into Ontology onto.setOntology( (OntModel)model ); //set the TestGenerator ontology + TestGenerator t = new TestGenerator(); //build an instance of TestGenerator t.setOntology(onto); //set the namespace - t.setNamespace( this.getURI(this.fileName, this.testNumber) ); + t.setNamespace( getURI( fileName, testNumber) ); //t.setNamespace( "http://oaei.ontologymatching.org/2011/gen/onto/101/onto.rdf#" ); - Alignment align = t.generate(onto, parameters); //generate the alignment + Alignment align = t.generate( onto, params ); //generate the alignment JENAOntology modified = (JENAOntology)t.getModifiedOntology(); //get the modified ontology @@ -172,13 +130,13 @@ public class ArbitraryTest { //build the directory to save the file boolean create; create = new File(testNumber).mkdir(); - if ( create ) System.out.println(" Succesufully created the directory "); - else System.out.println(" Error creating the directory "); + if ( create ) System.err.println(" Succesufully created the directory "); + else System.err.println(" Error creating the directory "); //new File(testNumber).mkdir(); //write the ontology into the directory if ( modified.getOntology() instanceof OntModel ) - writeOntology(modified.getOntology(), testNumber + "/" + fileName, this.getURI(this.fileName, this.testNumber)); //write the ontology + writeOntology(modified.getOntology(), testNumber + "/" + fileName, getURI( fileName, testNumber )); //write the ontology //write the alignment into the directory OutputStream stream = new FileOutputStream( testNumber + "/" + "refalign.rdf" ); // Outputing @@ -194,9 +152,9 @@ public class ArbitraryTest { System.err.println( "Error " + ex.getMessage() ); } - System.out.println( "***" ); - System.out.println( "END" ); - System.out.println( "***" ); + System.err.println( "***" ); + System.err.println( "END" ); + System.err.println( "***" ); } diff --git a/src/fr/inrialpes/exmo/align/gen/ClassHierarchy.java b/src/fr/inrialpes/exmo/align/gen/ClassHierarchy.java index 24133504d17a9604633ab309c19bdca06714c4f5..4435024b0f069436e3a0c702995427854cb36d8c 100644 --- a/src/fr/inrialpes/exmo/align/gen/ClassHierarchy.java +++ b/src/fr/inrialpes/exmo/align/gen/ClassHierarchy.java @@ -1,5 +1,5 @@ /* - * $Id: ClassHierarchy.java$ + * $Id$ * * Copyright (C) 2011, INRIA * @@ -127,7 +127,6 @@ public class ClassHierarchy { //modifies the class hierarchy after we have flattened it public boolean flattenClassHierarchy ( OntModel model, int level, ArrayList<OntClass> childClasses, ArrayList<OntClass> parentClasses, ArrayList<OntClass> superLevelClasses) { - List<URITree> childrenNodes = getNodesFromLevel( level ); URITree parentNode = null; diff --git a/src/fr/inrialpes/exmo/align/gen/GenerateBenchmark.java b/src/fr/inrialpes/exmo/align/gen/GenerateBenchmark.java index ba56ec13f5125b6b44cbd513c62a32a040239674..e6d9f0f780d0bd7cfed520f1a4e44226cc62a0ff 100644 --- a/src/fr/inrialpes/exmo/align/gen/GenerateBenchmark.java +++ b/src/fr/inrialpes/exmo/align/gen/GenerateBenchmark.java @@ -1,5 +1,5 @@ /* - * $Id: GenerateBenchmark.java$ + * $Id$ * * Copyright (C) 2011, INRIA * @@ -20,7 +20,11 @@ */ /* - * Generates the Benchmark dataset. + * Generates the OAEI Benchmark dataset from an ontology + * It can generate it in a continuous way (each test build on top of a previous one) + * or generate tests independently. + * + * Variations can also be obtained. */ package fr.inrialpes.exmo.align.gen; @@ -28,6 +32,14 @@ package fr.inrialpes.exmo.align.gen; //Java classes import java.io.FileOutputStream; import java.io.InputStream; +import java.io.File; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; +import java.util.Properties; //Jena API classes import com.hp.hpl.jena.ontology.OntModel; @@ -38,506 +50,345 @@ import com.hp.hpl.jena.util.FileManager; // Alignment API implementation classes import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; -import java.io.File; -import java.io.OutputStreamWriter; -import java.nio.charset.Charset; -import java.util.Properties; import fr.inrialpes.exmo.ontowrap.jena25.JENAOntology; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; + import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentVisitor; public class GenerateBenchmark { + private String urlprefix = "http://example.com/"; // Prefix (before testnumber) of test URL + private String dirprefix = ""; // Prefix (idem) of directory + private String filename = "onto.rdf"; // name of ontology to generate + private String alignname = "refalign.rdf"; // name of alignment to generate + private String fileName; //the initial file - private String testNumber; //the test number + //private String testNumber; //the test number private Properties parameters; //the parameters public final String namespace = "http://oaei.ontologymatching.org/2011/gen/"; + private TestGenerator generator; //build an instance of TestGenerator + private boolean debug = false; + + static String FULL = "1.0f"; //constructor - public GenerateBenchmark(String fileName) { + public GenerateBenchmark( String fileName ) { this.fileName = fileName; + generator = new TestGenerator(); } - //gets the prefix to build the namespace - public String getPrefix(String fileName) { - return fileName.substring(0, fileName.lastIndexOf(".")); + //gets the URI + public String getURI( String testNumber ) { + return urlprefix + "/" + testNumber + "/" + filename + "#"; // Do not like this #... + //return urlprefix + getPrefix(fileName) + "/" + testNumber + "/" + fileName + "#"; } - //gets the uri - public String getURI(String fileName, String testNumber) { - return this.namespace + this.getPrefix(fileName) + "/" + testNumber + "/" + fileName + "#"; + private String directoryName( String dir, String suffix ) { + if ( suffix == null ) return dir; + else return dir+"-"+suffix; } //loads ontology - public OntModel loadOntology (String fileName) { - InputStream in = FileManager.get().open( fileName ); + public OntModel loadOntology ( String file ) { + InputStream in = FileManager.get().open( file ); OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); - model.read(in, null); + model.read( in, null ); return model; } //writes ontology - public static void writeOntology(OntModel model, String destFile, String ns) { + public static void writeOntology( OntModel model, String destFile, String ns ) { try { - File f = new File(destFile); - FileOutputStream fout = new FileOutputStream(f); + File f = new File( destFile ); + FileOutputStream fout = new FileOutputStream( f ); Charset defaultCharset = Charset.forName("UTF8"); RDFWriter writer = model.getWriter("RDF/XML-ABBREV"); - writer.setProperty("showXmlDeclaration","true"); - model.setNsPrefix("", ns); - + writer.setProperty( "showXmlDeclaration","true" ); + model.setNsPrefix( "", ns ); model.createOntology(ns); writer.setProperty( "xmlbase", ns ); writer.write(model.getBaseModel(), new OutputStreamWriter(fout, defaultCharset), ""); fout.close(); } catch (Exception ex) { - System.out.println("Exception " + ex.getMessage()); + ex.printStackTrace(); } } - - //modifies an ontology - public void modifyOntology(TestGenerator t, String fileName, String testNumber, Properties params) { - //modify the model - try { - - System.out.println("From test " + fileName); - System.out.println("Test " + testNumber); - OntModel model = loadOntology(fileName); //load the initial ontology - JENAOntology onto = new JENAOntology(); //cast the model into Ontology - onto.setOntology( (OntModel)model ); - //set the TestGenerator ontology - t.setOntology(onto); - //set the namespace - t.setNamespace( this.getURI(this.fileName, testNumber) ); - //t.setNamespace( "http://oaei.ontologymatching.org/2011/gen/onto/101/onto.rdf#" ); - - Alignment align = null; - if ( fileName.equals(this.fileName) ) - align = t.generate(onto, params); //generate the alignment - else - align = t.generate(onto, params, this.parameters); //generate the alignment - - JENAOntology modified = (JENAOntology)t.getModifiedOntology(); //get the modified ontology - - //build the directory to save the file - boolean create; - create = new File(testNumber).mkdir(); - /* if ( create ) System.out.println(" Succesufully created the directory "); - else System.out.println(" Error creating the directory "); */ - - //write the ontology into the directory - if ( modified.getOntology() instanceof OntModel ) - writeOntology(modified.getOntology(), testNumber + "/" + this.fileName, this.getURI( this.fileName, testNumber)); //write the ontology - - //write the alignment into the directory - OutputStream stream = new FileOutputStream( testNumber + "/" + "refalign.rdf" ); - // Outputing - PrintWriter writer = new PrintWriter ( - new BufferedWriter( - new OutputStreamWriter( stream, "UTF-8" )), true); - AlignmentVisitor renderer = new RDFRendererVisitor( writer ); - align.render(renderer); - writer.flush(); - writer.close(); - - //retrieve the parameters - this.parameters = t.getParameters(); - + private void outputTestDirectory( JENAOntology onto, Alignment align, String testnumber, Properties params ) { + // build the directory to save the file + boolean create = new File( dirprefix+"/"+testnumber ).mkdir(); + /* if ( create ) System.err.println(" Succesufully created the directory "); + else System.err.println(" Error creating the directory "); */ + + // write the ontology into the directory + if ( onto.getOntology() instanceof OntModel ) + writeOntology( onto.getOntology(), dirprefix+"/"+testnumber+"/"+filename, getURI( testnumber )); + + try { + //write the alignment into the directory + OutputStream stream = new FileOutputStream( dirprefix+"/"+testnumber+"/"+alignname ); + // Outputing + PrintWriter writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( stream, "UTF-8" )), true); + AlignmentVisitor renderer = new RDFRendererVisitor( writer ); + align.render( renderer ); + writer.flush(); + writer.close(); + } catch ( Exception ex ) { + ex.printStackTrace(); } - catch ( Exception ex ) { - System.err.println( "Error " + ex.getMessage() ); - } - } - public String directoryName(float i1, String dir) { - String dirName = ""; - if ( ((Float)i1).toString().substring(0, 1).equals("0") ) { - dirName = dir + "-" + ((Float)i1).toString().substring(2, 3); - } - else { - dirName = dir; - } + //modifies an ontology + public Properties modifyOntology( String file, String testNumber, Properties params) { + System.err.println( "Source: "+file+" generate "+testNumber ); + //modify the model + if ( debug ) System.err.println( "From test " + file ); + if ( debug ) System.err.println( "Test " + testNumber ); + OntModel model = loadOntology( file ); //load the initial ontology + JENAOntology onto = new JENAOntology(); //cast the model into Ontology + onto.setOntology( (OntModel)model ); + //set the TestGenerator ontology + generator.setOntology( onto ); + //set the namespace + generator.setNamespace( getURI( testNumber ) ); + Alignment align = null; + if ( file.equals(this.fileName) ) // JE: In my opinion this test is tricky... (and all should be in params) + align = generator.generate( onto, params ); //generate the alignment + else + align = generator.generate( onto, params, parameters ); //generate the alignment + + JENAOntology modified = (JENAOntology)generator.getModifiedOntology(); //get the modified ontology + + outputTestDirectory( modified, align, testNumber, params ); + //retrieve the parameters + //parameters = generator.getParameters(); + return generator.getParameters(); + } - return dirName; + //modifies an ontology from an existing test + public Properties incrementModifyOntology( String pKey, String pVal, String suffix, String prevTest, String testNb ) { + Properties p = new Properties(); + p.setProperty( pKey, pVal ); + String prevDirName = directoryName( prevTest, suffix ); + String crtDirName = directoryName( testNb, suffix ); + return modifyOntology( dirprefix+"/"+prevDirName+"/"+this.fileName, crtDirName, p ); } + //generates the Benchmark - public void generate() { + public void generate( Properties params ) { + // Process params + if ( params.getProperty( "urlprefix" ) != null ) urlprefix = params.getProperty( "urlprefix" ); + if ( params.getProperty( "outdir" )!= null ) dirprefix = params.getProperty( "outdir" ); + if ( params.getProperty( "filename" ) != null ) filename = params.getProperty( "filename" ); + if ( params.getProperty( "alignname" ) != null ) alignname = params.getProperty( "alignname" ); + + System.err.println( urlprefix+" / "+dirprefix+" / "+filename+" / "+alignname ); + + //private String testnumber = ""; // will not work if no number... + //testnumber = params.getProperty( "testNumber" ); + //if ( testnumber == null ) + + // JE: All this should have been solved before + + //keep track of the alignment Properties paramsRenameResources; Properties paramsNoComments; Properties paramsNoInstance; Properties paramsNoProperty; Properties paramsFlatten; Properties paramsExpand; Properties paramsInitial; - Properties p = new Properties(); //modify the ontology according to this parameters + Properties p = new Properties(); //modify the ontology according to this parameters + this.parameters = new Properties(); + String prevDirName; String crtDirName; - this.parameters = new Properties(); - crtDirName = this.fileName; - - TestGenerator t = new TestGenerator(); //build an instance of TestGenerator - + String mod = params.getProperty( "modality" ); // "mult" + String hard = params.getProperty( "increment" ); + String max = params.getProperty( "maximum" ); + if ( debug ) System.err.println( " Mod: "+mod+" / Incr: "+hard ); + + String SUFFIX = null; + + // JE : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SO FAR SO GOOD /* * Test 101 + * Here it would be good to change the : */ - this.modifyOntology(t, this.fileName, "101", p); + parameters = modifyOntology( fileName, "101", p ); // JE ~~> The strange thing: it will generate the init + // Because it calls with the "p", this is the second case, + // Where the initial alignment is generated paramsInitial = (Properties)parameters.clone(); paramsRenameResources = (Properties)parameters.clone(); - prevDirName = "101" + "/"; - + prevDirName = "101"+"/"; /* * Tests 201, 202, 248, 249, 253, 258, 259, 250, 254, * 262, 257, 260, 265, 261, 266, 251, 252 */ + // Increment from 20 to 20 + //for ( float i1=0.20f; i1<=1.00f; i1+=0.20f ) { + // Increment from x to remaining + // JE: look at the (Float).toString() below... + boolean multModality = (mod != null && mod.startsWith( "mult" )); + //float i1 = 0.20f; + float i1 = 0.0f; + int maximum = Integer.parseInt( "5" ); + float incr = Float.parseFloat( "0.2" ); + try { + if ( hard != null && !hard.equals("") ) incr = Float.parseFloat( hard ); + } catch ( Exception ex ) { + ex.printStackTrace(); // continue with the default + } + for ( int i = 0; i1 < 1.00f ; i++ ) { // && i < maximum + //System.err.println( " **************************** "+i+": i1 = "+i1 ); + if ( !multModality ) i1 += incr; // traditional + else i1 += (1. - i1) * incr; // hardened + + if ( i1 < 1.0f ) { + SUFFIX = ((Float)i1).toString().substring(2, 3); + } else { + SUFFIX = null; + } + + /* 201-x *** no names */ + // This bootstraps because the 101 has no SUFFIX + p = new Properties(); + p.setProperty( ParametersIds.RENAME_CLASSES, ((Float)i1).toString() ); + p.setProperty( ParametersIds.RENAME_PROPERTIES, ((Float)i1).toString() ); + parameters = modifyOntology( dirprefix+"/"+prevDirName+this.fileName, directoryName( "201", SUFFIX ), p); - for ( float i1=0.20f; i1<=1.00f; i1+=0.20f ) { + /* 202-x *** no names + no comments */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_COMMENTS, FULL, SUFFIX, "201", "202" ); - /* - * 201-x *** no names - */ - p = new Properties(); - p.setProperty(ParametersIds.RENAME_CLASSES, ((Float)i1).toString()); - p.setProperty(ParametersIds.RENAME_PROPERTIES, ((Float)i1).toString()); - crtDirName = directoryName(i1, "201"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 202-x *** no names + no comments - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_COMMENTS, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "201") + "/"; - crtDirName = directoryName(i1, "202"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 248-x *** no names + no comments + no hierarchy - */ - p = new Properties(); - p.setProperty(ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY); - prevDirName = directoryName(i1, "202") + "/"; - crtDirName = directoryName(i1, "248"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 253-x *** no names + no comments + no hierarchy + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "248") + "/"; - crtDirName = directoryName(i1, "253"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 249-x *** no names + no comments + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "202") + "/"; - crtDirName = directoryName(i1, "249"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + /* 248-x *** no names + no comments + no hierarchy */ + parameters = incrementModifyOntology( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY, SUFFIX, "202", "248" ); + + /* 253-x *** no names + no comments + no hierarchy + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "248", "253" ); + + /* 249-x *** no names + no comments + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "202", "249" ); ////get the parameters paramsRenameResources = (Properties)this.parameters.clone(); - /* - * 250-x *** no names + no comments + no property - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_PROPERTIES, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "202") + "/"; - crtDirName = directoryName(i1, "250"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 254-x *** no names + no comments + no property + no hierarchy - */ - p = new Properties(); - p.setProperty(ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY); - prevDirName = directoryName(i1, "250") + "/"; - crtDirName = directoryName(i1, "254"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 262-x *** no names + no comments + no property + no hierarchy + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "254") + "/"; - crtDirName = directoryName(i1, "262"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 257-x *** no names + no comments + no property + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "250") + "/"; - crtDirName = directoryName(i1, "257"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 261-x *** no names + no comments + no property + expand - */ - p = new Properties(); - p.setProperty(ParametersIds.ADD_CLASSES, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "250") + "/"; - crtDirName = directoryName(i1, "261"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 266-x *** no names + no comments + no property + expand + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "261") + "/"; - crtDirName = directoryName(i1, "266"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 260-x *** no names + no comments + no property + flatten - */ - p = new Properties(); - p.setProperty(ParametersIds.LEVEL_FLATTENED, "2"); - prevDirName = directoryName(i1, "250") + "/"; - crtDirName = directoryName(i1, "260"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 265-x *** no names + no comments + no property + flatten + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "260") + "/"; - crtDirName = directoryName(i1, "265"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + /* 250-x *** no names + no comments + no property */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_PROPERTIES, FULL, SUFFIX, "202", "250" ); + + /* 254-x *** no names + no comments + no property + no hierarchy */ + parameters = incrementModifyOntology( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY, SUFFIX, "250", "254" ); + + /* 262-x *** no names + no comments + no property + no hierarchy + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "254", "262" ); + + /* 257-x *** no names + no comments + no property + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "250", "257" ); + + /* 261-x *** no names + no comments + no property + expand */ + parameters = incrementModifyOntology( ParametersIds.ADD_CLASSES, FULL, SUFFIX, "250", "261" ); + + /* 266-x *** no names + no comments + no property + expand + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "261", "266" ); + + /* 260-x *** no names + no comments + no property + flatten */ + parameters = incrementModifyOntology( ParametersIds.LEVEL_FLATTENED, "2", SUFFIX, "250", "260" ); + + /* 265-x *** no names + no comments + no property + flatten + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "260", "265" ); //re-establish the parameters - this.parameters = (Properties)paramsRenameResources.clone(); - - /* - * 251-x *** no names + no comments + flatten - */ - p = new Properties(); - p.setProperty(ParametersIds.LEVEL_FLATTENED, "2"); - prevDirName = directoryName(i1, "202") + "/"; - crtDirName = directoryName(i1, "251"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 258-x *** no names + no comments + flatten + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "251") + "/"; - crtDirName = directoryName(i1, "258"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + parameters = (Properties)paramsRenameResources.clone(); + + /* 251-x *** no names + no comments + flatten */ + parameters = incrementModifyOntology( ParametersIds.LEVEL_FLATTENED, "2", SUFFIX, "202", "251" ); + + /* 258-x *** no names + no comments + flatten + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "251", "258" ); //re-establish the parameters - this.parameters = (Properties)paramsRenameResources.clone(); - - /* - * 252-x *** no names + no comments + expand - */ - p = new Properties(); - p.setProperty(ParametersIds.ADD_CLASSES, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "202") + "/"; - crtDirName = directoryName(i1, "252"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 259-x *** no names + no comments + expand + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(i1, "252") + "/"; - crtDirName = directoryName(i1, "259"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + parameters = (Properties)paramsRenameResources.clone(); + + /* 252-x *** no names + no comments + expand */ + parameters = incrementModifyOntology( ParametersIds.ADD_CLASSES, FULL, SUFFIX, "202", "252" ); + + /* 259-x *** no names + no comments + expand + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "252", "259" ); // paramsNoProperty = modifier.getProperties(); //get the modifed properties - this.parameters = (Properties)paramsRenameResources.clone(); - prevDirName = directoryName(i1, "201") + "/"; + parameters = (Properties)paramsRenameResources.clone(); + prevDirName = directoryName( "201", SUFFIX ) + "/"; } //re-establish the parameters - this.parameters = (Properties)paramsInitial.clone(); + SUFFIX = null; + parameters = (Properties)paramsInitial.clone(); - /* - * Tests 221, 232, 233, 241 - */ + /* Tests 221, 232, 233, 241 */ - /* - * 221 *** no hierarchy - */ - p = new Properties(); - p.setProperty(ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY); - prevDirName = directoryName(1.00f, "101") + "/"; - crtDirName = directoryName(1.00f, "221"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 232 *** no hierarchy + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "221") + "/"; - crtDirName = directoryName(1.00f, "232"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 233 *** no hierarchy + no property - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_PROPERTIES, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "221") + "/"; - crtDirName = directoryName(1.00f, "233"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 241 *** no hierarchy + no property + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "233") + "/"; - crtDirName = directoryName(1.00f, "241"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + /* 221 *** no hierarchy */ + parameters = incrementModifyOntology( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY, SUFFIX, "101", "221" ); + + /* 232 *** no hierarchy + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "221", "232" ); + + /* 233 *** no hierarchy + no property */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_PROPERTIES, FULL, SUFFIX, "221", "233" ); + + /* 241 *** no hierarchy + no property + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "233", "241" ); //re-establish the parameters - this.parameters = (Properties)paramsInitial.clone(); + parameters = (Properties)paramsInitial.clone(); - /* - * Tests 222, 237 - */ + /* Tests 222, 237 */ - /* - * 222 *** flatten - */ - p = new Properties(); - p.setProperty(ParametersIds.LEVEL_FLATTENED, "2"); - prevDirName = directoryName(1.00f, "101") + "/"; - crtDirName = directoryName(1.00f, "222"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 237 *** flatten + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "222") + "/"; - crtDirName = directoryName(1.00f, "237"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + /* 222 *** flatten */ + parameters = incrementModifyOntology( ParametersIds.LEVEL_FLATTENED, "2", SUFFIX, "101", "222" ); + + /* 237 *** flatten + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "222", "237" ); //re-establish the parameters - this.parameters = (Properties)paramsInitial.clone(); + parameters = (Properties)paramsInitial.clone(); - /* - * Tests 223, 238 - */ + /* Tests 223, 238 */ - /* - * 223 *** expand - */ - p = new Properties(); - p.setProperty(ParametersIds.ADD_CLASSES, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "101") + "/"; - crtDirName = directoryName(1.00f, "223"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 238 *** expand + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "223") + "/"; - crtDirName = directoryName(1.00f, "238"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + /* 223 *** expand */ + parameters = incrementModifyOntology( ParametersIds.ADD_CLASSES, FULL, SUFFIX, "101", "223" ); - /* - * 224 *** no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "101") + "/"; - crtDirName = directoryName(1.00f, "224"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + /* 238 *** expand + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "223", "238" ); - /* - * 225 *** no restrictions - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_RESTRICTIONS, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "101") + "/"; - crtDirName = directoryName(1.00f, "225"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + /* 224 *** no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "101", "224" ); - /* - * Tests 228, 239, 246, 236, 240, 247 - */ + /* 225 *** no restrictions */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_RESTRICTIONS, FULL, SUFFIX, "101", "225" ); - /* - * 228 *** no property - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_PROPERTIES, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "101") + "/"; - crtDirName = directoryName(1.00f, "228"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 236 *** no property + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "228") + "/"; - crtDirName = directoryName(1.00f, "236"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 240 *** no property + expand - */ - p = new Properties(); - p.setProperty(ParametersIds.ADD_CLASSES, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "228") + "/"; - crtDirName = directoryName(1.00f, "240"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 247 *** no property + expand + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "240") + "/"; - crtDirName = directoryName(1.00f, "247"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 239 *** no property + flatten - */ - p = new Properties(); - p.setProperty(ParametersIds.LEVEL_FLATTENED, "2"); - prevDirName = directoryName(1.00f, "228") + "/"; - crtDirName = directoryName(1.00f, "239"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); - - /* - * 246 *** no property + flatten + no instance - */ - p = new Properties(); - p.setProperty(ParametersIds.REMOVE_INDIVIDUALS, ((Float)1.00f).toString()); - prevDirName = directoryName(1.00f, "239") + "/"; - crtDirName = directoryName(1.00f, "246"); - this.modifyOntology(t, prevDirName + this.fileName, crtDirName, p); + /* Tests 228, 239, 246, 236, 240, 247 */ - } + /* 228 *** no property */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_PROPERTIES, FULL, SUFFIX, "101", "228" ); + + /* 236 *** no property + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "228", "236" ); + + /* 240 *** no property + expand */ + parameters = incrementModifyOntology( ParametersIds.ADD_CLASSES, FULL, SUFFIX, "228", "240" ); + /* 247 *** no property + expand + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "240", "247" ); + + /* 239 *** no property + flatten */ + parameters = incrementModifyOntology( ParametersIds.LEVEL_FLATTENED, FULL, SUFFIX, "228", "239" ); + + /* 246 *** no property + flatten + no instance */ + parameters = incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "239", "246" ); + } } diff --git a/src/fr/inrialpes/exmo/align/gen/OntologyModifier.java b/src/fr/inrialpes/exmo/align/gen/OntologyModifier.java index dfd800b1e0b2e13dac49cbaf33b5cb727752c474..87bbbbed7666168f67449a63748edba35ef8d433 100644 --- a/src/fr/inrialpes/exmo/align/gen/OntologyModifier.java +++ b/src/fr/inrialpes/exmo/align/gen/OntologyModifier.java @@ -1263,13 +1263,12 @@ public class OntologyModifier { //flatten level - for noHierarchy public void _noHierarchy ( int level ) { + if ( level == 1 ) return; int size; boolean active = false; ArrayList<OntClass> levelClasses = new ArrayList<OntClass>(); //the list of classes from that level ArrayList<OntClass> parentLevelClasses = new ArrayList<OntClass>(); //the list of parent of the child classes from that level ArrayList<OntClass> superLevelClasses = new ArrayList<OntClass>(); //the list of parent of the parent classes from that level - if ( level == 1 ) //no change - return; checkClassHierarchy(); //check if the class hierarchy is built active = this.classHierarchy.flattenClassHierarchy( this.modifiedModel, level, levelClasses, parentLevelClasses, superLevelClasses); size = levelClasses.size(); @@ -1335,7 +1334,7 @@ public class OntologyModifier { for ( OntProperty prop : properties ) //list all properties if ( prop.getNameSpace().equals( this.namespace ) ) this.params.put( prop.getURI() , prop.getURI() ); //add them to the initial alignment - } + } //compute the alignment after the modifications @SuppressWarnings("unchecked") @@ -1541,38 +1540,23 @@ public class OntologyModifier { initializeAlignment(); //determine the elements from the initial reference alignment } - //add percentage classes - if ( name.equals( ParametersIds.ADD_CLASSES ) ) { + + if ( name.equals( ParametersIds.ADD_CLASSES ) ) { //add percentage classes System.out.println( "Add Class" + "[" + value + "]"); addSubClasses( value ); - } - - //remove percentage classes - if ( name.equals( ParametersIds.REMOVE_CLASSES ) ) { + } else if ( name.equals( ParametersIds.REMOVE_CLASSES ) ) { //remove percentage classes System.out.println( "Remove Class" + "[" + value + "]"); removeSubClasses( value ); - } - - //remove percentage comments - if ( name.equals( ParametersIds.REMOVE_COMMENTS ) ) { + } else if ( name.equals( ParametersIds.REMOVE_COMMENTS ) ) { //remove percentage comments System.out.println( "Remove Comments" + "[" + value + "]"); removeComments ( value ); - } - - //remove percentage properties - if ( name.equals( ParametersIds.REMOVE_PROPERTIES ) ) { + } else if ( name.equals( ParametersIds.REMOVE_PROPERTIES ) ) { //remove percentage properties System.out.println( "Remove Property" + "[" + value + "]"); removeProperties ( value ); - } - - //add percentage properties - if ( name.equals( ParametersIds.ADD_PROPERTIES ) ) { + } else if ( name.equals( ParametersIds.ADD_PROPERTIES ) ) { //add percentage properties System.out.println( "Add Property" + "[" + value + "]"); addProperties ( value ); - } - - //recursive add nbClasses starting from level level - if ( name.equals( ParametersIds.ADD_CLASSESLEVEL ) ) { + } else if ( name.equals( ParametersIds.ADD_CLASSESLEVEL ) ) { //recursive add nbClasses starting from level level aux = ((Float)value).toString(); int index = aux.indexOf("."); int level = Integer.valueOf( aux.substring(0, index) ); @@ -1581,49 +1565,28 @@ public class OntologyModifier { System.out.println( "nbClasses " + nbClasses ); float percentage = 1.00f; addClasses ( level, nbClasses, percentage ); - } - - //remove all the classes from the level level - if ( name.equals( ParametersIds.REMOVE_CLASSESLEVEL ) ) { + } else if ( name.equals( ParametersIds.REMOVE_CLASSESLEVEL ) ) { //remove all the classes from the level level System.out.println("Remove all classes from level" + (int)value ); removeClassesFromLevel ( (int)value ); - } - - //flatten a level - if ( name.equals( ParametersIds.LEVEL_FLATTENED ) ) { + } else if ( name.equals( ParametersIds.LEVEL_FLATTENED ) ) { //flatten a level //levelFlattened ( level ); levelFlattened ( (int)value ); System.out.println( "New class hierarchy level " + getMaxLevel() ) ; - } - - //rename classes - if ( name.equals( ParametersIds.RENAME_CLASSES ) ) { + } else if ( name.equals( ParametersIds.RENAME_CLASSES ) ) { //rename classes System.out.println("Rename classes" + "[" + value + "]" ); //System.out.println("\nValue = " + value + "\n"); //activeProperties, activeClasses, .. this.modifiedModel = renameResource ( false, true, value, true, false, false, 0); - } - - //rename properties - if ( name.equals( ParametersIds.RENAME_PROPERTIES ) ) { + } else if ( name.equals( ParametersIds.RENAME_PROPERTIES ) ) { //rename properties System.out.println("Rename properties " + "[" + value + "]" ); //System.out.println("\nValue = " + value + "\n"); //activeProperties, activeClasses, .. this.modifiedModel = renameResource ( true, false, value, true, false, false, 0); - } - - //remove percentage restrictions - if ( name.equals( ParametersIds.REMOVE_RESTRICTIONS ) ) { + } else if ( name.equals( ParametersIds.REMOVE_RESTRICTIONS ) ) { //remove percentage restrictions System.out.println("Remove restrictions" + "[" + value + "]"); removeRestrictions( value ); - } - - //remove percentage individuals - if ( name.equals( ParametersIds.REMOVE_INDIVIDUALS ) ) { + } else if ( name.equals( ParametersIds.REMOVE_INDIVIDUALS ) ) { //remove percentage individuals System.out.println("Remove individuals" + "[" + value + "]"); removeIndividuals( value ); - } - - //no hierarchy - if ( name.equals( ParametersIds.NO_HIERARCHY ) ) { + } else if ( name.equals( ParametersIds.NO_HIERARCHY ) ) { //no hierarchy System.out.println( "NoHierarchy" ); noHierarchy(); } diff --git a/src/fr/inrialpes/exmo/align/gen/ParametersIds.java b/src/fr/inrialpes/exmo/align/gen/ParametersIds.java index 4a8fb4d074610fa733da7b8d50d1539a8b81b8e5..3c2c580c50894fa01edb62a3348c733a9e5186d8 100644 --- a/src/fr/inrialpes/exmo/align/gen/ParametersIds.java +++ b/src/fr/inrialpes/exmo/align/gen/ParametersIds.java @@ -1,5 +1,5 @@ /* - * $Id: ParametersIds.java$ + * $Id$ * * Copyright (C) 2011, INRIA * @@ -32,8 +32,8 @@ public class ParametersIds { public static String REMOVE_COMMENTS = "removeComments"; //removes random comments public static String LEVEL_FLATTENED = "levelFlattened"; //flattens a level public static String ADD_PROPERTIES = "addProperties"; //adds random propeties - public static String REMOVE_CLASSESLEVEL= "removeClasses"; //remove classes from level - public static String ADD_CLASSESLEVEL = "addClassesLevel"; //add c classes beginning from level l -> the value of this parameters should be: + public static String REMOVE_CLASSESLEVEL= "removeClassLevel"; //remove classes from level + public static String ADD_CLASSESLEVEL = "addClassLevel"; //add c classes beginning from level l -> the value of this parameters should be: //beginning_level.number_of_classes_to_add public static String RENAME_PROPERTIES = "renameProperties"; //renames properties public static String RENAME_CLASSES = "renameClasses"; //renames classes diff --git a/src/fr/inrialpes/exmo/align/gen/TestGen.java b/src/fr/inrialpes/exmo/align/gen/TestGen.java index 9ae772dfa1bf4e0beddd6cc9eaa35ef9e7405920..ce4894bee1f9739bbf4ca55fe197a0691fdf0254 100644 --- a/src/fr/inrialpes/exmo/align/gen/TestGen.java +++ b/src/fr/inrialpes/exmo/align/gen/TestGen.java @@ -1,5 +1,5 @@ /* - * $Id: TestGen.java$ + * $Id$ * * Copyright (C) 2011, INRIA * @@ -21,11 +21,14 @@ package fr.inrialpes.exmo.align.gen; -import fr.inrialpes.exmo.align.impl.BasicParameters; import gnu.getopt.Getopt; import gnu.getopt.LongOpt; -/** Generates tests. +import java.util.Properties; + +/** + An utility application for generating tests from command line. + It can either generate a single test or a whole test suite from a single ontology. <pre> java -cp procalign.jar fr.inrialpes.exmo.align.gen.TestGen [options] @@ -38,37 +41,49 @@ import gnu.getopt.LongOpt; --fileName=file --> the file name of the ontology + --debug[=n] -d [n] --> Report debug info at level n, --testNumber=number --> the number of the generated test </pre> */ public class TestGen { - private BasicParameters params = null; + private Properties params = null; private String methodName = null; //the name of the method private String testNumber = null; //the number of the generated test private String fileName = null; //the name of the input file + private String dir = null; //the name of the input file + private int debug = 0; public static String ARBITRARY_TEST = "arbitraryTest"; //generate an arbitrary test public static String GENERATE_BENCHMARK = "generateBenchmark"; //generate the Benchmark dataset + public TestGen() { + fileName = "onto.rdf"; + } + public static void main(String[] args) { try { new TestGen().run( args ); } - catch (Exception ex) { ex.printStackTrace(); }; + catch ( Exception ex ) { ex.printStackTrace(); }; } public void run(String[] args) throws Exception { - LongOpt[] longopts = new LongOpt[4]; - params = new BasicParameters(); + LongOpt[] longopts = new LongOpt[8]; + params = new Properties(); longopts[0] = new LongOpt("method", LongOpt.REQUIRED_ARGUMENT, null, 'm'); - longopts[1] = new LongOpt("fileName", LongOpt.REQUIRED_ARGUMENT, null, 'p'); + longopts[1] = new LongOpt("fileName", LongOpt.REQUIRED_ARGUMENT, null, 'n'); longopts[2] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'); longopts[3] = new LongOpt("testNumber", LongOpt.REQUIRED_ARGUMENT, null, 't'); + longopts[4] = new LongOpt("debug", LongOpt.OPTIONAL_ARGUMENT, null, 'd'); + longopts[5] = new LongOpt("outdir", LongOpt.REQUIRED_ARGUMENT, null, 'o'); + longopts[6] = new LongOpt("urlprefix", LongOpt.REQUIRED_ARGUMENT, null, 'u'); + longopts[7] = new LongOpt("D", LongOpt.REQUIRED_ARGUMENT, null, 'D'); - Getopt g = new Getopt("", args, "h:m:p:t", longopts); + Getopt g = new Getopt("", args, "d::o:u:h:m:n:D:t", longopts); int c; - + String arg; + while ((c = g.getopt()) != -1) { switch (c) { case 'h': @@ -76,37 +91,56 @@ public class TestGen { return; case 'm': methodName = g.getOptarg(); - System.out.println("method " + "[" + methodName + "]"); + System.err.println("method " + "[" + methodName + "]"); break; - case 'p': + case 'n': fileName = g.getOptarg(); - System.out.println("fileName " + "[" + fileName + "]"); + params.setProperty( "filename", fileName ); + System.err.println("fileName " + "[" + fileName + "]"); break; case 't': testNumber = g.getOptarg(); - System.out.println("testNumber " + "[" + testNumber + "]"); + System.err.println("testNumber " + "[" + testNumber + "]"); break; + case 'o' : + /* Use output directory */ + params.setProperty( "outdir", g.getOptarg() ); + break; + case 'u' : + /* URLPrefix */ + params.setProperty( "urlprefix", g.getOptarg() ); + break; + case 'd' : + /* Debug level */ + arg = g.getOptarg(); + if ( arg != null ) debug = Integer.parseInt(arg.trim()); + else debug = 4; + break; + case 'D' : + /* Parameter definition: could be used for all parameters */ + arg = g.getOptarg(); + int index = arg.indexOf('='); + if ( index != -1 ) { + params.setProperty( arg.substring( 0, index), + arg.substring(index+1)); + } else { + System.err.println("Bad parameter syntax: "+g); + printUsage(); + System.exit(0); + } + break; } } //generate an arbitrary test - if (methodName.equals(this.ARBITRARY_TEST)) { - int currentNb = g.getOptind(); - int totalNb = args.length; - - //copy the vector of parameters - String[] parameters = new String[totalNb-currentNb]; - System.arraycopy(args, currentNb, parameters, 0, totalNb-currentNb); - + if ( methodName.equals( ARBITRARY_TEST ) ) { //build an ArbitraryTest object and modify the ontology according to it - ArbitraryTest at = new ArbitraryTest(this.fileName, this.testNumber, parameters); - at.modifyOntology(); - } - - //generate the benchmark - if (methodName.equals(this.GENERATE_BENCHMARK)) { - GenerateBenchmark gb = new GenerateBenchmark(this.fileName); - gb.generate(); + ArbitraryTest at = new ArbitraryTest(); + at.modifyOntology( fileName, testNumber, params ); + } else if ( methodName.equals( GENERATE_BENCHMARK ) ) { + //generate the benchmark + GenerateBenchmark gb = new GenerateBenchmark( fileName ); + gb.generate( params ); } } @@ -114,25 +148,25 @@ public class TestGen { public void printUsage() { System.out.println("TestGen [options]"); System.out.println("options are"); - System.out.println("--method=methodName, where methodName can be \"arbitraryTest\" or \"generateBenchmark\""); - System.out.println("--fileName=file"); + System.out.println("--method=methodName, where methodName can be \""+ARBITRARY_TEST+"\" or \""+GENERATE_BENCHMARK+"\""); + System.out.println("--fileName=file [default: onto.rdf]"); System.out.println("--testNumber=number, if the arbitraryTest is chosen"); - System.out.println("parameter value"); + System.out.println("-Dparameter=value"); System.out.println("where the parameters are"); System.out.println( "[--------------------------------------------------------------------------]" ); System.out.println( "[------------- The list of all modification is the following: --------------]" ); - System.out.println( "[1. Remove percentage subclasses \"removeClasses\" --------------]" ); - System.out.println( "[2. Remove percentage properties \"removeProperties\" --------------]" ); - System.out.println( "[3. Remove percentage comments \"removeComments\" --------------]" ); - System.out.println( "[4. Remove percentage restrictions \"removeRestrictions\" --------------]" ); - System.out.println( "[5. Remove individuals \"removeIndividuals\" ------------]" ); - System.out.println( "[6. Add percentage subclasses \"addClasses\" --------------]" ); - System.out.println( "[7. Add percentage properties \"addProperties\" --------------]" ); - System.out.println( "[8. Rename percentage classes \"renameClasses\" --------------]" ); - System.out.println( "[9. Rename percentage properties \"renameProperties\" --------------]" ); - System.out.println( "[10. noHierarchy \"noHierarchy\" ---------------]" ); - System.out.println( "[11. Level flattened \"levelFlattened\" ---------------]" ); - System.out.println( "[12. Add nbClasses to a specific level \"addClassesLevel\" ---------------]" ); + System.out.println( "[1. Remove percentage subclasses \""+ParametersIds.REMOVE_CLASSES+"\" --------------]" ); + System.out.println( "[2. Remove percentage properties \""+ParametersIds.REMOVE_PROPERTIES+"\" --------------]" ); + System.out.println( "[3. Remove percentage comments \""+ParametersIds.REMOVE_COMMENTS+"\" --------------]" ); + System.out.println( "[4. Remove percentage restrictions \""+ParametersIds.REMOVE_RESTRICTIONS+"\" --------------]" ); + System.out.println( "[5. Remove individuals \""+ParametersIds.REMOVE_INDIVIDUALS+"\" ------------]" ); + System.out.println( "[6. Add percentage subclasses \""+ParametersIds.ADD_CLASSES+"\" --------------]" ); + System.out.println( "[7. Add percentage properties \""+ParametersIds.ADD_PROPERTIES+"\" --------------]" ); + System.out.println( "[8. Rename percentage classes \""+ParametersIds.RENAME_CLASSES+"\" --------------]" ); + System.out.println( "[9. Rename percentage properties \""+ParametersIds.RENAME_PROPERTIES+"\" --------------]" ); + System.out.println( "[10. noHierarchy \""+ParametersIds.NO_HIERARCHY+"\" ---------------]" ); + System.out.println( "[11. Level flattened \""+ParametersIds.LEVEL_FLATTENED+"\" ---------------]" ); + System.out.println( "[12. Add nbClasses to a specific level \""+ParametersIds.ADD_CLASSESLEVEL+"\" ---------------]" ); System.out.println( "[--------------------------------------------------------------------------]" ); } diff --git a/src/fr/inrialpes/exmo/align/gen/TestGenerator.java b/src/fr/inrialpes/exmo/align/gen/TestGenerator.java index 4a3d1aa85ed2634e8205585a54d384c56fcf2355..844502fd3915cbf0d7317784e02c9de8e334e385 100644 --- a/src/fr/inrialpes/exmo/align/gen/TestGenerator.java +++ b/src/fr/inrialpes/exmo/align/gen/TestGenerator.java @@ -19,8 +19,13 @@ * USA. */ -/* This program modifies the input ontology o according to the set of parameters p - and returns the alignment between the initial ontology and the modified one +/* + * Generates a single test by taking as input either an ontology + * or an ontology and an alignment and generating a modified ontology + * and an alignment between this one and either the initial ontology + * or the first ontology of the alignments. + * + * Alterations are specified in a list of parameters. */ package fr.inrialpes.exmo.align.gen; @@ -33,8 +38,6 @@ import fr.inrialpes.exmo.ontowrap.jena25.JENAOntology; import java.util.Properties; import org.semanticweb.owl.align.Alignment; - - public class TestGenerator implements AlignedOntologyGenerator { private Properties parameters; //the set of parameters private Properties params; //the modifications @@ -44,7 +47,6 @@ public class TestGenerator implements AlignedOntologyGenerator { private String namespace = ""; //the namespace private OntologyModifier modifier = null; //the modifier - public TestGenerator() {} //returns the modified ontology @@ -59,8 +61,7 @@ public class TestGenerator implements AlignedOntologyGenerator { if ( o instanceof JENAOntology ) { this.model = ((JENAOntology)o).getOntology(); this.modifiedModel = ((JENAOntology)o).getOntology(); - } - else { + } else { System.err.println("Error : The object given is not an OntModel"); System.exit(-1); } @@ -76,6 +77,7 @@ public class TestGenerator implements AlignedOntologyGenerator { } //set the parameters + // JE: modifier may not have been initialised public void setParameters(Properties p) { parameters = p; modifier.setProperties(parameters); @@ -88,48 +90,60 @@ public class TestGenerator implements AlignedOntologyGenerator { } //generate the alingnment - public Alignment generate(Ontology o, Properties p) { + /** + * This in fact is dependent on: + * - p + * - model + * - modifiedModel + * - alignment + */ + public Alignment generate( Ontology o, Properties p ) { this.params = p; this.alignment = new URIAlignment(); + // Initialise the modifier class modifier = new OntologyModifier( this.model, this.modifiedModel, this.alignment); //build the ontology modifier for the first time - modifier.initializeAlignment(); //initialize the reference alignment - //set the new namespace modifier.setNewNamespace( this.namespace ); - - System.out.println( "[-------------------------------------------------]" ); - for(String key : this.params.stringPropertyNames()) { - String value = this.params.getProperty(key); //System.out.println( "[" +key + "] => [" + value + "]"); - modifier.modifyOntology( key, value ); //modify the ontology according to it + // JE: This should be put OUT of the modifier (this generate Properties... instead of alignments...) + modifier.initializeAlignment(); // initialize the reference alignment + + // Apply all modifications + //System.out.println( "[-------------------------------------------------]" ); + for( String key : this.params.stringPropertyNames() ) { + String value = this.params.getProperty(key); + //System.out.println( "[" +key + "] => [" + value + "]"); + modifier.modifyOntology( key, value ); //modify the ontology according to it } - System.out.println( "[-------------------------------------------------]" ); + //System.out.println( "[-------------------------------------------------]" ); - //saves the alignment into the file "refalign.rdf", null->System.out + // JE: this refalign should be variabilised + //saves the alignment into the file "refalign.rdf", null->System.out modifier.computeAlignment( "refalign.rdf" ); //at the end, compute the reference alignment this.alignment = modifier.getAlignment(); //get the reference alignment this.modifiedModel = modifier.getModifiedOntology(); //get the modified ontology return this.alignment; } - - //generate the alingnment //newParams => keeps track of the previous modifications public Alignment generate(Ontology o, Properties p, Properties newParams) { this.params = p; this.alignment = new URIAlignment(); modifier = new OntologyModifier( this.model, this.modifiedModel, this.alignment); //build the ontology modifier for the first time + // JE: These two lines (one commented and the next one) are the only difference with the other + // The first one is a different between incremental (an alignment has been initialised) //modifier.initializeAlignment(); //initialize the reference alignment modifier.setProperties(newParams); //set the new namespace modifier.setNewNamespace( this.namespace ); - System.out.println( "[-------------------------------------------------]" ); - for(String key : this.params.stringPropertyNames()) { - String value = this.params.getProperty(key); //System.out.println( "[" +key + "] => [" + value + "]"); + //System.out.println( "[-------------------------------------------------]" ); + for( String key : this.params.stringPropertyNames() ) { + String value = this.params.getProperty(key); + //System.out.println( "[" +key + "] => [" + value + "]"); modifier.modifyOntology( key, value ); //modify the ontology according to it } - System.out.println( "[-------------------------------------------------]" ); + //System.out.println( "[-------------------------------------------------]" ); //saves the alignment into the file "referenceAlignment.rdf", null->System.out modifier.computeAlignment( "refalign.rdf" ); //at the end, compute the reference alignment