summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-01-11 08:11:38 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-02-16 04:39:20 +0100
commit8ab1b7f70242d3efd74278d15bd5c0c8f2d6d1e2 (patch)
tree610b7d7d651d6414a67df5df5e80a171993d0ff4
parent9d913e0f6c4b2e25130b62db94463174199aa443 (diff)
feat: add more patterns to `@createdAt`
-rw-r--r--apaperless.yaml112
-rw-r--r--app/Main.hs40
-rw-r--r--app/Settings.hs68
3 files changed, 200 insertions, 20 deletions
diff --git a/apaperless.yaml b/apaperless.yaml
index bbc9bec..0142e31 100644
--- a/apaperless.yaml
+++ b/apaperless.yaml
@@ -2,8 +2,116 @@ defaultLanguage: deu+eng
suggestedTags:
- contents:
- createdAt
- - - ${d}([0-9]{2})\.${m}([0-9]{2})\.${y}([0-9]{4})
- - ${y}-${m}-${d}
+ - - - ${d}([0-9]{2})\.${m}([0-9]{2})\.${y}([0-9]{4})
+ - ${y}-${m}-${d}
+ - - ${d}([0-9]{2})/${m}([0-9]{2})/${y}([0-9]{4})
+ - ${y}-${m}-${d}
+ - - ${d}([0-9]{2})/${m}([0-9]{2})/${y}([0-9]{2})
+ - 20${y}-${m}-${d}
+ - - ${d}([0-9]{2})/${m}([0-9]{2})/${y}([0-9]{2})
+ - 19${y}-${m}-${d}
+ - - ${y}([0-9]{4})-${m}([0-9]{2})-${d}([0-9]{4})
+ - ${y}-${m}-${d}
+ - - ${d}([0-9]{2})\.${m}([0-9]{2})\.${y}([0-9]{2})
+ - 20${y}-${m}-${d}
+ - - ${d}([0-9]{2})\.${m}([0-9]{2})\.${y}([0-9]{2})
+ - 19${y}-${m}-${d}
+ - - ${d}([0-9]{2})\.? (Jan\.?|Januar) ${y}([0-9]{4})
+ - ${y}-01-${d}
+ - - ${d}([0-9]{2})\.? (Feb\.?|Februar) ${y}([0-9]{4})
+ - ${y}-02-${d}
+ - - ${d}([0-9]{2})\.? (Mär\.?|März) ${y}([0-9]{4})
+ - ${y}-03-${d}
+ - - ${d}([0-9]{2})\.? (Apr\.?|April) ${y}([0-9]{4})
+ - ${y}-04-${d}
+ - - ${d}([0-9]{2})\.? Mai\.? ${y}([0-9]{4})
+ - ${y}-05-${d}
+ - - ${d}([0-9]{2})\.? (Jun\.?|Juni) ${y}([0-9]{4})
+ - ${y}-06-${d}
+ - - ${d}([0-9]{2})\.? (Jul\.?|Juli) ${y}([0-9]{4})
+ - ${y}-07-${d}
+ - - ${d}([0-9]{2})\.? (Aug\.?|August) ${y}([0-9]{4})
+ - ${y}-08-${d}
+ - - ${d}([0-9]{2})\.? (Sep\.?|September) ${y}([0-9]{4})
+ - ${y}-09-${d}
+ - - ${d}([0-9]{2})\.? (Okt\.?|Oktober) ${y}([0-9]{4})
+ - ${y}-10-${d}
+ - - ${d}([0-9]{2})\.? (Nov\.?|November) ${y}([0-9]{4})
+ - ${y}-11-${d}
+ - - ${d}([0-9]{2})\.? (Dez\.?|Dezember) ${y}([0-9]{4})
+ - ${y}-12-${d}
+ - - ${d}([0-9])\.? (Jan\.?|Januar) ${y}([0-9]{4})
+ - ${y}-01-0${d}
+ - - ${d}([0-9])\.? (Feb\.?|Februar) ${y}([0-9]{4})
+ - ${y}-02-0${d}
+ - - ${d}([0-9])\.? (Mär\.?|März) ${y}([0-9]{4})
+ - ${y}-03-0${d}
+ - - ${d}([0-9])\.? (Apr\.?|April) ${y}([0-9]{4})
+ - ${y}-04-0${d}
+ - - ${d}([0-9])\.? Mai\.? ${y}([0-9]{4})
+ - ${y}-05-0${d}
+ - - ${d}([0-9])\.? (Jun\.?|Juni) ${y}([0-9]{4})
+ - ${y}-06-0${d}
+ - - ${d}([0-9])\.? (Jul\.?|Juli) ${y}([0-9]{4})
+ - ${y}-07-0${d}
+ - - ${d}([0-9])\.? (Aug\.?|August) ${y}([0-9]{4})
+ - ${y}-08-0${d}
+ - - ${d}([0-9])\.? (Sep\.?|September) ${y}([0-9]{4})
+ - ${y}-09-0${d}
+ - - ${d}([0-9])\.? (Okt\.?|Oktober) ${y}([0-9]{4})
+ - ${y}-10-0${d}
+ - - ${d}([0-9])\.? (Nov\.?|November) ${y}([0-9]{4})
+ - ${y}-11-0${d}
+ - - ${d}([0-9])\.? (Dez\.?|Dezember) ${y}([0-9]{4})
+ - ${y}-12-0${d}
+ - - Jan ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-01-0${d}
+ - - Feb ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-02-0${d}
+ - - Mar ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-03-0${d}
+ - - Apr ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-04-0${d}
+ - - May ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-05-0${d}
+ - - Jun ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-06-0${d}
+ - - Jul ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-07-0${d}
+ - - Aug ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-08-0${d}
+ - - Sep ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-09-0${d}
+ - - Oct ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-10-0${d}
+ - - Nov ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-11-0${d}
+ - - Dec ${d}([0-9]), ${y}([0-9]{4})
+ - ${y}-12-0${d}
+ - - Jan ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-01-${d}
+ - - Feb ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-02-${d}
+ - - Mar ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-03-${d}
+ - - Apr ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-04-${d}
+ - - May ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-05-${d}
+ - - Jun ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-06-${d}
+ - - Jul ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-07-${d}
+ - - Aug ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-08-${d}
+ - - Sep ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-09-${d}
+ - - Oct ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-10-${d}
+ - - Nov ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-11-${d}
+ - - Dec ${d}([0-9]{2}), ${y}([0-9]{4})
+ - ${y}-12-${d}
tag: SuggestTagByRE
- contents: correspondent
tag: SuggestTagByTags
diff --git a/app/Main.hs b/app/Main.hs
index f9452aa..41a546f 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -526,26 +526,34 @@ suggestTags :: S.Settings -> C.ProbabilityCache -> D.Document -> [(G.Tag, [G.Tag
suggestTags settings probabilityCache doc = do
flip map settings.suggestedTags $ \suggestedTag ->
case suggestedTag of
- S.SuggestTagByRE tagName pattern ->
+ S.SuggestTagByRE tagName searchReplaces ->
let tagValues =
- nub
- . mapMaybe
- ( -- XXX Whys is this so complicated?
- \match -> do
- captures <- snd <$> R.matchCaptures match
- pure
- ( foldl
- ( \template (captureName, captureOrdinal) ->
- T.replace
- ("${" <> R.getCaptureName captureName <> "}")
- (R.capturedText (captures !! (fromEnum captureOrdinal - 1)))
- template
+ nub . concat $
+ map
+ ( \searchReplace ->
+ mapMaybe
+ ( -- XXX Whys is this so complicated?
+ \match -> do
+ captures <- snd <$> R.matchCaptures match
+ pure
+ ( foldl
+ ( \template (captureName, captureOrdinal) ->
+ T.replace
+ ("${" <> R.getCaptureName captureName <> "}")
+ (R.capturedText (captures !! (fromEnum captureOrdinal - 1)))
+ template
+ )
+ (R.getTemplate searchReplace)
+ (HM.toList $ R.captureNames match)
+ )
+ )
+ ( R.allMatches
+ ( doc.index.content
+ R.*=~ R.getSearch searchReplace
)
- (R.getTemplate pattern)
- (HM.toList $ R.captureNames match)
)
)
- $ R.allMatches (doc.index.content R.*=~ (R.getSearch pattern))
+ searchReplaces
in (G.tag tagName (Just ""), map (G.tag tagName . Just) tagValues)
S.SuggestTagByTags tagName ->
let tagValues =
diff --git a/app/Settings.hs b/app/Settings.hs
index 43f721c..8f4017c 100644
--- a/app/Settings.hs
+++ b/app/Settings.hs
@@ -50,7 +50,71 @@ instance Monoid Settings where
-- @topic suggested-tags
SuggestTagByRE
"createdAt"
- [R.ed|${d}([0-9]{2})\.${m}([0-9]{2})\.${y}([0-9]{4})///${y}-${m}-${d}|],
+ [ -- DD.MM.YYYY
+ [R.ed|${d}([0-9]{2})\.${m}([0-9]{2})\.${y}([0-9]{4})///${y}-${m}-${d}|],
+ -- DD/MM/YYYY
+ [R.ed|${d}([0-9]{2})/${m}([0-9]{2})/${y}([0-9]{4})///${y}-${m}-${d}|],
+ -- DD/MM/YY (20YY)
+ [R.ed|${d}([0-9]{2})/${m}([0-9]{2})/${y}([0-9]{2})///20${y}-${m}-${d}|],
+ [R.ed|${d}([0-9]{2})/${m}([0-9]{2})/${y}([0-9]{2})///19${y}-${m}-${d}|],
+ -- YYYY-MM-DD
+ [R.ed|${y}([0-9]{4})-${m}([0-9]{2})-${d}([0-9]{4})///${y}-${m}-${d}|],
+ -- DD.MM.YY (20YY)
+ [R.ed|${d}([0-9]{2})\.${m}([0-9]{2})\.${y}([0-9]{2})///20${y}-${m}-${d}|],
+ [R.ed|${d}([0-9]{2})\.${m}([0-9]{2})\.${y}([0-9]{2})///19${y}-${m}-${d}|],
+ -- DD. Januar YYYY, DD Januar YYYY
+ [R.ed|${d}([0-9]{2})\.? (Jan\.?|Januar) ${y}([0-9]{4})///${y}-01-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Feb\.?|Februar) ${y}([0-9]{4})///${y}-02-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Mär\.?|März) ${y}([0-9]{4})///${y}-03-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Apr\.?|April) ${y}([0-9]{4})///${y}-04-${d}|],
+ [R.ed|${d}([0-9]{2})\.? Mai\.? ${y}([0-9]{4})///${y}-05-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Jun\.?|Juni) ${y}([0-9]{4})///${y}-06-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Jul\.?|Juli) ${y}([0-9]{4})///${y}-07-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Aug\.?|August) ${y}([0-9]{4})///${y}-08-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Sep\.?|September) ${y}([0-9]{4})///${y}-09-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Okt\.?|Oktober) ${y}([0-9]{4})///${y}-10-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Nov\.?|November) ${y}([0-9]{4})///${y}-11-${d}|],
+ [R.ed|${d}([0-9]{2})\.? (Dez\.?|Dezember) ${y}([0-9]{4})///${y}-12-${d}|],
+ -- D. Januar YYYY, D Januar YYYY
+ [R.ed|${d}([0-9])\.? (Jan\.?|Januar) ${y}([0-9]{4})///${y}-01-0${d}|],
+ [R.ed|${d}([0-9])\.? (Feb\.?|Februar) ${y}([0-9]{4})///${y}-02-0${d}|],
+ [R.ed|${d}([0-9])\.? (Mär\.?|März) ${y}([0-9]{4})///${y}-03-0${d}|],
+ [R.ed|${d}([0-9])\.? (Apr\.?|April) ${y}([0-9]{4})///${y}-04-0${d}|],
+ [R.ed|${d}([0-9])\.? Mai\.? ${y}([0-9]{4})///${y}-05-0${d}|],
+ [R.ed|${d}([0-9])\.? (Jun\.?|Juni) ${y}([0-9]{4})///${y}-06-0${d}|],
+ [R.ed|${d}([0-9])\.? (Jul\.?|Juli) ${y}([0-9]{4})///${y}-07-0${d}|],
+ [R.ed|${d}([0-9])\.? (Aug\.?|August) ${y}([0-9]{4})///${y}-08-0${d}|],
+ [R.ed|${d}([0-9])\.? (Sep\.?|September) ${y}([0-9]{4})///${y}-09-0${d}|],
+ [R.ed|${d}([0-9])\.? (Okt\.?|Oktober) ${y}([0-9]{4})///${y}-10-0${d}|],
+ [R.ed|${d}([0-9])\.? (Nov\.?|November) ${y}([0-9]{4})///${y}-11-0${d}|],
+ [R.ed|${d}([0-9])\.? (Dez\.?|Dezember) ${y}([0-9]{4})///${y}-12-0${d}|],
+ -- Jun D, YYYY
+ [R.ed|Jan ${d}([0-9]), ${y}([0-9]{4})///${y}-01-0${d}|],
+ [R.ed|Feb ${d}([0-9]), ${y}([0-9]{4})///${y}-02-0${d}|],
+ [R.ed|Mar ${d}([0-9]), ${y}([0-9]{4})///${y}-03-0${d}|],
+ [R.ed|Apr ${d}([0-9]), ${y}([0-9]{4})///${y}-04-0${d}|],
+ [R.ed|May ${d}([0-9]), ${y}([0-9]{4})///${y}-05-0${d}|],
+ [R.ed|Jun ${d}([0-9]), ${y}([0-9]{4})///${y}-06-0${d}|],
+ [R.ed|Jul ${d}([0-9]), ${y}([0-9]{4})///${y}-07-0${d}|],
+ [R.ed|Aug ${d}([0-9]), ${y}([0-9]{4})///${y}-08-0${d}|],
+ [R.ed|Sep ${d}([0-9]), ${y}([0-9]{4})///${y}-09-0${d}|],
+ [R.ed|Oct ${d}([0-9]), ${y}([0-9]{4})///${y}-10-0${d}|],
+ [R.ed|Nov ${d}([0-9]), ${y}([0-9]{4})///${y}-11-0${d}|],
+ [R.ed|Dec ${d}([0-9]), ${y}([0-9]{4})///${y}-12-0${d}|],
+ -- Jun DD, YYYY
+ [R.ed|Jan ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-01-${d}|],
+ [R.ed|Feb ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-02-${d}|],
+ [R.ed|Mar ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-03-${d}|],
+ [R.ed|Apr ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-04-${d}|],
+ [R.ed|May ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-05-${d}|],
+ [R.ed|Jun ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-06-${d}|],
+ [R.ed|Jul ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-07-${d}|],
+ [R.ed|Aug ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-08-${d}|],
+ [R.ed|Sep ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-09-${d}|],
+ [R.ed|Oct ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-10-${d}|],
+ [R.ed|Nov ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-11-${d}|],
+ [R.ed|Dec ${d}([0-9]{2}), ${y}([0-9]{4})///${y}-12-${d}|]
+ ],
SuggestTagByTags "correspondent"
],
defaultLanguage = "deu+eng"
@@ -61,7 +125,7 @@ instance A.FromJSON Settings
instance A.ToJSON Settings
data SuggestedTag
- = SuggestTagByRE T.Text (R.SearchReplace R.RE T.Text)
+ = SuggestTagByRE T.Text [R.SearchReplace R.RE T.Text]
| SuggestTagByTags T.Text
deriving (Show, Generic, Eq)