Good morning,
I am developing an application that upload an ontology and its information in a
jena model. After of this I use this information to edit manually all
information like classes, properties (data, object).
If a specific ontology has another ontologies imported I need to take
information from them and include it in a unique Jena Model.
I have problems with prefixes, because when I import main ontology to a jena
model it works well but when I add the imported ontologies (In importOntologies
methos) to the model the prefixes are not maintained.
Someone can help me with this?
Thanks in advance.
The code is here:
public Model uploadModelFromFile(HttpServletRequest
request,String user,String databaseName,String file,String path) {
Model model = null;
DAOOntologia daoOntologia=new DAOOntologia();
try {
if (jenaSDBConection == null)
jenaSDBConection = this.abrirConexionJenaSDB(databaseName);
StoreDesc storeDesc = new
StoreDesc(LayoutType.LayoutTripleNodesHash, DatabaseType.MySQL);
Store store =
StoreFactory.create(storeDesc, jenaSDBConection);
logger.trace("StoreUtils.isFormatted(store=" + store.hashCode() + ") == " +
StoreUtils.isFormatted(store));
try {
logger.trace("store.getSize() == " + store.getSize());
} catch
(com.hp.hpl.jena.sdb.sql.SDBExceptionSQL e) {
formatStore(store, true);
}
model =
SDBFactory.connectDefaultModel(store);
path=path+file;
InputStream in =
FileManager.get().open(path);
if (in == null) throw new
IllegalArgumentException("Archivo no encontrado");
model.read(in,
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
in.close();
model=importOntologies(model,
request,databaseName, user,path);
logger.trace("JENA (" +
model.hashCode() + ") [#" + numeroConexiones + " SDBConnections]");
} catch (Exception e) {
System.out.println(e.toString());
return null;
}
return model;
}
public Model importOntologies(Model model, HttpServletRequest
request,String databaseName, String user,String path){
DAOOntologia daoOntologia=new DAOOntologia();
DAOMySQL daoMysql=new DAOMySQL();
try{
HttpSession session = request.getSession();
user=(String)session.getAttribute("uname");
ServletContext context = session.getServletContext();
path = context.getRealPath("").replace("\\", "/");
path = path.substring(0, path.lastIndexOf("/"));
path += "/" + GetProperties.getString("files.raiz.upload");
logger.debug("path para guardar la ontologia ->" + path);
OntModel om = ModelFactory.createOntologyModel();
om.add(model);
om.setDynamicImports(true);
System.out.println("Importing ontologies:
"+om.listImportedOntologyURIs().size());
for(Iterator it = om.listImportedOntologyURIs().iterator(); it.hasNext();)
{
String uri=it.next().toString();
System.out.println("URI:"+uri);
//to know if uri it's a file web location
String fileName="";
int slashIndex =uri.lastIndexOf('/');
int periodIndex =uri.lastIndexOf('.');
if ((slashIndex!=-1)&&(periodIndex!=-1)){
fileName=uri.substring(slashIndex + 1);
System.out.println("File name:"+fileName);
}
if (fileName.contains(".owl")||(fileName.contains(".rdf")))
{
InputStream fIn=null;
fIn=daoOntologia.saveFileFromUrlWithJavaIO(request,uri,fileName);
if (fIn!=null){
model.read(fIn,"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
}
else{
model=null;
String sentenciaSql="drop database "+databaseName;
int iRes=daoMysql.executeQuery(sentenciaSql);
break;
}
}
else{
System.out.println("\t Ontology "+uri);
try{
URL myURL = new URL(uri);
URLConnection myURLConnection = myURL.openConnection();
myURLConnection.connect();
model.read(uri,"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
}
catch(Exception e){
daoOntologia.deleteSpecificOntology(databaseName, user,path);
model=null;
}
}
}
}
catch (Exception e){
System.out.println(e.getMessage());
model=null;
}
return model;
}
OPTIMA - Optimization Modelling & Analytics Area
ICT - European Software Institute Division
TECNALIA
Parque Tecnológico de Bizkaia, Edificio 202
E-48170 Zamudio (Spain)
mov.: 664 00 21 51
tel.: 902 760 002 / 946 430 850 (International calls)
[email protected]<mailto:[email protected]>
www.tecnalia.com<http://www.tecnalia.com/>