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
159
Issues
159
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
03d2b0e3
Commit
03d2b0e3
authored
Dec 12, 2024
by
Grégoire Locqueville
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed unused code in `Gargantext.API.Ngrams(.*)`
parent
d9196985
Pipeline
#7120
passed with stages
in 46 minutes and 17 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
5 additions
and
176 deletions
+5
-176
Ngrams.hs
src/Gargantext/API/Ngrams.hs
+1
-62
List.hs
src/Gargantext/API/Ngrams/List.hs
+1
-16
Tools.hs
src/Gargantext/API/Ngrams/Tools.hs
+0
-29
Types.hs
src/Gargantext/API/Ngrams/Types.hs
+0
-69
weeder.toml
weeder.toml
+3
-0
No files found.
src/Gargantext/API/Ngrams.hs
View file @
03d2b0e3
...
@@ -15,15 +15,10 @@ add get
...
@@ -15,15 +15,10 @@ add get
-}
-}
{-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
{-# OPTIONS_GHC -fno-warn-deprecations #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module
Gargantext.API.Ngrams
module
Gargantext.API.Ngrams
(
(
...
@@ -55,7 +50,6 @@ module Gargantext.API.Ngrams
...
@@ -55,7 +50,6 @@ module Gargantext.API.Ngrams
,
r_history
,
r_history
,
NgramsRepoElement
(
..
)
,
NgramsRepoElement
(
..
)
,
saveNodeStory
,
saveNodeStory
,
initRepo
,
TabType
(
..
)
,
TabType
(
..
)
...
@@ -64,7 +58,6 @@ module Gargantext.API.Ngrams
...
@@ -64,7 +58,6 @@ module Gargantext.API.Ngrams
-- Internals
-- Internals
,
getNgramsTableMap
,
getNgramsTableMap
,
dumpJsonTableMap
,
tableNgramsPull
,
tableNgramsPull
,
tableNgramsPut
,
tableNgramsPut
...
@@ -75,21 +68,18 @@ module Gargantext.API.Ngrams
...
@@ -75,21 +68,18 @@ module Gargantext.API.Ngrams
,
Versioned
(
..
)
,
Versioned
(
..
)
,
VersionedWithCount
(
..
)
,
VersionedWithCount
(
..
)
,
currentVersion
,
currentVersion
,
listNgramsChangedSince
,
MinSize
,
MaxSize
,
OrderBy
,
NgramsTable
,
MinSize
,
MaxSize
,
OrderBy
,
NgramsTable
,
UpdateTableNgramsCharts
,
UpdateTableNgramsCharts
)
)
where
where
import
Control.Lens
(
view
,
(
^..
),
(
+~
),
(
%~
),
msumOf
,
at
,
ix
,
_Just
,
Each
(
..
),
(
%%~
),
ifolded
,
to
,
withIndex
,
over
)
import
Control.Lens
(
view
,
(
^..
),
(
+~
),
(
%~
),
msumOf
,
at
,
ix
,
_Just
,
Each
(
..
),
(
%%~
),
ifolded
,
to
,
withIndex
,
over
)
import
Data.Aeson.Text
qualified
as
DAT
import
Data.List
qualified
as
List
import
Data.List
qualified
as
List
import
Data.Map.Strict
qualified
as
Map
import
Data.Map.Strict
qualified
as
Map
import
Data.Map.Strict.Patch
qualified
as
PM
import
Data.Map.Strict.Patch
qualified
as
PM
import
Data.Patch.Class
(
Action
(
act
),
Transformable
(
..
),
ours
)
import
Data.Patch.Class
(
Action
(
act
),
Transformable
(
..
),
ours
)
import
Data.Set
qualified
as
Set
import
Data.Set
qualified
as
Set
import
Data.Text
(
isInfixOf
,
toLower
,
unpack
)
import
Data.Text
(
isInfixOf
,
toLower
,)
import
Data.Text.Lazy.IO
as
DTL
(
writeFile
)
import
Formatting
(
hprint
,
int
,
(
%
))
import
Formatting
(
hprint
,
int
,
(
%
))
import
Gargantext.API.Ngrams.Tools
(
getNodeStory
)
import
Gargantext.API.Ngrams.Tools
(
getNodeStory
)
import
Gargantext.API.Ngrams.Types
import
Gargantext.API.Ngrams.Types
...
@@ -111,9 +101,6 @@ saveNodeStory nId a = do
...
@@ -111,9 +101,6 @@ saveNodeStory nId a = do
saver
<-
view
hasNodeStoryImmediateSaver
saver
<-
view
hasNodeStoryImmediateSaver
liftBase
$
saver
nId
a
liftBase
$
saver
nId
a
listTypeConflictResolution
::
ListType
->
ListType
->
ListType
listTypeConflictResolution
_
_
=
undefined
-- TODO Use Map User ListType
ngramsStatePatchConflictResolution
::
NgramsType
ngramsStatePatchConflictResolution
::
NgramsType
->
NgramsTerm
->
NgramsTerm
...
@@ -127,16 +114,6 @@ ngramsStatePatchConflictResolution _ngramsType _ngramsTerm
...
@@ -127,16 +114,6 @@ ngramsStatePatchConflictResolution _ngramsType _ngramsTerm
-- Current state:
-- Insertions are not considered as patches,
-- they do not extend history,
-- they do not bump version.
insertNewOnly
::
a
->
Maybe
b
->
a
insertNewOnly
m
=
maybe
m
(
const
$
errorTrace
"insertNewOnly: impossible"
)
-- TODO error handling
-- | TODO: incr the Version number
-- | TODO: incr the Version number
-- && should use patch
-- && should use patch
-- UNSAFE
-- UNSAFE
...
@@ -298,17 +275,6 @@ getNgramsTableMap nodeId ngramsType = do
...
@@ -298,17 +275,6 @@ getNgramsTableMap nodeId ngramsType = do
(
a
^.
a_state
.
ix
ngramsType
)
(
a
^.
a_state
.
ix
ngramsType
)
dumpJsonTableMap
::
HasNodeStory
env
err
m
=>
Text
->
NodeId
->
NgramsType
->
m
()
dumpJsonTableMap
fpath
nodeId
ngramsType
=
do
m
<-
getNgramsTableMap
nodeId
ngramsType
liftBase
$
DTL
.
writeFile
(
unpack
fpath
)
(
DAT
.
encodeToLazyText
m
)
pure
()
-- | TODO Errors management
-- | TODO Errors management
-- TODO: polymorphic for Annuaire or Corpus or ...
-- TODO: polymorphic for Annuaire or Corpus or ...
-- | Table of Ngrams is a ListNgrams formatted (sorted and/or cut).
-- | Table of Ngrams is a ListNgrams formatted (sorted and/or cut).
...
@@ -474,11 +440,6 @@ setNgramsTableScores nId listId ngramsType table = do
...
@@ -474,11 +440,6 @@ setNgramsTableScores nId listId ngramsType table = do
-- TODO: find a better place for the code above, All APIs stay here
-- TODO: find a better place for the code above, All APIs stay here
needsScores
::
Maybe
OrderBy
->
Bool
needsScores
(
Just
ScoreAsc
)
=
True
needsScores
(
Just
ScoreDesc
)
=
True
needsScores
_
=
False
getTableNgramsCorpus
::
(
HasNodeStory
env
err
m
)
getTableNgramsCorpus
::
(
HasNodeStory
env
err
m
)
=>
NodeId
=>
NodeId
->
TabType
->
TabType
...
@@ -510,25 +471,3 @@ getTableNgramsCorpus nId tabType listId limit_ offset listType minSize maxSize o
...
@@ -510,25 +471,3 @@ getTableNgramsCorpus nId tabType listId limit_ offset listType minSize maxSize o
-- TODO: limit?
-- TODO: limit?
-- Versioned { _v_version = v } <- getTableNgramsCorpus nId tabType listId 100000 Nothing Nothing Nothing Nothing Nothing Nothing
-- Versioned { _v_version = v } <- getTableNgramsCorpus nId tabType listId 100000 Nothing Nothing Nothing Nothing Nothing Nothing
-- This line above looks like a waste of computation to finally get only the version.
-- This line above looks like a waste of computation to finally get only the version.
-- See the comment about listNgramsChangedSince.
-- Did the given list of ngrams changed since the given version?
-- The returned value is versioned boolean value, meaning that one always retrieve the
-- latest version.
-- If the given version is negative then one simply receive the latest version and True.
-- Using this function is more precise than simply comparing the latest version number
-- with the local version number. Indeed there might be no change to this particular list
-- and still the version number has changed because of other lists.
--
-- Here the added value is to make a compromise between precision, computation, and bandwidth:
-- * currentVersion: good computation, good bandwidth, bad precision.
-- * listNgramsChangedSince: good precision, good bandwidth, bad computation.
-- * tableNgramsPull: good precision, good bandwidth (if you use the received data!), bad computation.
listNgramsChangedSince
::
HasNodeStory
env
err
m
=>
ListId
->
NgramsType
->
Version
->
m
(
Versioned
Bool
)
listNgramsChangedSince
listId
ngramsType
version
|
version
<
0
=
Versioned
<$>
currentVersion
listId
<*>
pure
True
|
otherwise
=
tableNgramsPull
listId
ngramsType
version
<&>
v_data
%~
(
==
mempty
)
src/Gargantext/API/Ngrams/List.hs
View file @
03d2b0e3
...
@@ -18,8 +18,6 @@ module Gargantext.API.Ngrams.List
...
@@ -18,8 +18,6 @@ module Gargantext.API.Ngrams.List
import
Data.ByteString.Lazy
qualified
as
BSL
import
Data.ByteString.Lazy
qualified
as
BSL
import
Data.Csv
qualified
as
Tsv
import
Data.Csv
qualified
as
Tsv
import
Data.HashMap.Strict
(
HashMap
)
import
Data.HashMap.Strict
qualified
as
HashMap
import
Data.Map.Strict
(
toList
)
import
Data.Map.Strict
(
toList
)
import
Data.Map.Strict
qualified
as
Map
import
Data.Map.Strict
qualified
as
Map
import
Data.Set
qualified
as
Set
import
Data.Set
qualified
as
Set
...
@@ -36,15 +34,13 @@ import Gargantext.API.Prelude (GargM, serverError, HasServerError)
...
@@ -36,15 +34,13 @@ import Gargantext.API.Prelude (GargM, serverError, HasServerError)
import
Gargantext.API.Routes.Named.List
qualified
as
Named
import
Gargantext.API.Routes.Named.List
qualified
as
Named
import
Gargantext.API.Worker
(
serveWorkerAPI
,
serveWorkerAPIEJob
)
import
Gargantext.API.Worker
(
serveWorkerAPI
,
serveWorkerAPIEJob
)
import
Gargantext.Core.NodeStory.Types
(
HasNodeStory
)
import
Gargantext.Core.NodeStory.Types
(
HasNodeStory
)
import
Gargantext.Core.Text.Ngrams
(
Ngrams
,
Ngrams
Type
(
NgramsTerms
))
import
Gargantext.Core.Text.Ngrams
(
NgramsType
(
NgramsTerms
))
import
Gargantext.Core.Types.Main
(
ListType
(
..
))
import
Gargantext.Core.Types.Main
(
ListType
(
..
))
import
Gargantext.Core.Worker.Jobs.Types
qualified
as
Jobs
import
Gargantext.Core.Worker.Jobs.Types
qualified
as
Jobs
import
Gargantext.Database.Action.Flow
(
reIndexWith
)
import
Gargantext.Database.Action.Flow
(
reIndexWith
)
import
Gargantext.Database.Admin.Types.Node
(
NodeId
(
_NodeId
),
ListId
)
import
Gargantext.Database.Admin.Types.Node
(
NodeId
(
_NodeId
),
ListId
)
import
Gargantext.Database.Query.Table.Node
(
getNode
)
import
Gargantext.Database.Query.Table.Node
(
getNode
)
import
Gargantext.Database.Schema.Ngrams
(
text2ngrams
,
NgramsId
)
import
Gargantext.Database.Schema.Node
(
_node_parent_id
)
import
Gargantext.Database.Schema.Node
(
_node_parent_id
)
import
Gargantext.Database.Types
(
Indexed
(
..
))
import
Gargantext.Prelude
hiding
(
concat
,
toList
)
import
Gargantext.Prelude
hiding
(
concat
,
toList
)
import
Gargantext.Utils.Jobs.Monad
(
MonadJobStatus
(
..
))
import
Gargantext.Utils.Jobs.Monad
(
MonadJobStatus
(
..
))
import
Prelude
qualified
import
Prelude
qualified
...
@@ -212,14 +208,3 @@ importTsvFile lId fp = do
...
@@ -212,14 +208,3 @@ importTsvFile lId fp = do
case
ngramsListFromTSVData
contents
of
case
ngramsListFromTSVData
contents
of
Left
err
->
serverError
$
err500
{
errReasonPhrase
=
err
}
Left
err
->
serverError
$
err500
{
errReasonPhrase
=
err
}
Right
ngramsList
->
postAsyncJSON
lId
ngramsList
(
noJobHandle
@
m
Proxy
)
Right
ngramsList
->
postAsyncJSON
lId
ngramsList
(
noJobHandle
@
m
Proxy
)
--
-- Utils
--
------------------------------------------------------------------------
toIndexedNgrams
::
HashMap
Text
NgramsId
->
Text
->
Maybe
(
Indexed
Int
Ngrams
)
toIndexedNgrams
m
t
=
Indexed
<$>
i
<*>
n
where
i
=
HashMap
.
lookup
t
m
n
=
Just
(
text2ngrams
t
)
src/Gargantext/API/Ngrams/Tools.hs
View file @
03d2b0e3
...
@@ -11,7 +11,6 @@ Portability : POSIX
...
@@ -11,7 +11,6 @@ Portability : POSIX
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
module
Gargantext.API.Ngrams.Tools
module
Gargantext.API.Ngrams.Tools
where
where
...
@@ -42,19 +41,6 @@ getRepo :: HasNodeStory env err m
...
@@ -42,19 +41,6 @@ getRepo :: HasNodeStory env err m
getRepo
listIds
=
do
getRepo
listIds
=
do
f
<-
getNodeListStoryMulti
f
<-
getNodeListStoryMulti
liftBase
$
f
listIds
liftBase
$
f
listIds
-- v <- liftBase $ f listIds
-- v' <- liftBase $ atomically $ readTVar v
-- pure $ v'
repoSize
::
Ord
k1
=>
NodeStory
(
Map
.
Map
k1
(
Map
.
Map
k2
a
))
p
->
NodeId
->
Map
.
Map
k1
Int
repoSize
repo
node_id
=
Map
.
map
Map
.
size
state'
where
state'
=
repo
^.
unNodeStory
.
at
node_id
.
_Just
.
a_state
getNodeStory
::
HasNodeStory
env
err
m
getNodeStory
::
HasNodeStory
env
err
m
...
@@ -62,8 +48,6 @@ getNodeStory :: HasNodeStory env err m
...
@@ -62,8 +48,6 @@ getNodeStory :: HasNodeStory env err m
getNodeStory
l
=
do
getNodeStory
l
=
do
f
<-
getNodeListStory
f
<-
getNodeListStory
liftBase
$
f
l
liftBase
$
f
l
-- v <- liftBase $ f l
-- pure v
getNodeListStory
::
HasNodeStory
env
err
m
getNodeListStory
::
HasNodeStory
env
err
m
...
@@ -134,19 +118,6 @@ mapTermListRoot nodeIds ngramsType repo =
...
@@ -134,19 +118,6 @@ mapTermListRoot nodeIds ngramsType repo =
<$>
listNgramsFromRepo
nodeIds
ngramsType
repo
<$>
listNgramsFromRepo
nodeIds
ngramsType
repo
filterListWithRootHashMap
::
ListType
->
HashMap
NgramsTerm
(
ListType
,
Maybe
NgramsTerm
)
->
HashMap
NgramsTerm
(
Maybe
RootTerm
)
filterListWithRootHashMap
lt
m
=
snd
<$>
HM
.
filter
isMapTerm
m
where
isMapTerm
(
l
,
maybeRoot
)
=
case
maybeRoot
of
Nothing
->
l
==
lt
Just
r
->
case
HM
.
lookup
r
m
of
Nothing
->
panicTrace
$
"[Garg.API.Ngrams.Tools] filterListWithRootHashMap, unknown key: "
<>
unNgramsTerm
r
Just
(
l'
,
_
)
->
l'
==
lt
filterListWithRoot
::
[
ListType
]
filterListWithRoot
::
[
ListType
]
->
HashMap
NgramsTerm
(
ListType
,
Maybe
NgramsTerm
)
->
HashMap
NgramsTerm
(
ListType
,
Maybe
NgramsTerm
)
->
HashMap
NgramsTerm
(
Maybe
RootTerm
)
->
HashMap
NgramsTerm
(
Maybe
RootTerm
)
...
...
src/Gargantext/API/Ngrams/Types.hs
View file @
03d2b0e3
...
@@ -217,30 +217,6 @@ makePrisms ''NgramsTable
...
@@ -217,30 +217,6 @@ makePrisms ''NgramsTable
instance
Each
NgramsTable
NgramsTable
NgramsElement
NgramsElement
where
instance
Each
NgramsTable
NgramsTable
NgramsElement
NgramsElement
where
each
=
_NgramsTable
.
each
each
=
_NgramsTable
.
each
-- TODO discuss
-- | TODO Check N and Weight
{-
toNgramsElement :: [NgramsTableData] -> [NgramsElement]
toNgramsElement ns = map toNgramsElement' ns
where
toNgramsElement' (NgramsTableData _ p t _ lt w) = NgramsElement t lt' (round w) p' c'
where
p' = case p of
Nothing -> Nothing
Just x -> lookup x mapParent
c' = maybe mempty identity $ lookup t mapChildren
lt' = maybe (panic "API.Ngrams: listypeId") identity lt
mapParent :: Map Int Text
mapParent = Map.fromListWith (<>) $ map (\(NgramsTableData i _ t _ _ _) -> (i,t)) ns
mapChildren :: Map Text (Set Text)
mapChildren = Map.mapKeys (\i -> (maybe (panic "API.Ngrams.mapChildren: ParentId with no Terms: Impossible") identity $ lookup i mapParent))
$ Map.fromListWith (<>)
$ map (first fromJust)
$ filter (isJust . fst)
$ map (\(NgramsTableData _ p t _ _ _) -> (p, Set.singleton t)) ns
-}
instance
ToSchema
NgramsTable
instance
ToSchema
NgramsTable
...
@@ -322,47 +298,6 @@ instance ToJSON a => ToJSON (PatchSet a) where
...
@@ -322,47 +298,6 @@ instance ToJSON a => ToJSON (PatchSet a) where
instance
(
Ord
a
,
FromJSON
a
)
=>
FromJSON
(
PatchSet
a
)
where
instance
(
Ord
a
,
FromJSON
a
)
=>
FromJSON
(
PatchSet
a
)
where
parseJSON
=
genericParseJSON
$
unPrefix
"_"
parseJSON
=
genericParseJSON
$
unPrefix
"_"
{-
instance (Ord a, Arbitrary a) => Arbitrary (PatchSet a) where
arbitrary = PatchSet <$> arbitrary <*> arbitrary
type instance Patched (PatchSet a) = Set a
type ConflictResolutionPatchSet a = SimpleConflictResolution' (Set a)
type instance ConflictResolution (PatchSet a) = ConflictResolutionPatchSet a
instance Ord a => Semigroup (PatchSet a) where
p <> q = PatchSet { _rem = (q ^. rem) `Set.difference` (p ^. add) <> p ^. rem
, _add = (q ^. add) `Set.difference` (p ^. rem) <> p ^. add
} -- TODO Review
instance Ord a => Monoid (PatchSet a) where
mempty = PatchSet mempty mempty
instance Ord a => Group (PatchSet a) where
invert (PatchSet r a) = PatchSet a r
instance Ord a => Composable (PatchSet a) where
composable _ _ = undefined
instance Ord a => Action (PatchSet a) (Set a) where
act p source = (source `Set.difference` (p ^. rem)) <> p ^. add
instance Applicable (PatchSet a) (Set a) where
applicable _ _ = mempty
instance Ord a => Validity (PatchSet a) where
validate p = check (Set.disjoint (p ^. rem) (p ^. add)) "_rem and _add should be dijoint"
instance Ord a => Transformable (PatchSet a) where
transformable = undefined
conflicts _p _q = undefined
transformWith conflict p q = undefined conflict p q
instance ToSchema a => ToSchema (PatchSet a)
-}
type
AddRem
=
Replace
(
Maybe
()
)
type
AddRem
=
Replace
(
Maybe
()
)
...
@@ -722,10 +657,6 @@ instance (ToJSON s, ToJSON p) => ToJSON (Repo s p) where
...
@@ -722,10 +657,6 @@ instance (ToJSON s, ToJSON p) => ToJSON (Repo s p) where
makeLenses
''
R
epo
makeLenses
''
R
epo
initRepo
::
Monoid
s
=>
Repo
s
p
initRepo
=
Repo
1
mempty
[]
--------------------
--------------------
...
...
weeder.toml
View file @
03d2b0e3
...
@@ -13,4 +13,7 @@ roots = [ '^Main\.main$'
...
@@ -13,4 +13,7 @@ roots = [ '^Main\.main$'
# Useful in the REPL. TODO go through each function in this module ---
# Useful in the REPL. TODO go through each function in this module ---
# I don't think we need that many variations around `runCmd`?
# I don't think we need that many variations around `runCmd`?
,
'Gargantext.API.Dev.*'
,
'Gargantext.API.Dev.*'
# This is for debugging the TSV parser in the REPL
,
'Gargantext.API.Ngrams.List.importTsvFile'
]
]
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