Skip to content
Browse files

Test harness compiling with full list of includes. Must add tests to …

…run.

Ignore-this: 393161446214a8dc68ce9a25431cbec1

darcs-hash:20110126192816-1786f-bb66390dbda8c9c56555105e2cdc026084f9dffa.gz
  • Loading branch information...
1 parent efdd398 commit db1ca4a121a7534b3220373271e718f3be30cdee @amccausl committed Jan 26, 2011
View
36 src/Data/RDF.hs
@@ -4,6 +4,9 @@
--
module Data.RDF (
+ -- * Parsing RDF
+ RdfParser(parseString, parseFile, parseURL),
+ ParseFailure(..), parseFile', parseURL', -- Imported from Text/RDF/RDF4H/ParserUtils
-- * Serializing RDF
RdfSerializer(hWriteG, writeG, hWriteH, writeH, hWriteTs, writeTs, hWriteT, writeT, hWriteN, writeN),
-- * RDF graph
@@ -21,7 +24,6 @@ module Data.RDF (
equalSubjects, equalPredicates, equalObjects,
subjectOf, predicateOf, objectOf,
Subject, Predicate, Object,
- ParseFailure(ParseFailure),
FastString(uniq,value),mkFastString,
s2b,b2s,unode,bnode,lnode,plainL,plainLL,typedL,
View, view,
@@ -30,7 +32,9 @@ module Data.RDF (
import Data.RDF.Namespace
import Data.RDF.Utils
+import Text.RDF.RDF4H.ParserUtils
+import Data.Maybe(fromMaybe)
import Data.ByteString.Lazy.Char8(ByteString)
import qualified Data.ByteString.Lazy.Char8 as B
import Data.List
@@ -142,6 +146,25 @@ class RDF rdf where
where toNodeSelector Nothing = Nothing
toNodeSelector (Just node) = Just (== node)
+-- |An RdfParser is a parser that knows how to parse 1 format of RDF and
+-- can parse an RDF document of that type from a string, a file, or a URL.
+-- Required configuration options will vary from instance to instance.
+class RdfParser p where
+
+ -- |Parse RDF from the given bytestring, yielding a failure with error message or
+ -- the resultant graph.
+ parseString :: forall rdf. (RDF rdf) => p -> ByteString -> (Either ParseFailure rdf)
+
+ -- |Parse RDF from the local file with the given path, yielding a failure with error
+ -- message or the resultant graph in the IO monad.
+ parseFile :: forall rdf. (RDF rdf) => p -> String -> IO (Either ParseFailure rdf)
+ parseFile r = parseFile' (parseString r)
+
+ -- |Parse RDF from the remote file with the given HTTP URL (https is not supported),
+ -- yielding a failure with error message or the resultant graph in the IO monad.
+ parseURL :: forall rdf. (RDF rdf) => p -> String -> IO (Either ParseFailure rdf)
+ parseURL r = parseURL' (parseString r)
+
-- |An RdfSerializer is a serializer of RDF to some particular output format, such as
-- NTriples or Turtle.
class RdfSerializer s where
@@ -312,11 +335,6 @@ newtype BaseUrl = BaseUrl ByteString
-- node selectors are used to match a triple.
type NodeSelector = Maybe (Node -> Bool)
--- |Represents a failure in parsing an N-Triples document, including
--- an error message with information about the cause for the failure.
-newtype ParseFailure = ParseFailure String
- deriving (Eq, Show)
-
-- |A node is equal to another node if they are both the same type
-- of node and if the field values are equal.
instance Eq Node where
@@ -421,6 +439,12 @@ instance Show LValue where
sortTriples :: Triples -> Triples
sortTriples = sort
+-- Keep the (Just t) triples (eliminating the Nothing comments), and unbox the
+-- triples, leaving a list of triples.
+justTriples :: [Maybe Triple] -> [Triple]
+justTriples = map (fromMaybe (error "ParserUtils.justTriples")) .
+ filter (/= Nothing)
+
-- |Answer the subject node of the triple.
{-# INLINE subjectOf #-}
subjectOf :: Triple -> Node
View
1 src/Data/RDF/MGraph.hs
@@ -35,7 +35,6 @@ import Data.List
--
-- * 'query' : O(log n)
newtype MGraph = MGraph (SPOMap, Maybe BaseUrl, PrefixMappings)
- deriving (Show)
instance RDF MGraph where
baseUrl = baseUrl'
View
1 src/Data/RDF/TriplesGraph.hs
@@ -42,6 +42,7 @@ import qualified Data.Map as Map
--
-- * 'query' : O(n)
newtype TriplesGraph = TriplesGraph (Triples, Maybe BaseUrl, PrefixMappings)
+ deriving (Eq)
instance RDF TriplesGraph where
baseUrl = baseUrl'
View
17 src/Text/RDF/RDF4H/NTriplesParser.hs
@@ -3,12 +3,14 @@
-- <http://www.w3.org/TR/rdf-testcases/#ntriples>.
module Text.RDF.RDF4H.NTriplesParser(
+ NTriplesParser(NTriplesParser), ParseFailure,
parseNTriplesRDF
) where
-- TODO: switch to OverloadedStrings and use ByteString literals (?).
import Data.RDF
+import Text.RDF.RDF4H.ParserUtils
import Data.Char(isLetter, isDigit, isLower)
import qualified Data.Map as Map
@@ -19,6 +21,21 @@ import Text.Parsec.ByteString.Lazy
import Data.ByteString.Lazy.Char8(ByteString)
import qualified Data.ByteString.Lazy.Char8 as B
+-- |NTriplesParser is an 'RdfParser' implementation for parsing RDF in the
+-- NTriples format. It requires no configuration options. To use this parser,
+-- pass an 'NTriplesParser' value as the first argument to any of the
+-- 'parseString', 'parseFile', or 'parseURL' methods of the 'RdfParser' type
+-- class.
+data NTriplesParser = NTriplesParser
+
+-- |'NTriplesParser' is an instance of 'RdfParser'.
+instance RdfParser NTriplesParser where
+ parseString _ bs = handleParse mkRdf (runParser nt_ntripleDoc () "" bs)
+
+ parseFile _ path = B.readFile path >>= return . runParser nt_ntripleDoc () path >>= return . handleParse mkRdf
+
+ parseURL p url = parseURL' (parseString p) url
+
parseNTriplesRDF :: forall rdf. (RDF rdf)
=> ByteString -- ^ The contents to parse
-> Either ParseFailure rdf -- ^ The RDF representation of the triples or ParseFailure
View
43 src/Text/RDF/RDF4H/ParserUtils.hs
@@ -1,39 +1,40 @@
-module Text.RDF.RDF4H.ParserUtils(parseFile, parseURL, justTriples) where
+{-# LANGUAGE RankNTypes #-}
-import Data.RDF
+module Text.RDF.RDF4H.ParserUtils(
+ ParseFailure(..),
+ parseFile', parseURL'
+) where
import Network.URI
import Network.HTTP
-import Data.Maybe(fromMaybe)
import Data.Char(intToDigit)
import Data.ByteString.Lazy.Char8(ByteString)
import qualified Data.ByteString.Lazy.Char8 as B
+-- |Represents a failure in parsing an N-Triples document, including
+-- an error message with information about the cause for the failure.
+newtype ParseFailure = ParseFailure String
+ deriving (Eq, Show)
+
-- A convenience function for terminating a parse with a parse failure, using
-- the given error message as the message for the failure.
-errResult :: RDF rdf => String -> Either ParseFailure rdf
+errResult :: forall rdf. String -> Either ParseFailure rdf
errResult msg = Left (ParseFailure msg)
--- Keep the (Just t) triples (eliminating the Nothing comments), and unbox the
--- triples, leaving a list of triples.
-justTriples :: [Maybe Triple] -> [Triple]
-justTriples = map (fromMaybe (error "ParserUtils.justTriples")) .
- filter (/= Nothing)
-
-parseFile :: forall rdf. (RDF rdf)
- => (ByteString -> Either ParseFailure rdf)
- -> FilePath
- -> IO (Either ParseFailure rdf)
-parseFile parser file = do str <- readFile file
- return (parser (s2b str))
+parseFile' :: forall rdf.
+ (ByteString -> Either ParseFailure rdf)
+ -> FilePath
+ -> IO (Either ParseFailure rdf)
+parseFile' parser file = do str <- B.readFile file
+ return (parser str)
-- |Parse the document at the given location URL with the given parser function.
-parseURL :: forall rdf. (RDF rdf)
- => (ByteString -> Either ParseFailure rdf) -- ^ Function to parse the document (should include this URL as a BaseUrl if it is appropriate)
- -> String -- ^ URL of the document to parse
- -> IO (Either ParseFailure rdf) -- ^ either a @ParseFailure@ or a new graph containing the parsed triples.
-parseURL parseFunc url =
+parseURL' :: forall rdf.
+ (ByteString -> Either ParseFailure rdf) -- ^ Function to parse the document (should include this URL as a BaseUrl if it is appropriate)
+ -> String -- ^ URL of the document to parse
+ -> IO (Either ParseFailure rdf) -- ^ either a @ParseFailure@ or a new graph containing the parsed triples.
+parseURL' parseFunc url =
maybe
(return (Left (ParseFailure $ "Unable to parse URL: " ++ url)))
p
View
48 src/Text/RDF/RDF4H/TurtleParser.hs
@@ -3,11 +3,13 @@
-- <http://www.w3.org/TeamSubmission/turtle/>.
module Text.RDF.RDF4H.TurtleParser(
+ TurtleParser(TurtleParser),
parseTurtleRDF
) where
import Data.RDF
import Data.RDF.Namespace
+import Text.RDF.RDF4H.ParserUtils
import Text.Parsec
import Text.Parsec.ByteString.Lazy
@@ -30,6 +32,52 @@ import Debug.Trace(trace)
-- To avoid compiler warnings when not being used.
_trace = trace
+-- |An 'RdfParser' implementation for parsing RDF in the
+-- Turtle format. It takes optional arguments representing the base URL to use
+-- for resolving relative URLs in the document (may be overridden in the document
+-- itself using the \@base directive), and the URL to use for the document itself
+-- for resolving references to <> in the document.
+-- To use this parser, pass a 'TurtleParser' value as the first argument to any of
+-- the 'parseString', 'parseFile', or 'parseURL' methods of the 'RdfParser' type
+-- class.
+data TurtleParser = TurtleParser (Maybe BaseUrl) (Maybe ByteString)
+
+-- |'TurtleParser' is an instance of 'RdfParser'.
+instance RdfParser TurtleParser where
+ -- |Parse the given string as a Turtle document. The arguments and return type have the same semantics
+ -- as <parseURL>, except that the last @String@ argument corresponds to the Turtle document itself as
+ -- a a string rather than a location URI.
+ parseString (TurtleParser bUrl dUrl) ttlStr = handleResult bUrl (runParser t_turtleDoc (initialState bUrl dUrl) "" (ttlStr))
+
+ -- |Parse the document at the given location URL as a Turtle document, using an optional @BaseUrl@
+ -- as the base URI, and using the given document URL as the URI of the Turtle document itself.
+ --
+ -- The @BaseUrl@ is used as the base URI within the document for resolving any relative URI references.
+ -- It may be changed within the document using the @\@base@ directive. At any given point, the current
+ -- base URI is the most recent @\@base@ directive, or if none, the @BaseUrl@ given to @parseURL@, or
+ -- if none given, the document URL given to @parseURL@. For example, if the @BaseUrl@ were
+ -- @http:\/\/example.org\/@ and a relative URI of @\<b>@ were encountered (with no preceding @\@base@
+ -- directive), then the relative URI would expand to @http:\/\/example.org\/b@.
+ --
+ -- The document URL is for the purpose of resolving references to 'this document' within the document,
+ -- and may be different than the actual location URL from which the document is retrieved. Any reference
+ -- to @\<>@ within the document is expanded to the value given here. Additionally, if no @BaseUrl@ is
+ -- given and no @\@base@ directive has appeared before a relative URI occurs, this value is used as the
+ -- base URI against which the relative URI is resolved.
+ --p
+ -- Returns either a @ParseFailure@ or a new graph containing the parsed triples.
+ parseURL ttlParser = parseURL' (parseString ttlParser)
+
+ -- |Parse the given file as a Turtle document. The arguments and return type have the same semantics
+ -- as 'parseURL', except that the last @String@ argument corresponds to a filesystem location rather
+ -- than a location URI.
+ --
+ -- Returns either a @ParseFailure@ or a new graph containing the parsed triples.
+ parseFile (TurtleParser bUrl dUrl) fPath = B.readFile fPath >>= \bs -> return $ handleResult bUrl (runParser t_turtleDoc (initialState bUrl dUrl) (maybe "" B.unpack dUrl) bs)
+
+{-# INLINE initialState #-}
+initialState bUrl docUrl = (bUrl, docUrl, 1, PrefixMappings Map.empty, [], [], [], Seq.empty)
+
parseTurtleRDF :: forall rdf. (RDF rdf)
=> Maybe BaseUrl -- ^ The base URL for the RDF if required
-> Maybe ByteString -- ^ DocUrl: The request URL for the RDF if available
View
76 testsuite/tests/Data/RDF/GraphTestUtils.hs
@@ -1,4 +1,4 @@
-module Text.RDF.RDF4H.GraphTestUtils where
+module Data.RDF.GraphTestUtils where
import Data.RDF
import Data.RDF.Namespace
@@ -29,33 +29,33 @@ instance Arbitrary PrefixMappings where
-- passed in to determine the graph implementation to be tested.
-- empty graph should have no triples
-p_empty :: Graph g => (g -> Triples) -> g -> Bool
+p_empty :: RDF g => (g -> Triples) -> g -> Bool
p_empty _triplesOf _empty = _triplesOf _empty == []
-- triplesOf any graph should return unique triples used to create it
-p_mkGraph_triplesOf :: Graph g => (g -> Triples) -> (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
-p_mkGraph_triplesOf _triplesOf _mkGraph ts bUrl pms =
- uordered (_triplesOf (_mkGraph ts bUrl pms)) == uordered ts
+p_mkRdf_triplesOf :: RDF g => (g -> Triples) -> (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
+p_mkRdf_triplesOf _triplesOf _mkRdf ts bUrl pms =
+ uordered (_triplesOf (_mkRdf ts bUrl pms)) == uordered ts
-- duplicate input triples should not be returned
-p_mkGraph_no_dupes :: Graph g => (g -> Triples) -> (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
-p_mkGraph_no_dupes _triplesOf _mkGraph ts bUrl pms =
+p_mkRdf_no_dupes :: RDF g => (g -> Triples) -> (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
+p_mkRdf_no_dupes _triplesOf _mkRdf ts bUrl pms =
case null ts of
True -> True
False -> result == uordered ts
where
tsWithDupe = head ts : ts
- result = _triplesOf $ _mkGraph tsWithDupe bUrl pms
+ result = _triplesOf $ _mkRdf tsWithDupe bUrl pms
-- query with all 3 wildcards should yield all triples in graph
-p_query_match_none :: Graph g => (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
-p_query_match_none _mkGraph ts bUrl pms = uordered ts == uordered result
+p_query_match_none :: RDF g => (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
+p_query_match_none _mkRdf ts bUrl pms = uordered ts == uordered result
where
- result = query (_mkGraph ts bUrl pms) Nothing Nothing Nothing
+ result = query (_mkRdf ts bUrl pms) Nothing Nothing Nothing
-- query with no wildcard and a triple in the graph should yield
-- a singleton list with just the triple.
-p_query_matched_spo :: Graph g => (g -> Triples) -> g -> Property
+p_query_matched_spo :: RDF g => (g -> Triples) -> g -> Property
p_query_matched_spo _triplesOf gr =
classify (null ts) "trivial" $
forAll (tripleFromGen _triplesOf gr) f
@@ -68,18 +68,18 @@ p_query_matched_spo _triplesOf gr =
-- query as in p_query_matched_spo after duplicating a triple in the
-- graph, so that we can verify that the results just have 1, even
-- if the graph itself doesn't ensure that there are no dupes internally.
-p_query_matched_spo_no_dupes :: Graph g => (g -> Triples) -> (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> g -> Property
-p_query_matched_spo_no_dupes _triplesOf _mkGraph gr =
+p_query_matched_spo_no_dupes :: RDF g => (g -> Triples) -> (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> g -> Property
+p_query_matched_spo_no_dupes _triplesOf _mkRdf gr =
classify (null ts) "trivial" $
forAll (tripleFromGen _triplesOf gr) f
where
ts = _triplesOf gr
f t = case t of
Nothing -> True
- Just t' -> [t'] == queryT (mkGraphWithDupe _triplesOf _mkGraph gr t') t'
+ Just t' -> [t'] == queryT (mkRdfWithDupe _triplesOf _mkRdf gr t') t'
-- query with no wildcard and a triple no in the graph should yield []
-p_query_unmatched_spo :: Graph g => (g -> Triples) -> g -> Triple -> Property
+p_query_unmatched_spo :: RDF g => (g -> Triples) -> g -> Triple -> Property
p_query_unmatched_spo _triplesOf gr t =
classify (t `elem` ts) "ignored" $
not (t `elem` ts) ==> [] == queryT gr t
@@ -89,41 +89,41 @@ p_query_unmatched_spo _triplesOf gr t =
-- query with fixed subject and wildcards for pred and obj should yield
-- a list with all triples having subject, and graph minus result triples
-- should yield all triple with unequal subjects.
-p_query_match_s :: Graph g => (g -> Triples) -> g -> Property
+p_query_match_s :: RDF g => (g -> Triples) -> g -> Property
p_query_match_s = mk_query_match_fn sameSubj f
where f t = (Just (subjectOf t), Nothing, Nothing)
-- query w/ fixed predicate and wildcards for subj and obj should yield
-- a list with all triples having predicate, and graph minus result triples
-- should yield all triple with unequal predicates.
-p_query_match_p :: Graph g => (g -> Triples) -> g -> Property
+p_query_match_p :: RDF g => (g -> Triples) -> g -> Property
p_query_match_p = mk_query_match_fn samePred f
where f t = (Nothing, Just (predicateOf t), Nothing)
-- likewise for fixed subject and predicate with object wildcard
-p_query_match_o :: Graph g => (g -> Triples) -> g -> Property
+p_query_match_o :: RDF g => (g -> Triples) -> g -> Property
p_query_match_o = mk_query_match_fn sameObj f
where f t = (Nothing, Nothing, Just (objectOf t))
-- verify likewise for fixed subject and predicate with wildcard object
-p_query_match_sp :: Graph g => (g -> Triples) -> g -> Property
+p_query_match_sp :: RDF g => (g -> Triples) -> g -> Property
p_query_match_sp = mk_query_match_fn same f
where same t1 t2 = sameSubj t1 t2 && samePred t1 t2
f t = (Just $ subjectOf t, Just $ predicateOf t, Nothing)
-- fixed subject and object with wildcard predicate
-p_query_match_so :: Graph g => (g -> Triples) -> g -> Property
+p_query_match_so :: RDF g => (g -> Triples) -> g -> Property
p_query_match_so = mk_query_match_fn same f
where same t1 t2 = sameSubj t1 t2 && sameObj t1 t2
f t = (Just $ subjectOf t, Nothing, Just $ objectOf t)
-- fixed predicate and object with wildcard subject
-p_query_match_po :: Graph g => (g -> Triples) -> g -> Property
+p_query_match_po :: RDF g => (g -> Triples) -> g -> Property
p_query_match_po = mk_query_match_fn same f
where same t1 t2 = samePred t1 t2 && sameObj t1 t2
f t = (Nothing, Just $ predicateOf t, Just $ objectOf t)
-mk_query_match_fn :: Graph g => (Triple -> Triple -> Bool)
+mk_query_match_fn :: RDF g => (Triple -> Triple -> Bool)
-> (Triple -> (Maybe Node, Maybe Node, Maybe Node))
-> (g -> Triples) -> g -> Property
mk_query_match_fn tripleCompareFn mkPatternFn _triplesOf gr =
@@ -141,17 +141,17 @@ mk_query_match_fn tripleCompareFn mkPatternFn _triplesOf gr =
all (tripleCompareFn t) results &&
all (not . tripleCompareFn t) notResults
-p_select_match_none :: Graph g => g -> Bool
+p_select_match_none :: RDF g => g -> Bool
p_select_match_none gr = select gr Nothing Nothing Nothing == removeDupes (triplesOf gr)
-p_select_match_s :: Graph g => (g -> Triples) -> g -> Property
+p_select_match_s :: RDF g => (g -> Triples) -> g -> Property
p_select_match_s =
p_select_match_fn same mkPattern
where
same = equivNode (==) subjectOf
mkPattern t = (Just (\n -> n == subjectOf t), Nothing, Nothing)
-p_select_match_p :: Graph g => (g -> Triples) -> g -> Property
+p_select_match_p :: RDF g => (g -> Triples) -> g -> Property
p_select_match_p =
p_select_match_fn same mkPattern
where
@@ -163,35 +163,35 @@ p_select_match_p =
lastChar _ = error "GraphTestUtils.p_select_match_p.lastChar"
-p_select_match_o :: Graph g => (g -> Triples) -> g -> Property
+p_select_match_o :: RDF g => (g -> Triples) -> g -> Property
p_select_match_o =
p_select_match_fn same mkPattern
where
same = equivNode (/=) objectOf
mkPattern t = (Nothing, Nothing, Just (\n -> n /= objectOf t))
-p_select_match_sp :: Graph g => (g -> Triples) -> g -> Property
+p_select_match_sp :: RDF g => (g -> Triples) -> g -> Property
p_select_match_sp =
p_select_match_fn same mkPattern
where
same t1 t2 = subjectOf t1 == subjectOf t2 && predicateOf t1 /= predicateOf t2
mkPattern t = (Just (\n -> n == subjectOf t), Just (\n -> n /= predicateOf t), Nothing)
-p_select_match_so :: Graph g => (g -> Triples) -> g -> Property
+p_select_match_so :: RDF g => (g -> Triples) -> g -> Property
p_select_match_so =
p_select_match_fn same mkPattern
where
same t1 t2 = subjectOf t1 /= subjectOf t2 && objectOf t1 == objectOf t2
mkPattern t = (Just (\n -> n /= subjectOf t), Nothing, Just (\n -> n == objectOf t))
-p_select_match_po :: Graph g => (g -> Triples) -> g -> Property
+p_select_match_po :: RDF g => (g -> Triples) -> g -> Property
p_select_match_po =
p_select_match_fn same mkPattern
where
same t1 t2 = predicateOf t1 == predicateOf t2 && objectOf t1 == objectOf t2
mkPattern t = (Nothing, Just (\n -> n == predicateOf t), Just (\n -> n == objectOf t))
-p_select_match_spo :: Graph g => (g -> Triples) -> g -> Property
+p_select_match_spo :: RDF g => (g -> Triples) -> g -> Property
p_select_match_spo =
p_select_match_fn same mkPattern
where
@@ -204,7 +204,7 @@ p_select_match_spo =
equivNode :: (Node -> Node -> Bool) -> (Triple -> Node) -> Triple -> Triple -> Bool
equivNode eqFn exFn t1 t2 = (exFn t1) `eqFn` (exFn t2)
-p_select_match_fn :: Graph g => (Triple -> Triple -> Bool)
+p_select_match_fn :: RDF g => (Triple -> Triple -> Bool)
-> (Triple -> (NodeSelector, NodeSelector, NodeSelector))
-> (g -> Triples) -> g -> Property
p_select_match_fn tripleCompareFn mkPatternFn _triplesOf gr =
@@ -222,19 +222,19 @@ p_select_match_fn tripleCompareFn mkPatternFn _triplesOf gr =
all (tripleCompareFn t) results &&
all (not . tripleCompareFn t) notResults
-mkGraphWithDupe :: Graph g => (g -> Triples) -> (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> g -> Triple -> g
-mkGraphWithDupe _triplesOf _mkGraph gr t = _mkGraph ts (baseUrl gr) (prefixMappings gr)
+mkRdfWithDupe :: RDF g => (g -> Triples) -> (Triples -> Maybe BaseUrl -> PrefixMappings -> g) -> g -> Triple -> g
+mkRdfWithDupe _triplesOf _mkRdf gr t = _mkRdf ts (baseUrl gr) (prefixMappings gr)
where ts = t : _triplesOf gr
-- Utility functions and test data ... --
-- a curried version of query that delegates to the actual query after unpacking
-- curried maybe node pattern.
-queryC :: Graph g => g -> (Maybe Node, Maybe Node, Maybe Node) -> Triples
+queryC :: RDF g => g -> (Maybe Node, Maybe Node, Maybe Node) -> Triples
queryC gr (s, p, o) = query gr s p o
-selectC :: Graph g => g -> (NodeSelector, NodeSelector, NodeSelector) -> Triples
+selectC :: RDF g => g -> (NodeSelector, NodeSelector, NodeSelector) -> Triples
selectC gr (s, p, o) = select gr s p o
uncurry3 :: (a -> b -> c -> d) -> ((a, b, c) -> d)
@@ -264,14 +264,14 @@ sameObj t1 t2 = objectOf t1 == objectOf t2
uordered :: Triples -> Triples
uordered = map head . group . sortTriples
-tripleFromGen :: Graph g => (g -> Triples) -> g -> Gen (Maybe Triple)
+tripleFromGen :: RDF g => (g -> Triples) -> g -> Gen (Maybe Triple)
tripleFromGen _triplesOf gr =
case null ts of
True -> return Nothing
False -> oneof $ map (return . Just) ts
where ts = _triplesOf gr
-queryT :: Graph g => g -> Triple -> Triples
+queryT :: RDF g => g -> Triple -> Triples
queryT gr t = query gr (Just $ subjectOf t) (Just $ predicateOf t) (Just $ objectOf t)
languages :: [ByteString]
View
24 testsuite/tests/Data/RDF/MGraph_Test.hs
@@ -1,7 +1,9 @@
+module Data.RDF.MGraph_Test where
+
import Data.RDF
import Data.RDF.Namespace
-import Text.RDF.RDF4H.MGraph
-import Text.RDF.RDF4H.GraphTestUtils
+import Data.RDF.MGraph
+import Data.RDF.GraphTestUtils
import qualified Data.Map as Map
import Control.Monad
@@ -12,7 +14,7 @@ import Test.QuickCheck
----------------------------------------------------
instance Arbitrary MGraph where
- arbitrary = liftM3 mkGraph arbitraryTs (return Nothing) (return $ PrefixMappings Map.empty)
+ arbitrary = liftM3 mkRdf arbitraryTs (return Nothing) (return $ PrefixMappings Map.empty)
--coarbitrary = undefined
instance Show MGraph where
@@ -21,8 +23,8 @@ instance Show MGraph where
_empty :: MGraph
_empty = empty
-_mkGraph :: Triples -> Maybe BaseUrl -> PrefixMappings -> MGraph
-_mkGraph = mkGraph
+_mkRdf :: Triples -> Maybe BaseUrl -> PrefixMappings -> MGraph
+_mkRdf = mkRdf
_triplesOf :: MGraph -> Triples
_triplesOf = triplesOf
@@ -34,20 +36,20 @@ _triplesOf = triplesOf
prop_mg_empty :: Bool
prop_mg_empty = p_empty _triplesOf _empty
-prop_mg_mkGraph_triplesOf :: Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
-prop_mg_mkGraph_triplesOf = p_mkGraph_triplesOf _triplesOf _mkGraph
+prop_mg_mkRdf_triplesOf :: Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
+prop_mg_mkRdf_triplesOf = p_mkRdf_triplesOf _triplesOf _mkRdf
-prop_mg_mkGraph_no_dupes :: Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
-prop_mg_mkGraph_no_dupes = p_mkGraph_no_dupes _triplesOf _mkGraph
+prop_mg_mkRdf_no_dupes :: Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
+prop_mg_mkRdf_no_dupes = p_mkRdf_no_dupes _triplesOf _mkRdf
prop_mg_query_match_none :: Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
-prop_mg_query_match_none = p_query_match_none _mkGraph
+prop_mg_query_match_none = p_query_match_none _mkRdf
prop_mg_query_matched_spo :: MGraph -> Property
prop_mg_query_matched_spo = p_query_matched_spo _triplesOf
prop_mg_query_matched_spo_no_dupes :: MGraph -> Property
-prop_mg_query_matched_spo_no_dupes = p_query_matched_spo_no_dupes _triplesOf _mkGraph
+prop_mg_query_matched_spo_no_dupes = p_query_matched_spo_no_dupes _triplesOf _mkRdf
prop_mg_query_unmatched_spo :: MGraph -> Triple -> Property
prop_mg_query_unmatched_spo = p_query_unmatched_spo _triplesOf
View
20 testsuite/tests/Data/RDF/TriplesGraph_Test.hs
@@ -1,7 +1,9 @@
+module Data.RDF.TriplesGraph_Test where
+
import Data.RDF
import Data.RDF.Namespace
-import Text.RDF.RDF4H.TriplesGraph
-import Text.RDF.RDF4H.GraphTestUtils
+import Data.RDF.TriplesGraph
+import Data.RDF.GraphTestUtils
--import Data.Map(Map)
import qualified Data.Map as Map
@@ -15,7 +17,7 @@ import Control.Monad
----------------------------------------------------
instance Arbitrary TriplesGraph where
- arbitrary = liftM3 mkGraph arbitraryTs (return Nothing) (return $ PrefixMappings Map.empty)
+ arbitrary = liftM3 mkRdf arbitraryTs (return Nothing) (return $ PrefixMappings Map.empty)
--coarbitrary = undefined
instance Show TriplesGraph where
@@ -24,8 +26,8 @@ instance Show TriplesGraph where
_empty :: TriplesGraph
_empty = empty
-_mkGraph :: Triples -> Maybe BaseUrl -> PrefixMappings -> TriplesGraph
-_mkGraph = mkGraph
+_mkRdf :: Triples -> Maybe BaseUrl -> PrefixMappings -> TriplesGraph
+_mkRdf = mkRdf
_triplesOf :: TriplesGraph -> Triples
_triplesOf = triplesOf
@@ -37,17 +39,17 @@ _triplesOf = triplesOf
prop_tg_empty :: Bool
prop_tg_empty = p_empty _triplesOf _empty
-prop_tg_mkGraph_triplesOf :: Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
-prop_tg_mkGraph_triplesOf = p_mkGraph_triplesOf _triplesOf _mkGraph
+prop_tg_mkRdf_triplesOf :: Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
+prop_tg_mkRdf_triplesOf = p_mkRdf_triplesOf _triplesOf _mkRdf
prop_tg_query_match_none :: Triples -> Maybe BaseUrl -> PrefixMappings -> Bool
-prop_tg_query_match_none = p_query_match_none _mkGraph
+prop_tg_query_match_none = p_query_match_none _mkRdf
prop_tg_query_matched_spo :: TriplesGraph -> Property
prop_tg_query_matched_spo = p_query_matched_spo _triplesOf
prop_tg_query_matched_spo_no_dupes :: TriplesGraph -> Property
-prop_tg_query_matched_spo_no_dupes = p_query_matched_spo_no_dupes _triplesOf _mkGraph
+prop_tg_query_matched_spo_no_dupes = p_query_matched_spo_no_dupes _triplesOf _mkRdf
prop_tg_query_unmatched_spo :: TriplesGraph -> Triple -> Property
prop_tg_query_unmatched_spo = p_query_unmatched_spo _triplesOf
View
16 testsuite/tests/Text/RDF/RDF4H/TurtleParser_ConformanceTest.hs
@@ -1,10 +1,10 @@
-module Main where
+module Text.RDF.RDF4H.TurtleParser_ConformanceTest where
import Data.RDF
+import Data.RDF.TriplesGraph
+import Data.RDF.GraphTestUtils
import Text.RDF.RDF4H.TurtleParser
import Text.RDF.RDF4H.NTriplesParser
-import Text.RDF.RDF4H.TriplesGraph
-import Text.RDF.RDF4H.GraphTestUtils
import Text.Printf
@@ -19,8 +19,8 @@ import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace(trace)
-main :: IO ()
-main = putStrLn "Running TurtleParser_ConformanceTest..." >> runAllCTests >>= putStrLn . show
+--main :: IO ()
+--main = putStrLn "Running TurtleParser_ConformanceTest..." >> runAllCTests >>= putStrLn . show
_debug = trace
@@ -86,7 +86,7 @@ checkBadConformanceTest i =
-- Determines if graphs are equivalent, returning Nothing if so or else a diagnostic message.
-- First graph is expected graph, second graph is actual.
-equivalent :: Graph gr => Either ParseFailure gr -> Either ParseFailure gr -> Maybe String
+equivalent :: RDF gr => Either ParseFailure gr -> Either ParseFailure gr -> Maybe String
equivalent (Left _) _ = Nothing
equivalent _ (Left _) = Nothing
equivalent (Right gr1) (Right gr2) = {- _debug (show (length gr1ts, length gr2ts)) -} (test $! zip gr1ts gr2ts)
@@ -124,7 +124,7 @@ handleLoad :: Either ParseFailure TriplesGraph -> Either ParseFailure TriplesGra
handleLoad res =
case res of
l@(Left _) -> l
- (Right gr) -> Right $ mkGraph (map normalize (triplesOf gr)) (baseUrl gr) (prefixMappings gr)
+ (Right gr) -> Right $ mkRdf (map normalize (triplesOf gr)) (baseUrl gr) (prefixMappings gr)
normalize :: Triple -> Triple
normalize t = let s' = normalizeN $ subjectOf t
@@ -146,7 +146,7 @@ assertLoadSuccess _ (Right _) = return ()
assertLoadFailure _ (Left _) = return ()
assertLoadFailure idStr _ = T.assertFailure $ "Bad test " ++ idStr ++ " loaded successfully."
-assertEquivalent :: Graph gr => String -> Either ParseFailure gr -> Either ParseFailure gr -> T.Assertion
+assertEquivalent :: RDF gr => String -> Either ParseFailure gr -> Either ParseFailure gr -> T.Assertion
assertEquivalent testname r1 r2 =
case equiv of
Nothing -> T.assert True
View
1 testsuite/tests/Text/RDF/RDF4H/XmlParser_Test.hs
@@ -22,6 +22,7 @@ import Network.HTTP (Request(..))
import Data.RDF
import Data.RDF.Namespace (mkPrefixedNS')
import Data.RDF.TriplesGraph (TriplesGraph(..))
+import Data.RDF.TriplesGraph_Test
import Text.RDF.RDF4H.XmlParser

0 comments on commit db1ca4a

Please sign in to comment.
Something went wrong with that request. Please try again.