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/Model | |
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/Model')
-rw-r--r-- | src/Data/JLD/Model/NodeMap.hs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Data/JLD/Model/NodeMap.hs b/src/Data/JLD/Model/NodeMap.hs index d0fb2f9..f76c662 100644 --- a/src/Data/JLD/Model/NodeMap.hs +++ b/src/Data/JLD/Model/NodeMap.hs | |||
@@ -10,13 +10,18 @@ module Data.JLD.Model.NodeMap ( | |||
10 | hasKey2, | 10 | hasKey2, |
11 | hasKey3, | 11 | hasKey3, |
12 | memberArray, | 12 | memberArray, |
13 | propsToKeyMap, | ||
13 | ) where | 14 | ) where |
14 | 15 | ||
15 | import Data.JLD.Prelude hiding (modify) | 16 | import Data.JLD.Prelude hiding (modify) |
16 | 17 | ||
17 | import Data.Aeson (Array, Value (..)) | 18 | import Data.Aeson (Array, Value (..)) |
19 | import Data.Aeson.Key qualified as K | ||
20 | import Data.Aeson.KeyMap (KeyMap) | ||
21 | import Data.Aeson.KeyMap qualified as KM | ||
22 | import Data.Foldable.WithIndex (FoldableWithIndex (..)) | ||
18 | import Data.JLD.Util (valueToArray) | 23 | import Data.JLD.Util (valueToArray) |
19 | import Data.Map.Strict qualified as M (alter, insert, lookup, member) | 24 | import Data.Map.Strict qualified as M (alter, insert, lookup, member, toList) |
20 | 25 | ||
21 | type PropertyKey = Maybe Text | 26 | type PropertyKey = Maybe Text |
22 | type PropertyMap = Map PropertyKey Value | 27 | type PropertyMap = Map PropertyKey Value |
@@ -55,3 +60,12 @@ memberArray :: GraphKey -> SubjectKey -> PropertyKey -> Value -> NodeMap -> Bool | |||
55 | memberArray graphName subject property value nodeMap = case lookup3 graphName subject property nodeMap of | 60 | memberArray graphName subject property value nodeMap = case lookup3 graphName subject property nodeMap of |
56 | Just (Array a) -> value `elem` a | 61 | Just (Array a) -> value `elem` a |
57 | _ -> False | 62 | _ -> False |
63 | |||
64 | propsToKeyMap :: PropertyMap -> KeyMap Value | ||
65 | propsToKeyMap = | ||
66 | ifoldl' | ||
67 | ( \maybeKey km value -> case maybeKey of | ||
68 | Just key -> KM.insert (K.fromText key) value km | ||
69 | Nothing -> km | ||
70 | ) | ||
71 | mempty | ||