Libraries for parsing *.owl and related files

Disclaimer: Dieser Thread wurde aus dem alten Forum importiert. Daher werden eventuell nicht alle Formatierungen richtig angezeigt. Der ursprüngliche Thread beginnt im zweiten Post dieses Threads.

*Libraries for parsing .owl and related files
Apparently we are going to play a bit with ontology data later in the semester. I had a look at what libraries exist for Java and Scala. The most promising ones seem to be


OWL API (Java; Tutorial):

In the following I present a usage example with Scala.

Add the SBT Dependency:

libraryDependencies += "net.sourceforge.owlapi" % "owlapi-apibinding" % "5.1.14"

Einfaches Auslesen und Ausgeben via Scala:

[code=java]import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.formats.FunctionalSyntaxDocumentFormat
import org.semanticweb.owlapi.model.IRI
import scala.jdk.StreamConverters._

object Test {
def main(args: Array[String]): Unit = {
val manager = OWLManager.createOWLOntologyManager
val ontology = manager.loadOntology(IRI.create(“file:///C:/…path to owl file from Protégé…/ontology.owl”))

// output all classes, object and data properties
ontology.classesInSignature().forEach(println)
ontology.objectPropertiesInSignature().forEach(println)
ontology.dataPropertiesInSignature().forEach(println)

// Example on how to deal with Java Streams (convert to Scala Streams for easier usage)
ontology
  .classesInSignature().toScala(LazyList)
  .map(_.objectPropertiesInSignature().toScala(List))
  .filter(_.nonEmpty)
  .foreach(prop => println("Object properties: " + prop))

// re-export in functional syntax to System.out
// ontology.saveOntology(new FunctionalSyntaxDocumentFormat, System.out)

}
}[/code]

SANSA OWL (Scala): Not tested.


I can very much recommend Scala for fiddling with formal languages. (MMT is also written in Scala.)
Feel free to extend this thread.


Indeed, OWL API is the one I remembered.

Also indeed, Scala is very nice for this kind of programs.