Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
teiwa
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
Model registry
Operate
Environments
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
teiwa
Commits
09f7f057
Commit
09f7f057
authored
4 years ago
by
Alice Brenon
Browse files
Options
Downloads
Patches
Plain Diff
Implement strictTEI filtering
parent
d786c741
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
lib/Text/TEIWA/Source.hs
+14
-3
14 additions, 3 deletions
lib/Text/TEIWA/Source.hs
with
14 additions
and
3 deletions
lib/Text/TEIWA/Source.hs
+
14
−
3
View file @
09f7f057
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module
Text.TEIWA.Source
(
module
Text.TEIWA.Source
(
Format
Format
,
Origin
(
..
)
,
Origin
(
..
)
...
@@ -15,7 +16,7 @@ module Text.TEIWA.Source (
...
@@ -15,7 +16,7 @@ module Text.TEIWA.Source (
import
Control.Monad.Except
(
MonadError
(
..
))
import
Control.Monad.Except
(
MonadError
(
..
))
import
Control.Monad.Reader
(
MonadReader
(
..
),
ReaderT
(
..
))
import
Control.Monad.Reader
(
MonadReader
(
..
),
ReaderT
(
..
))
import
Control.Monad.IO.Class
(
MonadIO
(
..
))
import
Control.Monad.IO.Class
(
MonadIO
(
..
))
import
Data.Text.Lazy
as
Text
(
Text
,
unpack
)
import
Data.Text.Lazy
as
Text
(
Text
,
toLower
,
unpack
)
import
Data.Text.Lazy.IO
as
Text
(
readFile
)
import
Data.Text.Lazy.IO
as
Text
(
readFile
)
import
Text.Parsec
(
ParsecT
,
SourceName
,
runParserT
)
import
Text.Parsec
(
ParsecT
,
SourceName
,
runParserT
)
import
Text.TEIWA.Annotation
(
import
Text.TEIWA.Annotation
(
...
@@ -23,20 +24,30 @@ import Text.TEIWA.Annotation (
...
@@ -23,20 +24,30 @@ import Text.TEIWA.Annotation (
)
)
import
Text.TEIWA.Config
(
Config
(
..
))
import
Text.TEIWA.Config
(
Config
(
..
))
import
Text.TEIWA.Error
(
Error
(
..
))
import
Text.TEIWA.Error
(
Error
(
..
))
import
Text.TEIWA.Source.Common
(
AnnotationContext
(
..
),
Row
)
import
Text.TEIWA.Source.Common
(
AnnotationContext
(
..
),
Field
,
Row
)
import
qualified
Text.TEIWA.Source.ConLLX
as
ConLLX
(
getContext
,
sentences
)
import
qualified
Text.TEIWA.Source.ConLLX
as
ConLLX
(
getContext
,
sentences
)
import
qualified
Text.TEIWA.Source.SSV
as
SSV
(
body
,
getContext
)
import
qualified
Text.TEIWA.Source.SSV
as
SSV
(
body
,
getContext
)
type
TEIWAParser
=
ParsecT
Text
()
(
ReaderT
Config
(
Either
Error
))
type
TEIWAParser
=
ParsecT
Text
()
(
ReaderT
Config
(
Either
Error
))
type
Format
=
TEIWAParser
Annotation
type
Format
=
TEIWAParser
Annotation
isTEI
::
Field
->
Bool
isTEI
=
(`
elem
`
[
"pos"
,
"lemma"
,
"msd"
])
filterAttributes
::
MonadReader
Config
m
=>
[(
Field
,
Field
)]
->
m
[(
Field
,
Field
)]
filterAttributes
attributes
=
reader
$
filterIf
.
strictTEI
where
filterIf
False
=
attributes
filterIf
True
=
[(
k'
,
v
)
|
(
k
,
v
)
<-
attributes
,
let
k'
=
Text
.
toLower
k
,
isTEI
k'
]
annotateToken
::
(
MonadError
Error
m
,
MonadReader
Config
m
)
=>
annotateToken
::
(
MonadError
Error
m
,
MonadReader
Config
m
)
=>
AnnotationContext
->
Row
->
m
TokenAnnotation
AnnotationContext
->
Row
->
m
TokenAnnotation
annotateToken
(
AnnotationContext
{
columnIndex
,
columnName
,
header
})
(
atLine
,
record
)
=
annotateToken
(
AnnotationContext
{
columnIndex
,
columnName
,
header
})
(
atLine
,
record
)
=
case
splitAt
columnIndex
record
of
case
splitAt
columnIndex
record
of
(
_
,
[]
)
->
throwError
.
MissingColumn
atLine
$
Text
.
unpack
columnName
(
_
,
[]
)
->
throwError
.
MissingColumn
atLine
$
Text
.
unpack
columnName
(
before
,
form
:
after
)
->
(
before
,
form
:
after
)
->
return
$
TokenAnnotation
{
form
,
annotated
=
zip
header
(
before
++
after
)
}
TokenAnnotation
form
<$>
filterAttributes
(
zip
header
$
before
++
after
)
coNLLX
::
Format
coNLLX
::
Format
coNLLX
=
do
coNLLX
=
do
...
...
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