Commits

Doug Burke committed 4478444

Major changes to ScopedName to improve performance; experimental

Comments (0)

Files changed (37)

+0.5.0.0:
+
+  - Changes to ScopedName to provide a significant reduction in the time
+    taken to write out a graph. As this is an experimental change the
+    record fields are no longer exported (to avoid exposing internal
+    details that may change).
+  
 0.4.0.0:
 
   - Use polyparse rather than parsec-2 for parsing. As part of this,

Swish/RDF/BuiltInDatatypes.hs

 --------------------------------------------------------------------------------
 
 module Swish.RDF.BuiltInDatatypes
-    ( allDatatypes, findRDFDatatype )
-where
+       ( allDatatypes, findRDFDatatype )
+    where
 
-import Swish.RDF.RDFDatatype
-    ( RDFDatatype
-    )
+import Swish.RDF.RDFDatatype (RDFDatatype)
 
-import Swish.Utils.LookupMap
-    ( LookupMap(..), mapFindMaybe
-    )
-
-import Swish.Utils.Namespace
-    ( ScopedName(..) )
-
-import Swish.RDF.RDFDatatypeXsdString
-    ( rdfDatatypeXsdString )
-
-import Swish.RDF.RDFDatatypeXsdInteger
-    ( rdfDatatypeXsdInteger )
+import Swish.Utils.LookupMap (LookupMap(..), mapFindMaybe)
+import Swish.Utils.Namespace (ScopedName)
+import Swish.RDF.RDFDatatypeXsdString (rdfDatatypeXsdString)
+import Swish.RDF.RDFDatatypeXsdInteger (rdfDatatypeXsdInteger)
 
 ------------------------------------------------------------
 --  Declare datatype map

Swish/RDF/BuiltInRules.hs

 
 import Swish.RDF.Datatype (typeRules, typeMkModifiers)
 import Swish.Utils.LookupMap (LookupMap(..), mapFindMaybe)
-import Swish.Utils.Namespace (ScopedName(..))
+import Swish.Utils.Namespace (ScopedName)
 
 ------------------------------------------------------------
 --  Declare variable binding filters list

Swish/RDF/ClassRestrictionRule.hs

 import Swish.RDF.VarBinding (VarBinding(..))
 import Swish.RDF.Vocabulary (namespaceRDFD)
 
-import Swish.Utils.Namespace (Namespace(..),ScopedName(..), namespaceToBuilder)
+import Swish.Utils.Namespace (Namespace(..),ScopedName, namespaceToBuilder)
 import Swish.Utils.PartOrderedCollection
     ( minima, maxima
     , partCompareEq, partComparePair

Swish/RDF/Datatype.hs

     , Rule(..)
     )
 
-import Swish.Utils.Namespace
-    ( ScopedName(..)
-    )
-
-import Swish.RDF.Vocabulary
-    ( swishName )
+import Swish.RDF.Vocabulary (swishName)
+import Swish.Utils.Namespace (ScopedName)
 
 import Swish.RDF.VarBinding
     ( VarBinding(..)

Swish/RDF/N3Formatter.hs

     , mapFind, mapFindMaybe, mapAdd, mapDelete, mapMerge
     )
 
-import Swish.Utils.Namespace
-    ( ScopedName(..), getScopeURI )
+import Swish.Utils.Namespace (ScopedName, getScopeLocal, getScopeURI)
 
 import Data.Char (isDigit)
 
     Nothing -> do
       pr <- getPrefixes
       let nsuri  = getScopeURI sn
-          local  = snLocal sn
+          local  = getScopeLocal sn
           premap = reverseLookupMap pr :: RevNamespaceMap
           prefix = mapFindMaybe nsuri premap
           

Swish/RDF/N3Parser.hs

 
 import Swish.Utils.Namespace
     ( Namespace(..)
-    , ScopedName(..)
+    , ScopedName
+    , getScopeNamespace
     , getScopedNameURI
+    , getScopeNamespace
     , makeURIScopedName
     , makeQNameScopedName
+    , makeNSScopedName
     , nullScopedName
     )
 
-import Swish.Utils.QName (QName)
+import Swish.Utils.QName (QName(..))
 
 import Swish.RDF.Vocabulary
     ( langName
                     -> Either String a
 parseAnyfromText parser mbase input =
   let pmap   = LookupMap [Namespace Nothing hashURI]
-      muri   = fmap makeQNameScopedName mbase
+      muri   = fmap (makeQNameScopedName Nothing) mbase
       smap   = LookupMap $ specialTable muri
       pstate = N3State
               { graphState = emptyRDFGraph
     
 -}
 operatorLabel :: ScopedName -> N3Parser RDFLabel
-operatorLabel snam@(ScopedName sns _) = do
+operatorLabel snam = do
   st <- stGet
-  let opmap = prefixUris st
+  let sns = getScopeNamespace snam
+      opmap = prefixUris st
       pkey = entryKey sns
       pval = entryVal sns
       
   let stmt = arc s p o
       oldp = prefixUris ost
       ogs = graphState ost
-      newp = mapReplaceOrAdd (snScope dtype) oldp
+      newp = mapReplaceOrAdd (getScopeNamespace dtype) oldp
   stUpdate $ \st -> st { prefixUris = newp, graphState = addArc stmt ogs }
 addStatement s p o = stUpdate (updateGraph (addArc (arc s p o) ))
 
 
 qname :: N3Parser ScopedName
 qname =
-  (char ':' *> toSN getDefaultPrefix)
+  -- (char ':' *> toSN getDefaultPrefix)
+  (char ':' >> g >>= return . uncurry makeNSScopedName)
   <|> (n3Name >>= fullOrLocalQName)
     where
-      toSN p = ScopedName <$> p <*> (n3Name <|> return "")
-          
+      g = (,) <$> getDefaultPrefix <*> (n3Name <|> return "")
+               
 fullOrLocalQName :: T.Text -> N3Parser ScopedName
 fullOrLocalQName name = 
   (char ':' *> fullQName name)
   <|> localQName name
   
 fullQName :: T.Text -> N3Parser ScopedName
-fullQName name = do
-  pre <- findPrefix name
-  lname <- n3Name <|> return ""
-  return $ ScopedName pre lname
+fullQName name = makeNSScopedName <$> findPrefix name <*> (n3Name <|> pure "")
   
 findPrefix :: T.Text -> N3Parser Namespace
 findPrefix pre = do
 localQName name = do
   st <- stGet
   if getAllowLocalNames st
-    then ScopedName <$> getDefaultPrefix <*> pure name
+    then let g = (,) <$> getDefaultPrefix <*> pure name
+         in uncurry makeNSScopedName <$> g
+            
     else fail ("Invalid 'bare' word: " ++ T.unpack name)-- TODO: not ideal error message; can we handle this case differently?
 
 {-

Swish/RDF/NTFormatter.hs

 import Swish.RDF.GraphClass
     ( Arc(..) )
 
-import Swish.Utils.Namespace (ScopedName(..), nsURI)
+import Swish.Utils.Namespace (ScopedName, getQName)
 import Swish.RDF.Vocabulary (isLang, langTag)
 
 import Swish.Utils.LookupMap
 
 -- TODO: can we use Network.URI to protect the URI?
 showScopedName :: ScopedName -> B.Builder
+{-
 showScopedName (ScopedName n l) = 
   let uri = T.pack (show (nsURI n)) `mappend` l
   in mconcat ["<", B.fromText (quote uri), ">"]
+-}
+-- showScopedName s = mconcat ["<", B.fromText (quote (T.pack (show (getQName s)))), ">"]
+showScopedName s = B.fromText (quote (T.pack (show (getQName s)))) -- looks like qname already adds the <> around this
 
 {-
 Swish.Utils.MiscHelpers contains a quote routine

Swish/RDF/NTParser.hs

 
 import Swish.RDF.GraphClass (arc)
 
-import Swish.Utils.Namespace (ScopedName(..), makeURIScopedName)
+import Swish.Utils.Namespace (ScopedName, makeURIScopedName)
 
 import Swish.RDF.Vocabulary (langName)
 

Swish/RDF/RDFDatatype.hs

     , DatatypeSub(..)
     )
 
-import Swish.Utils.Namespace
-    ( ScopedName(..) )
-
-import Swish.RDF.VarBinding
-    ( VarBindingModify(..) )
+import Swish.RDF.VarBinding (VarBindingModify(..))
+import Swish.Utils.Namespace (ScopedName)
 
 import Control.Monad (liftM)
 import Data.Maybe (fromMaybe, isJust, fromJust)

Swish/RDF/RDFDatatypeXsdInteger.hs

 
 import Swish.RDF.Ruleset (makeRuleset)
 
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..), namespaceToBuilder)
+import Swish.Utils.Namespace (Namespace(..), ScopedName, namespaceToBuilder, makeNSScopedName)
 
 import Swish.RDF.Vocabulary
     ( namespaceRDF
 
 -- |Type name for xsd:integer datatype
 typeNameXsdInteger :: ScopedName
-typeNameXsdInteger  = ScopedName namespaceXSD nameXsdInteger
+typeNameXsdInteger  = makeNSScopedName namespaceXSD nameXsdInteger
 
 -- |Namespace for xsd:integer datatype functions
 namespaceXsdInteger :: Namespace
     T.Text -> DatatypeRelPr Integer -> UnaryFnTable Integer
     -> DatatypeRel Integer
 mkIntRel2 nam pr fns = DatatypeRel
-    { dtRelName = ScopedName namespaceXsdInteger nam
+    { dtRelName = makeNSScopedName namespaceXsdInteger nam
     , dtRelFunc = altArgs pr fns unaryFnApp
     }
 
     T.Text -> DatatypeRelPr Integer -> BinaryFnTable Integer
     -> DatatypeRel Integer
 mkIntRel3 nam pr fns = DatatypeRel
-    { dtRelName = ScopedName namespaceXsdInteger nam
+    { dtRelName = makeNSScopedName namespaceXsdInteger nam
     , dtRelFunc = altArgs pr fns binaryFnApp
     }
 
     T.Text -> DatatypeRelPr Integer -> BinMaybeFnTable Integer
     -> DatatypeRel Integer
 mkIntRel3maybe nam pr fns = DatatypeRel
-    { dtRelName = ScopedName namespaceXsdInteger nam
+    { dtRelName = makeNSScopedName namespaceXsdInteger nam
     , dtRelFunc = altArgs pr fns binMaybeFnApp
     }
 
 
 modXsdIntegerAbs :: RDFDatatypeMod Integer
 modXsdIntegerAbs = DatatypeMod
-    { dmName = ScopedName namespaceXsdInteger "abs"
+    { dmName = makeNSScopedName namespaceXsdInteger "abs"
     , dmModf = [ f0, f1 ]
     , dmAppf = makeVmod11
     }
 
 modXsdIntegerNeg :: RDFDatatypeMod Integer
 modXsdIntegerNeg = DatatypeMod
-    { dmName = ScopedName namespaceXsdInteger "neg"
+    { dmName = makeNSScopedName namespaceXsdInteger "neg"
     , dmModf = [ f0, f1, f1 ]
     , dmAppf = makeVmod11inv
     }
 
 modXsdIntegerSum :: RDFDatatypeMod Integer
 modXsdIntegerSum = DatatypeMod
-    { dmName = ScopedName namespaceXsdInteger "sum"
+    { dmName = makeNSScopedName namespaceXsdInteger "sum"
     , dmModf = [ f0, f1, f2, f2 ]
     , dmAppf = makeVmod21inv
     }
 
 modXsdIntegerDiff :: RDFDatatypeMod Integer
 modXsdIntegerDiff = DatatypeMod
-    { dmName = ScopedName namespaceXsdInteger "diff"
+    { dmName = makeNSScopedName namespaceXsdInteger "diff"
     , dmModf = [ f0, f1, f2, f3 ]
     , dmAppf = makeVmod21inv
     }
 
 modXsdIntegerProd :: RDFDatatypeMod Integer
 modXsdIntegerProd = DatatypeMod
-    { dmName = ScopedName namespaceXsdInteger "prod"
+    { dmName = makeNSScopedName namespaceXsdInteger "prod"
     , dmModf = [ f0, f1, f2, f2 ]
     , dmAppf = makeVmod21inv
     }
 
 modXsdIntegerDivMod :: RDFDatatypeMod Integer
 modXsdIntegerDivMod = DatatypeMod
-    { dmName = ScopedName namespaceXsdInteger "divmod"
+    { dmName = makeNSScopedName namespaceXsdInteger "divmod"
     , dmModf = [ f0, f1 ]
     , dmAppf = makeVmod22
     }
 
 modXsdIntegerPower :: RDFDatatypeMod Integer
 modXsdIntegerPower = DatatypeMod
-    { dmName = ScopedName namespaceXsdInteger "power"
+    { dmName = makeNSScopedName namespaceXsdInteger "power"
     , dmModf = [ f0, f1 ]
     , dmAppf = makeVmod21
     }
 modXsdIntegerCompare ::
     T.Text -> (Integer->Integer->Bool) -> RDFDatatypeMod Integer
 modXsdIntegerCompare nam rel = DatatypeMod
-    { dmName = ScopedName namespaceXsdInteger nam
+    { dmName = makeNSScopedName namespaceXsdInteger nam
     , dmModf = [ f0 ]
     , dmAppf = makeVmod20
     }

Swish/RDF/RDFDatatypeXsdString.hs

     )
 
 import Swish.RDF.Ruleset (makeRuleset)
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..), namespaceToBuilder)
+import Swish.Utils.Namespace (Namespace(..), ScopedName, namespaceToBuilder, makeNSScopedName)
 
 import Swish.RDF.Vocabulary
     ( namespaceRDF
 nameXsdString :: T.Text
 nameXsdString = "string"
 
--- |Type name for @xsd:string@ datatype
+-- | Type name for @xsd:string@ datatype
 typeNameXsdString :: ScopedName
-typeNameXsdString  = ScopedName namespaceXSD nameXsdString
+typeNameXsdString  = makeNSScopedName namespaceXSD nameXsdString
 
 -- |Namespace for @xsd:string@ datatype functions
 namespaceXsdString :: Namespace
 mkStrRel2 ::
     T.Text -> DatatypeRelPr T.Text -> UnaryFnTable T.Text
     -> DatatypeRel T.Text
-mkStrRel2 nam pr fns = DatatypeRel
-    { dtRelName = ScopedName namespaceXsdString nam
+mkStrRel2 nam pr fns = 
+  DatatypeRel
+    { dtRelName = makeNSScopedName namespaceXsdString nam
     , dtRelFunc = altArgs pr fns unaryFnApp
     }
 
 modXsdStringCompare ::
     T.Text -> (T.Text->T.Text->Bool) -> RDFDatatypeMod T.Text
 modXsdStringCompare nam rel = DatatypeMod
-    { dmName = ScopedName namespaceXsdString nam
+    { dmName = makeNSScopedName namespaceXsdString nam
     , dmModf = [ f0 ]
     , dmAppf = makeVmod20
     }
 stringPlainValue ::
     RDFLabel -> RDFLabel -> RDFVarBindingModify
 stringPlainValue svar lvar = VarBindingModify
-        { vbmName   = ScopedName namespaceRDFD "stringPlain"
+        { vbmName   = makeNSScopedName namespaceRDFD "stringPlain"
         , vbmApply  = concatMap app1
         , vbmVocab  = [svar,lvar]
         , vbmUsage  = [[svar],[lvar],[]]

Swish/RDF/RDFGraph.hs

 import Swish.Utils.Namespace
     ( Namespace(..)
     , getScopedNameURI
-    , ScopedName(..)
+    , ScopedName
+    , getScopeLocal, getScopeNamespace
     , getQName
     , makeQNameScopedName
     , makeURIScopedName
     labelIsVar _            = False
     getLocal   (Blank loc)  = loc
     getLocal   (Var   loc)  = '?':loc
-    getLocal   (Res   sn)   = "Res_" ++ T.unpack (snLocal sn)
+    getLocal   (Res   sn)   = "Res_" ++ T.unpack (getScopeLocal sn)
     getLocal   (NoNode)     = "None"
     getLocal   _            = "Lit_"
     makeLabel  ('?':loc)    = Var loc
   
 -- | Converts to a Resource.
 instance ToRDFLabel QName where  
-  toRDFLabel = Res . makeQNameScopedName
+  toRDFLabel = Res . makeQNameScopedName Nothing
   
 -- | Converts from a Resource.
 instance FromRDFLabel QName where
 --  first character of local name is '_' and
 --  remaining characters of local name are all digits
 isMemberProp :: RDFLabel -> Bool
-isMemberProp (Res sn) = snScope sn == namespaceRDF &&
+isMemberProp (Res sn) = getScopeNamespace sn == namespaceRDF &&
                         T.head loc   == '_' &&
                         T.all isDigit (T.tail loc)
                         where
-                            loc = snLocal sn
+                            loc = getScopeLocal sn
 isMemberProp _        = False
 
 -- |Test if supplied labal is a blank node
 -- toRDFGraph arcs = emptyRDFGraph { statements = arcs }
 toRDFGraph arcs = 
   let lbls = concatMap (\(Arc s p o) -> [s,p,o]) arcs
-      ns1  = map (snScope . getScopedName) (filter isUri lbls)
-      ns2  = map (snScope . getDataType) (filter isTypedLiteral lbls)
+      ns1  = map (getScopeNamespace . getScopedName) (filter isUri lbls)
+      ns2  = map (getScopeNamespace . getDataType) (filter isTypedLiteral lbls)
       getDataType (Lit _ (Just dt)) = dt
       getDataType _ = nullScopedName -- should not happen
       nsmap = foldl' mapAddIfNew emptyNamespaceMap (ns1++ns2)

Swish/RDF/RDFParser.hs

     )
 
 import Swish.Utils.LookupMap (LookupMap(..))
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..))
+import Swish.Utils.Namespace (Namespace(..), ScopedName)
 
 import qualified Data.Text      as T
 import qualified Data.Text.Lazy as L
   case mhex of
     Left emsg     -> failBad $ "Internal error: unable to parse hex4: " ++ emsg
     Right (v, "") -> return $ chr v
-    Right (_, vs) -> failBad $ "Internal error: hex4 has remained of " ++ T.unpack vs
+    Right (_, vs) -> failBad $ "Internal error: hex4 remainder = " ++ T.unpack vs
         
 hex8 :: Parser a Char
 hex8 = do
     Right (v, "") -> if v <= 0x10FFFF
                      then return $ chr v
                      else failBad "\\UHHHHHHHH format is limited to a maximum of \\U0010FFFF"
-    Right (_, vs) -> failBad $ "Internal error: hex8 has remained of " ++ T.unpack vs
+    Right (_, vs) -> failBad $ "Internal error: hex8 remainder = " ++ T.unpack vs
         
 --------------------------------------------------------------------------------
 --

Swish/RDF/RDFProof.hs

     , toRDFGraph -}, emptyRDFGraph
     )
 
-import Swish.RDF.VarBinding
-    (  makeVarBinding
-    )
+import Swish.RDF.VarBinding (makeVarBinding)
 
 import Swish.RDF.Proof
     ( Proof(..), Step(..) )
 import Swish.RDF.Rule
     ( Expression(..), Rule(..) )
 
-import Swish.Utils.Namespace
-    ( ScopedName(..)
-    )
+import Swish.Utils.Namespace (ScopedName)
 
 import Swish.RDF.GraphClass
     ( Label(..), LDGraph(..), replaceArcs )

Swish/RDF/RDFProofContext.hs

 
 import Swish.RDF.Ruleset (makeRuleset)
 import Swish.RDF.Datatype (typeMkCanonicalForm)
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..))
+import Swish.Utils.Namespace (Namespace(..), makeNSScopedName)
 
 import Swish.RDF.Vocabulary
     ( namespaceRDFD
 sameDatatypedValue ::
     RDFLabel -> RDFLabel -> RDFLabel -> RDFLabel -> RDFVarBindingModify
 sameDatatypedValue val1 typ1 val2 typ2 = VarBindingModify
-        { vbmName   = ScopedName namespaceRDFD "sameValue"
+        { vbmName   = makeNSScopedName namespaceRDFD "sameValue"
         , vbmApply  = sameDatatypedValueApplyAll val1 typ1 val2 typ2
         , vbmVocab  = [val1,typ1,val2,typ2]
         , vbmUsage  = [[val2]]
 --  RDF subgraph entailment (from RDF semantics document section 2)
 --
 rdfsub :: RDFRule 
-rdfsub = makeRdfSubgraphEntailmentRule (ScopedName scopeRDF "sub")
+rdfsub = makeRdfSubgraphEntailmentRule (makeNSScopedName scopeRDF "sub")
 
 --  RDF simple entailment (from RDF semantics document section 7.1)
 --  (Note: rules se1 and se2 are combined here, because the scope of
 --  the "allocatedTo" modifier is the application of a single rule.)
 --
 rdfse :: RDFRule
-rdfse = makeRdfSimpleEntailmentRule (ScopedName scopeRDF "se")
+rdfse = makeRdfSimpleEntailmentRule (makeNSScopedName scopeRDF "se")
 
 --  RDF bnode-for-literal assignments (from RDF semantics document section 7.1)
 --

Swish/RDF/RDFRuleset.hs

 import Swish.RDF.Rule
     ( Formula(..), Rule(..), RuleMap
     , fwdCheckInference
-    , nullScope
+    , nullSN
     )
 
 import Swish.RDF.VarBinding
     , varBindingId
     )
 
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..), namespaceToBuilder)
+import Swish.Utils.Namespace (Namespace(..), ScopedName, makeNSScopedName, namespaceToBuilder)
 import Swish.RDF.Vocabulary (swishName, namespaceRDF, namespaceRDFS)
 
 {-
 -- | The null RDF formula.
 nullRDFFormula :: Formula RDFGraph
 nullRDFFormula = Formula
-    { formName = ScopedName nullScope "nullRDFGraph"
+    { formName = nullSN "nullRDFGraph"
     , formExpr = emptyRDFGraph
     }
 
     -> T.Text     -- ^ local name for the formula in the namespace
     -> B.Builder  -- ^ graph in Notation 3 format
     -> RDFFormula
-makeRDFFormula scope local gr = Formula
-    { formName = ScopedName scope local
+makeRDFFormula scope local gr = 
+  Formula
+    { formName = makeNSScopedName scope local
     , formExpr = makeRDFGraphFromN3Builder gr
     }
 
     --   'makeN3ClosureSimpleRule'.
     -> RDFRule
 makeN3ClosureRule scope local ant con =
-    makeRDFClosureRule (ScopedName scope local) [antgr] congr
+    makeRDFClosureRule (makeNSScopedName scope local) [antgr] congr
     where
         antgr = makeRDFGraphFromN3Builder ant
         congr = makeRDFGraphFromN3Builder con
     --   (See 'makeNodeAllocTo').
     -> RDFRule
 makeN3ClosureAllocatorRule scope local ant con vflt aloc =
-    makeRDFClosureRule (ScopedName scope local) [antgr] congr modc
+    makeRDFClosureRule (makeNSScopedName scope local) [antgr] congr modc
     where
         antgr = makeRDFGraphFromN3Builder ant
         congr = makeRDFGraphFromN3Builder con
         vmod  = aloc (allLabels labelIsVar antgr)
         modc  = fromMaybe varBindingId $ vbmCompose vmod vflt
 
-
 ------------------------------------------------------------
 --  Query binding modifier for "allocated to" logic
 ------------------------------------------------------------

Swish/RDF/Rule.hs

 
 module Swish.RDF.Rule
        ( Expression(..), Formula(..), Rule(..), RuleMap
-       , nullScope, nullFormula, nullRule
+       , nullScope, nullSN, nullFormula, nullRule
        , fwdCheckInference, bwdCheckInference
        , showsFormula, showsFormulae, showsWidth
        )
        where
 
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..))
+import Swish.Utils.Namespace (Namespace(..), ScopedName, makeScopedName)
 import Swish.Utils.LookupMap (LookupEntryClass(..), LookupMap(..))
 import Swish.Utils.ShowM (ShowM(..))
 
-import Network.URI (parseURI)
+import Network.URI (URI, parseURI)
 import Data.Maybe (fromJust)
 
+import qualified Data.Text as T
+
 ------------------------------------------------------------
 --  Expressions
 ------------------------------------------------------------
 
 -- | The namespace @http:\/\/id.ninebynine.org\/2003\/Ruleset\/null@
 nullScope :: Namespace
-nullScope = Namespace (Just "null") 
-            $ fromJust $ parseURI "http://id.ninebynine.org/2003/Ruleset/null"
+nullScope = Namespace (Just "null") nullScopeURI
+
+nullSN :: T.Text -> ScopedName
+nullSN = makeScopedName (Just "null") nullScopeURI
+
+tU :: String -> URI
+tU = fromJust . parseURI
+
+nullScopeURI :: URI
+nullScopeURI = tU "http://id.ninebynine.org/2003/Ruleset/null"
 
 -- | The null formula.
 nullFormula :: Formula ex
 nullFormula = Formula
-    { formName = ScopedName nullScope "nullFormula"
+    { formName = makeScopedName (Just "null") nullScopeURI "nullFormula"
     , formExpr = error "Null formula"
     }
 
 -- | The null rule.
 nullRule :: Rule ex
 nullRule = Rule
-    { ruleName = ScopedName nullScope "nullRule"
+    { ruleName = makeScopedName (Just "null") nullScopeURI "nullRule"
     , fwdApply = \ _ -> []
     , bwdApply = \ _ -> []
     , checkInference = \ _ _ -> False

Swish/RDF/Ruleset.hs

 
 import Swish.Utils.Namespace
     ( Namespace(..)
-    , ScopedName(..)
+    , ScopedName
     )
 
 import Swish.RDF.Rule (Formula(..), Rule(..))

Swish/RDF/SwishMonad.hs

     ( Formula(..)
     )
 
-import Swish.Utils.Namespace (ScopedName(..))
+import Swish.Utils.Namespace (ScopedName, getScopeNamespace)
 import Swish.Utils.QName (QName)
 
 import Swish.Utils.LookupMap
 
 findRuleset ::
     ScopedName -> SwishState -> Maybe RDFRuleset
-findRuleset nam state = mapFindMaybe (snScope nam) (rulesets state)
+findRuleset nam state = mapFindMaybe (getScopeNamespace nam) (rulesets state)
 
 findOpenVarModify :: ScopedName -> SwishState -> Maybe RDFOpenVarBindingModify
 findOpenVarModify nam _ = findRDFOpenVarBindingModifier nam

Swish/RDF/SwishScript.hs

 import Swish.RDF.Rule (Formula(..), Rule(..)) 
 import Swish.RDF.VarBinding (composeSequence)
 
-import Swish.Utils.Namespace (ScopedName(..))
+import Swish.Utils.Namespace (ScopedName, getScopeNamespace)
 import Swish.Utils.QName (QName, qnameFromURI)
 import Swish.Utils.LookupMap (mapReplaceOrAdd)
 import Swish.Utils.ListHelpers (equiv, flist)
                     (Right ags,Right rls) ->
                         modRulesets (mapReplaceOrAdd rs)
                         where
-                            rs = makeRuleset (snScope sn) ags rls
+                            rs = makeRuleset (getScopeNamespace sn) ags rls
             ; modify frs
             }
 
                     (Right cgr,Right dts) ->
                         modRulesets (mapReplaceOrAdd rs)
                         where
-                            rs  = makeRuleset (snScope sn) [] rls
+                            rs  = makeRuleset (getScopeNamespace sn) [] rls
                             rls = concatMap (`typeMkRules` cgr) dts
             ; modify frs
             }

Swish/RDF/VarBinding.hs

     , makeLookupMap, mapFindMaybe
     )
 
-import Swish.Utils.Namespace (ScopedName(..))
+import Swish.Utils.Namespace (ScopedName, getScopeLocal)
 import Swish.RDF.Vocabulary (swishName)
 import Swish.Utils.ListHelpers (equiv, subset, flist, headOrNothing, permutations)
 
     (VarBindingModify nam1 app1 voc1 use1)
     (VarBindingModify nam2 app2 voc2 use2)
     | not (null use12) = Just VarBindingModify
-        { vbmName  = swishName $ mconcat ["_", snLocal nam1, "_", snLocal nam2, "_"]
+        { vbmName  = swishName $ mconcat ["_", getScopeLocal nam1, "_", getScopeLocal nam2, "_"]
         , vbmApply = app2 . app1
         , vbmVocab = voc1 `union` voc2
         , vbmUsage = use12

Swish/RDF/Vocabulary.hs

     , namespaceLOG
     , namespaceDAML
     , namespaceDefault
-    , namespaceSwish, swishName
+    , namespaceSwish 
+    , swishName
     , namespaceLang,  langName, langTag, isLang
     , scopeRDF
     , scopeRDFS
     )
 where
 
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..))
+import Swish.Utils.Namespace (Namespace(..), ScopedName, getScopeLocal, getScopeNamespace, makeScopedName)
 
 import Data.Monoid (mappend, mconcat)
 import Data.Maybe (fromMaybe)
-import Network.URI (parseURI)
+import Network.URI (URI, parseURI)
 
 import qualified Data.Text as T
 
             parseURI ustr
   in Namespace (Just p) uri
 
+toNSU :: T.Text -> URI -> Namespace
+toNSU p = Namespace (Just p)
+
 namespaceXsdType :: T.Text -> Namespace
 namespaceXsdType dtn = toNS ("xsd_" `mappend` dtn)
                        (mconcat ["http://id.ninebynine.org/2003/XMLSchema/", dtn, "#"])
 namespaceDefault :: Namespace
 namespaceLang :: Namespace
 
-namespaceRDF     = toNS "rdf"     "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-namespaceRDFS    = toNS "rdfs"    "http://www.w3.org/2000/01/rdf-schema#"
-namespaceRDFD    = toNS "rdfd"    "http://id.ninebynine.org/2003/rdfext/rdfd#"
-namespaceOWL     = toNS "owl"     "http://www.w3.org/2002/07/owl#"
-namespaceXSD     = toNS "xsd"     "http://www.w3.org/2001/XMLSchema#"
+namespaceRDF     = toNSU "rdf"    namespaceRDFURI
+namespaceRDFS    = toNSU "rdfs"   namespaceRDFSURI
+namespaceRDFD    = toNSU "rdfd"   namespaceRDFDURI
+namespaceOWL     = toNSU "owl"    namespaceOWLURI
+namespaceXSD     = toNSU "xsd"    namespaceXSDURI
 namespaceMATH    = toNS "math"    "http://www.w3.org/2000/10/swap/math#"
-namespaceLOG     = toNS "log"     "http://www.w3.org/2000/10/swap/log#"
+namespaceLOG     = toNSU "log"    namespaceLOGURI
 namespaceDAML    = toNS "daml"    "http://www.daml.org/2000/10/daml-ont#"
-namespaceSwish   = toNS "swish"   "http://id.ninebynine.org/2003/Swish/"
-namespaceLang    = toNS "lang"    "http://id.ninebynine.org/2003/Swish/Lang/" -- To be replaced by urn:ietf:params:lang?
-namespaceDefault = toNS "default" "http://id.ninebynine.org/default/"
+namespaceSwish   = toNSU "swish"  namespaceSwishURI
+namespaceLang    = toNSU "lang"   namespaceLangURI
+namespaceDefault = toNSU "default" namespaceDefaultURI
+
+tU :: String -> URI
+tU = fromMaybe (error "Internal error processing namespace URI") . parseURI
+
+namespaceRDFURI, namespaceRDFSURI, namespaceRDFDURI, 
+  namespaceXSDURI, namespaceOWLURI, namespaceLOGURI,
+  namespaceSwishURI, 
+  namespaceLangURI, namespaceDefaultURI :: URI
+namespaceRDFURI   = tU "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+namespaceRDFSURI  = tU "http://www.w3.org/2000/01/rdf-schema#"
+namespaceRDFDURI  = tU "http://id.ninebynine.org/2003/rdfext/rdfd#"
+namespaceOWLURI   = tU "http://www.w3.org/2002/07/owl#"
+namespaceXSDURI   = tU "http://www.w3.org/2001/XMLSchema#"
+namespaceLOGURI   = tU "http://www.w3.org/2000/10/swap/log#"
+namespaceSwishURI = tU "http://id.ninebynine.org/2003/Swish/"
+namespaceLangURI  = tU "http://id.ninebynine.org/2003/Swish/Lang/" -- To be replaced by urn:ietf:params:lang?  
+namespaceDefaultURI = tU "http://id.ninebynine.org/default/"
 
 swishName :: T.Text -> ScopedName
-swishName = ScopedName namespaceSwish
+-- swishName = ScopedName namespaceSwish
+swishName = makeScopedName (Just "swish") namespaceSwishURI
 
 -----------------------------------------------------------
 --  Language tags
 --  distinct labels (but future developments may change that).
 
 langName :: T.Text -> ScopedName
-langName = ScopedName namespaceLang . T.toLower
+-- langName = ScopedName namespaceLang . T.toLower
+langName = makeScopedName (Just "lang") namespaceLangURI . T.toLower
 
 langTag :: ScopedName -> T.Text
-langTag = snLocal
+langTag = getScopeLocal
 
 isLang :: ScopedName -> Bool
-isLang sname = snScope sname == namespaceLang
+isLang sname = getScopeNamespace sname == namespaceLang
 
 ------------------------------------------------------------
 --  Define namespaces for RDF rules, axioms, etc
 ------------------------------------------------------------
 
 toRDF, toRDFS, toRDFD :: T.Text -> ScopedName
-toRDF  = ScopedName namespaceRDF
-toRDFS = ScopedName namespaceRDFS
-toRDFD = ScopedName namespaceRDFD
+toRDF  = makeScopedName (Just "rdf")  namespaceRDFURI
+toRDFS = makeScopedName (Just "rdfs") namespaceRDFSURI
+toRDFD = makeScopedName (Just "rdfd") namespaceRDFDURI
 
 rdfDatatype   :: ScopedName
 rdfResource   :: ScopedName
 rdfdMaxCardinality     = toRDFD "maxCardinality"
 
 xsdType             :: T.Text -> ScopedName
-xsdType             = ScopedName namespaceXSD
+xsdType             = makeScopedName (Just "xsd") namespaceXSDURI
 
 xsdString           :: ScopedName
 xsdString           = xsdType "string"
 xsdDateTime = xsdType "dateTime"
 
 owlSameAs   :: ScopedName
-owlSameAs   = ScopedName namespaceOWL  "sameAs"
+owlSameAs   = makeScopedName (Just "owl") namespaceOWLURI "sameAs"
 
 logImplies  :: ScopedName
-logImplies  = ScopedName namespaceLOG "implies"
+logImplies  = makeScopedName (Just "log") namespaceLOGURI "implies"
 
 defaultBase :: ScopedName
-defaultBase = ScopedName namespaceDefault "base"
+defaultBase = makeScopedName (Just "default") namespaceDefaultURI "base"
 
 --------------------------------------------------------------------------------
 --

Swish/Utils/Namespace.hs

     ( Namespace(..)
     , makeNamespaceQName
     -- , nullNamespace
-    , ScopedName(..)
+    , ScopedName
+    , getScopeNamespace, getScopeLocal
     , getScopePrefix, getScopeURI
     , getQName, getScopedNameURI
     , matchName
     , makeScopedName
     , makeQNameScopedName
     , makeURIScopedName
+    , makeNSScopedName
     , nullScopedName
     , namespaceToBuilder
     )
     where
 
-import Swish.Utils.QName (QName, newQName, getQNameURI, getNamespace, getLocalName)
+import Swish.Utils.QName (QName(..), newQName, getQNameURI, getNamespace, getLocalName)
 import Swish.Utils.LookupMap (LookupEntryClass(..))
 
 import Data.Monoid (Monoid(..))
 --  Some applications may handle null namespace URIs as meaning
 --  the local part is relative to some base URI.
 --
-data ScopedName = ScopedName { snScope :: Namespace, snLocal :: T.Text }
+data ScopedName = ScopedName 
+                  { snQName :: QName  -- ^ the full URI as a QName (optimisation, may be removed)
+                  , snScope :: Namespace
+                  , snLocal :: T.Text 
+                  }
+
+getScopeLocal :: ScopedName -> T.Text
+getScopeLocal = snLocal
+
+getScopeNamespace :: ScopedName -> Namespace
+getScopeNamespace = snScope
 
 getScopePrefix :: ScopedName -> Maybe T.Text
 getScopePrefix = nsPrefix . snScope
     (<=) = snLe
 
 instance Show ScopedName where
-    show (ScopedName n l) = case nsPrefix n of
+    show (ScopedName _ n l) = case nsPrefix n of
       Just pre -> T.unpack $ mconcat [pre, ":", l]
       _        -> "<" ++ show (nsURI n) ++ T.unpack l ++ ">"
 
 
 -- |Get QName corresponding to a scoped name
 getQName :: ScopedName -> QName
-getQName n = newQName (getScopeURI n) (snLocal n)
+-- getQName n = newQName (getScopeURI n) (snLocal n)
+getQName = snQName
 
 -- |Get URI corresponding to a scoped name (using RDF conventions)
 getScopedNameURI :: ScopedName -> URI
 
 -- |Construct a ScopedName from prefix, URI and local name
 makeScopedName :: Maybe T.Text -> URI -> T.Text -> ScopedName
-makeScopedName pre nsuri =
-    ScopedName (Namespace pre nsuri)
+makeScopedName pre nsuri local =
+  let l = T.unpack local
+      uristr = show nsuri ++ l
+      uri = fromMaybe (error ("Unable to parse URI from: '" ++ show nsuri ++ "' + '" ++ l ++ "'")) (parseURIReference uristr)
+      qn = QName uri nsuri local
+      
+  in ScopedName qn (Namespace pre nsuri) local
 
 {-
 TODO: should just pass URIs around.
 -}
 
 -- |Construct a ScopedName from a QName
-makeQNameScopedName :: QName -> ScopedName
-{-
-The following is not correct
-makeQNameScopedName qn = makeScopedName Nothing (getNamespace qn) (getLocalName qn)
-since you get
-swish> let sn1 = makeQNameScopedName  "file:///foo/bar/baz"
-swish> sn1
-<file:///foo/barbaz>
--}
-makeQNameScopedName qn = 
+makeQNameScopedName :: Maybe T.Text -> QName -> ScopedName
+makeQNameScopedName pre qn = ScopedName qn (Namespace pre (getNamespace qn)) (getLocalName qn)
+{-  
   let ns = getNamespace qn
       ln = getLocalName qn
   in makeScopedName Nothing ns ln
+-}
 
--- |Construct a ScopedName for a bare URI (the label is set to \"\").
+-- | Construct a ScopedName for a bare URI (the label is set to \"\").
 makeURIScopedName :: URI -> ScopedName
 makeURIScopedName uri = makeScopedName Nothing uri ""
 
--- |This should never appear as a valid name
+-- | Construct a ScopedName from a Namespace and local component
+makeNSScopedName :: Namespace -> T.Text -> ScopedName
+makeNSScopedName ns local = ScopedName (newQName (nsURI ns) local) ns local
+
+-- | This should never appear as a valid name
 nullScopedName :: ScopedName
 nullScopedName = makeURIScopedName nullURI
 

Swish/Utils/QName.hs

 --------------------------------------------------------------------------------
 
 -- At present we support using URI references rather than forcing an absolute
--- URI. This is partly to support the existing tests (to lazy to resolve whether
+-- URI. This is partly to support the existing tests (too lazy to resolve whether
 -- the tests really should be using relative URIs in this case).
 
 module Swish.Utils.QName
-    ( QName
+    ( QName(..)
     , newQName
     , qnameFromURI
     , getNamespace
 Name:               swish
-Version:            0.4.0.0
+Version:            0.5.0.0
 Stability:          experimental
 License:            LGPL
 License-file:       LICENSE 
   .
   Changes:
   .
+  [Version 0.5.0.0] Changes to @ScopedName@ to provide significant reduction
+  in time to write out a graph. This should be considered an experimental change;
+  as a consequence the record fields for ScopedName are no longer exported.
+  .
   [Version 0.4.0.0] Moving to using polyparse for parsing and @Text@ rather than
   @String@ where appropriate. Use of @URI@ and @Maybe Text@ rather than @String@ in the @Namespace@
   type. Removed the Swish.Utils.DateTime and Swish.Utils.TraceHelpers

tests/BuiltInMapTest.hs

     , getMaybeContextRule
     )
 
-import Swish.Utils.Namespace
-    ( ScopedName(..) )
+import Swish.Utils.Namespace (makeNSScopedName)
 
 import Swish.RDF.Vocabulary
     ( swishName
 testVarMod04 = testJust "testVarMod04" $
     findRDFOpenVarBindingModifier (swishName "nullVarBindingModify")
 testVarMod05 = testJust "testVarMod05" $
-    findRDFOpenVarBindingModifier (ScopedName namespaceXsdInteger "abs")
+    findRDFOpenVarBindingModifier (makeNSScopedName namespaceXsdInteger "abs")
 testVarMod06 = testJust "testVarMod06" $
-    findRDFOpenVarBindingModifier (ScopedName namespaceXsdInteger "divmod")
+    findRDFOpenVarBindingModifier (makeNSScopedName namespaceXsdInteger "divmod")
 testVarMod07 = testJust "testVarMod07" $
-    findRDFOpenVarBindingModifier (ScopedName namespaceXsdInteger "ge")
+    findRDFOpenVarBindingModifier (makeNSScopedName namespaceXsdInteger "ge")
 
 testVarModSuite :: Test
 testVarModSuite = TestList
 testFindAxiom01, testFindAxiom02, testFindAxiom03 :: Test
 
 testFindAxiom01 = testJust "testFindAxiom01" $
-    getMaybeContextAxiom (ScopedName scopeRDF "a1") allRulesets
+    getMaybeContextAxiom (makeNSScopedName scopeRDF "a1") allRulesets
 testFindAxiom02 = testJust "testFindAxiom02" $
-    getMaybeContextAxiom (ScopedName scopeRDFS "a01") allRulesets
+    getMaybeContextAxiom (makeNSScopedName scopeRDFS "a01") allRulesets
 testFindAxiom03 = testJust "testFindAxiom03" $
-    getMaybeContextAxiom (ScopedName (namespaceXsdType "integer") "dt")
+    getMaybeContextAxiom (makeNSScopedName (namespaceXsdType "integer") "dt")
         allRulesets
 
 testFindAxiomSuite :: Test
 testFindRule01, testFindRule02, testFindRule03, testFindRule04 :: Test
 
 testFindRule01 = testJust "testFindRule01" $
-    getMaybeContextRule (ScopedName scopeRDF "r1") allRulesets
+    getMaybeContextRule (makeNSScopedName scopeRDF "r1") allRulesets
 testFindRule02 = testJust "testFindRule02" $
-    getMaybeContextRule (ScopedName scopeRDFS "r1") allRulesets
+    getMaybeContextRule (makeNSScopedName scopeRDFS "r1") allRulesets
 testFindRule03 = testJust "testFindRule03" $
-    getMaybeContextRule (ScopedName scopeRDFD "r1") allRulesets
+    getMaybeContextRule (makeNSScopedName scopeRDFD "r1") allRulesets
 testFindRule04 = testJust "testFindRule04" $
-    getMaybeContextRule (ScopedName (namespaceXsdType "integer") "Abs")
+    getMaybeContextRule (makeNSScopedName (namespaceXsdType "integer") "Abs")
         allRulesets
 
 testFindRuleSuite :: Test

tests/N3FormatterTest.hs

     , resOwlSameAs
     )
 
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..), namespaceToBuilder)
+import Swish.Utils.Namespace (Namespace(..), makeNSScopedName, namespaceToBuilder)
 
 import Swish.Utils.LookupMap
     ( LookupMap(..)
 toNS p = Namespace (Just p) . toURI
 
 toRes :: Namespace -> T.Text -> RDFLabel
-toRes ns = Res . ScopedName ns
+toRes ns = Res . makeNSScopedName ns
 
 base1, base2, base3, base4, basef, baseu, basem :: Namespace
 base1 = toNS "base1" "http://id.ninebynine.org/wip/2003/test/graph1/node#"
 c6 = Blank "c6"
 
 p1, p2, p3, p21, p22, p23, p24, p25, p26 :: RDFLabel
-p1  = Res $ ScopedName base1 "p1"
-p2  = Res $ ScopedName base2 "p2"
-p3  = Res $ ScopedName base3 "p3"
-p21 = Res $ ScopedName base2 "p21"
-p22 = Res $ ScopedName base2 "p22"
-p23 = Res $ ScopedName base2 "p23"
-p24 = Res $ ScopedName base2 "p24"
-p25 = Res $ ScopedName base2 "p25"
-p26 = Res $ ScopedName base2 "p26"
+p1  = Res $ makeNSScopedName base1 "p1"
+p2  = Res $ makeNSScopedName base2 "p2"
+p3  = Res $ makeNSScopedName base3 "p3"
+p21 = Res $ makeNSScopedName base2 "p21"
+p22 = Res $ makeNSScopedName base2 "p22"
+p23 = Res $ makeNSScopedName base2 "p23"
+p24 = Res $ makeNSScopedName base2 "p24"
+p25 = Res $ makeNSScopedName base2 "p25"
+p26 = Res $ makeNSScopedName base2 "p26"
 
 o1, o2, o3 :: RDFLabel
-o1 = Res $ ScopedName base1 "o1"
-o2 = Res $ ScopedName base2 "o2"
-o3 = Res $ ScopedName base3 "o3"
+o1 = Res $ makeNSScopedName base1 "o1"
+o2 = Res $ makeNSScopedName base2 "o2"
+o3 = Res $ makeNSScopedName base3 "o3"
 
 l1txt, l2txt, l3txt, l11txt, l12txt, l13txt, l14txt :: B.Builder
 l1txt = "l1"
 
 lfr, lfoobar :: RDFLabel
 lfr = Lit "chat et chien" (Just (langName "fr"))
-lfoobar = Lit "foo bar" (Just (ScopedName base1 "o1"))
+lfoobar = Lit "foo bar" (Just (makeNSScopedName base1 "o1"))
   
 f1, f2 :: RDFLabel
-f1 = Res $ ScopedName base1 "f1"
-f2 = Res $ ScopedName base2 "f2"
+f1 = Res $ makeNSScopedName base1 "f1"
+f2 = Res $ makeNSScopedName base2 "f2"
 
 v1, v2, v3, v4 :: RDFLabel
 v1 = Var "var1"

tests/N3ParserTest.hs

 
 import Swish.Utils.Namespace (
   Namespace(..)
-  , ScopedName(..)
+  , ScopedName
   , makeScopedName
+  , makeNSScopedName
   , nullScopedName
   -- , makeUriScopedName
   , namespaceToBuilder
 parseUriRef2Test = parseItemTest parseURIref2FromText nullScopedName
 
 sname01 :: ScopedName
-sname01  = ScopedName namespaceRDF "type"
+sname01  = makeNSScopedName namespaceRDF "type"
 
 uriRef02 :: L.Text
 uriRef02 = "<http://id.ninebynine.org/wip/2003/test/graph1/node#s1> "
 xsdNS = toNS "xsd" "http://www.w3.org/2001/XMLSchema#"
 
 u1 :: RDFLabel
-u1 = Res $ ScopedName base1 ""
+u1 = Res $ makeNSScopedName base1 ""
 
 ds1, ds2, ds3 :: RDFLabel
-ds1 = Res $ ScopedName dbase "s1"
-ds2 = Res $ ScopedName dbase "s2"
-ds3 = Res $ ScopedName dbase "s3"
+ds1 = Res $ makeNSScopedName dbase "s1"
+ds2 = Res $ makeNSScopedName dbase "s2"
+ds3 = Res $ makeNSScopedName dbase "s3"
 
 dp1, dp2, dp3 :: RDFLabel
-dp1 = Res $ ScopedName dbase "p1"
-dp2 = Res $ ScopedName dbase "p2"
-dp3 = Res $ ScopedName dbase "p3"
+dp1 = Res $ makeNSScopedName dbase "p1"
+dp2 = Res $ makeNSScopedName dbase "p2"
+dp3 = Res $ makeNSScopedName dbase "p3"
 
 do1, do2, do3 :: RDFLabel
-do1 = Res $ ScopedName dbase "o1"
-do2 = Res $ ScopedName dbase "o2"
-do3 = Res $ ScopedName dbase "o3"
+do1 = Res $ makeNSScopedName dbase "o1"
+do2 = Res $ makeNSScopedName dbase "o2"
+do3 = Res $ makeNSScopedName dbase "o3"
 
 s1, s2, s3, sa :: RDFLabel
-s1 = Res $ ScopedName base1 "s1"
-s2 = Res $ ScopedName base2 "s2"
-s3 = Res $ ScopedName base3 "s3"
-sa = Res $ ScopedName basea "a"
+s1 = Res $ makeNSScopedName base1 "s1"
+s2 = Res $ makeNSScopedName base2 "s2"
+s3 = Res $ makeNSScopedName base3 "s3"
+sa = Res $ makeNSScopedName basea "a"
 
 b1, b2, b3, b4, b5, b6, b7, b8 :: RDFLabel
 b1 = Blank "b1"
 c6 = Blank "c6"
 
 p1, p2, p3, pa :: RDFLabel
-p1 = Res $ ScopedName base1 "p1" 
-p2 = Res $ ScopedName base2 "p2" 
-p3 = Res $ ScopedName base3 "p3" 
-pa = Res $ ScopedName basea "b" 
+p1 = Res $ makeNSScopedName base1 "p1" 
+p2 = Res $ makeNSScopedName base2 "p2" 
+p3 = Res $ makeNSScopedName base3 "p3" 
+pa = Res $ makeNSScopedName basea "b" 
 
 o1, o2, o3, oa :: RDFLabel
-o1 = Res $ ScopedName base1 "o1"
-o2 = Res $ ScopedName base2 "o2"
-o3 = Res $ ScopedName base3 "o3"
-oa = Res $ ScopedName basea "c"
+o1 = Res $ makeNSScopedName base1 "o1"
+o2 = Res $ makeNSScopedName base2 "o2"
+o3 = Res $ makeNSScopedName base3 "o3"
+oa = Res $ makeNSScopedName basea "c"
 
 l1, l2, l3 :: RDFLabel
 l1 = Lit "l1"  Nothing
 bFalse = Lit "false" $ Just xsdBoolean
 
 f1, f2 :: RDFLabel
-f1 = Res $ ScopedName base1 "f1"
-f2 = Res $ ScopedName base2 "f2" 
+f1 = Res $ makeNSScopedName base1 "f1"
+f2 = Res $ makeNSScopedName base2 "f2" 
 
 v1, v2, v3, v4 :: RDFLabel
 v1 = Var "var1"
     
     ns4 = Namespace Nothing $ toURI "http://example.org/ns/foo/bar#"
     ns5 = Namespace Nothing $ toURI "http://example.org/ns2#"
-    mUN a b = Res (ScopedName a b)
+    mUN a b = Res (makeNSScopedName a b)
     xa4 = mUN ns4 "a4"
     xb4 = mUN ns4 "b4"
     xc4 = mUN ns4 "c4"
       [ arc b a c ]
   where
     -- the document base is set to file:///dev/null to begin with
-    mUN = Res . ScopedName dbase
+    mUN = Res . makeNSScopedName dbase
     a = mUN "a"
     b = mUN "b"
     c = mUN "c"
 --
 --  This is the contents of
 --    http://www.w3.org/2000/10/rdf-tests/rdfcore/ntriples/test.nt
---  retrived on 2011-03-23 11:25:46
+--  retrieved on 2011-03-23 11:25:46
 --
 ------------------------------------------------------------
 

tests/QNameTest.hs

 testSQRoundTrip lbl uri = 
   let u = (fromJust . parseURIReference) uri
       qn = qnameFromURI u
-      sn = makeQNameScopedName qn
+      sn = makeQNameScopedName Nothing qn
   in TestList
      [ testIsEq "SQ:URI"   lbl u  (getScopedNameURI sn)
      , testIsEq "SQ:Qname" lbl qn (getQName sn)

tests/RDFDatatypeXsdIntegerTest.hs

 import Swish.RDF.Ruleset (Ruleset(..), getRulesetRule)
 import Swish.RDF.Rule    (Formula(..), Rule(..), nullFormula, nullRule)
 import Swish.RDF.VarBinding (makeVarBinding)
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..), makeScopedName)
+import Swish.Utils.Namespace (Namespace(..), ScopedName, makeScopedName, makeNSScopedName)
 import Swish.RDF.Vocabulary (namespaceDefault)
 import Swish.Utils.LookupMap (LookupMap(..), mapFindMaybe)
 import Swish.Utils.ListHelpers (equiv)
 toURI = fromJust . parseURI
 
 xsdIntName :: T.Text -> ScopedName
-xsdIntName = ScopedName namespaceXsdInteger 
+xsdIntName = makeNSScopedName namespaceXsdInteger 
 
 axiomXsdIntegerDT :: ScopedName
 axiomXsdIntegerDT       = xsdIntName "dt"
 
 pvRule0, pvRule1 :: Maybe (Rule RDFGraph)
 pvRule0 = mapFindMaybe
-            (ScopedName namespaceDefault "PassengerVehicle")
+            (makeNSScopedName namespaceDefault "PassengerVehicle")
             (LookupMap pvRules)
 pvRule1 = mapFindMaybe
-            (ScopedName namespaceDefault "PassengerVehicle1")
+            (makeNSScopedName namespaceDefault "PassengerVehicle1")
             (LookupMap pvRules)
 
 pv01inp :: B.Builder

tests/RDFGraphTest.hs

 
 import Swish.RDF.GraphClass (Label(..), arc)
 
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..), nullScopedName)
+import Swish.Utils.Namespace (Namespace(..), ScopedName, makeNSScopedName, nullScopedName)
 import Swish.Utils.QName (QName, qnameFromURI)
 
 import Swish.RDF.RDFGraph
 qu1s1 = toURI $ base1Str ++ "s1"
 
 qbes1, qbus1, qb1s1, qb2s2, qb3s3, qb3, qb3bm, qb4m :: ScopedName
-qbes1 = ScopedName basee "s1"
-qbus1 = ScopedName baseu "s1"
-qb1s1 = ScopedName base1 "s1"
-qb2s2 = ScopedName base2 "s2"
-qb3s3 = ScopedName base3 "s3"
-qb3   = ScopedName base3 ""
-qb3bm = ScopedName base3 "basemore"
-qb4m  = ScopedName base4 "more"
+qbes1 = makeNSScopedName basee "s1"
+qbus1 = makeNSScopedName baseu "s1"
+qb1s1 = makeNSScopedName base1 "s1"
+qb2s2 = makeNSScopedName base2 "s2"
+qb3s3 = makeNSScopedName base3 "s3"
+qb3   = makeNSScopedName base3 ""
+qb3bm = makeNSScopedName base3 "basemore"
+qb4m  = makeNSScopedName base4 "more"
 
 es1, us1, s1, s2, s3, s4, s5, s6, s7, s8 :: RDFLabel
 es1 = Res qbes1
 s8 = Blank "s8"
 
 st1, st2, st3 :: RDFLabel
-st1 = toRDFLabel $ ScopedName base1 "st1"
-st2 = toRDFLabel $ ScopedName base2 "st2" 
-st3 = toRDFLabel $ ScopedName base3 "st3"
+st1 = toRDFLabel $ makeNSScopedName base1 "st1"
+st2 = toRDFLabel $ makeNSScopedName base2 "st2" 
+st3 = toRDFLabel $ makeNSScopedName base3 "st3"
 
 bb, bb0, b1, b2, b3, b4, b5, b6, b7,
   b8, b9, b10 :: RDFLabel
 bn6 = Blank "6"
 
 p1, p2, p3, p4 :: RDFLabel
-p1 = Res $ ScopedName base1 "p1"
-p2 = Res $ ScopedName base2 "p2"
-p3 = Res $ ScopedName base3 "p3"
-p4 = Res $ ScopedName base3 "p4"
+p1 = Res $ makeNSScopedName base1 "p1"
+p2 = Res $ makeNSScopedName base2 "p2"
+p3 = Res $ makeNSScopedName base3 "p3"
+p4 = Res $ makeNSScopedName base3 "p4"
 
 o1, o2, o3, o4, o5, o6 :: RDFLabel
-o1 = Res $ ScopedName base1 "o1"
-o2 = Res $ ScopedName base2 "o2"
-o3 = Res $ ScopedName base3 "o3"
+o1 = Res $ makeNSScopedName base1 "o1"
+o2 = Res $ makeNSScopedName base2 "o2"
+o3 = Res $ makeNSScopedName base3 "o3"
 o4 = toRDFLabel qb3   
 o5 = Blank "o5"
 o6 = Blank "s5"
 
 qb1t1, qb1t2 :: ScopedName
-qb1t1 = ScopedName base1 "type1"
-qb1t2 = ScopedName base1 "type2"
+qb1t1 = makeNSScopedName base1 "type1"
+qb1t2 = makeNSScopedName base1 "type2"
 
 l1, l2, l2gb, l3, l4, l5, l6, l7, l8,
   l9, l10, l11, l12 :: RDFLabel
 -- Test cases for isMemberProp
 
 cm1, cm2, nm1, nm2 :: RDFLabel
-cm1  = Res $ ScopedName namespaceRDF "_1"
-cm2  = Res $ ScopedName namespaceRDF "_234567"
-nm1  = Res $ ScopedName namespaceRDF "987"
-nm2  = Res $ ScopedName namespaceRDF "_987a65"
+cm1  = Res $ makeNSScopedName namespaceRDF "_1"
+cm2  = Res $ makeNSScopedName namespaceRDF "_234567"
+nm1  = Res $ makeNSScopedName namespaceRDF "987"
+nm2  = Res $ makeNSScopedName namespaceRDF "_987a65"
 
 ------------------------------------------------------------
 --  RDFLabel construction and equality tests

tests/RDFProofContextTest.hs

 import Swish.RDF.Ruleset (getContextAxiom, getContextRule)
 import Swish.RDF.Rule (Formula(..), Rule(..), nullFormula, nullRule)
 
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..), namespaceToBuilder)
+import Swish.Utils.Namespace (Namespace(..), ScopedName, makeNSScopedName, namespaceToBuilder)
 import Swish.Utils.LookupMap (mapFindMaybe)
 
 import Swish.RDF.Vocabulary
 getAxiom nam = getContextAxiom (makeSName nam) nullRDFFormula rdfdContext
 
 makeSName :: String -> ScopedName
-makeSName nam = ScopedName ns (T.pack loc)
+makeSName nam = makeNSScopedName ns (T.pack loc)
     where
         (pre,_:loc) = break (==':') nam
         ns = case pre of
 
 rdfAxiomIntDt :: RDFFormula
 rdfAxiomIntDt = getContextAxiom
-                    (ScopedName (namespaceXsdType "integer") "dt")
+                    (makeNSScopedName (namespaceXsdType "integer") "dt")
                     nullFormula
                     allRulesets
 
 
 rdfAxiomStrDt :: RDFFormula
 rdfAxiomStrDt = getContextAxiom
-                    (ScopedName (namespaceXsdType "string") "dt")
+                    (makeNSScopedName (namespaceXsdType "string") "dt")
                     nullFormula
                     allRulesets
 

tests/RDFProofTest.hs

     )
 
 import Swish.RDF.Rule (Rule(..))
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..))
+import Swish.Utils.Namespace (Namespace(..), ScopedName, makeNSScopedName)
 
 import Test.HUnit
     ( Test(TestCase,TestList)
 vocab4 = allNodes (not . labelIsVar) graph4
 
 name4 :: ScopedName
-name4 = ScopedName scope4 "instance4"
+name4 = makeNSScopedName scope4 "instance4"
 
 rule4 :: RDFRule
 rule4 = makeRdfInstanceEntailmentRule name4 vocab4
          ]
 
 name5 :: ScopedName
-name5 = ScopedName scope5 "subgraph5"
+name5 = makeNSScopedName scope5 "subgraph5"
 
 rule5 :: RDFRule
 rule5 = makeRdfSubgraphEntailmentRule name5
          ]
 
 name6 :: ScopedName
-name6 = ScopedName scope5 "subgraph6"
+name6 = makeNSScopedName scope5 "subgraph6"
 
 rule6 :: RDFRule
 rule6 = makeRdfSimpleEntailmentRule name6

tests/RDFQueryTest.hs

     , varFilterNE
     )
 
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..), makeScopedName)
+import Swish.Utils.Namespace (Namespace(..), ScopedName, makeScopedName)
 import Swish.RDF.Vocabulary (namespaceRDF, langName, swishName, rdfType, rdfXMLLiteral)
 import Swish.RDF.N3Parser (parseN3)
 import Swish.Utils.ListHelpers (equiv)

tests/RDFRulesetTest.hs

 
 import Swish.RDF.Rule (Formula(..), Rule(..), fwdCheckInference )
 import Swish.RDF.Vocabulary (namespaceRDF, namespaceRDFS, namespaceOWL, scopeRDF)
-import Swish.Utils.Namespace (Namespace(..), ScopedName(..), makeScopedName, namespaceToBuilder)
+import Swish.Utils.Namespace (Namespace(..), ScopedName, makeScopedName, makeNSScopedName, namespaceToBuilder)
 
 import Test.HUnit
     ( Test(TestCase,TestList)
   , testSameAxioms    "testAX01" a1s (getRulesetAxioms r1)
   , testSameRules     "testRU01" r1s (getRulesetRules r1)
   , testEqual "testGeta11" (Just a11) $
-      getRulesetAxiom (ScopedName rn1 "a11") r1
+      getRulesetAxiom (makeNSScopedName rn1 "a11") r1
   , testEqual "testGeta11" (Just a12) $
-      getRulesetAxiom (ScopedName rn1 "a12") r1
+      getRulesetAxiom (makeNSScopedName rn1 "a12") r1
   , testEqual "testGetr11" (Just r11) $
-      getRulesetRule (ScopedName rn1 "r11") r1
+      getRulesetRule (makeNSScopedName rn1 "r11") r1
   , testEqual "testGetr12" (Just r12) $
-      getRulesetRule (ScopedName rn1 "r12") r1
+      getRulesetRule (makeNSScopedName rn1 "r12") r1
   , testEqual "testGetnone" Nothing $
-      getRulesetRule (ScopedName rn1 "none") r1
+      getRulesetRule (makeNSScopedName rn1 "none") r1
   ]
 
 ------------------------------------------------------------
 
 rdfr2grc :: RDFClosure 
 rdfr2grc = GraphClosure
-            { nameGraphRule = ScopedName scopeRDF "r2"
+            { nameGraphRule = makeNSScopedName scopeRDF "r2"
             , ruleAnt       = getArcs rdfr2ant
             , ruleCon       = getArcs rdfr2con
             , ruleModify    = fromJust rdfr2modc