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
195
Issues
195
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
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
5f8819bd
Commit
5f8819bd
authored
Dec 23, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[REFACT] HasDBid instance for ListType
parent
77c37772
Pipeline
#1318
failed with stage
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
10 deletions
+18
-10
Learn.hs
src/Gargantext/Core/Text/List/Learn.hs
+4
-3
Main.hs
src/Gargantext/Core/Types/Main.hs
+6
-0
NodeNodeNgrams.hs
src/Gargantext/Database/Admin/Trigger/NodeNodeNgrams.hs
+3
-3
NodesNodes.hs
src/Gargantext/Database/Admin/Trigger/NodesNodes.hs
+3
-3
NodeNgrams.hs
src/Gargantext/Database/Query/Table/NodeNgrams.hs
+2
-1
No files found.
src/Gargantext/Core/Text/List/Learn.hs
View file @
5f8819bd
...
@@ -24,8 +24,9 @@ import qualified Data.Map as Map
...
@@ -24,8 +24,9 @@ import qualified Data.Map as Map
import
qualified
Data.SVM
as
SVM
import
qualified
Data.SVM
as
SVM
import
qualified
Data.Vector
as
Vec
import
qualified
Data.Vector
as
Vec
import
Gargantext.Core
import
Gargantext.Core.Text.Metrics.Count
(
occurrencesWith
)
import
Gargantext.Core.Text.Metrics.Count
(
occurrencesWith
)
import
Gargantext.Core.Types.Main
(
ListType
(
..
)
,
listTypeId
,
fromListTypeId
)
import
Gargantext.Core.Types.Main
(
ListType
(
..
))
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Prelude.Utils
import
Gargantext.Prelude.Utils
...
@@ -43,7 +44,7 @@ trainList :: Double -> Double -> Map ListType [Vec.Vector Double] -> IO SVM.Mode
...
@@ -43,7 +44,7 @@ trainList :: Double -> Double -> Map ListType [Vec.Vector Double] -> IO SVM.Mode
trainList
x
y
=
(
train
x
y
)
.
trainList'
trainList
x
y
=
(
train
x
y
)
.
trainList'
where
where
trainList'
::
Map
ListType
[
Vec
.
Vector
Double
]
->
SVM
.
Problem
trainList'
::
Map
ListType
[
Vec
.
Vector
Double
]
->
SVM
.
Problem
trainList'
=
mapVec2problem
.
(
Map
.
mapKeys
(
fromIntegral
.
listTypeI
d
))
trainList'
=
mapVec2problem
.
(
Map
.
mapKeys
(
fromIntegral
.
toDBi
d
))
mapVec2problem
::
Map
Double
[
Vec
.
Vector
Double
]
->
SVM
.
Problem
mapVec2problem
::
Map
Double
[
Vec
.
Vector
Double
]
->
SVM
.
Problem
mapVec2problem
=
List
.
concat
.
(
map
(
\
(
a
,
as
)
->
zip
(
repeat
a
)
as
))
.
Map
.
toList
.
(
Map
.
map
vecs2maps
)
mapVec2problem
=
List
.
concat
.
(
map
(
\
(
a
,
as
)
->
zip
(
repeat
a
)
as
))
.
Map
.
toList
.
(
Map
.
map
vecs2maps
)
...
@@ -53,7 +54,7 @@ trainList x y = (train x y) . trainList'
...
@@ -53,7 +54,7 @@ trainList x y = (train x y) . trainList'
predictList
::
Model
->
[
Vec
.
Vector
Double
]
->
IO
[
Maybe
ListType
]
predictList
::
Model
->
[
Vec
.
Vector
Double
]
->
IO
[
Maybe
ListType
]
predictList
(
ModelSVM
m
_
_
)
vs
=
map
(
fromListTypeI
d
.
round
)
<$>
predict
m
vs
predictList
(
ModelSVM
m
_
_
)
vs
=
map
(
Just
.
fromDBi
d
.
round
)
<$>
predict
m
vs
------------------------------------------------------------------------
------------------------------------------------------------------------
data
Model
=
ModelSVM
{
modelSVM
::
SVM
.
Model
data
Model
=
ModelSVM
{
modelSVM
::
SVM
.
Model
...
...
src/Gargantext/Core/Types/Main.hs
View file @
5f8819bd
...
@@ -22,10 +22,12 @@ import Data.Aeson.TH (deriveJSON)
...
@@ -22,10 +22,12 @@ import Data.Aeson.TH (deriveJSON)
import
Data.Either
(
Either
(
..
))
import
Data.Either
(
Either
(
..
))
import
Data.Hashable
(
Hashable
)
import
Data.Hashable
(
Hashable
)
import
Data.Map
(
fromList
,
lookup
)
import
Data.Map
(
fromList
,
lookup
)
import
Data.Maybe
(
fromMaybe
)
import
Data.Semigroup
(
Semigroup
(
..
))
import
Data.Semigroup
(
Semigroup
(
..
))
import
Data.Swagger
import
Data.Swagger
import
Data.Text
(
Text
,
unpack
)
import
Data.Text
(
Text
,
unpack
)
import
GHC.Generics
(
Generic
)
import
GHC.Generics
(
Generic
)
import
Gargantext.Core
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
,
wellNamedSchema
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
,
wellNamedSchema
)
import
Gargantext.Database.Admin.Types.Node
-- (NodeType(..), Node, Hyperdata(..))
import
Gargantext.Database.Admin.Types.Node
-- (NodeType(..), Node, Hyperdata(..))
import
Gargantext.Prelude
import
Gargantext.Prelude
...
@@ -76,6 +78,10 @@ instance FromHttpApiData ListType where
...
@@ -76,6 +78,10 @@ instance FromHttpApiData ListType where
type
ListTypeId
=
Int
type
ListTypeId
=
Int
instance
HasDBid
ListType
where
toDBid
=
listTypeId
fromDBid
=
(
fromMaybe
(
panic
"Instance HasDBid fromDBid ListType"
))
.
fromListTypeId
-- FIXME Candidate: 0 and Stop : 1
-- FIXME Candidate: 0 and Stop : 1
listTypeId
::
ListType
->
ListTypeId
listTypeId
::
ListType
->
ListTypeId
listTypeId
StopTerm
=
0
listTypeId
StopTerm
=
0
...
...
src/Gargantext/Database/Admin/Trigger/NodeNodeNgrams.hs
View file @
5f8819bd
...
@@ -18,7 +18,7 @@ module Gargantext.Database.Admin.Trigger.NodeNodeNgrams
...
@@ -18,7 +18,7 @@ module Gargantext.Database.Admin.Trigger.NodeNodeNgrams
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Gargantext.Core
import
Gargantext.Core
import
Gargantext.Core.Types.Main
(
listTypeId
,
ListType
(
CandidateTerm
))
import
Gargantext.Core.Types.Main
(
ListType
(
CandidateTerm
))
import
Gargantext.Database.Admin.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Database.Admin.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Database.Prelude
(
Cmd
,
execPGSQuery
)
import
Gargantext.Database.Prelude
(
Cmd
,
execPGSQuery
)
import
Gargantext.Prelude
import
Gargantext.Prelude
...
@@ -108,8 +108,8 @@ triggerCoocInsert :: HasDBid NodeType => Cmd err Int64
...
@@ -108,8 +108,8 @@ triggerCoocInsert :: HasDBid NodeType => Cmd err Int64
triggerCoocInsert
=
execPGSQuery
query
(
toDBid
NodeCorpus
triggerCoocInsert
=
execPGSQuery
query
(
toDBid
NodeCorpus
,
toDBid
NodeDocument
,
toDBid
NodeDocument
,
toDBid
NodeList
,
toDBid
NodeList
,
listTypeI
d
CandidateTerm
,
toDBi
d
CandidateTerm
,
listTypeI
d
CandidateTerm
,
toDBi
d
CandidateTerm
)
)
where
where
query
::
DPS
.
Query
query
::
DPS
.
Query
...
...
src/Gargantext/Database/Admin/Trigger/NodesNodes.hs
View file @
5f8819bd
...
@@ -21,7 +21,7 @@ import Database.PostgreSQL.Simple.SqlQQ (sql)
...
@@ -21,7 +21,7 @@ import Database.PostgreSQL.Simple.SqlQQ (sql)
import
Gargantext.Core
import
Gargantext.Core
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Admin.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Database.Admin.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Core.Types.Main
(
listTypeId
,
ListType
(
CandidateTerm
))
import
Gargantext.Core.Types.Main
(
ListType
(
CandidateTerm
))
import
Gargantext.Database.Prelude
(
Cmd
,
execPGSQuery
)
import
Gargantext.Database.Prelude
(
Cmd
,
execPGSQuery
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
qualified
Database.PostgreSQL.Simple
as
DPS
import
qualified
Database.PostgreSQL.Simple
as
DPS
...
@@ -162,8 +162,8 @@ triggerCoocInsert lid = execPGSQuery query ( lid
...
@@ -162,8 +162,8 @@ triggerCoocInsert lid = execPGSQuery query ( lid
-- , nodeTypeId NodeCorpus
-- , nodeTypeId NodeCorpus
-- , nodeTypeId NodeDocument
-- , nodeTypeId NodeDocument
-- , nodeTypeId NodeList
-- , nodeTypeId NodeList
,
listTypeI
d
CandidateTerm
,
toDBi
d
CandidateTerm
,
listTypeI
d
CandidateTerm
,
toDBi
d
CandidateTerm
)
)
where
where
query
::
DPS
.
Query
query
::
DPS
.
Query
...
...
src/Gargantext/Database/Query/Table/NodeNgrams.hs
View file @
5f8819bd
...
@@ -34,6 +34,7 @@ import Database.PostgreSQL.Simple.FromRow (fromRow, field)
...
@@ -34,6 +34,7 @@ import Database.PostgreSQL.Simple.FromRow (fromRow, field)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.ToField
(
toField
)
import
Database.PostgreSQL.Simple.ToField
(
toField
)
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Gargantext.Core
import
Gargantext.Core.Types
import
Gargantext.Core.Types
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
import
Gargantext.Database.Schema.Ngrams
(
NgramsType
,
ngramsTypeId
,
fromNgramsTypeId
)
import
Gargantext.Database.Schema.Ngrams
(
NgramsType
,
ngramsTypeId
,
fromNgramsTypeId
)
...
@@ -82,7 +83,7 @@ insertNodeNgrams nns = runPGSQuery query (PGS.Only $ Values fields nns')
...
@@ -82,7 +83,7 @@ insertNodeNgrams nns = runPGSQuery query (PGS.Only $ Values fields nns')
-- nns' :: [(Int, ListTypeId, NgramsText, NgramsTypeId ,NgramsField, NgramsTag, NgramsClass, Double)]
-- nns' :: [(Int, ListTypeId, NgramsText, NgramsTypeId ,NgramsField, NgramsTag, NgramsClass, Double)]
nns'
=
map
(
\
(
NodeNgrams
_id
(
NodeId
node_id''
)
node_subtype
ngrams_terms
ngrams_type
ngrams_field
ngrams_tag
ngrams_class
weight
)
nns'
=
map
(
\
(
NodeNgrams
_id
(
NodeId
node_id''
)
node_subtype
ngrams_terms
ngrams_type
ngrams_field
ngrams_tag
ngrams_class
weight
)
->
[
toField
node_id''
->
[
toField
node_id''
,
toField
$
listTypeI
d
node_subtype
,
toField
$
toDBi
d
node_subtype
,
toField
$
ngrams_terms
,
toField
$
ngrams_terms
,
toField
$
ngramsTypeId
ngrams_type
,
toField
$
ngramsTypeId
ngrams_type
,
toField
$
fromMaybe
0
ngrams_field
,
toField
$
fromMaybe
0
ngrams_field
...
...
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