Skip to content

Instantly share code, notes, and snippets.

@balhoff
Last active August 29, 2015 13:56
Show Gist options
  • Save balhoff/8853706 to your computer and use it in GitHub Desktop.
Save balhoff/8853706 to your computer and use it in GitHub Desktop.
Getting OWLEntity label in Scala
package org.nescent.informatics.script
import org.semanticweb.owlapi.model.OWLEntity
import org.semanticweb.owlapi.model.OWLOntology
import scala.collection.JavaConversions._
import org.semanticweb.owlapi.model.OWLLiteral
import org.semanticweb.owlapi.model.OWLDataFactory
import org.semanticweb.owlapi.apibinding.OWLManager
object GetLabelExample {
val ont: OWLOntology = null
val factory: OWLDataFactory = OWLManager.getOWLDataFactory
class MultiLabelException(obj: OWLEntity) extends Exception
def getLabel(obj: OWLEntity): Option[String] = {
val labels = obj.getAnnotations(ont, factory.getRDFSLabel).map(_.getValue).collect(
{ case literal: OWLLiteral => literal.getLiteral.toString })
if (labels.size > 1) throw new MultiLabelException(obj)
else labels.headOption
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment