| 1 |
Phrase construction |
| 2 |
=================== |
| 3 |
|
| 4 |
Currently, in building a phrase (i.e., expression), I use the Token monoid. |
| 5 |
|
| 6 |
It would be nice to be able to keep potentially dropped parts. |
| 7 |
- "a {b} c d {e}" -> Token _ "a b c d", Token _ OBrace, ... |
| 8 |
? Really? |
| 9 |
|
| 10 |
|
| 11 |
Suggestion: Use a type like the following (1): |
| 12 |
|
| 13 |
data Expression = SimpleExp Token |
| 14 |
| ComposedExp Token SpecialExp Expression |
| 15 |
| ComposedExpR Token SpecialExp |
| 16 |
| ComposedExpL SpecialExp Expression |
| 17 |
|
| 18 |
data SpecialExp = HiddenExp Token |
| 19 |
| MultiExp (Multi Expression) |
| 20 |
| SwitchExp Token Token |
| 21 |
|
| 22 |
data Multi a = Single a |
| 23 |
| Multi a [a] (Multi a) |
| 24 |
| MultiR a [a] |
| 25 |
| MultiL [a] (Multi a) |
| 26 |
|
| 27 |
data Exp a b = Single a |
| 28 |
| Exp a b (Exp a b) |
| 29 |
| ExpR a b |
| 30 |
| ExpL b (Exp a b) |
| 31 |
|
| 32 |
data Expression' = Exp Token SpecialExp |
| 33 |
data Multi' a = Exp a [a] |
| 34 |
|
| 35 |
Problem: The list-like structure makes the monoid operation inefficient. |
| 36 |
- Note that most Expression's will be SimpleExp's. |
| 37 |
- Even otherwise: Its still only linear-time list concatenation. |
| 38 |
|
| 39 |
|
| 40 |
Porentially better (2): |
| 41 |
|
| 42 |
data Exp a b = Single a |
| 43 |
| Exp (Exp a b) b (Exp a b) |
| 44 |
| ExpR (Exp a b) b |
| 45 |
| ExpL b (Exp a b) |
| 46 |
|
| 47 |
Drawback: There are several trees that represent the same data. |
| 48 |
|
| 49 |
|
| 50 |
Another option (3): |
| 51 |
|
| 52 |
data Expression = [ExpUnit] -- or NonEmpty ExpUnit |
| 53 |
data ExpElement = SimpleExp Token |
| 54 |
| HiddenExp Expression |
| 55 |
| MultiExp (Multi Expression) |
| 56 |
| SwitchExp Token Token |
| 57 |
|
| 58 |
- simple |
| 59 |
- most Expression's will be [SimpleExp $ Token _] |
| 60 |
|
| 61 |
|
| 62 |
Yet Another Option (4): |
| 63 |
|
| 64 |
data Expression = SimpleExp Token |
| 65 |
| HiddenExp Expression |
| 66 |
| MultiExp [Expression] |
| 67 |
| SwitchExp Token Token |
| 68 |
| ComposedExp Expression Expression |
| 69 |
|
| 70 |
- simple and compact |
| 71 |
- still amiguous (SimpleExp "abc def" ~ ComposedExp (SE "abc") (SE "def")) |
| 72 |
|
| 73 |
|
| 74 |
Next Option -- drops HiddenExp (5): |
| 75 |
|
| 76 |
newtype Expression = Expression [Token] |
| 77 |
|
| 78 |
switchExp e f = Expression [a <> b, b <> a] |
| 79 |
simpleExp e = Expression [e] |
| 80 |
|
| 81 |
instance Semigroup Expression where |
| 82 |
Expression toks1 <> Expression toks2 = Expression $ |
| 83 |
[ tok1 <> tok2 | tok1 <- toks1, tok2 <- toks2 ] |
| 84 |
|
| 85 |
- instead of hidden exp, there could be an annotation of the whole expression |
| 86 |
including the hidden parts. |
| 87 |
- Duplicates data (There will be some sharing though). |
| 88 |
- Loss of information. |
| 89 |
- Probably OK for the source side of the resulting TEI dictionary. |
| 90 |
- The target side would be blown up (in case of many multi-exps). |
| 91 |
|
| 92 |
|
| 93 |
Questions: |
| 94 |
- Prohibit totally hidden expressions on the type level? |
| 95 |
- In which context would such composed expressions be allowed? |
| 96 |
- Is agressive splitting desirable at all? |
| 97 |
- Non-trivial expressions are not expected to be found by exact match |
| 98 |
anyways, in the resulting dictionary. |
| 99 |
- Units like "etw./jdn. meiden" should probably be treated differently |
| 100 |
(extract prefix into annotation). |
| 101 |
- Units like "meiden/vermeiden" should not occur at all. |
| 102 |
|
| 103 |
Considerations: |
| 104 |
- Simply use option (3) or similar and do not join SimpleExp's. |
| 105 |
- Does complicate things everywhere but on the unit level. |
| 106 |
- Only do this at the unit level. |
| 107 |
- potentially also in between <()>. |