Last active
August 29, 2015 13:56
-
-
Save balhoff/8853706 to your computer and use it in GitHub Desktop.
Getting OWLEntity label in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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