| 1 |
{- |
| 2 |
- Language/Ding/Enrich/Example/Identify.hs - example identification |
| 3 |
- |
| 4 |
- Copyright 2020 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 |
|
| 24 |
|
| 25 |
|
| 26 |
module Language.Ding.Enrich.Example.Identify |
| 27 |
( isPotentialExample |
| 28 |
, isExampleOf |
| 29 |
) where |
| 30 |
|
| 31 |
import Data.Char (isPunctuation) |
| 32 |
import Data.List (isInfixOf) |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
isPotentialExample :: String -> Bool |
| 38 |
isPotentialExample = (||) <$> isPhrase <*> containsSpecial |
| 39 |
|
| 40 |
|
| 41 |
isPhrase :: String -> Bool |
| 42 |
isPhrase = (>=3) . length . words |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
containsSpecial :: String -> Bool |
| 47 |
|
| 48 |
-- TODO?: This also catches '/' and '-'. |
| 49 |
-- * The latter is likely worse (ex.: "A-Dur") |
| 50 |
containsSpecial = any isPunctuation |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
isExampleOf :: String -> String -> Bool |
| 57 |
|
| 58 |
-- TODO: |
| 59 |
-- * Better example identification, suggestions: |
| 60 |
-- * consider umlauts, e.g. "Ball" ~ "zwei große Bälle" |
| 61 |
-- * consider change in capitalisation, e.g. "Ball" ~ "ein großer Fußball" |
| 62 |
-- * [consider whitespace, e.g. "lang" ~/~ "... langweilig ..."] |
| 63 |
-- * Require the example to be longer than the exemplified unit. |
| 64 |
-- * Define a minimum number of words and/or characters in difference. |
| 65 |
-- * Prevent phrases where for example only the gender changes to match. |
| 66 |
-- * In particular important, if umlauts receive special treatment. |
| 67 |
-- * Require a maximum size (number of chars/words) for the non-example. |
| 68 |
isExampleOf = flip isInfixOf |
| 69 |
|
| 70 |
-- Simple way to perform more flexible matching (not very efficient): |
| 71 |
--isExampleOf _ "" = False |
| 72 |
--isExampleOf pex hw = prefixMatch hw ex || hasExample (tail pex) hw |
| 73 |
--prefixMatch :: String -> String -> Bool |
| 74 |
--prefixMatch = ??? |
| 75 |
|
| 76 |
|
| 77 |
-- vi: ft=haskell ts=2 sw=2 et |