Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 0e35c6cf authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

- rewrote test set generation around TestSet

- allows for generating continuous or random testsets from the same pattern
parent c52728c5
No related branches found
No related tags found
No related merge requests found
......@@ -23,78 +23,32 @@
* 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;
import java.util.Properties;
public class BenchmarkGenerator {
public class BenchmarkGenerator extends TestSet {
private String initOntoFile; //the initial file
private Properties align; //the alignment parameter
private TestGenerator generator; // a TestGenerator
private boolean debug = false;
static String FULL = "1.0f";
//constructor
public BenchmarkGenerator( String fileName ) {
initOntoFile = fileName;
generator = new TestGenerator();
}
//generates the Benchmark
public void generate( Properties params ) {
public void initTestCases( Properties params ) {
// Process params
if ( params.getProperty( "urlprefix" ) != null ) generator.setURLPrefix( params.getProperty( "urlprefix" ) );
if ( params.getProperty( "outdir" )!= null ) generator.setDirPrefix( params.getProperty( "outdir" ) );
String ontoname = params.getProperty( "ontoname" );
if ( ontoname != null ) {
generator.setOntoFilename( params.getProperty( "ontoname" ) );
} else {
ontoname = "onto.rdf"; // could be better
}
if ( params.getProperty( "alignname" ) != null ) generator.setAlignFilename( params.getProperty( "alignname" ) );
debug = ( params.getProperty( "debug" ) != null );
generator.setDebug( debug );
//private String testnumber = ""; // will not work if no number...
//testnumber = params.getProperty( "testNumber" );
//if ( testnumber == null )
//keep track of the alignment
Properties alignRenameResources;
Properties alignInitial;
Properties p = new Properties(); //modify the ontology according to this parameters
String prevDirName;
// Test configuration parameters
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;
/*
* Test 101
* Generate the initial situation
*/
align = generator.modifyOntology( initOntoFile, (Properties)null, "101", p );
alignInitial = (Properties)align.clone();
alignRenameResources = (Properties)align.clone();
prevDirName = "101"+"/";
/* Test 101 Generate the initial situation */
root = initTests( "101" );
/*
* Tests 201, 202, 248, 249, 253, 258, 259, 250, 254,
* 262, 257, 260, 265, 261, 266, 251, 252
*/
// JE: look at the (Float).toString() below...
boolean multModality = (mod != null && mod.startsWith( "mult" ));
float i1 = 0.0f;
int maximum = Integer.parseInt( "5" );
......@@ -104,155 +58,157 @@ public class BenchmarkGenerator {
} catch ( Exception ex ) {
ex.printStackTrace(); // continue with the default
}
String PREVTEST = "101";
for ( int i = 0; i1 < 1.00f ; i++ ) { // && i < maximum
if ( i > 0 ) PREVTEST = "201"+SUFFIX; // The previous suffix
if ( !multModality ) i1 += incr; // traditional
else i1 += (1. - i1) * incr; // hardened
if ( debug ) System.err.println( " ******************************************************** "+i+": i1 = "+i1 );
//if ( debug ) System.err.println( " ******************************************************** "+i+": i1 = "+i1 );
if ( i1 < 1.0f ) {
SUFFIX = ((Float)i1).toString().substring(2, 3);
SUFFIX = "-"+((Float)i1).toString().substring(2, 3); // 2 4 6 8
} else {
SUFFIX = null;
SUFFIX = "";
}
/* 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() );
// This dirprefix business could have been solved before...
String dirprefix = params.getProperty( "outdir" );
if (dirprefix != null ) { dirprefix = dirprefix+"/"; } else { dirprefix = ""; }
align = generator.modifyOntology( dirprefix+prevDirName+ontoname, align, generator.directoryName( "201", SUFFIX ), p);
/* 202-x *** no names + no comments */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_COMMENTS, FULL, SUFFIX, "201", align, "202" );
/* 248-x *** no names + no comments + no hierarchy */
align = generator.incrementModifyOntology( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY, SUFFIX, "202", align, "248" );
/* 253-x *** no names + no comments + no hierarchy + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "248", align, "253" );
/* 249-x *** no names + no comments + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "202", align, "249" );
////get the parameters
alignRenameResources = (Properties)align.clone();
/* 250-x *** no names + no comments + no property */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_PROPERTIES, FULL, SUFFIX, "202", align, "250" );
/* 254-x *** no names + no comments + no property + no hierarchy */
align = generator.incrementModifyOntology( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY, SUFFIX, "250", align, "254" );
/* 262-x *** no names + no comments + no property + no hierarchy + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "254", align, "262" );
/* 257-x *** no names + no comments + no property + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "250", align, "257" );
/* 261-x *** no names + no comments + no property + expand */
align = generator.incrementModifyOntology( ParametersIds.ADD_CLASSES, FULL, SUFFIX, "250", align, "261" );
/* 266-x *** no names + no comments + no property + expand + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "261", align, "266" );
/* 260-x *** no names + no comments + no property + flatten */
align = generator.incrementModifyOntology( ParametersIds.LEVEL_FLATTENED, "2", SUFFIX, "250", align, "260" );
/* 265-x *** no names + no comments + no property + flatten + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "260", align, "265" );
//re-establish the parameters
align = (Properties)alignRenameResources.clone();
/* 251-x *** no names + no comments + flatten */
align = generator.incrementModifyOntology( ParametersIds.LEVEL_FLATTENED, "2", SUFFIX, "202", align, "251" );
/* 258-x *** no names + no comments + flatten + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "251", align, "258" );
//re-establish the parameters
align = (Properties)alignRenameResources.clone();
/* 252-x *** no names + no comments + expand */
align = generator.incrementModifyOntology( ParametersIds.ADD_CLASSES, FULL, SUFFIX, "202", align, "252" );
/* 259-x *** no names + no comments + expand + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "252", align, "259" );
// alignNoProperty = modifier.getProperties(); //get the modifed properties
align = (Properties)alignRenameResources.clone();
prevDirName = generator.directoryName( "201", SUFFIX ) + "/";
addTestChild( PREVTEST, "201"+SUFFIX,
newProperties( ParametersIds.RENAME_CLASSES, ((Float)i1).toString(),
ParametersIds.RENAME_PROPERTIES, ((Float)i1).toString() ) );
/* 202-x *** no names + no comments */
addTestChild( "201"+SUFFIX, "202"+SUFFIX,
newProperties( ParametersIds.REMOVE_COMMENTS, FULL ) );
/* 248-x *** no names + no comments + no hierarchy */
addTestChild( "202"+SUFFIX, "248"+SUFFIX,
newProperties( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY ) );
/* 253-x *** no names + no comments + no hierarchy + no instance */
addTestChild( "248"+SUFFIX, "253"+SUFFIX,
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 249-x *** no names + no comments + no instance */
addTestChild( "202"+SUFFIX, "249"+SUFFIX,
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 250-x *** no names + no comments + no property */
addTestChild( "202"+SUFFIX, "250"+SUFFIX,
newProperties( ParametersIds.REMOVE_PROPERTIES, FULL ) );
/* 254-x *** no names + no comments + no property + no hierarchy */
addTestChild( "250"+SUFFIX, "254"+SUFFIX,
newProperties( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY ) );
/* 262-x *** no names + no comments + no property + no hierarchy + no instance */
addTestChild( "254"+SUFFIX, "262"+SUFFIX,
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 257-x *** no names + no comments + no property + no instance */
addTestChild( "250"+SUFFIX, "257"+SUFFIX,
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 261-x *** no names + no comments + no property + expand */
addTestChild( "250"+SUFFIX, "261"+SUFFIX,
newProperties( ParametersIds.ADD_CLASSES, FULL ) );
/* 266-x *** no names + no comments + no property + expand + no instance */
addTestChild( "261"+SUFFIX, "266"+SUFFIX,
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 260-x *** no names + no comments + no property + flatten */
addTestChild( "250"+SUFFIX, "260"+SUFFIX,
newProperties( ParametersIds.LEVEL_FLATTENED, "2" ) );
/* 265-x *** no names + no comments + no property + flatten + no instance */
addTestChild( "260"+SUFFIX, "265"+SUFFIX,
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 251-x *** no names + no comments + flatten */
addTestChild( "202"+SUFFIX, "251"+SUFFIX,
newProperties( ParametersIds.LEVEL_FLATTENED, "2" ) );
/* 258-x *** no names + no comments + flatten + no instance */
addTestChild( "251"+SUFFIX, "258"+SUFFIX,
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 252-x *** no names + no comments + expand */
addTestChild( "202"+SUFFIX, "252"+SUFFIX,
newProperties( ParametersIds.ADD_CLASSES, FULL ) );
/* 259-x *** no names + no comments + expand + no instance */
addTestChild( "252"+SUFFIX, "259"+SUFFIX,
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
}
//re-establish the parameters
SUFFIX = null;
align = (Properties)alignInitial.clone();
/* Tests 221, 232, 233, 241 */
/* 221 *** no hierarchy */
align = generator.incrementModifyOntology( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY, SUFFIX, "101", align, "221" );
/* 232 *** no hierarchy + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "221", align, "232" );
/* 233 *** no hierarchy + no property */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_PROPERTIES, FULL, SUFFIX, "221", align, "233" );
/* 241 *** no hierarchy + no property + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "233", align, "241" );
//re-establish the align
align = (Properties)alignInitial.clone();
/* Tests 222, 237 */
addTestChild( "101", "221",
newProperties( ParametersIds.NO_HIERARCHY, ParametersIds.NO_HIERARCHY ) );
/* 232 *** no hierarchy + no instance */
addTestChild( "221", "232",
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 233 *** no hierarchy + no property */
addTestChild( "221", "233",
newProperties( ParametersIds.REMOVE_PROPERTIES, FULL ) );
/* 241 *** no hierarchy + no property + no instance */
addTestChild( "233", "241",
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 222 *** flatten */
align = generator.incrementModifyOntology( ParametersIds.LEVEL_FLATTENED, "2", SUFFIX, "101", align, "222" );
/* 237 *** flatten + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "222", align, "237" );
//re-establish the parameters
align = (Properties)alignInitial.clone();
/* Tests 223, 238 */
addTestChild( "101", "222",
newProperties( ParametersIds.LEVEL_FLATTENED, "2" ) );
/* 237 *** flatten + no instance */
addTestChild( "222", "237",
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 223 *** expand */
align = generator.incrementModifyOntology( ParametersIds.ADD_CLASSES, FULL, SUFFIX, "101", align, "223" );
/* 238 *** expand + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "223", align, "238" );
addTestChild( "101", "223",
newProperties( ParametersIds.ADD_CLASSES, FULL ) );
/* 238 *** expand + no instance */
addTestChild( "223", "238",
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL) );
/* 224 *** no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "101", align, "224" );
addTestChild( "101", "224",
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 225 *** no restrictions */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_RESTRICTIONS, FULL, SUFFIX, "101", align, "225" );
/* Tests 228, 239, 246, 236, 240, 247 */
addTestChild( "101", "225",
newProperties( ParametersIds.REMOVE_RESTRICTIONS, FULL ) );
/* 228 *** no property */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_PROPERTIES, FULL, SUFFIX, "101", align, "228" );
/* 236 *** no property + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "228", align, "236" );
/* 240 *** no property + expand */
align = generator.incrementModifyOntology( ParametersIds.ADD_CLASSES, FULL, SUFFIX, "228", align, "240" );
/* 247 *** no property + expand + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "240", align, "247" );
addTestChild( "101", "228",
newProperties( ParametersIds.REMOVE_PROPERTIES, FULL ) );
/* 236 *** no property + no instance */
addTestChild( "228", "236",
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 240 *** no property + expand */
addTestChild( "228", "240",
newProperties( ParametersIds.ADD_CLASSES, FULL ) );
/* 247 *** no property + expand + no instance */
addTestChild( "240", "247",
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
/* 239 *** no property + flatten */
addTestChild( "228", "239",
newProperties( ParametersIds.LEVEL_FLATTENED, FULL ) );
/* 246 *** no property + flatten + no instance */
addTestChild( "239", "246",
newProperties( ParametersIds.REMOVE_INDIVIDUALS, FULL ) );
}
/* 239 *** no property + flatten */
align = generator.incrementModifyOntology( ParametersIds.LEVEL_FLATTENED, FULL, SUFFIX, "228", align, "239" );
/*
*101 --> 201
* 201 --> 202
* 202 --> 248
* 248 --> 253
* 202 --> 249
* 202 --> 250
* 250 --> 254
* 254 --> 262
* 250 --> 257
* 250 --> 261
* 261 --> 266
* 250 --> 260
* 260 --> 265
* 202 --> 251
* 251 --> 258
* 202 --> 252
* 252 --> 259
//-------
*101 --> 221
* 221 --> 232
* 221 --> 233
* 233 --> 241
*101 --> 222
* 222 --> 237
*101 --> 223
* 223 --> 238
*101 --> 224
*101 --> 225
*101 --> 228
* 228 --> 236
* 228 --> 240
* 240 --> 247
* 228 --> 239
* 239 --> 246
*/
/* 246 *** no property + flatten + no instance */
align = generator.incrementModifyOntology( ParametersIds.REMOVE_INDIVIDUALS, FULL, SUFFIX, "239", align, "246" );
}
}
......@@ -103,15 +103,14 @@ public class OntologyModifier {
//Ontology init, Ontology modified, Alignment align
// JE: Here the alignment is useless... it is used only if nothing is computed!
public OntologyModifier ( OntModel model, Alignment alignment ) {
this.model = model;
this.modifiedModel = model;
modifiedModel = model;
namespace = model.getNsPrefixURI(""); // JE: ???
this.alignment = alignment;
this.isBuild = false;
this.isAlign = false;
this.isChanged = false;
this.namespace = model.getNsPrefixURI("");
this.namespaceNew = "";
this.params = new Properties();
isBuild = false;
isAlign = false;
isChanged = false;
namespaceNew = "";
params = new Properties();
}
//no-args constructor
......@@ -119,9 +118,9 @@ public class OntologyModifier {
//if we add / remove a class we need to keep track of the class hierarchy
public void buildClassHierarchy () {
this.classHierarchy = new ClassHierarchy();
this.classHierarchy.buildClassHierarchy( this.modifiedModel );
//this.classHierarchy.printClassHierarchy();
classHierarchy = new ClassHierarchy();
classHierarchy.buildClassHierarchy( modifiedModel );
//classHierarchy.printClassHierarchy();
}
//generates a random string with the length "length"
......@@ -133,7 +132,7 @@ public class OntologyModifier {
for (int i = 0; i < length; i++) {
text[i] = characters.charAt( generator.nextInt(length) );
}
return new String(text).toUpperCase();
return new String(text); // JE suppressed toUpperCase()
}
//removes spaces from a string
......@@ -167,7 +166,7 @@ public class OntologyModifier {
try {
translatedText = Translate.execute(source, Language.ENGLISH, Language.FRENCH);
} catch (Exception e) {
System.out.println( "Exception " + e.getMessage() );
System.err.println( "Exception " + e.getMessage() );
}
return removeSpaces ( translatedText );
}
......@@ -212,7 +211,7 @@ public class OntologyModifier {
*/
public String parseString (String str, boolean activeTranslateString, boolean activeSynonym) {
// System.out.println ( "str = [" + str + "]" );
// System.err.println ( "str = [" + str + "]" );
char [] parsed = str.toCharArray();
String newString = "";
......@@ -259,7 +258,7 @@ public class OntologyModifier {
//replaces the label of the property
public void replacePropertyLabel( String uri, String newLabel, boolean activeRandomString, boolean activeTranslateString, boolean activeSynonym, int activeStringOperation ) {
OntProperty prop = this.modifiedModel.getOntProperty( uri );
OntProperty prop = modifiedModel.getOntProperty( uri );
if ( prop.getLabel( "en" ) != null ) {
if ( activeTranslateString ) {
prop.setLabel( newLabel, "fr" );
......@@ -270,7 +269,7 @@ public class OntologyModifier {
}
//gets the URIs of the properties and their translation
public HashMap<String, String> getPropertiesIdentifiers ( float percentage, boolean activeRandomString, boolean activeTranslateString, boolean activeSynonym, int activeStringOperation) {
public HashMap<String, String> getPropertiesIdentifiers( float percentage, boolean activeRandomString, boolean activeTranslateString, boolean activeSynonym, int activeStringOperation) {
HashMap<String, String> propertiesIdentifiers = new HashMap<String, String>(); //the HashMap of the properties identifiers
List<String> propertiesName = new ArrayList<String>(); //the properties identifiers
......@@ -283,6 +282,7 @@ public class OntologyModifier {
//builds the list of all unrenamed properties from the model
for ( OntProperty p : properties ) {
String uri = base + p.getLocalName();
// JE: I am affraid that this.params is a terible thing here
if ( this.params.containsKey( uri ) ) {
String key = uri;
String value = this.params.getProperty( key );
......@@ -296,13 +296,15 @@ public class OntologyModifier {
renamedProperties = nbProperties - notRenamedProperties.size();
toBeRenamed = (int)(percentage*nbProperties) - renamedProperties; // -renamedProperties -> for Benchmark
// JE: same thing as for classes... but strange
// JE: should be the symptom of a bug
if ( toBeRenamed < 0 ) toBeRenamed = 0;
//builds the list of properties to be renamed
int [] n = this.randNumbers(notRenamedProperties.size(), toBeRenamed);
int [] n = randNumbers(notRenamedProperties.size(), toBeRenamed);
for ( int i=0; i<toBeRenamed; i++ ) {
OntProperty p = notRenamedProperties.get(n[i]);
propertiesTo.add(p);
if ( p.getNameSpace().equals( this.namespace ) )
if ( p.getNameSpace().equals( namespace ) )
propertiesName.add( p.getLocalName() );
}
......@@ -310,23 +312,23 @@ public class OntologyModifier {
String nameSpace = prop.getNameSpace();
String localName = prop.getLocalName();
//has the same Namespace as the Ontology Namespace
if ( nameSpace.equals( this.namespace ) ) {
if ( nameSpace.equals( namespace ) ) {
if ( !propertiesIdentifiers.containsKey( localName ) ) {
if ( activeTranslateString ) { //replace the URI with the translated one
String translateStrg = parseString ( localName, true, false);
propertiesIdentifiers.put( localName , translateStrg );
replacePropertyLabel( prop.getURI(), translateStrg, activeRandomString, activeTranslateString, activeSynonym, activeStringOperation );
if ( params.containsKey( this.base + prop.getLocalName() ) ) { //this.params.remove( prop.getURI() );
this.params.put( this.base + prop.getLocalName() , this.base + translateStrg );//the reference alignment
if ( params.containsKey( base + prop.getLocalName() ) ) { //this.params.remove( prop.getURI() );
this.params.put( base + prop.getLocalName() , base + translateStrg );//the reference alignment
}
}
else if ( activeRandomString ) { //replace the URI with a random string
String newStrg = getRandomString();
propertiesIdentifiers.put( localName , newStrg );
replacePropertyLabel( prop.getURI(), newStrg, activeRandomString, activeTranslateString, activeSynonym, activeStringOperation );
if ( params.containsKey( this.base + prop.getLocalName() ) ) { //this.params.remove( prop.getURI() );
this.params.put( this.base + prop.getLocalName() , this.base + newStrg);//the reference alignment
if ( params.containsKey( base + prop.getLocalName() ) ) { //this.params.remove( prop.getURI() );
this.params.put( base + prop.getLocalName() , base + newStrg);//the reference alignment
}
}
else if ( activeSynonym ) {
......@@ -370,7 +372,7 @@ public class OntologyModifier {
//replaces the label of the class
public void replaceClassLabel( String uri, String newLabel, boolean activeRandomString, boolean activeTranslateString, boolean activeSynonym, int activeStringOperation ) {
OntClass c = this.modifiedModel.getOntClass( uri );
OntClass c = modifiedModel.getOntClass( uri );
if ( c.getLabel( "en" ) != null ) {
if ( activeTranslateString ) {
......@@ -387,9 +389,10 @@ public class OntologyModifier {
int nbClasses, toBeRenamed, renamedClasses;
List<OntClass> notRenamedClasses = new ArrayList<OntClass>(); //the list of not renamed classes
List<OntClass> classes = this.getOntologyClasses(); //the list of ontology classes
List<OntClass> classes = getOntologyClasses(); //the list of ontology classes
List<OntClass> classesTo = new ArrayList<OntClass>(); //the list of classes to be renamed
// params contains those classes which have already been renamed
//builds the list of all unrenamed classes from the model
for ( OntClass c : classes ) {
String uri = base + c.getLocalName();
......@@ -403,13 +406,14 @@ public class OntologyModifier {
}
}
nbClasses = classes.size(); //the number of renamed classes
renamedClasses = nbClasses - notRenamedClasses.size();
nbClasses = classes.size();
renamedClasses = nbClasses - notRenamedClasses.size(); //the number of renamed classes
toBeRenamed = (int)(percentage*nbClasses) - renamedClasses; // -renamedClasses -> for Benchmark
// JE: toBeRenamed is negative when classes have been added to the model!
// JE TOCHECK IF THIS IS STILL CORRECT
if ( toBeRenamed < 0 ) toBeRenamed = 0;
//build the list of classes to be renamed
int [] n = this.randNumbers(notRenamedClasses.size(), toBeRenamed);
int[] n = randNumbers( notRenamedClasses.size(), toBeRenamed );
for ( int i=0; i<toBeRenamed; i++ ) {
OntClass cls = notRenamedClasses.get(n[i]);
classesTo.add(cls);
......@@ -422,7 +426,7 @@ public class OntologyModifier {
String localName = cls.getLocalName();
//has the same Namespace as the Ontology Namespace
if ( nameSpace.equals( this.namespace ) ) {
if ( nameSpace.equals( namespace ) ) {
if ( !classesIdentifiers.containsKey( localName ) ) {
if ( activeTranslateString ) { //replace the URI with the translated one
String translateStrg = parseString (localName, true, false);
......@@ -485,28 +489,26 @@ public class OntologyModifier {
HashMap<String, String> propertiesIdentifiers = null; //the HashMap of the properties identifiers
HashMap<String, String> classesIdentifiers = null; //the HashMap of the classes identifiers
String subjectLocalName, subjectNameSpace;
String predicateLocalName, predicateNameSpace;
String objectLocalName, objectNameSpace;
boolean isPred, isSubj, isObj;
isPred = isSubj = isObj = false;
OntModel newModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);//create new Model
OntModel newModel = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );//create new Model
//get properties and classes identifiers
if ( activeProperties )
propertiesIdentifiers = getPropertiesIdentifiers( percentage, activeRandomString, activeTranslateString, activeSynonym, activeStringOperation);
if ( activeClasses )
classesIdentifiers = getClassesIdentifiers ( percentage, activeRandomString, activeTranslateString, activeSynonym, activeStringOperation);
statements = this.modifiedModel.listStatements().toList(); //get all the statements of the model
classesIdentifiers = getClassesIdentifiers( percentage, activeRandomString, activeTranslateString, activeSynonym, activeStringOperation );
//iterate and modify the identifiers
for ( Statement stm : statements ) {
for ( Statement stm : modifiedModel.listStatements().toList() ) {
Resource subject = stm.getSubject(); //the subject
Property predicate = stm.getPredicate(); //the predicate
RDFNode object = stm.getObject(); //the object
String subjectLocalName, subjectNameSpace;
String predicateLocalName, predicateNameSpace;
String objectLocalName, objectNameSpace;
boolean isPred, isSubj, isObj;
Resource subj = null;
Property pred = null;
Resource obj = null;
......@@ -517,7 +519,7 @@ public class OntologyModifier {
if ( activeProperties ) {
if ( propertiesIdentifiers.containsKey( subject.getLocalName() ) ) {
//if the namespace of the subject is the same as the namespace of the property identifier
if ( subject.getNameSpace().equals( this.namespace ) ) {//that we want to remove
if ( subject.getNameSpace().equals( namespace ) ) {//that we want to remove
isSubj = true;
subjectNameSpace = subject.getNameSpace();
subjectLocalName = subject.getLocalName();
......@@ -530,7 +532,7 @@ public class OntologyModifier {
if ( classesIdentifiers.containsKey( subject.getLocalName() ) ) {
//if the namespace of the subject is the same as the namespace of the property identifier
//that we want to remove
if (subject.getNameSpace().equals( this.namespace ) ) {
if (subject.getNameSpace().equals( namespace ) ) {
isSubj = true;
subjectNameSpace = subject.getNameSpace();
subjectLocalName = subject.getLocalName();
......@@ -644,7 +646,7 @@ public class OntologyModifier {
@SuppressWarnings("unchecked")
public List<OntClass> getOntologyClasses () {
List<OntClass> classes = new ArrayList<OntClass>();
for ( Iterator it = this.modifiedModel.listNamedClasses(); it.hasNext(); ) {
for ( Iterator it = modifiedModel.listNamedClasses(); it.hasNext(); ) {
OntClass aux = (OntClass)it.next();
if ( ( aux ).getNameSpace().equals( this.namespace ) ) {
classes.add( aux );
......@@ -657,7 +659,7 @@ public class OntologyModifier {
@SuppressWarnings("unchecked")
public List<OntProperty> getOntologyProperties () {
List<OntProperty> properties = new ArrayList<OntProperty>();
for ( Iterator it = this.modifiedModel.listAllOntProperties(); it.hasNext(); ) {
for ( Iterator it = modifiedModel.listAllOntProperties(); it.hasNext(); ) {
OntProperty prop = (OntProperty)it.next();
if ( prop.getNameSpace().equals( this.namespace ) )
properties.add( prop );
......@@ -666,12 +668,13 @@ public class OntologyModifier {
}
//adds a class with a random URI to the parent class parentURI
public OntClass addClass ( OntClass parentClass, String childURI ) {
OntClass childClass = this.modifiedModel.createClass( this.namespace + childURI );//create a new class to the model
public OntClass addClass ( OntClass parentClass, String name ) {
String childURI = namespace+name;
OntClass childClass = modifiedModel.createClass( childURI );//create a new class to the model
this.classHierarchy.addClass( this.namespace + childURI, parentClass.getURI() );//add the node in the hierarchy of classes
classHierarchy.addClass( childURI, parentClass.getURI() );//add the node in the hierarchy of classes
parentClass.addSubClass( childClass ); //add the childClass as subclass of parentClass
this.modifiedModel.add( childClass, RDFS.subClassOf, parentClass ); //add the class to the model
modifiedModel.add( childClass, RDFS.subClassOf, parentClass ); //add the class to the model
return childClass;
}
......@@ -679,14 +682,13 @@ public class OntologyModifier {
public void addSubClasses ( float percentage ) {
List<OntClass> classes = getOntologyClasses(); //get the list of classes from the Ontology
int nbClasses = classes.size(); //number of classes from the Ontology
int toAdd = (int) ( percentage * nbClasses );
int toAdd = (int)(percentage*nbClasses);
checkClassHierarchy(); //check if the classHierarchy is built
//build the list of properties to be renamed
int [] n = this.randNumbers(nbClasses, toAdd);
int[] n = this.randNumbers( nbClasses, toAdd );
for ( int i=0; i<toAdd; i++ ) {
String childURI = this.getRandomString(); //give a random URI to the new class
addClass( classes.get(n[i]), childURI );
addClass( classes.get(n[i]), getRandomString() ); //give a random URI to the new class
}
}
......@@ -703,12 +705,12 @@ public class OntologyModifier {
checkClassHierarchy(); //check if the class hierarchy is built
if ( level == 1 ) { //the parent of the class is Thing, we add the class and then the rest of the classes
classURI = this.getRandomString();
parentClass = this.modifiedModel.createClass( this.namespace + classURI );//create a new class to the model
parentClass = modifiedModel.createClass( this.namespace + classURI );//create a new class to the model
this.classHierarchy.addClass( this.namespace + classURI, "Thing" ); //add the node in the hierarchy of classes
childClasses.add(parentClass);
}
else {
parentClasses = this.classHierarchy.getClassesFromLevel(this.modifiedModel, level);
parentClasses = this.classHierarchy.getClassesFromLevel(modifiedModel, level);
int nbParentClasses = parentClasses.size(); //number of classes from the Ontology
int toAdd = (int) ( percentage * nbClasses ); // 1 can be replaced by percentage
......@@ -733,14 +735,13 @@ public class OntologyModifier {
//changes the unionOf, intersectionOf
public OntModel changeDomainRange ( HashMap<String, String> uris ) {
OntModel newModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);//create new Model
List<Statement> statements = this.modifiedModel.listStatements().toList(); //get all the statements of the model
boolean isSubj, isObj, isPred;
String subjectNameSpace, subjectLocalName;
String objectNameSpace, objectLocalName;
String predicateNameSpace, predicateLocalName;
//iterate and modify the identifiers
for ( Statement stm : statements ) {
for ( Statement stm : modifiedModel.listStatements().toList() ) {
Resource subject = stm.getSubject(); //the subject
Property predicate = stm.getPredicate(); //the predicate
RDFNode object = stm.getObject(); //the object
......@@ -800,7 +801,7 @@ public class OntologyModifier {
@SuppressWarnings("unchecked")
public void checkClassesRestrictions ( OntClass childClass, OntClass parentClass ) {
Restriction restr = null;
for ( Iterator it = this.modifiedModel.listRestrictions(); it.hasNext(); ) {
for ( Iterator it = modifiedModel.listRestrictions(); it.hasNext(); ) {
restr = (Restriction)it.next(); //get the restriction
/* isAllValuesFromRestriction */
if ( restr.isAllValuesFromRestriction() ) {
......@@ -827,9 +828,9 @@ public class OntologyModifier {
public String removeClass ( OntClass cls ) {
OntClass parentClass;
ArrayList<OntClass> subClasses = new ArrayList<OntClass>(); //the list of all the subclasses of the class
OntClass thing = this.modifiedModel.createClass( OWL.Thing.getURI() ); //Thing class
OntClass thing = modifiedModel.createClass( OWL.Thing.getURI() ); //Thing class
checkClassHierarchy(); //check if the class hierarchy is built
parentClass = this.classHierarchy.removeClass( this.modifiedModel, cls );//get the parent of the class
parentClass = this.classHierarchy.removeClass( modifiedModel, cls );//get the parent of the class
for (Iterator it1 = cls.listSubClasses(); it1.hasNext(); ) { //build the list of subclasses
OntClass subCls = (OntClass)it1.next(); //because we can't change the
......@@ -870,7 +871,7 @@ public class OntologyModifier {
}
//checks if the class appears like unionOf.. and replaces its appearence with the superclass
this.modifiedModel = changeDomainRange( uris );
modifiedModel = changeDomainRange( uris );
//remove the URI of the class from the reference alignment
for ( String key : this.params.stringPropertyNames() ) {
......@@ -886,26 +887,25 @@ public class OntologyModifier {
public void removeClassesFromLevel ( int level ) {
HashMap<String, String> uris = new HashMap<String, String>();
String parentURI = "";
//System.out.println( "Level " + level );
//System.err.println( "Level " + level );
/* if ( level == 1 ) //except classes from level 1
return; */
List<OntClass> classes = new ArrayList<OntClass>();
checkClassHierarchy(); //check if the class hierarchy is built
classes = this.classHierarchy.getClassesFromLevel(this.modifiedModel, level);
classes = this.classHierarchy.getClassesFromLevel(modifiedModel, level);
for ( int i=0; i<classes.size(); i++ ) { //remove the classes from the hierarchy
parentURI = removeClass ( classes.get(i) );
uris.put(classes.get(i).getURI(), parentURI);
}
//checks if the class appears like unionOf .. and replaces its appearence with the superclass
this.modifiedModel = changeDomainRange( uris );
modifiedModel = changeDomainRange( uris );
}
//remove percentage individuals from Ontology
public void removeIndividuals( float percentage ) {
boolean isSubj, isObj; //the individual can appear as subject or object
List<Individual> individuals = this.modifiedModel.listIndividuals().toList();
List<Individual> individuals = modifiedModel.listIndividuals().toList();
List<Individual> individualsTo = new ArrayList<Individual>(); //the list of individuals to be removed
List<Statement> statements = this.modifiedModel.listStatements().toList();
int nbIndividuals = individuals.size(); //the number of individuals
int toBeRemoved = (int)( percentage*nbIndividuals ); //the number of individuals to be removed
......@@ -916,7 +916,7 @@ public class OntologyModifier {
//this.params.remove( indiv.getURI() );
}
for ( Statement st : statements ) {
for ( Statement st : modifiedModel.listStatements().toList() ) {
Resource subject = st.getSubject();
RDFNode object = st.getObject();
isSubj = isObj = false;
......@@ -927,9 +927,9 @@ public class OntologyModifier {
if ( individualsTo.contains( object.asResource() ) )
isObj = true;
if ( isSubj ) //the individual appears as subject in the statement
this.modifiedModel.remove( st );
modifiedModel.remove( st );
if ( isObj ) //the individual appears as object in the statement
this.modifiedModel.remove( st );
modifiedModel.remove( st );
}
}
......@@ -943,7 +943,6 @@ public class OntologyModifier {
List<String> pr = new ArrayList<String>();
boolean isObj, isSubj, isPred;
List<Statement> statements = this.modifiedModel.listStatements().toList();//get all of the statements
int nbProperties = properties.size(); //the number of properties
int toBeRemoved = (int)( percentage*nbProperties ); //the number of properties to be removed
......@@ -991,15 +990,15 @@ public class OntologyModifier {
//since we don't respect any order the value can appear as a value, thus we must iterate among all params to delete it
for ( String key : this.params.stringPropertyNames() ) {
String value = this.params.getProperty(key);
if ( pr.contains( this.namespace + key.substring(key.indexOf(this.base) + this.base.length()) ) ) { //System.out.println( "Elimin " + key );
if ( pr.contains( this.namespace + key.substring(key.indexOf(this.base) + this.base.length()) ) ) { //System.err.println( "Elimin " + key );
this.params.remove( key );
}
if ( pr.contains( this.namespace + value.substring(key.indexOf(this.base) + this.base.length()) ) ) { //System.out.println( "Elimin " + key );
if ( pr.contains( this.namespace + value.substring(key.indexOf(this.base) + this.base.length()) ) ) { //System.err.println( "Elimin " + key );
this.params.remove( key );
}
}
for ( Statement st : statements ) { //remove the declaration of properties from the model
for ( Statement st : modifiedModel.listStatements().toList() ) { //remove the declaration of properties from the model
Resource subject = st.getSubject();
Property predicate = st.getPredicate();
RDFNode object = st.getObject();
......@@ -1019,7 +1018,7 @@ public class OntologyModifier {
isObj = true;
if ( isSubj || isPred || isObj ) //remove the statement in which the prop
this.modifiedModel.remove( st ); //appears as subject, predicate or object
modifiedModel.remove( st ); //appears as subject, predicate or object
}
}
......@@ -1036,8 +1035,8 @@ public class OntologyModifier {
int toBeAdd = (int)( percentage*nbProperties ); //the number of properties to be add
for ( int i=0; i<toBeAdd/2; i++ ) { //add object properties
//p = this.modifiedModel.createObjectProperty( this.namespace + "OBJECT_PROPERTY_" + getRandomString() );
p = this.modifiedModel.createObjectProperty( this.namespace + getRandomString() );
//p = modifiedModel.createObjectProperty( this.namespace + "OBJECT_PROPERTY_" + getRandomString() );
p = modifiedModel.createObjectProperty( this.namespace + getRandomString() );
index = classRand.nextInt( nbClasses ); //pick random domain
p.addDomain( classes.get( index ) );
index = classRand.nextInt( nbClasses ); //pick random range
......@@ -1045,8 +1044,8 @@ public class OntologyModifier {
}
for ( int i=toBeAdd/2; i<toBeAdd; i++ ) { //add datatype properties
//d = this.modifiedModel.createDatatypeProperty( this.namespace + "DATATYPE_PROPERTY_" + getRandomString() );
d = this.modifiedModel.createDatatypeProperty( this.namespace + getRandomString() );
//d = modifiedModel.createDatatypeProperty( this.namespace + "DATATYPE_PROPERTY_" + getRandomString() );
d = modifiedModel.createDatatypeProperty( this.namespace + getRandomString() );
index = classRand.nextInt( nbClasses ); //add domain
d.addDomain( classes.get( index ) );
d.addRange( XSD.xstring ); //add range -> string
......@@ -1057,7 +1056,7 @@ public class OntologyModifier {
@SuppressWarnings("unchecked")
public void removeClassesComments ( float percentage ) {
ArrayList<Literal> comments = new ArrayList<Literal>();
List<OntClass> classes = this.modifiedModel.listNamedClasses().toList();
List<OntClass> classes = modifiedModel.listNamedClasses().toList();
ArrayList<OntClass> classesTo = new ArrayList<OntClass>();
int nbClasses = classes.size();
int toBeRemoved = (int)( percentage * nbClasses ); //number of classes comments to be removed
......@@ -1081,7 +1080,7 @@ public class OntologyModifier {
@SuppressWarnings("unchecked")
public void removePropertiesComments ( float percentage ) {
ArrayList<Literal> comments = new ArrayList<Literal>(); // an array list to hold all the comments
List<OntProperty> properties = this.modifiedModel.listAllOntProperties().toList();
List<OntProperty> properties = modifiedModel.listAllOntProperties().toList();
ArrayList<OntProperty> propertiesTo = new ArrayList<OntProperty>();
int nbProperties = properties.size();
int toBeRemoved = (int)( percentage * nbProperties ); //the number of properties comments to be removed
......@@ -1105,7 +1104,7 @@ public class OntologyModifier {
@SuppressWarnings("unchecked")
public void removeIndividualsComments ( float percentage ) {
ArrayList<Literal> comments = new ArrayList<Literal>(); // an array list to hold all the comments
List<Individual> individuals = this.modifiedModel.listIndividuals().toList();
List<Individual> individuals = modifiedModel.listIndividuals().toList();
ArrayList<Individual> individualsTo = new ArrayList<Individual>();
int nbIndividuals = individuals.size();
int toBeRemoved = (int)( percentage * nbIndividuals ); //number of classes to be removed
......@@ -1128,7 +1127,7 @@ public class OntologyModifier {
@SuppressWarnings("unchecked")
public void removeOntologiesComments ( float percentage ) {
ArrayList<Literal> comments = new ArrayList<Literal>(); // an array list to hold all the comments
List<Ontology> ontologies = this.modifiedModel.listOntologies().toList();
List<Ontology> ontologies = modifiedModel.listOntologies().toList();
ArrayList<Ontology> ontologiesTo = new ArrayList<Ontology>();
int nbOntologies = ontologies.size();
int toBeRemoved = (int)( percentage * nbOntologies ); //the number of Ontologies comments to be removed
......@@ -1166,7 +1165,7 @@ public class OntologyModifier {
if ( level == 1 ) //no change
return;
checkClassHierarchy(); //check if the class hierarchy is built
active = this.classHierarchy.flattenClassHierarchy( this.modifiedModel, level, levelClasses, parentLevelClasses, superLevelClasses);
active = this.classHierarchy.flattenClassHierarchy( modifiedModel, level, levelClasses, parentLevelClasses, superLevelClasses);
size = levelClasses.size();
/* remove duplicates from list */
......@@ -1196,10 +1195,10 @@ public class OntologyModifier {
restr.add(r);
if ( r.isSomeValuesFromRestriction() )
restr.add(r);
//System.out.println( cls.getURI() + cls.getLocalName() );
//System.err.println( cls.getURI() + cls.getLocalName() );
}
}
//System.out.println( restr.size() );
//System.err.println( restr.size() );
if ( !restrictions.containsKey( parentClass.getURI() ) ) {
restrictions.put( parentClass.getURI(), restr );
......@@ -1210,11 +1209,11 @@ public class OntologyModifier {
if ( active ) { //if ( !parentClass.getURI().equals( "Thing" ) ) {
OntClass superClass = superLevelClasses.get( i ); //parent class of the child class parents
//System.out.println("SuperClass class [" + superClass.getURI() + "]");
//System.out.println("Parent class [" + parentClass.getURI() + "]");
//System.out.println("Child class [" + childClass.getURI() + "]");
//System.err.println("SuperClass class [" + superClass.getURI() + "]");
//System.err.println("Parent class [" + parentClass.getURI() + "]");
//System.err.println("Child class [" + childClass.getURI() + "]");
if ( this.modifiedModel.containsResource(parentClass) ) {
if ( modifiedModel.containsResource(parentClass) ) {
//to check if the class appears as unionOf, someValuesFrom, allValuesFrom ..
unionOf.put(parentClass.getURI(), superClass.getURI());
checkClassesRestrictions ( parentClass, superClass );
......@@ -1223,9 +1222,9 @@ public class OntologyModifier {
childClass.addSuperClass( superClass );
parentClass.removeSubClass( childClass );
} else {
OntClass superClass = this.modifiedModel.createClass( OWL.Thing.getURI() ); //Thing class
OntClass superClass = modifiedModel.createClass( OWL.Thing.getURI() ); //Thing class
if ( this.modifiedModel.containsResource(parentClass) ) {
if ( modifiedModel.containsResource(parentClass) ) {
//to check if the class appears as unionOf..
unionOf.put(parentClass.getURI(), superClass.getURI());
checkClassesRestrictions ( parentClass, superClass );
......@@ -1247,7 +1246,7 @@ public class OntologyModifier {
}
//checks if the class appears like unionOf, someValuesFrom, allValuesFrom .. and replaces its appearence with the superclass
this.modifiedModel = changeDomainRange(unionOf);
modifiedModel = changeDomainRange(unionOf);
//remove the parentClass from the alignment
for ( String key : this.params.stringPropertyNames() ) {
......@@ -1271,7 +1270,7 @@ public class OntologyModifier {
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
checkClassHierarchy(); //check if the class hierarchy is built
active = this.classHierarchy.flattenClassHierarchy( this.modifiedModel, level, levelClasses, parentLevelClasses, superLevelClasses);
active = this.classHierarchy.flattenClassHierarchy( modifiedModel, level, levelClasses, parentLevelClasses, superLevelClasses);
size = levelClasses.size();
for ( int i=0; i<size; i++ ) {
......@@ -1302,7 +1301,7 @@ public class OntologyModifier {
public void removeRestrictions( float percentage ) {
List<Restriction> restrictions = new ArrayList<Restriction>();
List<Restriction> restrictionsTo = new ArrayList<Restriction>(); //the array list of restrictions to be removed
restrictions = this.modifiedModel.listRestrictions().toList();
restrictions = modifiedModel.listRestrictions().toList();
int nbRestrictions = restrictions.size(); //the number of restrictions
int toBeRemoved = (int)( percentage*nbRestrictions ); //the number of restrictions to be removed
......@@ -1333,10 +1332,10 @@ public class OntologyModifier {
}
public void initializeAlignment() {
List<OntClass> classes = this.modifiedModel.listNamedClasses().toList();//all classes
List<OntProperty> properties = this.modifiedModel.listAllOntProperties().toList();//all properties
List<Individual> individuals = this.modifiedModel.listIndividuals().toList();//all individuals
List<Ontology> ontologies = this.modifiedModel.listOntologies().toList();//all Ontologies
List<OntClass> classes = modifiedModel.listNamedClasses().toList();//all classes
List<OntProperty> properties = modifiedModel.listAllOntProperties().toList();//all properties
List<Individual> individuals = modifiedModel.listIndividuals().toList();//all individuals
List<Ontology> ontologies = modifiedModel.listOntologies().toList();//all Ontologies
this.params = new Properties();
......@@ -1373,30 +1372,29 @@ public class OntologyModifier {
String value = this.params.getProperty(key);
URI uri1 = URI.create(key);
URI uri2 = URI.create(this.namespaceNew + value.substring(value.indexOf(this.base) + this.base.length()));
//System.out.println( "[" + key + "][" + value + "]" );
//System.err.println( "[" + key + "][" + value + "]" );
this.alignment.addAlignCell( uri1, uri2, "=", 1 );
}
} catch (AlignmentException aex) { System.out.println( "Exception " + aex.getMessage() );
} catch (AlignmentException aex) { System.err.println( "Exception " + aex.getMessage() );
} catch (Exception ex) { System.err.println("Exception " + ex.getMessage());
}
}
public void setNewNamespace(String newNamespace) {
this.namespaceNew = newNamespace;
//System.out.println("New namespace [" + this.namespaceNew + "]");
//System.err.println("New namespace [" + this.namespaceNew + "]");
}
//change the namespace of the modified ontology
// JE: ??
public OntModel changeNamespace () {
List<Statement> statements = this.modifiedModel.listStatements().toList(); //the statements of the model
this.isChanged = true;
boolean isSubj, isPred, isObj;;
OntModel newModel = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );//create new Model
//iterate through all the statements and change the namespace
for ( Statement stm : statements ) {
for ( Statement stm : modifiedModel.listStatements().toList() ) {
Resource subject = stm.getSubject(); //the subject
Property predicate = stm.getPredicate(); //the predicate
RDFNode object = stm.getObject(); //the object
......@@ -1468,23 +1466,18 @@ public class OntologyModifier {
//returns the modified ontology after changing the namespace
public OntModel getModifiedOntology () {
//System.out.println( "->change namespace" );
this.modifiedModel = changeNamespace(); //change the namespace of the modified ontology
//System.out.println( "->namespace changed" );
return this.modifiedModel;
}
//set the model
public void setModel( OntModel model ) {
this.model = model;
//System.err.println( "->change namespace" );
modifiedModel = changeNamespace(); //change the namespace of the modified ontology
//System.err.println( "->namespace changed" );
return modifiedModel;
}
public void setModifiedModel(OntModel model) {
this.modifiedModel = model;
modifiedModel = model;
}
public OntModel getModifiedModel() {
return this.modifiedModel;
return modifiedModel;
}
//get properties
......@@ -1505,80 +1498,78 @@ public class OntologyModifier {
//OntModel model, OntModel modifiedModel, Alignment alignment
public void modifyOntology( String name, String param ) {
if ( param == null ) return;
if ( name == null || name.equals("") ) {
System.err.println( "No parameter" ); //no parameter as input
return;
};
float value = 0.0f;
String aux = "";
if ( name == null || param == null || name.equals("") ) {
System.out.println( "No parameter" ); //no parameter as input
} else {
if ( param.equals( ParametersIds.NO_HIERARCHY ) )
;
else if( param != null) //the value of the parameter
value = Float.valueOf( param ).floatValue(); // ??
else
aux = param;
if ( !this.isAlign ) {
initializeAlignment(); //determine the elements from the initial reference alignment
}
if ( param.equals( ParametersIds.NO_HIERARCHY ) )
;
else if( param != null) //the value of the parameter
value = Float.valueOf( param ).floatValue(); // ??
else
aux = param;
if ( name.equals( ParametersIds.ADD_CLASSES ) ) { //add percentage classes
System.out.println( "Add Class" + "[" + value + "]");
addSubClasses( value );
} else if ( name.equals( ParametersIds.REMOVE_CLASSES ) ) { //remove percentage classes
System.out.println( "Remove Class" + "[" + value + "]");
removeSubClasses( value );
} else if ( name.equals( ParametersIds.REMOVE_COMMENTS ) ) { //remove percentage comments
System.out.println( "Remove Comments" + "[" + value + "]");
removeComments ( value );
} else if ( name.equals( ParametersIds.REMOVE_PROPERTIES ) ) { //remove percentage properties
System.out.println( "Remove Property" + "[" + value + "]");
removeProperties ( value );
} else if ( name.equals( ParametersIds.ADD_PROPERTIES ) ) { //add percentage properties
System.out.println( "Add Property" + "[" + value + "]");
addProperties ( value );
} 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) );
int nbClasses = Integer.valueOf( aux.substring(index+1, aux.length()) );
System.out.println( "level " + level );
System.out.println( "nbClasses " + nbClasses );
float percentage = 1.00f;
addClasses ( level, nbClasses, percentage );
} 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 );
} else if ( name.equals( ParametersIds.LEVEL_FLATTENED ) ) { //flatten a level
//levelFlattened ( level );
levelFlattened ( (int)value );
System.out.println( "New class hierarchy level " + getMaxLevel() ) ;
} 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);
} 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);
} else if ( name.equals( ParametersIds.REMOVE_RESTRICTIONS ) ) { //remove percentage restrictions
System.out.println("Remove restrictions" + "[" + value + "]");
removeRestrictions( value );
} else if ( name.equals( ParametersIds.REMOVE_INDIVIDUALS ) ) { //remove percentage individuals
System.out.println("Remove individuals" + "[" + value + "]");
removeIndividuals( value );
} else if ( name.equals( ParametersIds.NO_HIERARCHY ) ) { //no hierarchy
System.out.println( "NoHierarchy" );
noHierarchy();
}
if ( !this.isAlign ) {
initializeAlignment(); //determine the elements from the initial reference alignment
}
//rebuild the class hierarchy every time
this.isBuild = false;
this.isChanged = false;
if ( name.equals( ParametersIds.ADD_CLASSES ) ) { //add percentage classes
System.err.println( "Add Class" + "[" + value + "]");
addSubClasses( value );
} else if ( name.equals( ParametersIds.REMOVE_CLASSES ) ) { //remove percentage classes
System.err.println( "Remove Class" + "[" + value + "]");
removeSubClasses( value );
} else if ( name.equals( ParametersIds.REMOVE_COMMENTS ) ) { //remove percentage comments
System.err.println( "Remove Comments" + "[" + value + "]");
removeComments ( value );
} else if ( name.equals( ParametersIds.REMOVE_PROPERTIES ) ) { //remove percentage properties
System.err.println( "Remove Property" + "[" + value + "]");
removeProperties ( value );
} else if ( name.equals( ParametersIds.ADD_PROPERTIES ) ) { //add percentage properties
System.err.println( "Add Property" + "[" + value + "]");
addProperties ( value );
} 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) );
int nbClasses = Integer.valueOf( aux.substring(index+1, aux.length()) );
System.err.println( "level " + level );
System.err.println( "nbClasses " + nbClasses );
float percentage = 1.00f;
addClasses ( level, nbClasses, percentage );
} else if ( name.equals( ParametersIds.REMOVE_CLASSESLEVEL ) ) { //remove all the classes from the level level
System.err.println("Remove all classes from level" + (int)value );
removeClassesFromLevel ( (int)value );
} else if ( name.equals( ParametersIds.LEVEL_FLATTENED ) ) { //flatten a level
//levelFlattened ( level );
levelFlattened ( (int)value );
System.err.println( "New class hierarchy level " + getMaxLevel() ) ;
} else if ( name.equals( ParametersIds.RENAME_CLASSES ) ) { //rename classes
System.err.println("Rename classes" + "[" + value + "]" );
//System.err.println("\nValue = " + value + "\n"); //activeProperties, activeClasses, ..
modifiedModel = renameResource ( false, true, value, true, false, false, 0);
} else if ( name.equals( ParametersIds.RENAME_PROPERTIES ) ) { //rename properties
System.err.println("Rename properties " + "[" + value + "]" );
//System.err.println("\nValue = " + value + "\n"); //activeProperties, activeClasses, ..
modifiedModel = renameResource ( true, false, value, true, false, false, 0);
} else if ( name.equals( ParametersIds.REMOVE_RESTRICTIONS ) ) { //remove percentage restrictions
System.err.println("Remove restrictions" + "[" + value + "]");
removeRestrictions( value );
} else if ( name.equals( ParametersIds.REMOVE_INDIVIDUALS ) ) { //remove percentage individuals
System.err.println("Remove individuals" + "[" + value + "]");
removeIndividuals( value );
} else if ( name.equals( ParametersIds.NO_HIERARCHY ) ) { //no hierarchy
System.err.println( "NoHierarchy" );
noHierarchy();
}
}
//rebuild the class hierarchy every time
this.isBuild = false;
this.isChanged = false;
}
......
......@@ -71,7 +71,7 @@ public class TestGen {
params = new Properties();
longopts[0] = new LongOpt("method", LongOpt.REQUIRED_ARGUMENT, null, 'm');
longopts[1] = new LongOpt("init", LongOpt.REQUIRED_ARGUMENT, null, 'i');
longopts[1] = new LongOpt("initonto", LongOpt.REQUIRED_ARGUMENT, null, 'i');
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');
......@@ -140,12 +140,11 @@ public class TestGen {
TestGenerator tg = new TestGenerator();
tg.modifyOntology( fileName, (Properties)null, testNumber, params );
} else if ( methodName.equals( GENERATE_BENCHMARK ) ) { //generate the benchmark
GenerateBenchmark gb = new GenerateBenchmark( fileName );
BenchmarkGenerator gb = new BenchmarkGenerator();
gb.generate( params );
}
}
public void printUsage() {
System.out.println("TestGen [options]");
System.out.println("options are");
......
......@@ -116,6 +116,8 @@ public class TestGenerator implements AlignedOntologyGenerator {
//writes ontology
public static void writeOntology( OntModel model, String destFile, String ns ) {
// JE: How to ensure that it generates the owl:Ontology close?
// Otherwise, some parsers cannot parse it correctly
try {
File f = new File( destFile );
FileOutputStream fout = new FileOutputStream( f );
......@@ -169,14 +171,22 @@ public class TestGenerator implements AlignedOntologyGenerator {
return modifyOntology( dirprefix+"/"+prevDirName+"/"+ontoname, al, crtDirName, p );
}
/**
* Generate a test by altering an existing test
*/
public Properties incrementModifyOntology( String prevTestDir, Properties al, String testDir, Properties params ) {
// JE: maybe ERROR crtDirName
return modifyOntology( dirprefix+"/"+prevTestDir+"/"+ontoname, al, testDir, params );
}
//modifies an ontology
/**
* Generate a test from an ontology
*/
public Properties modifyOntology( String file, Properties al, String testNumber, Properties params) {
if ( debug ) System.err.println( "Source: "+file+" generate "+testNumber );
if ( debug ) System.err.println( "Source: "+file+" Target "+testNumber );
//set the TestGenerator ontology
OntModel onto = loadOntology( file ); // who needs model?
OntModel onto = loadOntology( file );
//set the namespace
setNamespace( getURI( testNumber ) );
Alignment align = null;
......@@ -189,13 +199,16 @@ public class TestGenerator implements AlignedOntologyGenerator {
return modifier.getProperties();
}
// ******************************************************* GENERATOR
//generate the alingnment
public Alignment generate( OntModel onto, Properties p, Properties initalign ) {
if ( debug ) System.err.println( urlprefix+" / "+dirprefix+" / "+ontoname+" / "+alignname );
params = p;
public Alignment generate( OntModel onto, Properties params, Properties initalign ) {
if ( debug ) {
System.err.println( "[-------------------------------------------------]" );
System.err.println( urlprefix+" / "+dirprefix+" / "+ontoname+" / "+alignname );
}
// Initialise the modifier class
modifier = new OntologyModifier( onto, new URIAlignment()); //build the ontology modifier for the first time
modifier = new OntologyModifier( onto, new URIAlignment() );
modifier.setNewNamespace( namespace );
// Initialize the reference alignment
if ( initalign == null ) {
......@@ -205,10 +218,34 @@ public class TestGenerator implements AlignedOntologyGenerator {
}
// Apply all modifications
if ( debug ) System.out.println( "[-------------------------------------------------]" );
/*
// JE: Here there is an obvious problems that the modifications are NOT applied in the specified order!
// Hence we should have a mega reordering of these parameter (for all of these, if they are here, do something)
// That would be better as a list in this case than parameters
// But parameters are more flexible...
applyModification( modifier, params, ParametersIds.REMOVE_CLASSES );
applyModification( modifier, params, ParametersIds.REMOVE_PROPERTIES );
applyModification( modifier, params, ParametersIds.REMOVE_COMMENTS );
applyModification( modifier, params, ParametersIds.REMOVE_RESTRICTIONS );
applyModification( modifier, params, ParametersIds.ADD_CLASSES );
applyModification( modifier, params, ParametersIds.ADD_PROPERTIES );
// SUPPRESSED FOR TESTING THAT THIS IS THE CULPRIT
//if ( params.getProperty( ParametersIds.ADD_CLASSES ) == null ) applyModification( modifier, params, ParametersIds.RENAME_CLASSES );
applyModification( modifier, params, ParametersIds.RENAME_CLASSES );
applyModification( modifier, params, ParametersIds.RENAME_PROPERTIES );
// UNTIL HERE, WE USE THE DOCUMENTED ORDER
applyModification( modifier, params, ParametersIds.REMOVE_CLASSESLEVEL );
applyModification( modifier, params, ParametersIds.LEVEL_FLATTENED );
applyModification( modifier, params, ParametersIds.NO_HIERARCHY );
applyModification( modifier, params, ParametersIds.ADD_CLASSESLEVEL );
applyModification( modifier, params, ParametersIds.REMOVE_INDIVIDUALS );
*/
for( String key : params.stringPropertyNames() ) {
String value = params.getProperty(key);
if ( debug ) System.out.println( "[" +key + "] => [" + value + "]");
//if ( debug ) System.out.println( "[" +key + "] => [" + value + "]");
modifier.modifyOntology( key, value ); //modify the ontology according to it
}
......@@ -222,4 +259,9 @@ public class TestGenerator implements AlignedOntologyGenerator {
public Alignment generate( OntModel onto, Properties p ) {
return generate( onto, p, (Properties)null );
}
public void applyModification( OntologyModifier modifier, Properties p, String m ) {
modifier.modifyOntology( m, p.getProperty( m ) );
}
}
/*
* $Id$
*
* Copyright (C) 2011, INRIA
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
/*
* This class describes a test set (such as the benchmark test set of OAEI)
* It is described as a hierarchy of test cases which can be generated from one another
* This class is an abstract
* 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;
import java.util.Properties;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
public abstract class TestSet {
private String initOntoFile; //the initial ontology file
protected boolean continuous = false;
protected boolean debug = false;
private TestGenerator generator; // a TestGenerator
protected TestCase root;
protected HashMap<String,TestCase> tests;
static String FULL = "1.0f";
public TestSet() {
generator = new TestGenerator();
tests = new HashMap<String,TestCase>();
}
public void addTestChild( String from, String name, Properties params ) {
addTestChild( tests.get( from ), name, params );
}
public void addTestChild( TestCase father, String name, Properties params ) {
//System.err.println( name + " ["+father+"]" );
TestCase c = father.addSubTest( name, params );
tests.put( name, c );
}
public TestCase initTests( String name ) {
TestCase c = TestCase.initTestTree( name );
tests.put( name, c );
return c;
}
public Properties newProperties( String k, String v, String k2, String v2 ) {
Properties p = newProperties( k2, v2 );
p.setProperty( k, v );
return p;
}
public Properties newProperties( String k, String v ) {
Properties p = new Properties();
p.setProperty( k, v );
return p;
}
// ----------------------------------------------------------
// Declare test generation tree
public abstract void initTestCases( Properties params );
// ----------------------------------------------------------
// Generates the test set
public void generate( Properties params ) {
// Initialises test cases tree
initTestCases( params );
// Print it
if ( debug ) printTestHierarchy( root, 0 );
// Generator parameters... are these OK?
generator.setDebug( debug );
initOntoFile = params.getProperty( "filename" ); // If no filename error
if ( params.getProperty( "urlprefix" ) != null ) generator.setURLPrefix( params.getProperty( "urlprefix" ) );
if ( params.getProperty( "outdir" ) != null ) generator.setDirPrefix( params.getProperty( "outdir" ) );
if ( params.getProperty( "continuous" ) != null ) continuous = true;
String ontoname = params.getProperty( "ontoname" );
if ( ontoname != null ) {
generator.setOntoFilename( params.getProperty( "ontoname" ) );
} else {
ontoname = "onto.rdf"; // could be better
}
if ( params.getProperty( "alignname" ) != null ) generator.setAlignFilename( params.getProperty( "alignname" ) );
// Generate all tests
startTestGeneration();
}
// Recursively generate tests
public void startTestGeneration() {
Properties newalign;
newalign = generator.modifyOntology( initOntoFile, (Properties)null, root.name, new Properties() );
for ( TestCase sub : root.subTests ) {
generateTest( sub, newalign );
}
}
public void generateTest( TestCase c, Properties align ) {
Properties newalign;
if ( continuous ) {
newalign = generator.incrementModifyOntology( c.father.name, (Properties)align.clone(), c.name, c.parameters );
} else {
newalign = generator.modifyOntology( initOntoFile, (Properties)null, c.name, c.cumulated );
}
for ( TestCase sub : c.subTests ) {
generateTest( sub, newalign );
}
}
public void printTestHierarchy( TestCase c, int level ) {
for ( int i = 0; i < level; i++ ) System.out.print( " " );
System.out.print( c.name+" [" );
for ( Object k : c.cumulated.keySet() ) {
System.out.print( " "+k+"="+c.cumulated.getProperty( (String)k )+";" );
}
System.out.println( " ]" );
for ( TestCase sub : c.subTests ) printTestHierarchy( sub, level+1 );
}
}
class TestCase {
public String name = null; // test name = directory
public TestCase father = null; // test this one is generated from
public Properties parameters = null; // new modifications to apply
public Properties cumulated = null; // cummulated modifications from root
public Set<TestCase> subTests = null; // tests derived from this one
public TestCase(){
subTests = new HashSet<TestCase>();
}
public TestCase( String n ){
subTests = new HashSet<TestCase>();
name = n;
}
public TestCase( String n, Properties p ){
subTests = new HashSet<TestCase>();
name = n;
parameters = p;
}
public TestCase addSubTest( String name, Properties params ) {
TestCase t = new TestCase( name, params );
// Add the diferential parameters (eventually)
t.father = this;
subTests.add( t );
t.cumulated = (Properties)cumulated.clone();
for ( Object k : params.keySet() ) {
t.cumulated.setProperty( (String)k, params.getProperty( (String)k ) );
}
return t;
}
public static TestCase initTestTree( String n ) {
TestCase c = new TestCase( n );
c.cumulated = new Properties();
return c;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment