Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
outillage
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alice Brenon
outillage
Commits
b1cf10a1
Commit
b1cf10a1
authored
2 years ago
by
Alice Brenon
Browse files
Options
Downloads
Patches
Plain Diff
Implement new features to merge script
parent
7b177653
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/merge.hs
+41
-10
41 additions, 10 deletions
scripts/merge.hs
with
41 additions
and
10 deletions
scripts/merge.hs
+
41
−
10
View file @
b1cf10a1
#!/
usr
/
bin
/
env
-
S
runhaskell
--ghc-arg="-Wall" --ghc-arg="-i lib"
#!/
usr
/
bin
/
env
-
S
runhaskell
--ghc-arg="-Wall" --ghc-arg="-i lib"
{-# LANGUAGE DeriveGeneric, ExplicitNamespaces, OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric, ExplicitNamespaces, OverloadedStrings
, ScopedTypeVariables
#-}
import
Control.Monad.Except
(
ExceptT
(
..
),
runExceptT
)
import
Control.Monad.Except
(
ExceptT
(
..
),
runExceptT
)
import
Data.Map
((
!?
))
import
Data.Foldable
(
toList
)
import
Data.Map
(
Map
,
(
!?
))
import
Data.Maybe
(
catMaybes
)
import
Data.Maybe
(
catMaybes
)
import
Data.
Vector
(
Vector
,
toList
)
import
Data.
Text
(
Text
,
pack
)
import
GEODE.Metadata
(
Contrastive
,
Entry
,
Has
(
..
),
PrimaryKey
,
type
(
@
)(
..
),
indexBy
,
readNamedTsv
,
tsvFile
)
import
GEODE.Metadata
(
Contrastive
(
..
)
,
Entry
,
Has
(
..
),
MultiText
(
..
),
PrimaryKey
,
type
(
@
)(
..
),
indexBy
,
readNamedTsv
,
tsvFile
)
import
System.Environment
(
getArgs
)
import
System.Environment
(
getArgs
)
import
System.Exit
(
die
)
import
System.Exit
(
die
)
import
System.Script
(
syntax
)
import
System.Script
(
syntax
)
merge
::
Vector
(
PrimaryKey
@
Entry
)
->
Vector
(
PrimaryKey
@
Contrastive
)
->
[
PrimaryKey
@
Entry
@
Contrastive
]
leftJoin
::
forall
a
b
c
t
.
(
Foldable
t
,
Functor
t
,
Has
PrimaryKey
a
,
Has
PrimaryKey
b
)
=>
merge
left
right
=
catMaybes
(
mergeRow
<$>
toList
right
)
(
a
->
Maybe
b
->
c
)
->
t
a
->
t
b
->
t
c
leftJoin
f
left
right
=
outputRow
<$>
left
where
where
indexed
=
get
<$>
indexBy
get
left
indexed
::
Map
PrimaryKey
b
mergeRow
(
pK
:@:
contrastive
)
=
indexed
=
indexBy
get
right
(
\
entry
->
(
pK
:@:
entry
:@:
contrastive
))
<$>
(
indexed
!?
pK
)
outputRow
leftLine
=
f
leftLine
(
indexed
!?
get
leftLine
)
rightJoin
::
(
Foldable
t
,
Functor
t
,
Has
PrimaryKey
a
,
Has
PrimaryKey
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
)
=>
(
a
->
b
->
c
)
->
t
a
->
t
b
->
[
c
]
join
f
left
right
=
catMaybes
.
toList
$
outputRow
<$>
left
where
indexed
::
Map
PrimaryKey
b
indexed
=
indexBy
get
right
outputRow
leftLine
=
f
leftLine
<$>
(
indexed
!?
get
leftLine
)
merge
::
(
PrimaryKey
@
Entry
)
->
(
PrimaryKey
@
Contrastive
)
->
(
PrimaryKey
@
Entry
@
Contrastive
)
merge
(
pK
:@:
e
)
(
_
:@:
c
)
=
pK
:@:
e
:@:
c
tag
::
Text
->
Maybe
PrimaryKey
->
(
PrimaryKey
@
Entry
@
Contrastive
)
->
(
PrimaryKey
@
Entry
@
Contrastive
)
tag
_
Nothing
l
=
l
tag
name
(
Just
_
)
(
pK
:@:
e
:@:
contr
)
=
pK
:@:
e
:@:
contr
{
subCorpus
=
MultiText
(
name
:
subCorpora
)
}
where
MultiText
subCorpora
=
subCorpus
contr
main
::
IO
()
main
::
IO
()
main
=
getArgs
>>=
run
main
=
getArgs
>>=
run
where
where
run
[
left
,
right
,
output
]
=
run
[
left
,
right
,
output
]
=
runExceptT
(
merge
runExceptT
((
join
merge
)
<$>
ExceptT
(
readNamedTsv
left
)
<*>
ExceptT
(
readNamedTsv
right
)
)
>>=
either
die
(
tsvFile
output
)
run
[
name
,
left
,
right
,
output
]
=
runExceptT
((
rightJoin
(
tag
$
pack
name
))
<$>
ExceptT
(
readNamedTsv
left
)
<$>
ExceptT
(
readNamedTsv
left
)
<*>
ExceptT
(
readNamedTsv
right
)
)
<*>
ExceptT
(
readNamedTsv
right
)
)
>>=
either
die
(
tsvFile
output
)
>>=
either
die
(
tsvFile
output
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment