diff options
author | Volpeon <github@volpeon.ink> | 2023-05-28 08:13:08 +0200 |
---|---|---|
committer | Volpeon <github@volpeon.ink> | 2023-05-28 08:13:08 +0200 |
commit | 8c49a30faa431b8b56a4b4926e7dae56b1311fea (patch) | |
tree | 6a103b49cdfe6df38fadad1f9d59521dd92ebf74 /src/Data/JLD/Flattening | |
parent | Added Node Map Merging algorithm (diff) | |
download | hs-jsonld-8c49a30faa431b8b56a4b4926e7dae56b1311fea.tar.gz hs-jsonld-8c49a30faa431b8b56a4b4926e7dae56b1311fea.tar.bz2 hs-jsonld-8c49a30faa431b8b56a4b4926e7dae56b1311fea.zip |
Completed untested Flattening implementation
Diffstat (limited to 'src/Data/JLD/Flattening')
-rw-r--r-- | src/Data/JLD/Flattening/Global.hs | 7 | ||||
-rw-r--r-- | src/Data/JLD/Flattening/NodeMap.hs | 18 |
2 files changed, 19 insertions, 6 deletions
diff --git a/src/Data/JLD/Flattening/Global.hs b/src/Data/JLD/Flattening/Global.hs new file mode 100644 index 0000000..591d3ad --- /dev/null +++ b/src/Data/JLD/Flattening/Global.hs | |||
@@ -0,0 +1,7 @@ | |||
1 | module Data.JLD.Flattening.Global (JLDFlatteningT) where | ||
2 | |||
3 | import Data.JLD.Prelude | ||
4 | |||
5 | import Data.JLD.Error (JLDError) | ||
6 | |||
7 | type JLDFlatteningT e m = ExceptT (JLDError e) m | ||
diff --git a/src/Data/JLD/Flattening/NodeMap.hs b/src/Data/JLD/Flattening/NodeMap.hs index 919aec7..65db9ab 100644 --- a/src/Data/JLD/Flattening/NodeMap.hs +++ b/src/Data/JLD/Flattening/NodeMap.hs | |||
@@ -2,8 +2,9 @@ module Data.JLD.Flattening.NodeMap (NodeMap, BNMParams (..), buildNodeMap, merge | |||
2 | 2 | ||
3 | import Data.JLD.Prelude | 3 | import Data.JLD.Prelude |
4 | 4 | ||
5 | import Data.JLD.Control.Monad.RES (REST, execREST, withErrorRES') | 5 | import Data.JLD.Control.Monad.RES (REST, runREST, withErrorRES') |
6 | import Data.JLD.Error (JLDError (..)) | 6 | import Data.JLD.Error (JLDError (..)) |
7 | import Data.JLD.Flattening.Global (JLDFlatteningT) | ||
7 | import Data.JLD.Model.IRI (isBlankIri) | 8 | import Data.JLD.Model.IRI (isBlankIri) |
8 | import Data.JLD.Model.Keyword (Keyword (..), isKeywordLike, isNotKeyword) | 9 | import Data.JLD.Model.Keyword (Keyword (..), isKeywordLike, isNotKeyword) |
9 | import Data.JLD.Model.NodeMap (NodeMap, PropertyMap) | 10 | import Data.JLD.Model.NodeMap (NodeMap, PropertyMap) |
@@ -12,7 +13,7 @@ import Data.JLD.Model.NodeObject (isNodeObject) | |||
12 | import Data.JLD.Util (valueIsScalar, valueToArray, valueToNonNullArray) | 13 | import Data.JLD.Util (valueIsScalar, valueToArray, valueToNonNullArray) |
13 | 14 | ||
14 | import Control.Monad.Except (MonadError (..)) | 15 | import Control.Monad.Except (MonadError (..)) |
15 | import Data.Aeson (Array, Key, Object, Value (..)) | 16 | import Data.Aeson (Array, Object, Value (..)) |
16 | import Data.Aeson.Key qualified as K (toText) | 17 | import Data.Aeson.Key qualified as K (toText) |
17 | import Data.Aeson.KeyMap qualified as KM (filterWithKey, insert, lookup, member, singleton) | 18 | import Data.Aeson.KeyMap qualified as KM (filterWithKey, insert, lookup, member, singleton) |
18 | import Data.Foldable.WithIndex (FoldableWithIndex (..), iforM_) | 19 | import Data.Foldable.WithIndex (FoldableWithIndex (..), iforM_) |
@@ -85,7 +86,10 @@ bnmBuildNodeMap value paramsFn = do | |||
85 | , bnmParamsActiveSubject = bnmEnvActiveSubject | 86 | , bnmParamsActiveSubject = bnmEnvActiveSubject |
86 | , bnmParamsActiveProperty = bnmEnvActiveProperty | 87 | , bnmParamsActiveProperty = bnmEnvActiveProperty |
87 | } | 88 | } |
88 | (nodeMap', list) <- buildNodeMap value params | 89 | (nodeMap', list) <- |
90 | buildNodeMap value params |> runExceptT >=> \case | ||
91 | Left err -> throwError <| Left err | ||
92 | Right a -> pure a | ||
89 | bnmModifyNodeMap <| const nodeMap' | 93 | bnmModifyNodeMap <| const nodeMap' |
90 | pure list | 94 | pure list |
91 | 95 | ||
@@ -269,10 +273,12 @@ buildNodeMap' element = case element of | |||
269 | -- | 273 | -- |
270 | _ -> pure () | 274 | _ -> pure () |
271 | 275 | ||
272 | buildNodeMap :: Monad m => Value -> (BNMParams -> BNMParams) -> m (NodeMap, Maybe Array) | 276 | buildNodeMap :: Monad m => Value -> (BNMParams -> BNMParams) -> JLDFlatteningT e m (NodeMap, Maybe Array) |
273 | buildNodeMap document paramsFn = do | 277 | buildNodeMap document paramsFn = do |
274 | BNMState{..} <- buildNodeMap' document |> execREST env st | 278 | (result, BNMState{..}) <- buildNodeMap' document |> runREST env st |
275 | pure (bnmStateNodeMap, bnmStateList) | 279 | case result of |
280 | Left (Left err) -> throwError err | ||
281 | _ -> pure (bnmStateNodeMap, bnmStateList) | ||
276 | where | 282 | where |
277 | BNMParams{..} = | 283 | BNMParams{..} = |
278 | paramsFn | 284 | paramsFn |