using System; using System.Data; using System.Configuration; //Java namespace using ikvm.io; //Pellet namespaces using org.mindswap; using org.mindswap.pellet; //using org.mindswap.pellet.jena.PelletReasonerFactory; using org.mindswap.pellet.jena; //Jena namespaces using com.hp.hpl.jena.ontology; using com.hp.hpl.jena.rdf.model; using com.hp.hpl.jena.reasoner; namespace wsGeoConceptsSemWebLayer { /// /// Class to test some Pellet reasoning Services /// public class PelletServices { /// /// Check the consitency of an Ontology file stored in local machine, using PelletInfGraph. /// /// Local file path for loading the ontology /// Consistence of the ontology, and Consistency check execution time public string checkConsistencyWithJenaAndPelletInfGraph(string strOntologyPath) { PelletOptions.USE_COMPLETION_QUEUE = true; PelletOptions.USE_SMART_RESTORE = false; #region Variables string strResult = ""; java.io.InputStream fstreamOntologyBase = null; java.io.InputStream fstreamOntology = null; OntModel omGeoConcepts = null; PelletInfGraph pinfgraphGeoConcepts = null; string strOntologyPathBase = ""; #endregion Variables try { //Default value for string if (strOntologyPath == "") { strOntologyPath = "C:\\SemWeb\\GeoConceps_V1.0_20080117.owl"; strOntologyPathBase = "C:\\SemWeb\\geo_2007.owl"; } #region read the ontology omGeoConcepts = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); omGeoConcepts.setStrictMode(false); // Default ontology test if (strOntologyPathBase != "") { fstreamOntologyBase = new java.io.FileInputStream(strOntologyPathBase); omGeoConcepts.read(fstreamOntologyBase, ""); } fstreamOntology = new java.io.FileInputStream(strOntologyPath); omGeoConcepts.read(fstreamOntology, ""); #endregion read the ontology // get a PelletInfGraph object pinfgraphGeoConcepts = (PelletInfGraph)omGeoConcepts.getGraph(); #region Make a consistent check. Get execution time. DateTime dtimeIni = DateTime.Now; bool bIsConsistent = pinfgraphGeoConcepts.isConsistent(); DateTime dtimeFin = DateTime.Now; TimeSpan tspanExecTime = dtimeFin - dtimeIni; #endregion Make a consistent check. Get execution time. strResult = "Is consistent: " + bIsConsistent.ToString() + "\nExecution time: " + tspanExecTime.TotalSeconds.ToString() + "seconds"; } catch (Exception ex) { throw (ex); } finally { #region Free resources if (pinfgraphGeoConcepts != null) pinfgraphGeoConcepts.close(); if (omGeoConcepts != null) omGeoConcepts.close(); if (fstreamOntologyBase != null) fstreamOntologyBase.close(); if (fstreamOntology != null) fstreamOntology.close(); #endregion Free resources } return strResult; } /// /// Check the consitency of an Ontology file stored in local machine, using Jena API and OntModel. /// /// Local file path for loading the ontology /// Consistence of the ontology, and Consistency check execution time public string checkConsistencyWithJenaAndOntModel(string strOntologyPath) { PelletOptions.USE_COMPLETION_QUEUE = true; PelletOptions.USE_SMART_RESTORE = false; #region Variables string strResult = ""; java.io.InputStream fstreamOntologyBase = null; java.io.InputStream fstreamOntology = null; OntModel omGeoConcepts = null; string strOntologyPathBase = ""; #endregion Variables try { //Default value for string if (strOntologyPath == "") { strOntologyPath = "C:\\SemWeb\\GeoConceps_V1.0_20080117.owl"; strOntologyPathBase = "C:\\SemWeb\\geo_2007.owl"; } #region read the ontology omGeoConcepts = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); omGeoConcepts.setStrictMode(false); // Default ontology test if (strOntologyPathBase != "") { fstreamOntologyBase = new java.io.FileInputStream(strOntologyPathBase); omGeoConcepts.read(fstreamOntologyBase, ""); } fstreamOntology = new java.io.FileInputStream(strOntologyPath); omGeoConcepts.read(fstreamOntology, ""); #endregion read the ontology #region Make a consistent check. Get execution time. DateTime dtimeIni = DateTime.Now; omGeoConcepts.prepare(); DateTime dtimeFin = DateTime.Now; TimeSpan tspanExecTime = dtimeFin - dtimeIni; #endregion Make a consistent check. Get execution time. ValidityReport vrptGeoConcepts = omGeoConcepts.validate(); #region Consistence report if (vrptGeoConcepts.isClean()) { strResult = strResult + "The model is clean. "; } else if (vrptGeoConcepts.isValid()) { strResult = strResult + "The ontology is Consistent. "; } else { java.util.Iterator itReports = vrptGeoConcepts.getReports(); while (itReports.hasNext()) { strResult = strResult + itReports.next().ToString() + " "; } } #endregion Consistence report strResult = strResult + "\nExecution time: " + tspanExecTime.TotalSeconds.ToString() + "seconds"; } catch (Exception ex) { throw (ex); } finally { #region Free resources if (omGeoConcepts != null) omGeoConcepts.close(); if (fstreamOntologyBase != null) fstreamOntologyBase.close(); if (fstreamOntology != null) fstreamOntology.close(); #endregion Free resources } return strResult; } } }