diff --git a/scripts/merge.hs b/scripts/merge.hs index 99b022f6e76ec88da7dae5a6df552524c652fc4b..a625ef5b615dd7729343914b813c4f92710cdbe3 100755 --- a/scripts/merge.hs +++ b/scripts/merge.hs @@ -6,42 +6,42 @@ import Data.Foldable (toList) import Data.Map (Map, (!?)) import Data.Maybe (catMaybes) import Data.Text (Text, pack) -import GEODE.Metadata (Contrastive(..), Entry, Has(..), MultiText(..), PrimaryKey, type(@)(..), indexBy, readNamedTsv, tsvFile) +import GEODE.Metadata (Contrastive(..), Entry, Has(..), MultiText(..), ArticleRecord, type(@)(..), indexBy, readNamedTsv, tsvFile) import System.Environment (getArgs) import System.Exit (die) import System.Script (syntax) -leftJoin :: forall a b c t. (Foldable t, Functor t, Has PrimaryKey a, Has PrimaryKey b) => +leftJoin :: forall a b c t. (Foldable t, Functor t, Has ArticleRecord a, Has ArticleRecord b) => (a -> Maybe b -> c) -> t a -> t b -> t c leftJoin f left right = outputRow <$> left where - indexed :: Map PrimaryKey b + indexed :: Map ArticleRecord b indexed = indexBy get right outputRow leftLine = f leftLine (indexed !? get leftLine) -rightJoin :: (Foldable t, Functor t, Has PrimaryKey a, Has PrimaryKey b) => +rightJoin :: (Foldable t, Functor t, Has ArticleRecord a, Has ArticleRecord b) => (Maybe a -> b -> c) -> t a -> t b -> t c rightJoin f left right = leftJoin (flip f) right left -join :: forall a b c t. (Foldable t, Functor t, Has PrimaryKey a, Has PrimaryKey b) => +join :: forall a b c t. (Foldable t, Functor t, Has ArticleRecord a, Has ArticleRecord b) => (a -> b -> c) -> t a -> t b -> [c] join f left right = catMaybes . toList $ outputRow <$> left where - indexed :: Map PrimaryKey b + indexed :: Map ArticleRecord b indexed = indexBy get right outputRow leftLine = f leftLine <$> (indexed !? get leftLine) -merge :: (PrimaryKey @ Entry) -> (PrimaryKey @ Contrastive) -> (PrimaryKey @ Entry @ Contrastive) +merge :: (ArticleRecord @ Entry) -> (ArticleRecord @ Contrastive) -> (ArticleRecord @ Entry @ Contrastive) merge (pK :@: e) (_ :@: c) = pK :@: e :@: c -tag :: Text -> Maybe PrimaryKey -> (PrimaryKey @ Entry @ Contrastive) -> (PrimaryKey @ Entry @ Contrastive) +tag :: Text -> Maybe ArticleRecord -> (ArticleRecord @ Entry @ Contrastive) -> (ArticleRecord @ Entry @ Contrastive) tag _ Nothing l = l -tag name (Just _) (pK :@: e :@: contr) = - pK :@: e :@: contr { subCorpus = MultiText (name : subCorpora) } +tag name (Just _) (pK :@: e :@: contrastive) = + pK :@: e :@: contrastive { subCorpus = MultiText (name : subCorpora) } where - MultiText subCorpora = subCorpus contr + MultiText subCorpora = subCorpus contrastive main :: IO () main = getArgs >>= run diff --git a/scripts/select.hs b/scripts/select.hs index ba1c5f3632f4f7c64a9fa8b83500f71be9bb3758..fe4b70c9fa5c1f62381de09968aa1e83cabebe32 100755 --- a/scripts/select.hs +++ b/scripts/select.hs @@ -6,12 +6,12 @@ import Control.Monad.Except (ExceptT(..), runExceptT) import Data.Map ((!?)) import Data.Maybe (catMaybes) import Data.Vector (Vector, toList) -import GEODE.Metadata (Entry, Has(..), PrimaryKey, type(@), indexBy, readNamedTsv, tsvFile) +import GEODE.Metadata (Entry, Has(..), ArticleRecord, type(@), indexBy, readNamedTsv, tsvFile) import System.Environment (getArgs) import System.Exit (die) import System.Script (syntax) -getMeta :: Vector PrimaryKey -> Vector (PrimaryKey @ Entry) -> [(PrimaryKey @ Entry)] +getMeta :: Vector ArticleRecord -> Vector (ArticleRecord @ Entry) -> [(ArticleRecord @ Entry)] getMeta coords meta = catMaybes ((indexed !?) <$> toList coords) where indexed = indexBy get meta