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
922f5f43
Commit
922f5f43
authored
1 year ago
by
Alice Brenon
Browse files
Options
Downloads
Patches
Plain Diff
More comprehensive measure script taking both sign- and lexical units-levels into account
parent
0124d259
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/textometry/measure.hs
+49
-0
49 additions, 0 deletions
scripts/textometry/measure.hs
with
49 additions
and
0 deletions
scripts/textometry/
siz
e.hs
→
scripts/textometry/
measur
e.hs
+
49
−
0
View file @
922f5f43
...
...
@@ -2,37 +2,48 @@
{-# LANGUAGE ExplicitNamespaces #-}
import
Conllu.Tree
(
IndexedDocument
(
..
))
import
Conllu.Tree.Count
(
Count
(
..
))
import
Data.ByteString
as
ByteString
(
readFile
)
import
Data.Csv
(
DefaultOrdered
(
..
),
ToNamedRecord
(
..
))
import
Data.Serialize
(
decode
)
import
Data.Text
as
Text
(
length
)
import
Data.Text.IO
as
Text
(
hGetContents
)
import
GEODE.Metadata
(
type
(
@
)(
..
),
ArticleRecord
(
..
),
Document
(
..
),
ReadTSV
(
..
),
Record
(
..
)
,
WriteTSV
(
..
),
for
,
getHeader
,
glue
)
,
WithDefaultHeader
(
..
),
WriteTSV
(
..
),
for
,
getHeader
)
import
GHC.Generics
(
Generic
)
import
System.Environment
(
getArgs
)
import
System.FilePath
((
</>
))
import
System.IO
(
IOMode
(
ReadMode
),
hFileSize
,
withFile
)
import
System.Script
(
syntax
,
warn
)
newtype
Size
=
Size
{
size
::
Int
}
deriving
(
Eq
,
Generic
,
Ord
,
Show
)
data
Sizes
=
Sizes
{
bytes
::
Int
,
characters
::
Int
}
deriving
(
Eq
,
Generic
,
Ord
,
Show
)
instance
DefaultOrdered
Size
instance
ToNamedRecord
Size
instance
DefaultOrdered
Size
s
instance
ToNamedRecord
Size
s
type
Result
=
ArticleRecord
@
Size
type
Result
=
ArticleRecord
@
Sizes
@
Count
--type Result = ArticleRecord @ Sizes @ Count
measureIn
::
FilePath
->
ArticleRecord
->
IO
()
measureIn
inputRoot
article
=
ByteString
.
readFile
path
>>=
either
warn
measure
.
decode
measureIn
::
FilePath
->
FilePath
->
ArticleRecord
->
IO
()
measureIn
textRoot
treeRoot
article
=
do
sizes
<-
withFile
(
textRoot
</>
relativePath
article
"txt"
)
ReadMode
measure
ByteString
.
readFile
treeFile
>>=
either
warn
(
writeTSV
()
.
(
:
[]
)
.
glue3
article
sizes
.
_total
)
.
decode
where
path
=
inputRoot
</>
relativePath
article
"tree"
--skipAndWarn msg = Nothing <$ warn msg
measure
(
IndexedDocument
{
_total
})
=
writeTSV
()
[
glue
article
$
Size
_total
]
treeFile
=
treeRoot
</>
relativePath
article
"tree"
measure
h
=
Sizes
<$>
(
fromInteger
<$>
hFileSize
h
)
<*>
(
Text
.
length
<$>
hGetContents
h
)
glue3
a
b
c
=
WithDefaultHeader
(
a
:@:
b
:@:
c
)
main
::
IO
()
main
=
getArgs
>>=
run
where
run
[
input
Root
]
=
do
run
[
textRoot
,
tree
Root
]
=
do
Document
{
rows
}
<-
readTSV
()
writeTSV
()
[
getHeader
(
for
::
Result
)]
mapM_
(
measureIn
input
Root
)
rows
run
_
=
syntax
"
INPUT
_ROOT"
mapM_
(
measureIn
textRoot
tree
Root
)
rows
run
_
=
syntax
"
TEXT_ROOT TREE
_ROOT"
This diff is collapsed.
Click to expand it.
Alice Brenon
@abrenon
mentioned in commit
ea0e05e5
·
1 year ago
mentioned in commit
ea0e05e5
mentioned in commit ea0e05e5b34647fe105b390e5866cd100e9d5770
Toggle commit list
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