Skip to content

Instantly share code, notes, and snippets.

@aldonline
Last active December 10, 2015 08:48
Show Gist options
  • Save aldonline/4410275 to your computer and use it in GitHub Desktop.
Save aldonline/4410275 to your computer and use it in GitHub Desktop.
Implicit Scala to RDF Value conversions
object rdfStringOps {
import org.openrdf.model._
private lazy val vf = impl.ValueFactoryImpl.getInstance
implicit class RDFStringOps( val str:String ){
def uri = vf createURI str
def lit = vf createLiteral str
def lit( xsdt:URI ) = vf.createLiteral( str, xsdt )
def lit( lang:String ) = vf.createLiteral( str, lang )
}
}
object usageExamples {
import rdfStringOps._
val uri = "http://foo.com/a".uri
val plainLiteral = "some text".lit
val literalWithLanguageTag = "some text" lit "en"
val typedLiteral = "5" lit "http://www.w3.org/2001/XMLSchema#int".uri
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment