1. Doug Burke
  2. swish

Commits

Doug Burke  committed 14040c4

Noted that To/FromRDFLabel duplicate existing functionality in Swish.RDF.RDFDatatype

  • Participants
  • Parent commits 0e0b55c
  • Branches default
  • Tags 0.3.1.1

Comments (0)

Files changed (4)

File Swish/RDF/Datatype.hs

View file
 --  * supertypes may be introduced retrospectively,
 --
 --  * the relationship expressed with respect to a single datatype
---      cannot indicate hiow to do injections/restrictions between the
+--      cannot indicate how to do injections/restrictions between the
 --      underlying value types.
 --
 --  [@ex@]      is the type of expression with which the datatype may be used.

File Swish/RDF/RDFDatatype.hs

View file
     RDFDatatypeVal vt -> ModifierFn vt -> RDFModifierFn
 makeRDFModifierFn dtval fn ivs =
     let
-        ivals = mapM (rdfNodeExtract dtval) ivs
+        ivals = mapM (fromRDFLabel dtval) ivs
         ovals | isJust ivals = fn (fromJust ivals)
               | otherwise    = []
     in
-        fromMaybe [] $ mapM (rdfNodeInject dtval) ovals
-
--- |Extract datatyped value from 'RDFLabel' value, or return @Nothing@.
---
-rdfNodeExtract :: RDFDatatypeVal vt -> RDFLabel -> Maybe vt
-rdfNodeExtract dtval node
-    | isDatatyped dtname node = mapL2V dtmap $ getLiteralText node
-    | otherwise               = Nothing
-    where
-        dtname = tvalName dtval
-        dtmap  = tvalMap  dtval
-
--- |Return new RDF literal node with a representation of the supplied
---  value, or @Nothing@.
---
-rdfNodeInject :: RDFDatatypeVal vt -> vt -> Maybe RDFLabel
-rdfNodeInject dtval val = maybeNode valstr
-    where
-        valstr = mapV2L (tvalMap  dtval) val
-        maybeNode Nothing    = Nothing
-        maybeNode (Just str) = Just $ Lit str (Just (tvalName dtval))
+        fromMaybe [] $ mapM (toRDFLabel dtval) ovals
 
 ------------------------------------------------------------
 --  Helpers to map between datatype values and RDFLabels
 ------------------------------------------------------------
 
+-- | Convert from a typed literal to a Haskell value,
+-- with the possibility of failure.
 fromRDFLabel ::
     RDFDatatypeVal vt -> RDFLabel -> Maybe vt
 fromRDFLabel dtv lab
         dtnam = tvalName dtv
         dtmap = tvalMap dtv
 
+-- | Convert a Haskell value to a typed literal (label),
+-- with the possibility of failure.
 toRDFLabel :: RDFDatatypeVal vt -> vt -> Maybe RDFLabel
 toRDFLabel dtv =
     liftM (makeDatatypedLiteral dtnam) . mapV2L dtmap
         dtnam = tvalName dtv
         dtmap = tvalMap dtv
 
+-- | Create a typed literal from the given value.
 makeDatatypedLiteral :: ScopedName -> String -> RDFLabel
 makeDatatypedLiteral dtnam strval =
     Lit strval (Just dtnam)

File Swish/RDF/RDFGraph.hs

View file
 canonical form described in section 2.3.1 of
 <http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#lexical-space>.
   
+Note that this is very similar to
+'Swish.RDF.RDFDatatype.toRDFLabel' and should be moved into
+a @Swish.RDF.Datatype@ module.
 -}
 
 class ToRDFLabel a where
 
  - @xsd:date@ to @Day@
 
+Note that this is very similar to
+'Swish.RDF.RDFDatatype.fromRDFLabel' and should be moved into
+a @Swish.RDF.Datatype@ module.
 -}
 
 class FromRDFLabel a where

File TODO

View file
   Errr, there is Swish.RDF.Datatype which looks to have the
   semantics we need (ie remove the To/FromRDFLabel typeclasses); 
   it may still be useful to have a typeclass for conversion between
-  strings and values for the formatter/parser code.
+  strings and values for the formatter/parser code (such as,
+  perhaps, Swish.RDF.Datatype.DatatypeMap)