{-# LANGUAGE OverloadedStrings #-} -- | Havdalah — separation and distinction. -- -- Architecture §3.1: -- havdalah :: Input -> [(Category, Content)] -- "Separate an input into distinguished categories" -- -- Havdalah is the act of making distinctions. In the processing -- pipeline, it takes the output of vayomer (structured symbolic output) -- and separates it into categories that can be named (kriah). -- -- Te'amim inform the separation — the text's own divisions guide havdalah. module Shoresh.Havdalah ( havdalah , separateByDomain , separateByTeamim ) where import Shoresh.Types import Shoresh.Teamim (ParsedVerse(..), AnnotatedWord(..), primaryDivision) import Data.Text (Text) import qualified Data.Text as T import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map -- | Separate input into distinguished categories. -- Uses both semantic domain analysis and te'amim structure. havdalah :: [(Shoresh, SemanticDomain)] -> [(Text, [(Shoresh, SemanticDomain)])] havdalah items = let grouped = Map.toList $ Map.fromListWith (++) [ (domainName d, [(sh, d)]) | (sh, d) <- items ] in grouped where domainName :: SemanticDomain -> Text domainName d = T.pack (show d) -- | Separate roots by their semantic domain. separateByDomain :: [ShoreshEntry] -> Map SemanticDomain [ShoreshEntry] separateByDomain entries = Map.fromListWith (++) [ (sePrimaryDomain e, [e]) | e <- entries ] -- | Separate using te'amim structure. -- The te'amim parse tree tells us where the text itself -- draws its divisions. Havdalah follows the text's own structure. separateByTeamim :: ParsedVerse -> ([Text], [Text]) separateByTeamim verse = let (left, right) = primaryDivision verse in (collectWords left, collectWords right) where collectWords :: ParsedVerse -> [Text] collectWords (Leaf w) = [awWord w] collectWords (Branch _ l r) = collectWords l ++ collectWords r