Last active
December 10, 2015 08:48
-
-
Save aldonline/4410275 to your computer and use it in GitHub Desktop.
Implicit Scala to RDF Value conversions
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
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