diff options
author | Volpeon <github@volpeon.ink> | 2023-05-26 07:40:13 +0200 |
---|---|---|
committer | Volpeon <github@volpeon.ink> | 2023-05-26 07:40:13 +0200 |
commit | 11d0fb47c292a0ca25a9c377499d2b221d97a5cb (patch) | |
tree | e729e2a4508763b3073b7eae9a56bc9c6a9ca0f7 /src/Data/JLD/Model/GraphObject.hs | |
download | hs-jsonld-11d0fb47c292a0ca25a9c377499d2b221d97a5cb.tar.gz hs-jsonld-11d0fb47c292a0ca25a9c377499d2b221d97a5cb.tar.bz2 hs-jsonld-11d0fb47c292a0ca25a9c377499d2b221d97a5cb.zip |
Init
Diffstat (limited to 'src/Data/JLD/Model/GraphObject.hs')
-rw-r--r-- | src/Data/JLD/Model/GraphObject.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Data/JLD/Model/GraphObject.hs b/src/Data/JLD/Model/GraphObject.hs new file mode 100644 index 0000000..3db9e6b --- /dev/null +++ b/src/Data/JLD/Model/GraphObject.hs | |||
@@ -0,0 +1,22 @@ | |||
1 | module Data.JLD.Model.GraphObject (isGraphObject, isNotGraphObject, toGraphObject) where | ||
2 | |||
3 | import Data.JLD.Prelude | ||
4 | |||
5 | import Data.JLD.Model.Keyword (Keyword (..), isKeyword) | ||
6 | |||
7 | import Data.Aeson (Object, Value (..)) | ||
8 | import Data.Aeson.Key qualified as K (toText) | ||
9 | import Data.Aeson.KeyMap qualified as KM (keys, singleton, member) | ||
10 | import Data.Vector qualified as V (singleton) | ||
11 | |||
12 | isGraphObject :: Value -> Bool | ||
13 | isGraphObject (Object o) | ||
14 | | KM.member (show KeywordGraph) o = | ||
15 | all (`isKeyword` [KeywordGraph, KeywordId, KeywordIndex, KeywordContext]) (K.toText <$> KM.keys o) | ||
16 | isGraphObject _ = False | ||
17 | |||
18 | isNotGraphObject :: Value -> Bool | ||
19 | isNotGraphObject = isGraphObject .> not | ||
20 | |||
21 | toGraphObject :: Value -> Object | ||
22 | toGraphObject = V.singleton .> Array .> KM.singleton (show KeywordGraph) | ||