public string getReasonerName() { OWLOntologyManager owlMan = org.semanticweb.owlapi.apibinding.OWLManager.createOWLOntologyManager(); OWLOntology ont = owlMan.createOntology(); OWLReasoner reas = this.createReasoner(ont); return(reas.getReasonerName()); }
public org.semanticweb.owlapi.reasoner.OWLReasoner createReasoner(OWLOntology ontology, org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration config) { org.semanticweb.HermiT.Configuration configuration = new org.semanticweb.HermiT.Configuration(); configuration.reasonerProgressMonitor = config.getProgressMonitor(); configuration.throwInconsistentOntologyException = false; return(new org.semanticweb.HermiT.Reasoner(configuration, ontology)); }
public string getReasonerVersion() { OWLOntologyManager owlMan = org.semanticweb.owlapi.apibinding.OWLManager.createOWLOntologyManager(); OWLOntology ont = owlMan.createOntology(); OWLReasoner reas = this.createReasoner(ont); org.semanticweb.owlapi.util.Version ver = reas.getReasonerVersion(); return(ver.getMajor() + "." + ver.getMinor() + "." + ver.getPatch()); }
public java.util.Set GetConceptChild(OWLOntology ontology) { if (this.conceptChild == null) { this.conceptChild = GetConcept(ontology).getSubClasses(ontology); } return(this.conceptChild); }
public OWLClass GetConcept(OWLOntology ontology) { if (this.concept == null) { this.concept = getClass(ontology.getClassesInSignature(), this.conceptKey); } return(this.concept); }
public org.semanticweb.owlapi.reasoner.OWLReasoner createReasoner(OWLOntology ontology) { var config = new org.semanticweb.HermiT.Configuration(); config.reasonerProgressMonitor = progrMonitor; config.throwInconsistentOntologyException = false; return(new org.semanticweb.HermiT.Reasoner(config, ontology)); }
/// <summary> /// Searches for reasoners in reasonerDllFolder, instantiate a reasoner and shows the info about this reasoner. /// </summary> /// <param name="reasonerDllFolder"></param> public static void GetOwlInfo(string reasonerDllFolder) { manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.createOntology(ontologyIRI); ReasoningService aa = new ReasoningService(reasonerDllFolder); OWLReasoner reasoner = aa.reasonerFact.createReasoner(ontology); Console.WriteLine(aa.reasonerFact.getReasonerName() + " Version:" + aa.reasonerFact.getReasonerVersion() + "\r\n Description:" + aa.reasonerFact.getReasonerDescription()); Console.WriteLine("Press enter to go further..."); Console.ReadLine(); }
public java.util.Set GetConceptParents(OWLOntology ontology) { if (this.conceptParent == null) { if (GetConcept(ontology) != null) //Si no es una instancia, obtener la clase { this.conceptParent = GetConcept(ontology).getSuperClasses(ontology); } else { //Es una instancia entonces no tiene padres this.conceptParent = null; } } return(this.conceptParent); }
private void toolStripButton_load_Click(object sender, EventArgs e) { if (Locked) { return; } OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Ontology Files|*.owl;*.rdf;*.rdfs"; if (dialog.ShowDialog() == DialogResult.OK) { OwlManager = new OWLManager(); OwlOntology = new OWLOntology(); initializeOntology(dialog.FileName); fromOntologyPath = dialog.FileName; clearLabels(); clearQuery(); initializeLabels(); } }
public static void Initialize(string ontologyProfilePath) { try { Manager = OWLManager.createOWLOntologyManager(); //tento řádek je potřebný kvůli nedokonale převedené knihovně z javy, kvůli které se načítá owl parser [email protected] s = new [email protected](); // načtení owl souboru, který obsahuje metamodel a který každá vložená báze individuí importuje byte[] owlResourceUPMM = Properties.Resources.UPMM; java.io.ByteArrayInputStream upmmInputStream = new java.io.ByteArrayInputStream(owlResourceUPMM); OWLOntology ontologyUPMM = Manager.loadOntologyFromOntologyDocument(upmmInputStream); MetamodelIRI = ontologyUPMM.getOntologyID().getOntologyIRI(); Trace.WriteLine("Loaded Metamodel Ontology : " + MetamodelIRI); // načtení owl báze konkrétního profilu java.io.File processModel = new java.io.File(ontologyProfilePath); OWLOntology knowledgeProfile = Manager.loadOntologyFromOntologyDocument(processModel); ProfileIRI = knowledgeProfile.getOntologyID().getOntologyIRI(); Trace.WriteLine("Loaded Profile Ontology : " + ProfileIRI); // vytvoření reasoneru nad profilem Reasoner = new StructuralReasonerFactory().createReasoner(knowledgeProfile, new SimpleConfiguration()); PelletReasoner = new PelletReasonerFactory().createReasoner(knowledgeProfile, new SimpleConfiguration()); //Reasoner = new Reasoner.ReasonerFactory().createReasoner(knowledgeProfile); HermiT Trace.WriteLine("Reasoner is running!"); DataFactory = Manager.getOWLDataFactory(); } catch (Exception ex) { throw new ApplicationException("Ontology loading failed!", ex); } }
/// <summary> /// proceso para cargar las clases, subclases y axiomas de la ontologia /// </summary> private void LoadOWLAPI() { //Inicializamos variables OntologyConcept ontologyConcept = null; int weigth = 1; string claseKey = string.Empty; string claseValor = string.Empty; //OWLClass _class; //Se carga la ontologia string path = url; java.io.File file = new java.io.File(path); //Aseguramos una ontologia en el managet ontology = ontologyManager.loadOntologyFromOntologyDocument(file); //Creamos el datafactory para obtener los labels de las clases OWLDataFactory df = ontologyManager.getOWLDataFactory(); OWLAnnotationProperty label = df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()); //Obtenemos las clases de la ontologia y las recorremos para obtener las anotaciones java.util.Set clases = ontology.getClassesInSignature(); for (java.util.Iterator iteratorClases = clases.iterator(); iteratorClases.hasNext();) { OWLClass clase = (OWLClass)iteratorClases.next(); List <Anotacion> Anotaciones = new List <Anotacion>(); java.util.Set lit = clase.getAnnotations(ontology, label); //Se recorren las anotaciones tipo Label for (java.util.Iterator iteratorAnno = lit.iterator(); iteratorAnno.hasNext();) { OWLAnnotation anno = (OWLAnnotation)iteratorAnno.next(); OWLLiteral val = (OWLLiteral)anno.getValue(); string valorAnotacion = string.Empty; if (val.hasLang("es")) { //Se debe hacer un tratamiento a la cadena por los acentos valorAnotacion = ToAscii(val.getLiteral()).Trim(); } else { valorAnotacion = val.getLiteral().Trim(); } //Agregar la anotacion a la lista Anotacion annotemp = new Anotacion(anno.getSignature().ToString(), valorAnotacion, val.getLang()); Anotaciones.Add(annotemp); //Añadimos la anotacion a la lista de valores a consultar verificando que no este repetido if (!valores.Contains(valorAnotacion) && !string.IsNullOrEmpty(valorAnotacion)) { valores.Add(valorAnotacion); } //Reportar la anotacion encontrada Trace.WriteLine(clase.getSignature().ToString() + " -> " + valorAnotacion); //Almacenamos todas anotaciones en un string para el valor de la clase claseValor = claseValor + " " + valorAnotacion; //En caso de tener individuos se almacena en la lista de valores para su búsqueda Trace.WriteLine("Obteniendo conceptos de los individuos"); string individuoKey = string.Empty; java.util.Set individuos = clase.getIndividuals(ontology); for (java.util.Iterator iteratorIndividuos = individuos.iterator(); iteratorIndividuos.hasNext();) { OWLIndividual individuo = (OWLIndividual)iteratorIndividuos.next(); java.util.Set litind = individuo.asOWLNamedIndividual().getAnnotations(ontology, df.getRDFSLabel()); //Se recorre las anotaciones tipo Label individuo for (java.util.Iterator iteratorAnnoind = litind.iterator(); iteratorAnnoind.hasNext();) { OWLAnnotation annoind = (OWLAnnotation)iteratorAnnoind.next(); OWLLiteral valind = (OWLLiteral)annoind.getValue(); string valorAnotacionind = string.Empty; if (valind.hasLang("es")) { //Se debe hacer un tratamiento a la cadena por los acentos valorAnotacionind = ToAscii(valind.getLiteral()).Trim(); } else { valorAnotacionind = valind.getLiteral().Trim(); } //Agregar la anotacion a la lista Anotacion annotempind = new Anotacion(annoind.getSignature().ToString(), valorAnotacionind, valind.getLang()); Anotaciones.Add(annotempind); //Añadimos la anotacion a la lista de valores a consultar verificando que no este repetido if (!valores.Contains(valorAnotacionind) && !string.IsNullOrEmpty(valorAnotacionind)) { valores.Add(valorAnotacionind); } //Reportar la anotacion encontrada Trace.WriteLine(clase.getSignature().ToString() + ":" + individuo.getSignature().ToString() + " -> " + valorAnotacionind); //Almacenamos todas anotaciones en un string para el valor de la clase claseValor = claseValor + " " + valorAnotacionind; } } //Agregar el concepto a la lista claseKey = clase.getSignature().ToString(); ontologyConcept = new OntologyConcept(claseKey, claseValor, weigth, clase, clase.getSuperClasses(ontology), clase.getSubClasses(ontology)); ontologyConcept.Anotaciones = Anotaciones; //Reinicializamos el valor para la nueva clase claseValor = ""; //Verificar que se obtengan conceptos diferentes. Las claseKey se repiten siempre que aporten anotaciones diferentes if (!this.concepts.ContainsKey(claseKey) && !this.concepts.ContainsValue(ontologyConcept) && !valores.Contains(ontologyConcept.ConceptValue) && !string.IsNullOrEmpty(ontologyConcept.ConceptValue)) { this.concepts.Add(claseKey, ontologyConcept); } } } }
public static string GetOWLXML(CNL.DL.Paragraph para, bool owlXml, string externext, Dictionary <string, string> invUriMappings, AnnotationManager annotMan, string ontologyBase = null, Dictionary <string, Tuple <string, string> > prefixes = null, string defaultGuid = null, Dictionary <string, List <string> > owlOntologyAnnotation = null, string generatedBy = "CogniPy") { prefixes = prefixes ?? new Dictionary <string, Tuple <string, string> >(); if (ontologyBase == null) { ontologyBase = "http://www.ontorion.com/ontologies/Ontology" + Guid.NewGuid().ToString("N"); } //var ontologyBase = (ontologyNs ?? "http://www.ontorion.com/ontologies/Ontology" + Guid.NewGuid().ToString("N")); //if(!String.IsNullOrEmpty(defaultGuid)) // ontologyBase = (ontologyNs ?? "http://www.ontorion.com/ontologies/Ontology" + defaultGuid); if (!ontologyBase.EndsWith("/") && !ontologyBase.EndsWith("#") && !ontologyBase.Contains("#")) { ontologyBase += "#"; } OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); CogniPy.ARS.Transform transform = new CogniPy.ARS.Transform(); transform.InvUriMappings = invUriMappings; var df = manager.getOWLDataFactory(); ontology = manager.createOntology(IRI.create(ontologyBase)); org.semanticweb.owlapi.vocab.PrefixOWLOntologyFormat owlxmlFormat = null; if (owlXml) { owlxmlFormat = new org.semanticweb.owlapi.io.OWLXMLOntologyFormat(); } else { owlxmlFormat = new org.semanticweb.owlapi.io.RDFXMLOntologyFormat(); } owlxmlFormat.setDefaultPrefix(ontologyBase); foreach (var kv in prefixes) { owlxmlFormat.setPrefix(kv.Key.Replace("$", "."), kv.Value.Item1); // should we put here the Item2 (the location) and not the inner namespace??? if (!String.IsNullOrEmpty(kv.Value.Item2) && !(kv.Value.Item2.EndsWith(".encnl") || kv.Value.Item2.EndsWith(".encnl#"))) // do not export cnl imports (not in OWL!) { // here we need to use Item1 because we cannot export into OWL the specific location of the ontology ---> this is bad practice as in this way we loose the generality of the owl file // imagine that the location is C://mydirectory/... and I add into an owl file: owl:import "C:/mydirectory/". This mean that only on my computer I will be able to import this file. // On the other hand if we write owl:import "namespace of the file" there is a good chance that when someone else will open the file, the file will be imported from internet. var decl = manager.getOWLDataFactory().getOWLImportsDeclaration(OWLPathUriTools.Path2IRI(kv.Value.Item1.TrimEnd('#'))); manager.applyChange(new AddImport(ontology, decl)); } } manager.setOntologyFormat(ontology, owlxmlFormat); if (owlOntologyAnnotation != null) { foreach (var keyVal in owlOntologyAnnotation) { foreach (string val in keyVal.Value) { manager.applyChange(new AddOntologyAnnotation( ontology, manager.getOWLDataFactory().getOWLAnnotation( manager.getOWLDataFactory().getOWLAnnotationProperty(IRI.create(keyVal.Key)), manager.getOWLDataFactory().getOWLLiteral(val)))); } } } transform.setOWLDataFactory(false, ontologyBase, df, owlxmlFormat, CNL.EN.CNLFactory.lex); var paraFromAnnotStatements = annotMan.getDLAnnotationAxioms(); var stmts = para.Statements; foreach (var p in paraFromAnnotStatements) { stmts.AddRange(p.Value); } var conv = transform.Convert(new CogniPy.CNL.DL.Paragraph(null) { Statements = stmts }); var om = new org.coode.xml.OWLOntologyXMLNamespaceManager(manager, ontology); foreach (var axiom in conv.axioms) { if (axiom.comment != null) { var dp = axiom.comment.IndexOf(':'); var x = axiom.comment.Substring(0, dp); if (x.Trim() == "Namespace") { var ontologyIri = axiom.comment.Substring(dp + 1).Trim(); if (ontologyIri.EndsWith(".")) { ontologyIri = ontologyIri.Substring(0, ontologyIri.Length - 1); } if (ontologyIri.StartsWith("\'") && ontologyIri.Length > 2) { ontologyIri = ontologyIri.Substring(1, ontologyIri.Length - 2).Replace("\'\'", "\'"); } manager.removeOntology(ontology); ontology = manager.createOntology(IRI.create(ontologyIri)); om.setDefaultNamespace(ontologyIri + "#"); transform.setOWLDataFactory(true, ontologyBase, df, owlxmlFormat, CNL.EN.CNLFactory.lex); } else if (x.Trim() == "References") { var refs = CNLTools.ParseReferences(axiom.comment.Substring(dp)); foreach (Match match in refs) { var onto = match.Groups["ont"].Value; if (onto.StartsWith("\'") && onto.Length > 2) { onto = onto.Substring(1, onto.Length - 2).Replace("\'\'", "\'").Trim(); } if (!string.IsNullOrEmpty(onto)) { if (onto.ToLower().EndsWith(".encnl")) { onto = OWLConverter.PathToIRIString(onto.Substring(0, onto.Length - ".encnl".Length) + externext); } var ns = match.Groups["ns"].Value; if (ns.StartsWith("\'") && ns.Length > 2) { ns = ns.Substring(1, ns.Length - 2).Replace("\'\'", "\'").Trim(); } else if (string.IsNullOrEmpty(ns)) { ns = onto; } om.setPrefix(match.Groups["pfx"].Value, ns); owlxmlFormat.setPrefix(match.Groups["pfx"].Value, ns); var decl = manager.getOWLDataFactory().getOWLImportsDeclaration(OWLPathUriTools.Path2IRI(onto)); manager.applyChange(new AddImport(ontology, decl)); } } } else { //manager.applyChange(new AddOntologyAnnotation( // ontology, // manager.getOWLDataFactory().getOWLAnnotation( // manager.getOWLDataFactory().getOWLAnnotationProperty(IRI.create(ontologyBase + x)), // manager.getOWLDataFactory().getOWLLiteral(axiom.comment.Substring(dp))))); } } else if (axiom.axiom != null) { manager.addAxiom(ontology, axiom.axiom); } } foreach (var axiom in conv.additions) { manager.addAxiom(ontology, axiom); } var ontout = new org.semanticweb.owlapi.io.StringDocumentTarget(); manager.saveOntology(ontology, owlxmlFormat, ontout); manager.removeOntology(ontology); var retdoc = new XmlDocument(); retdoc.LoadXml(ontout.toString()); foreach (var elem in retdoc.ChildNodes) { if (elem is XmlComment) { retdoc.RemoveChild(elem as XmlComment); } } retdoc.AppendChild(retdoc.CreateComment("Generated by " + generatedBy + ", (with support from OwlApi)")); return(SerializeDoc(retdoc)); }
public org.semanticweb.owlapi.reasoner.OWLReasoner createReasoner(OWLOntology ontology, org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration config) { return(new com.clarkparsia.pellet.owlapiv3.PelletReasoner(ontology, config, BufferingMode.BUFFERING)); }
public org.semanticweb.owlapi.reasoner.OWLReasoner createReasoner(OWLOntology ontology) { var config = new SimpleConfiguration(progrMonitor); return(new com.clarkparsia.pellet.owlapiv3.PelletReasoner(ontology, config, BufferingMode.BUFFERING)); }
private void MainForm_Load(object sender, EventArgs e) { OwlManager = new OWLManager(); OwlOntology = new OWLOntology(); panel_reasoner.BackColor = Color.Red; }