rdf4h is a library for working with RDF in Haskell. At present it includes parsers and serializers for RDF in the N-Triples and Turtle formats, and parsing support for RDF/XML. It provides abilities such as querying for triples containing a particular subject, predicate, or object, or selecting triples that satisfy an arbitrary predicate function.
Once the Haskell platform has been installed, simply:
$ cabal update
$ cabal install rdf4h
The rdf4h
library is split in to two parts.
Data.RDF
defines the RDF, RdfSerializer and RdfParser type classes. It also provides an API for RDF graph inspection.Text.RDF.RDF4H.*
provides the parsers and serializers for supported RDF formats.
{-# LANGUAGE OverloadedStrings #-}
import Data.RDF
import Data.RDF.TriplesGraph
import Text.RDF.RDF4H.NTriplesParser
rdfGraph1 :: IO TriplesGraph
rdfGraph1 = fmap fromEither (parseFile NTriplesParser "test1.nt")
rdfGraph2 :: IO TriplesGraph
rdfGraph2 = fmap fromEither (parseFile NTriplesParser "test2.nt")
example :: IO ()
example = do
g1 <- rdfGraph1
g2 <- rdfGraph2
let node1 = lnode $ PlainL "foo"
putStrLn $ "Subjects of g1: " ++ show (map subjectOf (triplesOf g1))
putStrLn $ "RDF contains literal 'foo': " ++ show (rdfContainsNode g1 node1)
putStrLn $ "Isomorphism test: " ++ show (isIsomorphic g1 g2)
putStrLn $ "Unsorted triples: " ++ show (triplesOf g2)
putStrLn $ "Sorted triples: " ++ show ((sortTriples . triplesOf) g2)
putStrLn $ "Query: " ++ show (query g1 Nothing Nothing (Just node1))
Please use the GitHub issue tracker to report any bugs you might find. New contributors are most welcome! See the TODO.org file for some ideas on how to contribute.
- hsparql is a DSL for
programmatic creation and execution of SPARQL queries. It makes use
of the
RDF
type class inrdf4h
, allowing the two packages to be combined easily. - swish is a toolkit for RDF inference and for implementing RDF file processors. It explores Haskell as "a scripting language for the semantic web".