module Data.RDF.Namespace(
Namespace(..), mkPlainNS, mkPrefixedNS, mkPrefixedNS',
PrefixMapping(PrefixMapping), PrefixMappings(PrefixMappings), toPMList,
mergePrefixMappings,
mkUri,
prefixOf, uriOf,
rdf, rdfs, dc, dct, owl, xsd, skos, foaf, ex, ex2,
standard_ns_mappings, ns_mappings
)
where
import qualified Data.Text as T
import Data.RDF.Types
import qualified Data.Map as Map
standard_namespaces :: [Namespace]
standard_namespaces = [rdf, rdfs, dc, dct, owl, xsd, skos, foaf, ex, ex2]
standard_ns_mappings :: PrefixMappings
standard_ns_mappings = ns_mappings standard_namespaces
ns_mappings :: [Namespace] -> PrefixMappings
ns_mappings ns = PrefixMappings $ Map.fromList $
map (\(PrefixedNS pre uri) -> (pre, uri)) ns
rdf :: Namespace
rdf = mkPrefixedNS' "rdf" "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
rdfs :: Namespace
rdfs = mkPrefixedNS' "rdfs" "http://www.w3.org/2000/01/rdf-schema#"
dc :: Namespace
dc = mkPrefixedNS' "dc" "http://purl.org/dc/elements/1.1/"
dct :: Namespace
dct = mkPrefixedNS' "dct" "http://purl.org/dc/terms/"
owl :: Namespace
owl = mkPrefixedNS' "owl" "http://www.w3.org/2002/07/owl#"
xsd :: Namespace
xsd = mkPrefixedNS' "xsd" "http://www.w3.org/2001/XMLSchema#"
skos :: Namespace
skos = mkPrefixedNS' "skos" "http://www.w3.org/2004/02/skos/core#"
foaf :: Namespace
foaf = mkPrefixedNS' "foaf" "http://xmlns.com/foaf/0.1/"
ex :: Namespace
ex = mkPrefixedNS' "ex" "http://www.example.org/"
ex2 :: Namespace
ex2 = mkPrefixedNS' "ex2" "http://www2.example.org/"
mergePrefixMappings :: PrefixMappings -> PrefixMappings -> PrefixMappings
mergePrefixMappings (PrefixMappings p1s) (PrefixMappings p2s) =
PrefixMappings $ Map.union p1s p2s
toPMList :: PrefixMappings -> [(T.Text, T.Text)]
toPMList (PrefixMappings m) = Map.toList m
mkUri :: Namespace -> T.Text -> T.Text
mkUri ns local = uriOf ns `T.append` local
mkPlainNS :: T.Text -> Namespace
mkPlainNS = PlainNS
mkPrefixedNS :: T.Text -> T.Text -> Namespace
mkPrefixedNS = PrefixedNS
mkPrefixedNS' :: String -> String -> Namespace
mkPrefixedNS' s1 s2 = mkPrefixedNS (T.pack s1) (T.pack s2)
uriOf :: Namespace -> T.Text
uriOf (PlainNS uri) = uri
uriOf (PrefixedNS _ uri) = uri
prefixOf :: Namespace -> Maybe T.Text
prefixOf (PlainNS _) = Nothing
prefixOf (PrefixedNS p _) = Just p