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/ActiveContext.hs | |
download | hs-jsonld-11d0fb47c292a0ca25a9c377499d2b221d97a5cb.tar.gz hs-jsonld-11d0fb47c292a0ca25a9c377499d2b221d97a5cb.tar.bz2 hs-jsonld-11d0fb47c292a0ca25a9c377499d2b221d97a5cb.zip |
Init
Diffstat (limited to 'src/Data/JLD/Model/ActiveContext.hs')
-rw-r--r-- | src/Data/JLD/Model/ActiveContext.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Data/JLD/Model/ActiveContext.hs b/src/Data/JLD/Model/ActiveContext.hs new file mode 100644 index 0000000..5423036 --- /dev/null +++ b/src/Data/JLD/Model/ActiveContext.hs | |||
@@ -0,0 +1,44 @@ | |||
1 | module Data.JLD.Model.ActiveContext ( ActiveContext (..), newActiveContext, lookupTerm, containsProtectedTerm,) where | ||
2 | |||
3 | import Data.JLD.Prelude | ||
4 | |||
5 | import Data.JLD.Model.Direction (Direction) | ||
6 | import Data.JLD.Model.InverseContext (InverseContext) | ||
7 | import Data.JLD.Model.Language (Language) | ||
8 | import Data.JLD.Model.TermDefinition (TermDefinition (..)) | ||
9 | |||
10 | import Data.Map.Strict qualified as M (lookup) | ||
11 | import Data.RDF (IRIRef) | ||
12 | import Text.URI (URI) | ||
13 | |||
14 | data ActiveContext = ActiveContext | ||
15 | { activeContextTerms :: Map Text TermDefinition | ||
16 | , activeContextBaseIri :: Maybe IRIRef | ||
17 | , activeContextBaseUrl :: Maybe URI | ||
18 | , activeContextInverseContext :: InverseContext | ||
19 | , activeContextPreviousContext :: Maybe ActiveContext | ||
20 | , activeContextVocabularyMapping :: Maybe Text | ||
21 | , activeContextDefaultLanguage :: Maybe Language | ||
22 | , activeContextDefaultBaseDirection :: Maybe Direction | ||
23 | } | ||
24 | deriving (Eq, Show) | ||
25 | |||
26 | newActiveContext :: (ActiveContext -> ActiveContext) -> ActiveContext | ||
27 | newActiveContext fn = | ||
28 | fn | ||
29 | ActiveContext | ||
30 | { activeContextTerms = mempty | ||
31 | , activeContextBaseIri = Nothing | ||
32 | , activeContextBaseUrl = Nothing | ||
33 | , activeContextInverseContext = mempty | ||
34 | , activeContextPreviousContext = Nothing | ||
35 | , activeContextVocabularyMapping = Nothing | ||
36 | , activeContextDefaultLanguage = Nothing | ||
37 | , activeContextDefaultBaseDirection = Nothing | ||
38 | } | ||
39 | |||
40 | lookupTerm :: Text -> ActiveContext -> Maybe TermDefinition | ||
41 | lookupTerm key ActiveContext{..} = M.lookup key activeContextTerms | ||
42 | |||
43 | containsProtectedTerm :: ActiveContext -> Bool | ||
44 | containsProtectedTerm = activeContextTerms .> any termDefinitionProtectedFlag | ||