Skip to content

Commit

Permalink
Merge pull request #5 from EmaroLab/OWLapi5-Manipulation
Browse files Browse the repository at this point in the history
Owl api5 manipulation
  • Loading branch information
buoncubi authored Jun 1, 2017
2 parents b16df34 + 1eca880 commit 299866e
Show file tree
Hide file tree
Showing 203 changed files with 98,734 additions and 64,705 deletions.
374 changes: 217 additions & 157 deletions .gitignore

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions amor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Alessio Capitanelli.
* Copyright (C) 2017 Luca Buoncompagni.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down Expand Up @@ -30,10 +30,11 @@ repositories {

dependencies {

//compile group: 'org.openrdf.sesame', name: 'sesame-model', version: '2.7.0'
//runtime group: 'org.openrdf.sesame', name: 'sesame-model', version: '2.7.14'

compile group: 'com.github.galigator.openllet', name: 'openllet-owlapi', version: '2.5.1'
compile group: 'net.sourceforge.owlapi', name: 'owlapi-distribution', version: '5.0.2'
//compile group: 'net.sourceforge.owlapi', name: 'org.semanticweb.hermit', version: '1.3.8.510'

compile group: 'com.github.galigator.openllet', name: 'openllet-owlapi', version: '2.5.1'
compile group: 'net.sourceforge.owlapi', name: 'owlapi-distribution', version: '5.0.5'
}

2 changes: 0 additions & 2 deletions amor/src/main/java/it/emarolab/amor/examples/Benchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,5 @@ public static void main(String[] args) {
//
//


// todo: cheep track of changes in queries and benchmarks in the 'files/benchmarks' directory
}
}
187 changes: 93 additions & 94 deletions amor/src/main/java/it/emarolab/amor/examples/BufferingTest.java
Original file line number Diff line number Diff line change
@@ -1,102 +1,101 @@
package it.emarolab.amor.examples;

import org.semanticweb.owlapi.model.OWLLiteral;

import it.emarolab.amor.owlInterface.OWLReferences;
import it.emarolab.amor.owlInterface.OWLReferencesInterface.OWLReferencesContainer;
import org.semanticweb.owlapi.model.OWLLiteral;

public class BufferingTest {

// ontology configurations
public static final String OWLREFERENCES_NAME = "refName";
public static final String ONTOLOGY_FILE_PATH = "files/ontologies/ontology_manipulation.owl";
public static final String ONTOLOGY_IRI_PATH = "http://www.semanticweb.org/luca-buoncompagni/aMor/examples";
public static final Boolean BUFFERING_REASONER = true; // if true you must to update manually the reasoner. Otherwise it synchronizes itself any time is needed
public static final Boolean BUFFERING_OWLMANIPULATOR = true; // if true you must to apply changes manually. Otherwise their are applied as soon as possible.

// ontological entities name
public static final Integer INITIAL_CNT = 3;
public static final String CNT_IND = "Counter"; // this is an individual with cares about the new ID to assign to X_IND
public static final String CNT_DATAPROP = "hasMaxCount";
public static final String X1_IND = "Ind1"; // this is an individual which must have a unique (in the ontology w.r.t. CNT_IND) identifier
public static final String X2_IND = "Ind2"; // this is an individual which must have a unique (in the ontology w.r.t. CNT_IND) identifier
public static final String X3_IND = "Ind3"; // this is an individual which must have a unique (in the ontology w.r.t. CNT_IND) identifier
public static final String X_DATAPROP = "hasId";
public static void main(String[] args) {
// 1) let create new ontology with default reasoner (Pellet) and start GUI result visualisation
OWLReferences ontoRef = OWLReferencesContainer.newOWLReferencesCreated( OWLREFERENCES_NAME, ONTOLOGY_FILE_PATH, ONTOLOGY_IRI_PATH, BUFFERING_REASONER);
ontoRef.setOWLManipulatorBuffering( BUFFERING_OWLMANIPULATOR); // if not specified, default value=false {@link OWLManipulator#DEFAULT_CHANGE_BUFFERING}
// 2) add base ontological entities
ontoRef.addIndividual( CNT_IND);
ontoRef.addDataPropertyB2Individual( CNT_IND, CNT_DATAPROP, INITIAL_CNT);
ontoRef.addIndividual( X1_IND);
ontoRef.addIndividual( X2_IND);
ontoRef.addIndividual( X3_IND);
applyChanges( ontoRef); // this considers BUFFERING_MANIPULATOR flag
// 3) get the starting cnt
Integer javaCnt = 0;
OWLLiteral ontoCnt = ontoRef.getOnlyDataPropertyB2Individual( CNT_IND, CNT_DATAPROP);
if( ontoCnt != null)
javaCnt = Integer.valueOf( ontoCnt.getLiteral());
// 4) assign a new id for couple of times and apply owl manipulator changes (if flag is true)
assignIncrementalId( ontoRef, X1_IND, javaCnt); // id1 = INITIAL_CNT, cnt = INITIAL_CNT + 1;
assignIncrementalId( ontoRef, X2_IND, javaCnt); // id2 = INITIAL_CNT, cnt = INITIAL_CNT + 1;
javaCnt = assignIncrementalId( ontoRef, X3_IND, javaCnt); // id3 = INITIAL_CNT, cnt = INITIAL_CNT + 1;
applyChanges( ontoRef); // this considers BUFFERING_MANIPULATOR flag
// 5) do something similar to (3) for testing purposes
assignIncrementalId( ontoRef, X1_IND, javaCnt); // id1 = INITIAL_CNT + 1, cnt = INITIAL_CNT + 2;
assignIncrementalId( ontoRef, X2_IND, javaCnt); // id2 = INITIAL_CNT + 1, cnt = INITIAL_CNT + 2;
javaCnt = assignIncrementalId( ontoRef, X3_IND, javaCnt); // id3 = INITIAL_CNT + 1, cnt = INITIAL_CNT + 2;
applyChanges( ontoRef); // this considers BUFFERING_MANIPULATOR flag
// 6) do something similar to (3) for testing purposes
assignIncrementalId( ontoRef, X1_IND, javaCnt); // id1 = INITIAL_CNT + 2, cnt = INITIAL_CNT + 3;
assignIncrementalId( ontoRef, X2_IND, javaCnt); // id2 = INITIAL_CNT + 2, cnt = INITIAL_CNT + 3;
javaCnt = assignIncrementalId( ontoRef, X3_IND, javaCnt); // id3 = INITIAL_CNT + 2, cnt = INITIAL_CNT + 3;
applyChanges( ontoRef); // this considers BUFFERING_MANIPULATOR flag
// 7) reason (if it is buffer)
reason( ontoRef);
// 8) show results
ontoRef.printOntologyOnConsole();
System.err.println( ontoRef.getIndividualB2Thing());
ontoRef.saveOntology();
}
// procedure to assign a new id to X_IND and update the counter to point to an ID not assigned to any individuals
private static Integer assignIncrementalId( OWLReferences ontoRef, String ind, Integer cnt){
// get the actual value of the counter
OWLLiteral ontoCnt = ontoRef.getOWLLiteral( cnt);
OWLLiteral newOntoCount = ontoRef.getOWLLiteral( cnt + 1);
// get the actual value of the id
OWLLiteral ontoId = ontoRef.getOnlyDataPropertyB2Individual( ind, X_DATAPROP);
// update the new id to the individual by overwriting the old value
ontoRef.replaceDataProperty( ontoRef.getOWLIndividual( ind), ontoRef.getOWLDataProperty( X_DATAPROP), ontoId, ontoCnt);
// get the actual cnt
OWLLiteral oldCnt = ontoRef.getOnlyDataPropertyB2Individual( CNT_IND, CNT_DATAPROP);
// update the counter individual by overwriting the old value
ontoRef.replaceDataProperty( ontoRef.getOWLIndividual( CNT_IND), ontoRef.getOWLDataProperty( CNT_DATAPROP), oldCnt, newOntoCount);
return cnt + 1;
}
// apply changes w.r.t. to buggering flag
private static void applyChanges( OWLReferences ontoRef){
if( BUFFERING_OWLMANIPULATOR)
ontoRef.applyOWLManipulatorChanges();
}
// update the state of the reasoner w.r.t. buffering flag
private static void reason( OWLReferences ontoRef){
if( BUFFERING_REASONER)
ontoRef.synchronizeReasoner();
}
// ontology configurations
public static final String OWLREFERENCES_NAME = "refName";
public static final String ONTOLOGY_FILE_PATH = "files/ontologies/ontology_manipulation.owl";
public static final String ONTOLOGY_IRI_PATH = "http://www.semanticweb.org/luca-buoncompagni/aMor/examples";
public static final Boolean BUFFERING_REASONER = true; // if true you must to update manually the reasoner. Otherwise it synchronizes itself any time is needed
public static final Boolean BUFFERING_OWLMANIPULATOR = true; // if true you must to apply changes manually. Otherwise their are applied as soon as possible.

// ontological entities name
public static final Integer INITIAL_CNT = 3;
public static final String CNT_IND = "Counter"; // this is an individual with cares about the new ID to assign to X_IND
public static final String CNT_DATAPROP = "hasMaxCount";
public static final String X1_IND = "Ind1"; // this is an individual which must have a unique (in the ontology w.r.t. CNT_IND) identifier
public static final String X2_IND = "Ind2"; // this is an individual which must have a unique (in the ontology w.r.t. CNT_IND) identifier
public static final String X3_IND = "Ind3"; // this is an individual which must have a unique (in the ontology w.r.t. CNT_IND) identifier
public static final String X_DATAPROP = "hasId";

public static void main(String[] args) {
// 1) let create new ontology with default reasoner (Pellet) and start GUI result visualisation
OWLReferences ontoRef = OWLReferencesContainer.newOWLReferencesCreated( OWLREFERENCES_NAME, ONTOLOGY_FILE_PATH, ONTOLOGY_IRI_PATH, BUFFERING_REASONER);
ontoRef.setOWLManipulatorBuffering( BUFFERING_OWLMANIPULATOR); // if not specified, default value=false {@link OWLManipulator#DEFAULT_CHANGE_BUFFERING}

// 2) add base ontological entities
ontoRef.addIndividual( CNT_IND);
ontoRef.addDataPropertyB2Individual( CNT_IND, CNT_DATAPROP, INITIAL_CNT);
ontoRef.addIndividual( X1_IND);
ontoRef.addIndividual( X2_IND);
ontoRef.addIndividual( X3_IND);
applyChanges( ontoRef); // this considers BUFFERING_MANIPULATOR flag

// 3) get the starting cnt
Integer javaCnt = 0;
OWLLiteral ontoCnt = ontoRef.getOnlyDataPropertyB2Individual( CNT_IND, CNT_DATAPROP);
if( ontoCnt != null)
javaCnt = Integer.valueOf( ontoCnt.getLiteral());

// 4) assign a new id for couple of times and apply owl manipulator changes (if flag is true)
assignIncrementalId( ontoRef, X1_IND, javaCnt); // id1 = INITIAL_CNT, cnt = INITIAL_CNT + 1;
assignIncrementalId( ontoRef, X2_IND, javaCnt); // id2 = INITIAL_CNT, cnt = INITIAL_CNT + 1;
javaCnt = assignIncrementalId( ontoRef, X3_IND, javaCnt); // id3 = INITIAL_CNT, cnt = INITIAL_CNT + 1;
applyChanges( ontoRef); // this considers BUFFERING_MANIPULATOR flag

// 5) do something similar to (3) for testing purposes
assignIncrementalId( ontoRef, X1_IND, javaCnt); // id1 = INITIAL_CNT + 1, cnt = INITIAL_CNT + 2;
assignIncrementalId( ontoRef, X2_IND, javaCnt); // id2 = INITIAL_CNT + 1, cnt = INITIAL_CNT + 2;
javaCnt = assignIncrementalId( ontoRef, X3_IND, javaCnt); // id3 = INITIAL_CNT + 1, cnt = INITIAL_CNT + 2;
applyChanges( ontoRef); // this considers BUFFERING_MANIPULATOR flag

// 6) do something similar to (3) for testing purposes
assignIncrementalId( ontoRef, X1_IND, javaCnt); // id1 = INITIAL_CNT + 2, cnt = INITIAL_CNT + 3;
assignIncrementalId( ontoRef, X2_IND, javaCnt); // id2 = INITIAL_CNT + 2, cnt = INITIAL_CNT + 3;
javaCnt = assignIncrementalId( ontoRef, X3_IND, javaCnt); // id3 = INITIAL_CNT + 2, cnt = INITIAL_CNT + 3;
applyChanges( ontoRef); // this considers BUFFERING_MANIPULATOR flag

// 7) reason (if it is buffer)
reason( ontoRef);

// 8) show results
ontoRef.printOntologyOnConsole();

System.err.println( ontoRef.getIndividualB2Thing());

ontoRef.saveOntology();

}

// procedure to assign a new id to X_IND and update the counter to point to an ID not assigned to any individuals
private static Integer assignIncrementalId( OWLReferences ontoRef, String ind, Integer cnt){
// get the actual value of the counter
OWLLiteral ontoCnt = ontoRef.getOWLLiteral( cnt);
OWLLiteral newOntoCount = ontoRef.getOWLLiteral( cnt + 1);
// get the actual value of the id
OWLLiteral ontoId = ontoRef.getOnlyDataPropertyB2Individual( ind, X_DATAPROP);
// update the new id to the individual by overwriting the old value
ontoRef.replaceDataProperty( ontoRef.getOWLIndividual( ind), ontoRef.getOWLDataProperty( X_DATAPROP), ontoId, ontoCnt);
// get the actual cnt
OWLLiteral oldCnt = ontoRef.getOnlyDataPropertyB2Individual( CNT_IND, CNT_DATAPROP);
// update the counter individual by overwriting the old value
ontoRef.replaceDataProperty( ontoRef.getOWLIndividual( CNT_IND), ontoRef.getOWLDataProperty( CNT_DATAPROP), oldCnt, newOntoCount);
return cnt + 1;
}

// apply changes w.r.t. to buggering flag
private static void applyChanges( OWLReferences ontoRef){
if( BUFFERING_OWLMANIPULATOR)
ontoRef.applyOWLManipulatorChanges();
}

// update the state of the reasoner w.r.t. buffering flag
private static void reason( OWLReferences ontoRef){
if( BUFFERING_REASONER)
ontoRef.synchronizeReasoner();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@

public class OWLRefDebuggingExample {

public static void main(String[] args) {
// 1) you may want to save on file the logs of the system. Set it to default (time-hour base name) or provide a directory path
// you can enable and disable logs by changing the flags in the class Logger.LoggerFlag or you may want to set it like:
Logger.LoggerFlag.setLogOntologyExporter( true); // [PARAMETER]
Logger.setPrintOnFile( FileManager.DEFAULT_command); // [PARAMETER]
// 2) let now open the pizza ontology from web with pellet reasoner (default)
String ontoRefName = "ontoRef3"; // this must be a unique identifier for all the references you what to create into the system
Boolean bufferingReasoner = false; // reasoning is automatically synchronised
String pizzaOntologyIri = "http://www.co-ode.org/ontologies/pizza/pizza.owl";
String filePath = "http://protege.stanford.edu/ontologies/pizza/pizza.owl";
OWLReferences ontoRef = OWLReferencesContainer.newOWLReferenceFromWeb( ontoRefName, filePath, pizzaOntologyIri, bufferingReasoner);
// 3) you may want to print the ontology.
ontoRef.printOntologyOnConsole();
// 4) [PERAMETER] the system comes with a simple GUI from which it is possible to see the state of the ontology
// during run time as well as make some basic changes. Be aware that the GUI is not stable yet!
//NOT PORTED TO OWL API 5 JET
Thread t = new Thread( new GuiRunner( ontoRefName));
t.start();
// 5) be sure to see all logs!
Logger.flush();
// wait to give the possibility to interact with the GUI
try {
for( int i = 0; i < 100 ; i++) // about 20 minutes
Thread.sleep( 15000);
} catch (InterruptedException e) {}
}
public static void main(String[] args) {
// 1) you may want to save on file the logs of the system. Set it to default (time-hour base name) or provide a directory path
// you can enable and disable logs by changing the flags in the class Logger.LoggerFlag or you may want to set it like:
Logger.LoggerFlag.setLogOntologyExporter( true); // [PARAMETER]
Logger.setPrintOnFile( FileManager.DEFAULT_command); // [PARAMETER]

// 2) let now open the pizza ontology from web with pellet reasoner (default)
String ontoRefName = "ontoRef3"; // this must be a unique identifier for all the references you what to create into the system
Boolean bufferingReasoner = false; // reasoning is automatically synchronised
String pizzaOntologyIri = "http://www.co-ode.org/ontologies/pizza/pizza.owl";
String filePath = "http://protege.stanford.edu/ontologies/pizza/pizza.owl";
OWLReferences ontoRef = OWLReferencesContainer.newOWLReferenceFromWeb( ontoRefName, filePath, pizzaOntologyIri, bufferingReasoner);

// 3) you may want to print the ontology.
ontoRef.printOntologyOnConsole();

// 4) [PERAMETER] the system comes with a simple GUI from which it is possible to see the state of the ontology
// during run time as well as make some basic changes. Be aware that the GUI is not stable yet!
//NOT PORTED TO OWL API 5 JET
Thread t = new Thread( new GuiRunner( ontoRefName));
t.start();

// 5) be sure to see all logs!
Logger.flush();

// wait to give the possibility to interact with the GUI
try {
for( int i = 0; i < 100 ; i++) // about 20 minutes
Thread.sleep( 15000);
} catch (InterruptedException e) {}
}
}
Loading

0 comments on commit 299866e

Please sign in to comment.