Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext-prelude
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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-prelude
Commits
e250af8a
Verified
Commit
e250af8a
authored
Apr 14, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NLP] implement reading lang configs for other languages
parent
175d4b29
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
9 deletions
+39
-9
gargantext-prelude.cabal
gargantext-prelude.cabal
+4
-1
package.yaml
package.yaml
+1
-0
NLP.hs
src/Gargantext/Prelude/NLP.hs
+15
-3
Types.hs
src/Gargantext/Prelude/NLP/Types.hs
+5
-4
Utils.hs
src/Gargantext/Prelude/Utils.hs
+14
-1
No files found.
gargantext-prelude.cabal
View file @
e250af8a
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.3
4.7
.
-- This file has been generated from package.yaml by hpack version 0.3
5.1
.
--
-- see: https://github.com/sol/hpack
...
...
@@ -57,6 +57,7 @@ library
OverloadedStrings
RankNTypes
RecordWildCards
StrictData
build-depends:
MonadRandom
, SHA
...
...
@@ -115,6 +116,7 @@ executable gargantext-prelude-exe
OverloadedStrings
RankNTypes
RecordWildCards
StrictData
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
MonadRandom
...
...
@@ -176,6 +178,7 @@ test-suite gargantext-prelude-test
OverloadedStrings
RankNTypes
RecordWildCards
StrictData
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
MonadRandom
...
...
package.yaml
View file @
e250af8a
...
...
@@ -71,6 +71,7 @@ default-extensions:
-
OverloadedStrings
-
RankNTypes
-
RecordWildCards
-
StrictData
library
:
source-dirs
:
src
...
...
src/Gargantext/Prelude/NLP.hs
View file @
e250af8a
...
...
@@ -13,28 +13,38 @@ module Gargantext.Prelude.NLP
(
NLPConfig
(
..
),
readConfig
)
where
import
qualified
Data.Ini
as
Ini
import
qualified
Data.Map.Strict
as
Map
import
Data.Text
(
Text
,
unpack
)
import
qualified
Data.Text
as
T
import
Data.Maybe
import
Gargantext.Prelude
import
Gargantext.Prelude.Config
(
readIniFile'
,
val
)
import
Gargantext.Prelude.NLP.Types
(
NLPConfig
(
..
))
import
Gargantext.Prelude.Utils
(
listToMaybeAll
)
import
Network.URI
(
parseURI
)
import
Protolude
hiding
(
show
)
import
System.IO
(
FilePath
)
type
URL
=
Text
iniSection
::
Text
iniSection
=
"nlp"
readConfig
::
FilePath
->
IO
NLPConfig
readConfig
fp
=
do
ini
<-
readIniFile'
fp
let
val'
=
val
ini
"nlp"
let
val'
=
val
ini
iniSection
let
m_nlp_en
=
parseURI
$
cs
$
val'
"EN"
let
m_nlp_fr
=
parseURI
$
cs
$
val'
"FR"
let
m_nlp_all
=
parseURI
$
cs
$
val'
"All"
let
mRet
=
NLPConfig
<$>
m_nlp_en
<*>
m_nlp_fr
<*>
m_nlp_all
let
m_nlp_keys
=
filter
(
\
k
->
k
`
notElem
`
[
"EN"
,
"FR"
,
"All"
])
$
fromRight
[]
$
Ini
.
keys
iniSection
ini
let
m_nlp_other
=
listToMaybeAll
$
(
\
k
->
(,)
k
<$>
(
parseURI
$
cs
$
val'
k
))
<$>
m_nlp_keys
let
mRet
=
NLPConfig
<$>
m_nlp_en
<*>
m_nlp_fr
<*>
m_nlp_all
<*>
(
Map
.
fromList
<$>
m_nlp_other
)
case
mRet
of
Nothing
->
panic
$
T
.
concat
[
"Cannot read config file: _nlp_en = "
...
...
@@ -42,5 +52,7 @@ readConfig fp = do
,
", _nlp_fr = "
,
T
.
pack
$
show
m_nlp_fr
,
", _nlp_all = "
,
T
.
pack
$
show
m_nlp_all
]
,
T
.
pack
$
show
m_nlp_all
,
", _nlp_other = "
,
T
.
pack
$
show
m_nlp_other
]
Just
ret
->
pure
ret
src/Gargantext/Prelude/NLP/Types.hs
View file @
e250af8a
...
...
@@ -14,16 +14,17 @@ Portability : POSIX
module
Gargantext.Prelude.NLP.Types
where
import
Control.Lens
(
makeLenses
)
import
qualified
Data.Map.Strict
as
Map
import
qualified
Data.Text
as
T
import
GHC.Generics
(
Generic
)
import
Network.Socket
(
PortNumber
)
import
Network.URI
(
URI
)
import
Protolude
data
NLPConfig
=
NLPConfig
{
_nlp_en
::
!
URI
,
_nlp_fr
::
!
URI
,
_nlp_all
::
!
URI
}
data
NLPConfig
=
NLPConfig
{
_nlp_en
::
URI
,
_nlp_fr
::
URI
,
_nlp_all
::
URI
,
_nlp_other
::
(
Map
.
Map
T
.
Text
URI
)
}
deriving
(
Generic
,
Show
)
makeLenses
''
N
LPConfig
src/Gargantext/Prelude/Utils.hs
View file @
e250af8a
...
...
@@ -17,12 +17,13 @@ module Gargantext.Prelude.Utils
where
import
Control.Monad.Random.Class
(
MonadRandom
)
import
Protolude
import
qualified
System.Random.Shuffle
as
SRS
------------------------------------------------------------------------
-- | Misc Utils
shuffle
::
MonadRandom
m
=>
[
a
]
->
m
[
a
]
shuffle
ns
=
SRS
.
shuffleM
ns
shuffle
ns
=
SRS
.
shuffleM
ns
--------------------------------------------------------------------------
-- TODO gargDB instance for NodeType
...
...
@@ -31,3 +32,15 @@ data NodeToHash = NodeToHash { nodeType :: NodeType
, nodeId :: NodeId
}
-}
-- | Convert list of Maybe's to `Nothing` if at least 1 element is a
-- `Nothing` or `Just` otherwise.
listToMaybeAll
::
[
Maybe
a
]
->
Maybe
[
a
]
listToMaybeAll
lst
=
if
length
lst
==
length
cm
then
Just
cm
else
Nothing
where
cm
=
catMaybes
lst
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