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
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
14
Merge Requests
14
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
f4246b5a
Commit
f4246b5a
authored
Nov 14, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HasDbid small refactoring
parent
1829c501
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
18 deletions
+25
-18
Core.hs
src/Gargantext/Core.hs
+25
-18
No files found.
src/Gargantext/Core.hs
View file @
f4246b5a
...
...
@@ -137,27 +137,34 @@ class HasDBid a where
-- NOTE: We try to use numeric codes for countries
-- https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
-- https://en.wikipedia.org/wiki/ISO_3166-1_numeric#004
dbIds
::
[(
Lang
,
Int
)]
dbIds
=
[
(
All
,
0
)
,
(
DE
,
276
)
,
(
EL
,
300
)
,
(
EN
,
2
)
,
(
ES
,
724
)
,
(
FR
,
1
)
,
(
IT
,
380
)
,
(
PL
,
616
)
,
(
PT
,
620
)
,
(
RU
,
643
)
,
(
UK
,
804
)
,
(
ZH
,
156
)
]
-- The pattern matching ensures this mapping will always be total
-- once we add a new 'Lang'.
lang2id
::
Map
Lang
Int
lang2id
=
Map
.
fromList
$
allLangs
<&>
\
lid
->
case
lid
of
All
->
(
lid
,
0
)
DE
->
(
lid
,
276
)
EL
->
(
lid
,
300
)
EN
->
(
lid
,
2
)
ES
->
(
lid
,
724
)
FR
->
(
lid
,
1
)
IT
->
(
lid
,
380
)
PL
->
(
lid
,
616
)
PT
->
(
lid
,
620
)
RU
->
(
lid
,
643
)
UK
->
(
lid
,
804
)
ZH
->
(
lid
,
156
)
-- | /static/ conversion map between an 'Int' and a 'Lang'. Automatically kept up-to-date
-- as it's derived from 'lang2id'.
id2lang
::
Map
Int
Lang
id2lang
=
Map
.
fromList
.
map
swap
.
Map
.
toList
$
lang2id
instance
HasDBid
Lang
where
toDBid
lang
=
case
Map
.
lookup
lang
$
Map
.
fromList
dbIds
of
Just
la
->
la
Nothing
->
panic
"[G.Core] Add this lang to DB ids"
-- /NOTE/ this lookup cannot fail because 'dbIds' is defined as a total function
-- over its domain.
toDBid
lang
=
lang2id
Map
.!
lang
fromDBid
dbId
=
case
Map
.
lookup
dbId
$
Map
.
fromList
$
map
swap
dbIds
of
fromDBid
dbId
=
case
Map
.
lookup
dbId
id2lang
of
Just
la
->
la
Nothing
->
panic
"HasDBid lang, not implemented"
...
...
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