Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
147
Issues
147
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
7997ab36
Commit
7997ab36
authored
May 14, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CSV Parser] Parser for Gargantext (legacy) CSV files.
parent
02e3e8d2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
12 deletions
+84
-12
package.yaml
package.yaml
+2
-0
Prelude.hs
src/Gargantext/Prelude.hs
+0
-12
CSV.hs
src/Gargantext/Text/Parsers/CSV.hs
+82
-0
CSV_hs
src/Gargantext/Text/Parsers/CSV_hs
+0
-0
No files found.
package.yaml
View file @
7997ab36
...
...
@@ -33,6 +33,7 @@ library:
-
Gargantext.Text.Ngrams.PosTagging.CoreNLP
-
Gargantext.Text.Ngrams.PosTagging.Parser
-
Gargantext.Text.Ngrams.Token.Text
-
Gargantext.Text.Parsers.CSV
-
Gargantext.Text.Parsers.Date
-
Gargantext.Database
-
Gargantext.API
...
...
@@ -47,6 +48,7 @@ library:
-
base16-bytestring
-
bytestring
-
case-insensitive
-
cassava
-
conduit
-
conduit-extra
-
containers
...
...
src/Gargantext/Prelude.hs
View file @
7997ab36
...
...
@@ -75,18 +75,6 @@ pr = reverse
map2
::
(
t
->
b
)
->
[[
t
]]
->
[[
b
]]
map2
fun
=
map
(
map
fun
)
pz
::
[
a
]
->
[
b
]
->
[(
a
,
b
)]
pz
=
zip
pd
::
Int
->
[
a
]
->
[
a
]
pd
=
drop
ptk
::
Int
->
[
a
]
->
[
a
]
ptk
=
take
pzw
::
(
a
->
b
->
c
)
->
[
a
]
->
[
b
]
->
[
c
]
pzw
=
zipWith
-- Exponential Average
eavg
::
[
Double
]
->
Double
eavg
(
x
:
xs
)
=
a
*
x
+
(
1
-
a
)
*
(
eavg
xs
)
...
...
src/Gargantext/Text/Parsers/CSV.hs
0 → 100644
View file @
7997ab36
{-|
Module : Gargantext.Text.Parsers.CSV
Description :
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
Here is a longer description of this module, containing some
commentary with @some markup@.
-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module
Gargantext.Text.Parsers.CSV
where
import
GHC.Generics
(
Generic
)
import
GHC.IO
(
FilePath
)
import
Data.Either
(
Either
(
Left
,
Right
))
import
Data.Text
(
Text
)
import
Control.Applicative
import
qualified
Data.ByteString.Lazy
as
BL
import
Data.Csv
import
qualified
Data.Vector
as
V
import
Data.Text
(
pack
)
import
Data.Char
(
ord
)
import
Gargantext.Prelude
data
CsvDoc
=
CsvDoc
{
title
::
!
Text
,
source
::
!
Text
,
publication_year
::
!
Int
,
publication_month
::
!
Int
,
publication_day
::
!
Int
,
abstract
::
!
Text
,
authors
::
!
Text
}
deriving
(
Show
,
Generic
)
instance
FromNamedRecord
CsvDoc
where
parseNamedRecord
r
=
CsvDoc
<$>
r
.:
"title"
<*>
r
.:
"source"
<*>
r
.:
"publication_year"
<*>
r
.:
"publication_month"
<*>
r
.:
"publication_day"
<*>
r
.:
"abstract"
<*>
r
.:
"authors"
instance
ToNamedRecord
CsvDoc
where
toNamedRecord
(
CsvDoc
t
s
py
pm
pd
abst
aut
)
=
namedRecord
[
"title"
.=
t
,
"source"
.=
s
,
"publication_year"
.=
py
,
"publication_month"
.=
pm
,
"publication_day"
.=
pd
,
"abstract"
.=
abst
,
"authors"
.=
aut
]
csvDecodeOptions
::
DecodeOptions
csvDecodeOptions
=
(
defaultDecodeOptions
{
decDelimiter
=
fromIntegral
$
ord
'
\t
'
}
)
csvEncodeOptions
::
EncodeOptions
csvEncodeOptions
=
(
defaultEncodeOptions
{
encDelimiter
=
fromIntegral
$
ord
'
\t
'
}
)
readCsv
::
FilePath
->
IO
(
Header
,
V
.
Vector
CsvDoc
)
readCsv
fp
=
do
csvData
<-
BL
.
readFile
fp
case
decodeByNameWith
csvDecodeOptions
csvData
of
Left
e
->
panic
(
pack
e
)
Right
csvDocs
->
pure
csvDocs
writeCsv
::
FilePath
->
(
Header
,
V
.
Vector
CsvDoc
)
->
IO
()
writeCsv
fp
(
h
,
vs
)
=
BL
.
writeFile
fp
$
encodeByNameWith
csvEncodeOptions
h
(
V
.
toList
vs
)
src/Gargantext/Text/Parsers/CSV_hs
deleted
100644 → 0
View file @
02e3e8d2
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment