Debian Codegraph @

importers/ding2tei/src/Language/TEI/ToXML/Grammar.hs

raw symbols SCIP
1 {-
2 - Language/TEI/ToXML/Grammar.hs - convert grammar information to TEI XML (AST)
3 -
4 - Copyright 2020,2022 Einhard Leichtfuß
5 -
6 - This file is part of ding2tei-haskell.
7 -
8 - ding2tei-haskell is free software: you can redistribute it and/or modify
9 - it under the terms of the GNU Affero General Public License as published
10 - by the Free Software Foundation, either version 3 of the License, or
11 - (at your option) any later version.
12 -
13 - ding2tei-haskell is distributed in the hope that it will be useful,
14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 - GNU Affero General Public License for more details.
17 -
18 - You should have received a copy of the GNU Affero General Public License
19 - along with ding2tei-haskell. If not, see <https://www.gnu.org/licenses/>.
20 -}
21
22 {-|
23 - Convert grammar annotations to TEI XML.
24 -}
25 module Language.TEI.ToXML.Grammar (convGrammar) where
26
27
28 import Text.XML.Light
29
30 import Data.NatLang.Grammar
31 import Data.NatLang.Usage (Usage)
32 import Language.TEI.Show.Grammar
33
34
35 -- | Convert a list of grammar informations to a gramGrp element.
36 -- If the list is empty, evaluates to `Nothing'.
37 convGrammar :: [GrammarInfo] -> Maybe Element
38 convGrammar [] = Nothing
39 convGrammar gs = Just $ unode "gramGrp" $ concatMap convGrammarInfo gs
40
41
42 -- Notes:
43 -- * For collocates, follows the suggestion from TEI Lex-0 (however stick with
44 -- <colloc>) [0].
45 -- * For POS collocates, a potential subtype is simply appended.
46 -- * For Case collocates, the potential interrogative pronouns are prepended,
47 -- in the same form they appear in the Ding.
48 convGrammarInfo :: GrammarInfo -> [Element]
49 convGrammarInfo (GramLexCategory gram) = convGramLexCat gram
50 convGrammarInfo (Collocate colloc usgs) = pure $ convCollocate colloc usgs
51
52
53 -- Note: It seems impossible to represent the present usage annotations
54 -- (TODO).
55 convCollocate :: Collocate -> [Usage] -> Element
56 convCollocate (CollocCase iProns cas) _usgs = unode "colloc" $
57 "[" ++ prefix ++ "+ " ++ showCase cas ++ "]"
58 where
59 prefix =
60 case iProns of
61 [] -> ""
62 (p:ps) -> p ++ concatMap (", " ++) ps
63
64 convCollocate (CollocPOS pos) _usgs = unode "colloc" $
65 "[+ " ++ showPrimaryPOS pos ++ subType ++ "]"
66 where
67 subType =
68 case pos of
69 (Verb vTypes) -> concatMap ((' ':) . showVerbType) vTypes
70 (Pronoun pTypes) -> concatMap ((' ':) . showPronounType) pTypes
71 _ -> ""
72
73 -- Note: Ignore potential singulare/plurale tantum attribute.
74 -- - Does not occur in Ding version 1.9.
75 convCollocate (CollocNumber number) _usgs = unode "colloc" $
76 "[+ " ++ showPrimaryNumber number ++ "]"
77
78
79 convGramLexCat :: GramLexCategory -> [Element]
80 convGramLexCat (PartOfSpeech pos) = convPOS pos
81 convGramLexCat (Gender gen) = [unode "gen" (showGender gen)]
82 convGramLexCat (Number num) = unode "number" (showPrimaryNumber num)
83 : convNumberSubc num
84 convGramLexCat (Case cas) = [unode "case" (showCase cas)]
85
86
87 convPOS :: PartOfSpeech -> [Element]
88 convPOS pos = unode "pos" (showPrimaryPOS pos)
89 : case pos of
90 (Verb vTypes) -> map (unode "subc" . showVerbType) vTypes
91 (Pronoun pTypes) -> map (unode "subc" . showPronounType) pTypes
92 _ -> []
93
94
95 convNumberSubc :: Number -> [Element]
96 convNumberSubc (Singular True) = [unode "subc" shownSingulareTantum]
97 convNumberSubc (Plural True) = [unode "subc" shownPluraleTantum]
98 convNumberSubc _ = []
99
100
101 -- References:
102 -- * [0] https://dariah-eric.github.io/lexicalresources/pages/TEILex0/TEILex0.html#collocates
103
104 -- vi: ft=haskell ts=2 sw=2 et