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
154
Issues
154
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
b5c9a011
Commit
b5c9a011
authored
Dec 22, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[REFACT] HasDBid
parent
bb4b74f6
Pipeline
#1317
failed with stage
Changes
24
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
219 additions
and
146 deletions
+219
-146
Core.hs
src/Gargantext/Core.hs
+29
-3
Terms.hs
src/Gargantext/Core/Text/Terms.hs
+3
-1
Multi.hs
src/Gargantext/Core/Text/Terms/Multi.hs
+8
-3
Delete.hs
src/Gargantext/Database/Action/Delete.hs
+5
-4
Flow.hs
src/Gargantext/Database/Action/Flow.hs
+1
-2
Pairing.hs
src/Gargantext/Database/Action/Flow/Pairing.hs
+2
-1
NgramsByNode.hs
src/Gargantext/Database/Action/Metrics/NgramsByNode.hs
+39
-27
TFICF.hs
src/Gargantext/Database/Action/Metrics/TFICF.hs
+3
-1
Search.hs
src/Gargantext/Database/Action/Search.hs
+7
-6
Config.hs
src/Gargantext/Database/Admin/Config.hs
+11
-3
NodeNodeNgrams.hs
src/Gargantext/Database/Admin/Trigger/NodeNodeNgrams.hs
+12
-13
Nodes.hs
src/Gargantext/Database/Admin/Trigger/Nodes.hs
+11
-12
NodesNodes.hs
src/Gargantext/Database/Admin/Trigger/NodesNodes.hs
+3
-2
Node.hs
src/Gargantext/Database/Admin/Types/Node.hs
+4
-4
Facet.hs
src/Gargantext/Database/Query/Facet.hs
+9
-8
NgramsPostag.hs
src/Gargantext/Database/Query/Table/NgramsPostag.hs
+3
-0
Node.hs
src/Gargantext/Database/Query/Table/Node.hs
+8
-8
Children.hs
src/Gargantext/Database/Query/Table/Node/Children.hs
+8
-7
Insert.hs
src/Gargantext/Database/Query/Table/Node/Document/Insert.hs
+11
-11
Select.hs
src/Gargantext/Database/Query/Table/Node/Select.hs
+3
-3
NodeNode.hs
src/Gargantext/Database/Query/Table/NodeNode.hs
+14
-14
Tree.hs
src/Gargantext/Database/Query/Tree.hs
+7
-7
Root.hs
src/Gargantext/Database/Query/Tree/Root.hs
+5
-4
NgramsPostag.hs
src/Gargantext/Database/Schema/NgramsPostag.hs
+13
-2
No files found.
src/Gargantext/Core.hs
View file @
b5c9a011
...
@@ -18,6 +18,7 @@ import Data.Aeson
...
@@ -18,6 +18,7 @@ import Data.Aeson
import
Data.Either
(
Either
(
Left
))
import
Data.Either
(
Either
(
Left
))
import
Data.Swagger
import
Data.Swagger
import
Servant.API
import
Servant.API
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Language of a Text
-- | Language of a Text
-- For simplicity, we suppose text has an homogenous language
-- For simplicity, we suppose text has an homogenous language
...
@@ -42,9 +43,34 @@ instance FromJSON Lang
...
@@ -42,9 +43,34 @@ instance FromJSON Lang
instance
ToSchema
Lang
instance
ToSchema
Lang
instance
FromHttpApiData
Lang
instance
FromHttpApiData
Lang
where
where
parseUrlPiece
"EN"
=
pure
EN
parseUrlPiece
"EN"
=
pure
EN
parseUrlPiece
"FR"
=
pure
FR
parseUrlPiece
"FR"
=
pure
FR
parseUrlPiece
"All"
=
pure
All
parseUrlPiece
"All"
=
pure
All
parseUrlPiece
_
=
Left
"Unexpected value of OrderBy"
parseUrlPiece
_
=
Left
"Unexpected value of OrderBy"
allLangs
::
[
Lang
]
allLangs
::
[
Lang
]
allLangs
=
[
minBound
..
]
allLangs
=
[
minBound
..
]
class
HasDBid
a
where
hasDBid
::
a
->
Int
fromDBid
::
Int
->
a
instance
HasDBid
Lang
where
hasDBid
All
=
0
hasDBid
FR
=
1
hasDBid
EN
=
2
fromDBid
0
=
All
fromDBid
1
=
FR
fromDBid
2
=
EN
fromDBid
_
=
panic
"HasDBid lang, not implemented"
------------------------------------------------------------------------
data
PostTagAlgo
=
CoreNLP
deriving
(
Show
,
Read
)
instance
HasDBid
PostTagAlgo
where
hasDBid
CoreNLP
=
1
fromDBid
1
=
CoreNLP
fromDBid
_
=
panic
"HasDBid posTagAlgo : Not implemented"
src/Gargantext/Core/Text/Terms.hs
View file @
b5c9a011
...
@@ -63,7 +63,7 @@ data TermType lang
...
@@ -63,7 +63,7 @@ data TermType lang
=
Mono
{
_tt_lang
::
!
lang
}
=
Mono
{
_tt_lang
::
!
lang
}
|
Multi
{
_tt_lang
::
!
lang
}
|
Multi
{
_tt_lang
::
!
lang
}
|
MonoMulti
{
_tt_lang
::
!
lang
}
|
MonoMulti
{
_tt_lang
::
!
lang
}
|
Unsupervised
{
_tt_lang
::
!
lang
|
Unsupervised
{
_tt_lang
::
!
lang
,
_tt_windowSize
::
!
Int
,
_tt_windowSize
::
!
Int
,
_tt_ngramsSize
::
!
Int
,
_tt_ngramsSize
::
!
Int
,
_tt_model
::
!
(
Maybe
(
Tries
Token
()
))
,
_tt_model
::
!
(
Maybe
(
Tries
Token
()
))
...
@@ -140,6 +140,8 @@ terms (Unsupervised lang n s m) txt = termsUnsupervised (Unsupervised lang n s (
...
@@ -140,6 +140,8 @@ terms (Unsupervised lang n s m) txt = termsUnsupervised (Unsupervised lang n s (
where
where
m'
=
maybe
(
newTries
n
txt
)
identity
m
m'
=
maybe
(
newTries
n
txt
)
identity
m
-- terms (WithList list) txt = pure . concat $ extractTermsWithList list txt
-- terms (WithList list) txt = pure . concat $ extractTermsWithList list txt
------------------------------------------------------------------------
------------------------------------------------------------------------
text2term
::
Lang
->
[
Text
]
->
Terms
text2term
::
Lang
->
[
Text
]
->
Terms
...
...
src/Gargantext/Core/Text/Terms/Multi.hs
View file @
b5c9a011
...
@@ -28,12 +28,17 @@ import qualified Gargantext.Core.Text.Terms.Multi.Lang.Fr as Fr
...
@@ -28,12 +28,17 @@ import qualified Gargantext.Core.Text.Terms.Multi.Lang.Fr as Fr
import
Gargantext.Core.Text.Terms.Multi.RAKE
(
multiterms_rake
)
import
Gargantext.Core.Text.Terms.Multi.RAKE
(
multiterms_rake
)
-------------------------------------------------------------------
-- To be removed
multiterms
::
Lang
->
Text
->
IO
[
Terms
]
multiterms
::
Lang
->
Text
->
IO
[
Terms
]
multiterms
lang
txt
=
concat
multiterms
=
multiterms'
tokenTag2terms
<$>
map
(
map
tokenTag2terms
)
multiterms'
::
(
TokenTag
->
a
)
->
Lang
->
Text
->
IO
[
a
]
multiterms'
f
lang
txt
=
concat
<$>
map
(
map
f
)
<$>
map
(
filter
(
\
t
->
_my_token_pos
t
==
Just
NP
))
<$>
map
(
filter
(
\
t
->
_my_token_pos
t
==
Just
NP
))
<$>
tokenTags
lang
txt
<$>
tokenTags
lang
txt
-------------------------------------------------------------------
tokenTag2terms
::
TokenTag
->
Terms
tokenTag2terms
::
TokenTag
->
Terms
tokenTag2terms
(
TokenTag
ws
t
_
_
)
=
Terms
ws
t
tokenTag2terms
(
TokenTag
ws
t
_
_
)
=
Terms
ws
t
...
...
src/Gargantext/Database/Action/Delete.hs
View file @
b5c9a011
...
@@ -24,7 +24,8 @@ import Servant
...
@@ -24,7 +24,8 @@ import Servant
import
Gargantext.Core.Types.Individu
(
User
(
..
))
import
Gargantext.Core.Types.Individu
(
User
(
..
))
import
Gargantext.Database.Action.User
(
getUserId
)
import
Gargantext.Database.Action.User
(
getUserId
)
import
Gargantext.Database.Action.Share
(
delFolderTeam
)
import
Gargantext.Database.Action.Share
(
delFolderTeam
)
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
import
Gargantext.Core
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Admin.Types.Hyperdata.File
import
Gargantext.Database.Admin.Types.Hyperdata.File
import
Gargantext.Database.Admin.Types.Node
-- (NodeType(..))
import
Gargantext.Database.Admin.Types.Node
-- (NodeType(..))
import
Gargantext.Database.Prelude
(
Cmd
'
,
HasConfig
,
HasConnectionPool
)
import
Gargantext.Database.Prelude
(
Cmd
'
,
HasConfig
,
HasConnectionPool
)
...
@@ -44,13 +45,13 @@ deleteNode :: (HasConfig env, HasConnectionPool env, HasNodeError err)
...
@@ -44,13 +45,13 @@ deleteNode :: (HasConfig env, HasConnectionPool env, HasNodeError err)
deleteNode
u
nodeId
=
do
deleteNode
u
nodeId
=
do
node'
<-
N
.
getNode
nodeId
node'
<-
N
.
getNode
nodeId
case
(
view
node_typename
node'
)
of
case
(
view
node_typename
node'
)
of
nt
|
nt
==
nodeTypeI
d
NodeUser
->
panic
"Not allowed to delete NodeUser (yet)"
nt
|
nt
==
hasDBi
d
NodeUser
->
panic
"Not allowed to delete NodeUser (yet)"
nt
|
nt
==
nodeTypeI
d
NodeTeam
->
do
nt
|
nt
==
hasDBi
d
NodeTeam
->
do
uId
<-
getUserId
u
uId
<-
getUserId
u
if
_node_userId
node'
==
uId
if
_node_userId
node'
==
uId
then
N
.
deleteNode
nodeId
then
N
.
deleteNode
nodeId
else
delFolderTeam
u
nodeId
else
delFolderTeam
u
nodeId
nt
|
nt
==
nodeTypeI
d
NodeFile
->
do
nt
|
nt
==
hasDBi
d
NodeFile
->
do
node
<-
getNodeWith
nodeId
(
Proxy
::
Proxy
HyperdataFile
)
node
<-
getNodeWith
nodeId
(
Proxy
::
Proxy
HyperdataFile
)
let
(
HyperdataFile
{
_hff_path
=
path
})
=
node
^.
node_hyperdata
let
(
HyperdataFile
{
_hff_path
=
path
})
=
node
^.
node_hyperdata
GPU
.
removeFile
$
unpack
path
GPU
.
removeFile
$
unpack
path
...
...
src/Gargantext/Database/Action/Flow.hs
View file @
b5c9a011
...
@@ -258,8 +258,7 @@ insertMasterDocs c lang hs = do
...
@@ -258,8 +258,7 @@ insertMasterDocs c lang hs = do
-- this will enable global database monitoring
-- this will enable global database monitoring
-- maps :: IO Map Ngrams (Map NgramsType (Map NodeId Int))
-- maps :: IO Map Ngrams (Map NgramsType (Map NodeId Int))
mapNgramsDocs
<-
mapNodeIdNgrams
mapNgramsDocs
<-
mapNodeIdNgrams
<$>
documentIdWithNgrams
(
extractNgramsT
$
withLang
lang
documentsWithId
)
documentsWithId
<$>
documentIdWithNgrams
(
extractNgramsT
$
withLang
lang
documentsWithId
)
documentsWithId
terms2id
<-
insertNgrams
$
Map
.
keys
mapNgramsDocs
terms2id
<-
insertNgrams
$
Map
.
keys
mapNgramsDocs
-- to be removed
-- to be removed
...
...
src/Gargantext/Database/Action/Flow/Pairing.hs
View file @
b5c9a011
...
@@ -24,6 +24,7 @@ import Data.Set (Set)
...
@@ -24,6 +24,7 @@ import Data.Set (Set)
import
Gargantext.API.Ngrams.Tools
import
Gargantext.API.Ngrams.Tools
import
Gargantext.API.Ngrams.Types
(
NgramsTerm
(
..
))
import
Gargantext.API.Ngrams.Types
(
NgramsTerm
(
..
))
import
Gargantext.API.Prelude
(
GargNoServer
)
import
Gargantext.API.Prelude
(
GargNoServer
)
import
Gargantext.Core
import
Gargantext.Core.Types
(
TableResult
(
..
))
import
Gargantext.Core.Types
(
TableResult
(
..
))
import
Gargantext.Core.Types.Main
import
Gargantext.Core.Types.Main
import
Gargantext.Database
import
Gargantext.Database
...
@@ -54,7 +55,7 @@ isPairedWith nId nt = runOpaQuery (selectQuery nt nId)
...
@@ -54,7 +55,7 @@ isPairedWith nId nt = runOpaQuery (selectQuery nt nId)
selectQuery
::
NodeType
->
NodeId
->
Query
(
Column
PGInt4
)
selectQuery
::
NodeType
->
NodeId
->
Query
(
Column
PGInt4
)
selectQuery
nt'
nId'
=
proc
()
->
do
selectQuery
nt'
nId'
=
proc
()
->
do
(
node
,
node_node
)
<-
queryJoin
-<
()
(
node
,
node_node
)
<-
queryJoin
-<
()
restrict
-<
(
node
^.
node_typename
)
.==
(
pgInt4
$
nodeTypeI
d
nt'
)
restrict
-<
(
node
^.
node_typename
)
.==
(
pgInt4
$
hasDBi
d
nt'
)
restrict
-<
(
node_node
^.
nn_node1_id
)
.==
(
toNullable
$
pgNodeId
nId'
)
restrict
-<
(
node_node
^.
nn_node1_id
)
.==
(
toNullable
$
pgNodeId
nId'
)
returnA
-<
node
^.
node_id
returnA
-<
node
^.
node_id
...
...
src/Gargantext/Database/Action/Metrics/NgramsByNode.hs
View file @
b5c9a011
...
@@ -25,9 +25,9 @@ import Data.Tuple.Extra (first, second, swap)
...
@@ -25,9 +25,9 @@ import Data.Tuple.Extra (first, second, swap)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Debug.Trace
(
trace
)
import
Debug.Trace
(
trace
)
import
Gargantext.Core
import
Gargantext.API.Ngrams.Types
(
NgramsTerm
(
..
))
import
Gargantext.API.Ngrams.Types
(
NgramsTerm
(
..
))
import
Gargantext.Data.HashMap.Strict.Utils
as
HM
import
Gargantext.Data.HashMap.Strict.Utils
as
HM
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
import
Gargantext.Database.Admin.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Database.Admin.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
)
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
)
import
Gargantext.Database.Schema.Ngrams
(
ngramsTypeId
,
NgramsType
(
..
))
import
Gargantext.Database.Schema.Ngrams
(
ngramsTypeId
,
NgramsType
(
..
))
...
@@ -57,7 +57,8 @@ groupNodesByNgramsWith f m =
...
@@ -57,7 +57,8 @@ groupNodesByNgramsWith f m =
$
HM
.
toList
m
$
HM
.
toList
m
------------------------------------------------------------------------
------------------------------------------------------------------------
getNodesByNgramsUser
::
CorpusId
getNodesByNgramsUser
::
HasDBid
NodeType
=>
CorpusId
->
NgramsType
->
NgramsType
->
Cmd
err
(
HashMap
NgramsTerm
(
Set
NodeId
))
->
Cmd
err
(
HashMap
NgramsTerm
(
Set
NodeId
))
getNodesByNgramsUser
cId
nt
=
getNodesByNgramsUser
cId
nt
=
...
@@ -65,13 +66,14 @@ getNodesByNgramsUser cId nt =
...
@@ -65,13 +66,14 @@ getNodesByNgramsUser cId nt =
<$>
selectNgramsByNodeUser
cId
nt
<$>
selectNgramsByNodeUser
cId
nt
where
where
selectNgramsByNodeUser
::
CorpusId
selectNgramsByNodeUser
::
HasDBid
NodeType
=>
CorpusId
->
NgramsType
->
NgramsType
->
Cmd
err
[(
NodeId
,
Text
)]
->
Cmd
err
[(
NodeId
,
Text
)]
selectNgramsByNodeUser
cId'
nt'
=
selectNgramsByNodeUser
cId'
nt'
=
runPGSQuery
queryNgramsByNodeUser
runPGSQuery
queryNgramsByNodeUser
(
cId'
(
cId'
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
ngramsTypeId
nt'
,
ngramsTypeId
nt'
-- , 100 :: Int -- limit
-- , 100 :: Int -- limit
-- , 0 :: Int -- offset
-- , 0 :: Int -- offset
...
@@ -84,7 +86,7 @@ getNodesByNgramsUser cId nt =
...
@@ -84,7 +86,7 @@ getNodesByNgramsUser cId nt =
JOIN nodes_nodes nn ON nn.node2_id = nng.node2_id
JOIN nodes_nodes nn ON nn.node2_id = nng.node2_id
JOIN nodes n ON nn.node2_id = n.id
JOIN nodes n ON nn.node2_id = n.id
WHERE nn.node1_id = ? -- CorpusId
WHERE nn.node1_id = ? -- CorpusId
AND n.typename = ? --
NodeTypeI
d
AND n.typename = ? --
hasDBi
d
AND nng.ngrams_type = ? -- NgramsTypeId
AND nng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
GROUP BY nng.node2_id, ng.terms
GROUP BY nng.node2_id, ng.terms
...
@@ -94,7 +96,8 @@ getNodesByNgramsUser cId nt =
...
@@ -94,7 +96,8 @@ getNodesByNgramsUser cId nt =
|]
|]
------------------------------------------------------------------------
------------------------------------------------------------------------
-- TODO add groups
-- TODO add groups
getOccByNgramsOnlyFast
::
CorpusId
getOccByNgramsOnlyFast
::
HasDBid
NodeType
=>
CorpusId
->
NgramsType
->
NgramsType
->
[
NgramsTerm
]
->
[
NgramsTerm
]
->
Cmd
err
(
HashMap
NgramsTerm
Int
)
->
Cmd
err
(
HashMap
NgramsTerm
Int
)
...
@@ -140,7 +143,8 @@ getOccByNgramsOnlyFast' cId lId nt tms = trace (show (cId, lId)) $
...
@@ -140,7 +143,8 @@ getOccByNgramsOnlyFast' cId lId nt tms = trace (show (cId, lId)) $
-- just slower than getOccByNgramsOnlyFast
-- just slower than getOccByNgramsOnlyFast
getOccByNgramsOnlySlow
::
NodeType
getOccByNgramsOnlySlow
::
HasDBid
NodeType
=>
NodeType
->
CorpusId
->
CorpusId
->
[
ListId
]
->
[
ListId
]
->
NgramsType
->
NgramsType
...
@@ -153,7 +157,8 @@ getOccByNgramsOnlySlow t cId ls nt ngs =
...
@@ -153,7 +157,8 @@ getOccByNgramsOnlySlow t cId ls nt ngs =
getScore'
NodeDocument
=
getNgramsByDocOnlyUser
getScore'
NodeDocument
=
getNgramsByDocOnlyUser
getScore'
_
=
getNodesByNgramsOnlyUser
getScore'
_
=
getNodesByNgramsOnlyUser
getOccByNgramsOnlySafe
::
CorpusId
getOccByNgramsOnlySafe
::
HasDBid
NodeType
=>
CorpusId
->
[
ListId
]
->
[
ListId
]
->
NgramsType
->
NgramsType
->
[
NgramsTerm
]
->
[
NgramsTerm
]
...
@@ -169,7 +174,8 @@ getOccByNgramsOnlySafe cId ls nt ngs = do
...
@@ -169,7 +174,8 @@ getOccByNgramsOnlySafe cId ls nt ngs = do
pure
slow
pure
slow
selectNgramsOccurrencesOnlyByNodeUser
::
CorpusId
selectNgramsOccurrencesOnlyByNodeUser
::
HasDBid
NodeType
=>
CorpusId
->
NgramsType
->
NgramsType
->
[
NgramsTerm
]
->
[
NgramsTerm
]
->
Cmd
err
[(
NgramsTerm
,
Int
)]
->
Cmd
err
[(
NgramsTerm
,
Int
)]
...
@@ -178,7 +184,7 @@ selectNgramsOccurrencesOnlyByNodeUser cId nt tms =
...
@@ -178,7 +184,7 @@ selectNgramsOccurrencesOnlyByNodeUser cId nt tms =
runPGSQuery
queryNgramsOccurrencesOnlyByNodeUser
runPGSQuery
queryNgramsOccurrencesOnlyByNodeUser
(
Values
fields
((
DPS
.
Only
.
unNgramsTerm
)
<$>
tms
)
(
Values
fields
((
DPS
.
Only
.
unNgramsTerm
)
<$>
tms
)
,
cId
,
cId
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
ngramsTypeId
nt
,
ngramsTypeId
nt
)
)
where
where
...
@@ -196,7 +202,7 @@ queryNgramsOccurrencesOnlyByNodeUser = [sql|
...
@@ -196,7 +202,7 @@ queryNgramsOccurrencesOnlyByNodeUser = [sql|
JOIN nodes_nodes nn ON nn.node2_id = nng.node2_id
JOIN nodes_nodes nn ON nn.node2_id = nng.node2_id
JOIN nodes n ON nn.node2_id = n.id
JOIN nodes n ON nn.node2_id = n.id
WHERE nn.node1_id = ? -- CorpusId
WHERE nn.node1_id = ? -- CorpusId
AND n.typename = ? --
NodeTypeI
d
AND n.typename = ? --
hasDBi
d
AND nng.ngrams_type = ? -- NgramsTypeId
AND nng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
GROUP BY nng.node2_id, ng.terms
GROUP BY nng.node2_id, ng.terms
...
@@ -211,14 +217,15 @@ queryNgramsOccurrencesOnlyByNodeUser' = [sql|
...
@@ -211,14 +217,15 @@ queryNgramsOccurrencesOnlyByNodeUser' = [sql|
JOIN nodes_nodes nn ON nn.node2_id = nng.node2_id
JOIN nodes_nodes nn ON nn.node2_id = nng.node2_id
JOIN nodes n ON nn.node2_id = n.id
JOIN nodes n ON nn.node2_id = n.id
WHERE nn.node1_id = ? -- CorpusId
WHERE nn.node1_id = ? -- CorpusId
AND n.typename = ? --
NodeTypeI
d
AND n.typename = ? --
hasDBi
d
AND nng.ngrams_type = ? -- NgramsTypeId
AND nng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
GROUP BY nng.node2_id, ng.terms
GROUP BY nng.node2_id, ng.terms
|]
|]
------------------------------------------------------------------------
------------------------------------------------------------------------
getNodesByNgramsOnlyUser
::
CorpusId
getNodesByNgramsOnlyUser
::
HasDBid
NodeType
=>
CorpusId
->
[
ListId
]
->
[
ListId
]
->
NgramsType
->
NgramsType
->
[
NgramsTerm
]
->
[
NgramsTerm
]
...
@@ -231,7 +238,8 @@ getNodesByNgramsOnlyUser cId ls nt ngs =
...
@@ -231,7 +238,8 @@ getNodesByNgramsOnlyUser cId ls nt ngs =
(
splitEvery
1000
ngs
)
(
splitEvery
1000
ngs
)
getNgramsByNodeOnlyUser
::
NodeId
getNgramsByNodeOnlyUser
::
HasDBid
NodeType
=>
NodeId
->
[
ListId
]
->
[
ListId
]
->
NgramsType
->
NgramsType
->
[
NgramsTerm
]
->
[
NgramsTerm
]
...
@@ -246,7 +254,8 @@ getNgramsByNodeOnlyUser cId ls nt ngs =
...
@@ -246,7 +254,8 @@ getNgramsByNodeOnlyUser cId ls nt ngs =
(
splitEvery
1000
ngs
)
(
splitEvery
1000
ngs
)
------------------------------------------------------------------------
------------------------------------------------------------------------
selectNgramsOnlyByNodeUser
::
CorpusId
selectNgramsOnlyByNodeUser
::
HasDBid
NodeType
=>
CorpusId
->
[
ListId
]
->
[
ListId
]
->
NgramsType
->
NgramsType
->
[
NgramsTerm
]
->
[
NgramsTerm
]
...
@@ -258,7 +267,7 @@ selectNgramsOnlyByNodeUser cId ls nt tms =
...
@@ -258,7 +267,7 @@ selectNgramsOnlyByNodeUser cId ls nt tms =
,
Values
[
QualifiedIdentifier
Nothing
"int4"
]
,
Values
[
QualifiedIdentifier
Nothing
"int4"
]
(
DPS
.
Only
<$>
(
map
(
\
(
NodeId
n
)
->
n
)
ls
))
(
DPS
.
Only
<$>
(
map
(
\
(
NodeId
n
)
->
n
)
ls
))
,
cId
,
cId
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
ngramsTypeId
nt
,
ngramsTypeId
nt
)
)
where
where
...
@@ -275,14 +284,15 @@ queryNgramsOnlyByNodeUser = [sql|
...
@@ -275,14 +284,15 @@ queryNgramsOnlyByNodeUser = [sql|
JOIN nodes_nodes nn ON nn.node2_id = nng.node2_id
JOIN nodes_nodes nn ON nn.node2_id = nng.node2_id
JOIN nodes n ON nn.node2_id = n.id
JOIN nodes n ON nn.node2_id = n.id
WHERE nn.node1_id = ? -- CorpusId
WHERE nn.node1_id = ? -- CorpusId
AND n.typename = ? --
NodeTypeI
d
AND n.typename = ? --
hasDBi
d
AND nng.ngrams_type = ? -- NgramsTypeId
AND nng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
GROUP BY ng.terms, nng.node2_id
GROUP BY ng.terms, nng.node2_id
|]
|]
selectNgramsOnlyByNodeUser'
::
CorpusId
selectNgramsOnlyByNodeUser'
::
HasDBid
NodeType
=>
CorpusId
->
[
ListId
]
->
[
ListId
]
->
NgramsType
->
NgramsType
->
[
Text
]
->
[
Text
]
...
@@ -293,7 +303,7 @@ selectNgramsOnlyByNodeUser' cId ls nt tms =
...
@@ -293,7 +303,7 @@ selectNgramsOnlyByNodeUser' cId ls nt tms =
,
Values
[
QualifiedIdentifier
Nothing
"int4"
]
,
Values
[
QualifiedIdentifier
Nothing
"int4"
]
(
DPS
.
Only
<$>
(
map
(
\
(
NodeId
n
)
->
n
)
ls
))
(
DPS
.
Only
<$>
(
map
(
\
(
NodeId
n
)
->
n
)
ls
))
,
cId
,
cId
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
ngramsTypeId
nt
,
ngramsTypeId
nt
)
)
where
where
...
@@ -358,14 +368,16 @@ queryNgramsOnlyByDocUser = [sql|
...
@@ -358,14 +368,16 @@ queryNgramsOnlyByDocUser = [sql|
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | TODO filter by language, database, any social field
-- | TODO filter by language, database, any social field
getNodesByNgramsMaster
::
UserCorpusId
->
MasterCorpusId
->
Cmd
err
(
HashMap
Text
(
Set
NodeId
))
getNodesByNgramsMaster
::
HasDBid
NodeType
=>
UserCorpusId
->
MasterCorpusId
->
Cmd
err
(
HashMap
Text
(
Set
NodeId
))
getNodesByNgramsMaster
ucId
mcId
=
unionsWith
(
<>
)
getNodesByNgramsMaster
ucId
mcId
=
unionsWith
(
<>
)
.
map
(
HM
.
fromListWith
(
<>
)
.
map
(
\
(
n
,
t
)
->
(
t
,
Set
.
singleton
n
)))
.
map
(
HM
.
fromListWith
(
<>
)
.
map
(
\
(
n
,
t
)
->
(
t
,
Set
.
singleton
n
)))
-- . takeWhile (not . List.null)
-- . takeWhile (not . List.null)
-- . takeWhile (\l -> List.length l > 3)
-- . takeWhile (\l -> List.length l > 3)
<$>
mapM
(
selectNgramsByNodeMaster
1000
ucId
mcId
)
[
0
,
500
..
10000
]
<$>
mapM
(
selectNgramsByNodeMaster
1000
ucId
mcId
)
[
0
,
500
..
10000
]
selectNgramsByNodeMaster
::
Int
selectNgramsByNodeMaster
::
HasDBid
NodeType
=>
Int
->
UserCorpusId
->
UserCorpusId
->
MasterCorpusId
->
MasterCorpusId
->
Int
->
Int
...
@@ -374,13 +386,13 @@ selectNgramsByNodeMaster n ucId mcId p = runPGSQuery
...
@@ -374,13 +386,13 @@ selectNgramsByNodeMaster n ucId mcId p = runPGSQuery
queryNgramsByNodeMaster'
queryNgramsByNodeMaster'
(
ucId
(
ucId
,
ngramsTypeId
NgramsTerms
,
ngramsTypeId
NgramsTerms
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
p
,
p
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
p
,
p
,
n
,
n
,
mcId
,
mcId
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
ngramsTypeId
NgramsTerms
,
ngramsTypeId
NgramsTerms
)
)
...
@@ -394,7 +406,7 @@ queryNgramsByNodeMaster' = [sql|
...
@@ -394,7 +406,7 @@ queryNgramsByNodeMaster' = [sql|
JOIN node_node_ngrams nng ON nng.node2_id = n.id
JOIN node_node_ngrams nng ON nng.node2_id = n.id
JOIN ngrams ng ON nng.ngrams_id = ng.id
JOIN ngrams ng ON nng.ngrams_id = ng.id
WHERE nn.node1_id = ? -- UserCorpusId
WHERE nn.node1_id = ? -- UserCorpusId
-- AND n.typename = ? --
NodeTypeI
d
-- AND n.typename = ? --
hasDBi
d
AND nng.ngrams_type = ? -- NgramsTypeId
AND nng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
AND node_pos(n.id,?) >= ?
AND node_pos(n.id,?) >= ?
...
@@ -409,8 +421,8 @@ queryNgramsByNodeMaster' = [sql|
...
@@ -409,8 +421,8 @@ queryNgramsByNodeMaster' = [sql|
JOIN node_node_ngrams nng ON n.id = nng.node2_id
JOIN node_node_ngrams nng ON n.id = nng.node2_id
JOIN ngrams ng ON ng.id = nng.ngrams_id
JOIN ngrams ng ON ng.id = nng.ngrams_id
WHERE n.parent_id = ? -- Master Corpus
NodeTypeI
d
WHERE n.parent_id = ? -- Master Corpus
hasDBi
d
AND n.typename = ? --
NodeTypeI
d
AND n.typename = ? --
hasDBi
d
AND nng.ngrams_type = ? -- NgramsTypeId
AND nng.ngrams_type = ? -- NgramsTypeId
GROUP BY n.id, ng.terms
GROUP BY n.id, ng.terms
)
)
...
...
src/Gargantext/Database/Action/Metrics/TFICF.hs
View file @
b5c9a011
...
@@ -19,6 +19,7 @@ module Gargantext.Database.Action.Metrics.TFICF
...
@@ -19,6 +19,7 @@ module Gargantext.Database.Action.Metrics.TFICF
import
Data.HashMap.Strict
(
HashMap
)
import
Data.HashMap.Strict
(
HashMap
)
import
qualified
Data.HashMap.Strict
as
HM
import
qualified
Data.HashMap.Strict
as
HM
import
Data.Maybe
(
fromMaybe
)
import
Data.Maybe
(
fromMaybe
)
import
Gargantext.Core
import
Gargantext.Core.Text.Metrics.TFICF
import
Gargantext.Core.Text.Metrics.TFICF
import
Gargantext.Database.Action.Metrics.NgramsByNode
(
getNodesByNgramsUser
,
getOccByNgramsOnlyFast
)
import
Gargantext.Database.Action.Metrics.NgramsByNode
(
getNodesByNgramsUser
,
getOccByNgramsOnlyFast
)
import
Gargantext.Database.Admin.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Database.Admin.Types.Node
-- (ListId, CorpusId, NodeId)
...
@@ -29,7 +30,8 @@ import Gargantext.API.Ngrams.Types
...
@@ -29,7 +30,8 @@ import Gargantext.API.Ngrams.Types
import
Gargantext.Prelude
import
Gargantext.Prelude
import
qualified
Data.Set
as
Set
import
qualified
Data.Set
as
Set
getTficf
::
UserCorpusId
getTficf
::
HasDBid
NodeType
=>
UserCorpusId
->
MasterCorpusId
->
MasterCorpusId
->
NgramsType
->
NgramsType
->
Cmd
err
(
HashMap
NgramsTerm
Double
)
->
Cmd
err
(
HashMap
NgramsTerm
Double
)
...
...
src/Gargantext/Database/Action/Search.hs
View file @
b5c9a011
...
@@ -22,8 +22,9 @@ import Data.Text (Text, words, unpack, intercalate)
...
@@ -22,8 +22,9 @@ import Data.Text (Text, words, unpack, intercalate)
import
Data.Time
(
UTCTime
)
import
Data.Time
(
UTCTime
)
import
Database.PostgreSQL.Simple
(
Query
)
import
Database.PostgreSQL.Simple
(
Query
)
import
Database.PostgreSQL.Simple.ToField
import
Database.PostgreSQL.Simple.ToField
import
Gargantext.Core
import
Gargantext.Core.Types
import
Gargantext.Core.Types
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataDocument
(
..
),
HyperdataContact
(
..
))
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataDocument
(
..
),
HyperdataContact
(
..
))
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
,
runOpaQuery
,
runCountOpaQuery
)
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
,
runOpaQuery
,
runCountOpaQuery
)
import
Gargantext.Database.Query.Facet
import
Gargantext.Database.Query.Facet
...
@@ -49,7 +50,7 @@ searchDocInDatabase p t = runOpaQuery (queryDocInDatabase p t)
...
@@ -49,7 +50,7 @@ searchDocInDatabase p t = runOpaQuery (queryDocInDatabase p t)
queryDocInDatabase
_
q
=
proc
()
->
do
queryDocInDatabase
_
q
=
proc
()
->
do
row
<-
queryNodeSearchTable
-<
()
row
<-
queryNodeSearchTable
-<
()
restrict
-<
(
_ns_search
row
)
@@
(
pgTSQuery
(
unpack
q
))
restrict
-<
(
_ns_search
row
)
@@
(
pgTSQuery
(
unpack
q
))
restrict
-<
(
_ns_typename
row
)
.==
(
pgInt4
$
nodeTypeI
d
NodeDocument
)
restrict
-<
(
_ns_typename
row
)
.==
(
pgInt4
$
hasDBi
d
NodeDocument
)
returnA
-<
(
_ns_id
row
,
_ns_hyperdata
row
)
returnA
-<
(
_ns_id
row
,
_ns_hyperdata
row
)
------------------------------------------------------------------------
------------------------------------------------------------------------
...
@@ -87,7 +88,7 @@ queryInCorpus cId t q = proc () -> do
...
@@ -87,7 +88,7 @@ queryInCorpus cId t q = proc () -> do
then
(
nn
^.
nn_category
)
.==
(
toNullable
$
pgInt4
0
)
then
(
nn
^.
nn_category
)
.==
(
toNullable
$
pgInt4
0
)
else
(
nn
^.
nn_category
)
.>=
(
toNullable
$
pgInt4
1
)
else
(
nn
^.
nn_category
)
.>=
(
toNullable
$
pgInt4
1
)
restrict
-<
(
n
^.
ns_search
)
@@
(
pgTSQuery
(
unpack
q
))
restrict
-<
(
n
^.
ns_search
)
@@
(
pgTSQuery
(
unpack
q
))
restrict
-<
(
n
^.
ns_typename
)
.==
(
pgInt4
$
nodeTypeI
d
NodeDocument
)
restrict
-<
(
n
^.
ns_typename
)
.==
(
pgInt4
$
hasDBi
d
NodeDocument
)
returnA
-<
FacetDoc
(
n
^.
ns_id
)
returnA
-<
FacetDoc
(
n
^.
ns_id
)
(
n
^.
ns_date
)
(
n
^.
ns_date
)
(
n
^.
ns_name
)
(
n
^.
ns_name
)
...
@@ -132,10 +133,10 @@ selectContactViaDoc
...
@@ -132,10 +133,10 @@ selectContactViaDoc
selectContactViaDoc
cId
aId
q
=
proc
()
->
do
selectContactViaDoc
cId
aId
q
=
proc
()
->
do
(
doc
,
(
corpus_doc
,
(
_contact_doc
,
(
annuaire_contact
,
contact
))))
<-
queryContactViaDoc
-<
()
(
doc
,
(
corpus_doc
,
(
_contact_doc
,
(
annuaire_contact
,
contact
))))
<-
queryContactViaDoc
-<
()
restrict
-<
(
doc
^.
ns_search
)
@@
(
pgTSQuery
$
unpack
q
)
restrict
-<
(
doc
^.
ns_search
)
@@
(
pgTSQuery
$
unpack
q
)
restrict
-<
(
doc
^.
ns_typename
)
.==
(
pgInt4
$
nodeTypeI
d
NodeDocument
)
restrict
-<
(
doc
^.
ns_typename
)
.==
(
pgInt4
$
hasDBi
d
NodeDocument
)
restrict
-<
(
corpus_doc
^.
nn_node1_id
)
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
(
corpus_doc
^.
nn_node1_id
)
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
(
annuaire_contact
^.
nn_node1_id
)
.==
(
toNullable
$
pgNodeId
aId
)
restrict
-<
(
annuaire_contact
^.
nn_node1_id
)
.==
(
toNullable
$
pgNodeId
aId
)
restrict
-<
(
contact
^.
node_typename
)
.==
(
toNullable
$
pgInt4
$
nodeTypeI
d
NodeContact
)
restrict
-<
(
contact
^.
node_typename
)
.==
(
toNullable
$
pgInt4
$
hasDBi
d
NodeContact
)
returnA
-<
(
contact
^.
node_id
returnA
-<
(
contact
^.
node_id
,
contact
^.
node_date
,
contact
^.
node_date
,
contact
^.
node_hyperdata
,
contact
^.
node_hyperdata
...
@@ -265,6 +266,6 @@ textSearch :: TSQuery -> ParentId
...
@@ -265,6 +266,6 @@ textSearch :: TSQuery -> ParentId
->
Cmd
err
[(
Int
,
Value
,
Value
,
Value
,
Value
,
Maybe
Int
)]
->
Cmd
err
[(
Int
,
Value
,
Value
,
Value
,
Value
,
Maybe
Int
)]
textSearch
q
p
l
o
ord
=
runPGSQuery
textSearchQuery
(
q
,
p
,
p
,
typeId
,
ord
,
o
,
l
)
textSearch
q
p
l
o
ord
=
runPGSQuery
textSearchQuery
(
q
,
p
,
p
,
typeId
,
ord
,
o
,
l
)
where
where
typeId
=
nodeTypeI
d
NodeDocument
typeId
=
hasDBi
d
NodeDocument
src/Gargantext/Database/Admin/Config.hs
View file @
b5c9a011
...
@@ -14,6 +14,8 @@ TODO: configure nodes table in Haskell (Config typenames etc.)
...
@@ -14,6 +14,8 @@ TODO: configure nodes table in Haskell (Config typenames etc.)
-}
-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module
Gargantext.Database.Admin.Config
module
Gargantext.Database.Admin.Config
where
where
...
@@ -22,6 +24,7 @@ import Data.List (lookup)
...
@@ -22,6 +24,7 @@ import Data.List (lookup)
import
Data.Maybe
(
fromMaybe
)
import
Data.Maybe
(
fromMaybe
)
import
Data.Text
(
Text
,
pack
)
import
Data.Text
(
Text
,
pack
)
import
Data.Tuple.Extra
(
swap
)
import
Data.Tuple.Extra
(
swap
)
import
Gargantext.Core
(
HasDBid
(
..
))
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Schema.Node
import
Gargantext.Prelude
import
Gargantext.Prelude
...
@@ -36,6 +39,11 @@ userMaster = "gargantua"
...
@@ -36,6 +39,11 @@ userMaster = "gargantua"
userArbitrary
::
Text
userArbitrary
::
Text
userArbitrary
=
"user1"
userArbitrary
=
"user1"
instance
HasDBid
NodeType
where
hasDBid
=
nodeTypeId
fromDBid
=
fromNodeTypeId
nodeTypeId
::
NodeType
->
NodeTypeId
nodeTypeId
::
NodeType
->
NodeTypeId
nodeTypeId
n
=
nodeTypeId
n
=
case
n
of
case
n
of
...
@@ -88,10 +96,10 @@ nodeTypeId n =
...
@@ -88,10 +96,10 @@ nodeTypeId n =
-- NodeFavorites -> 15
-- NodeFavorites -> 15
hasNodeType
::
forall
a
.
Node
a
->
NodeType
->
Bool
hasNodeType
::
forall
a
.
Node
a
->
NodeType
->
Bool
hasNodeType
n
nt
=
(
view
node_typename
n
)
==
(
nodeTypeI
d
nt
)
hasNodeType
n
nt
=
(
view
node_typename
n
)
==
(
hasDBi
d
nt
)
isInNodeTypes
::
forall
a
.
Node
a
->
[
NodeType
]
->
Bool
isInNodeTypes
::
forall
a
.
Node
a
->
[
NodeType
]
->
Bool
isInNodeTypes
n
ts
=
elem
(
view
node_typename
n
)
(
map
nodeTypeI
d
ts
)
isInNodeTypes
n
ts
=
elem
(
view
node_typename
n
)
(
map
hasDBi
d
ts
)
-- | Nodes are typed in the database according to a specific ID
-- | Nodes are typed in the database according to a specific ID
--
--
...
@@ -99,7 +107,7 @@ nodeTypeInv :: [(NodeTypeId, NodeType)]
...
@@ -99,7 +107,7 @@ nodeTypeInv :: [(NodeTypeId, NodeType)]
nodeTypeInv
=
map
swap
nodeTypes
nodeTypeInv
=
map
swap
nodeTypes
nodeTypes
::
[(
NodeType
,
NodeTypeId
)]
nodeTypes
::
[(
NodeType
,
NodeTypeId
)]
nodeTypes
=
[
(
n
,
nodeTypeI
d
n
)
|
n
<-
allNodeTypes
]
nodeTypes
=
[
(
n
,
hasDBi
d
n
)
|
n
<-
allNodeTypes
]
fromNodeTypeId
::
NodeTypeId
->
NodeType
fromNodeTypeId
::
NodeTypeId
->
NodeType
fromNodeTypeId
tId
=
fromMaybe
(
panic
$
pack
$
"Type Id "
<>
show
tId
<>
" does not exist"
)
fromNodeTypeId
tId
=
fromMaybe
(
panic
$
pack
$
"Type Id "
<>
show
tId
<>
" does not exist"
)
...
...
src/Gargantext/Database/Admin/Trigger/NodeNodeNgrams.hs
View file @
b5c9a011
...
@@ -17,16 +17,15 @@ module Gargantext.Database.Admin.Trigger.NodeNodeNgrams
...
@@ -17,16 +17,15 @@ module Gargantext.Database.Admin.Trigger.NodeNodeNgrams
where
where
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
qualified
Database.PostgreSQL.Simple
as
DPS
import
Gargantext.Core
import
Gargantext.Core.Types.Main
(
listTypeId
,
ListType
(
CandidateTerm
))
import
Gargantext.Core.Types.Main
(
listTypeId
,
ListType
(
CandidateTerm
))
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
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
import
qualified
Database.PostgreSQL.Simple
as
DPS
triggerCountInsert
::
Cmd
err
Int64
triggerCountInsert
::
HasDBid
NodeType
=>
Cmd
err
Int64
triggerCountInsert
=
execPGSQuery
query
(
nodeTypeId
NodeDocument
,
nodeTypeI
d
NodeList
)
triggerCountInsert
=
execPGSQuery
query
(
hasDBid
NodeDocument
,
hasDBi
d
NodeList
)
where
where
query
::
DPS
.
Query
query
::
DPS
.
Query
query
=
[
sql
|
query
=
[
sql
|
...
@@ -61,10 +60,10 @@ triggerCountInsert = execPGSQuery query (nodeTypeId NodeDocument, nodeTypeId Nod
...
@@ -61,10 +60,10 @@ triggerCountInsert = execPGSQuery query (nodeTypeId NodeDocument, nodeTypeId Nod
EXECUTE PROCEDURE set_ngrams_global_count();
EXECUTE PROCEDURE set_ngrams_global_count();
|]
|]
triggerCountInsert2
::
Cmd
err
Int64
triggerCountInsert2
::
HasDBid
NodeType
=>
Cmd
err
Int64
triggerCountInsert2
=
execPGSQuery
query
(
nodeTypeI
d
NodeCorpus
triggerCountInsert2
=
execPGSQuery
query
(
hasDBi
d
NodeCorpus
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
nodeTypeI
d
NodeList
,
hasDBi
d
NodeList
)
)
where
where
query
::
DPS
.
Query
query
::
DPS
.
Query
...
@@ -105,10 +104,10 @@ triggerCountInsert2 = execPGSQuery query ( nodeTypeId NodeCorpus
...
@@ -105,10 +104,10 @@ triggerCountInsert2 = execPGSQuery query ( nodeTypeId NodeCorpus
|]
|]
-- TODO add the groups
-- TODO add the groups
triggerCoocInsert
::
Cmd
err
Int64
triggerCoocInsert
::
HasDBid
NodeType
=>
Cmd
err
Int64
triggerCoocInsert
=
execPGSQuery
query
(
nodeTypeI
d
NodeCorpus
triggerCoocInsert
=
execPGSQuery
query
(
hasDBi
d
NodeCorpus
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
nodeTypeI
d
NodeList
,
hasDBi
d
NodeList
,
listTypeId
CandidateTerm
,
listTypeId
CandidateTerm
,
listTypeId
CandidateTerm
,
listTypeId
CandidateTerm
)
)
...
...
src/Gargantext/Database/Admin/Trigger/Nodes.hs
View file @
b5c9a011
...
@@ -18,18 +18,17 @@ module Gargantext.Database.Admin.Trigger.Nodes
...
@@ -18,18 +18,17 @@ module Gargantext.Database.Admin.Trigger.Nodes
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
qualified
Database.PostgreSQL.Simple
as
DPS
import
Gargantext.Core
(
HasDBid
(
..
))
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
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
import
qualified
Database.PostgreSQL.Simple
as
DPS
triggerSearchUpdate
::
Cmd
err
Int64
triggerSearchUpdate
::
HasDBid
NodeType
=>
Cmd
err
Int64
triggerSearchUpdate
=
execPGSQuery
query
(
nodeTypeI
d
NodeDocument
triggerSearchUpdate
=
execPGSQuery
query
(
hasDBi
d
NodeDocument
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
nodeTypeI
d
NodeContact
,
hasDBi
d
NodeContact
)
)
where
where
query
::
DPS
.
Query
query
::
DPS
.
Query
...
@@ -70,13 +69,13 @@ triggerSearchUpdate = execPGSQuery query ( nodeTypeId NodeDocument
...
@@ -70,13 +69,13 @@ triggerSearchUpdate = execPGSQuery query ( nodeTypeId NodeDocument
type
Secret
=
Text
type
Secret
=
Text
triggerUpdateHash
::
Secret
->
Cmd
err
Int64
triggerUpdateHash
::
HasDBid
NodeType
=>
Secret
->
Cmd
err
Int64
triggerUpdateHash
secret
=
execPGSQuery
query
(
nodeTypeI
d
NodeDocument
triggerUpdateHash
secret
=
execPGSQuery
query
(
hasDBi
d
NodeDocument
,
nodeTypeI
d
NodeContact
,
hasDBi
d
NodeContact
,
secret
,
secret
,
secret
,
secret
,
nodeTypeI
d
NodeDocument
,
hasDBi
d
NodeDocument
,
nodeTypeI
d
NodeContact
,
hasDBi
d
NodeContact
,
secret
,
secret
,
secret
,
secret
)
)
...
...
src/Gargantext/Database/Admin/Trigger/NodesNodes.hs
View file @
b5c9a011
...
@@ -18,7 +18,8 @@ module Gargantext.Database.Admin.Trigger.NodesNodes
...
@@ -18,7 +18,8 @@ module Gargantext.Database.Admin.Trigger.NodesNodes
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
-- import Database.PostgreSQL.Simple.Types (Values(..), QualifiedIdentifier(..))
-- import Database.PostgreSQL.Simple.Types (Values(..), QualifiedIdentifier(..))
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
import
Gargantext.Core
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
(
listTypeId
,
ListType
(
CandidateTerm
))
import
Gargantext.Database.Prelude
(
Cmd
,
execPGSQuery
)
import
Gargantext.Database.Prelude
(
Cmd
,
execPGSQuery
)
...
@@ -28,7 +29,7 @@ import qualified Database.PostgreSQL.Simple as DPS
...
@@ -28,7 +29,7 @@ import qualified Database.PostgreSQL.Simple as DPS
type
MasterListId
=
ListId
type
MasterListId
=
ListId
triggerDeleteCount
::
MasterListId
->
Cmd
err
Int64
triggerDeleteCount
::
MasterListId
->
Cmd
err
Int64
triggerDeleteCount
lId
=
execPGSQuery
query
(
lId
,
nodeTypeI
d
NodeList
)
triggerDeleteCount
lId
=
execPGSQuery
query
(
lId
,
hasDBi
d
NodeList
)
where
where
query
::
DPS
.
Query
query
::
DPS
.
Query
query
=
[
sql
|
query
=
[
sql
|
...
...
src/Gargantext/Database/Admin/Types/Node.hs
View file @
b5c9a011
...
@@ -99,11 +99,11 @@ instance (Typeable hyperdata, ToSchema hyperdata) =>
...
@@ -99,11 +99,11 @@ instance (Typeable hyperdata, ToSchema hyperdata) =>
instance
(
Arbitrary
nodeId
instance
(
Arbitrary
nodeId
,
Arbitrary
hashId
,
Arbitrary
hashId
,
Arbitrary
nodeTypeI
d
,
Arbitrary
hasDBi
d
,
Arbitrary
userId
,
Arbitrary
userId
,
Arbitrary
nodeParentId
,
Arbitrary
nodeParentId
,
Arbitrary
hyperdata
,
Arbitrary
hyperdata
)
=>
Arbitrary
(
NodePoly
nodeId
hashId
nodeTypeI
d
userId
nodeParentId
)
=>
Arbitrary
(
NodePoly
nodeId
hashId
hasDBi
d
userId
nodeParentId
NodeName
UTCTime
hyperdata
)
where
NodeName
UTCTime
hyperdata
)
where
--arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
--arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
arbitrary
=
Node
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
arbitrary
=
Node
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
...
@@ -112,10 +112,10 @@ instance (Arbitrary nodeId
...
@@ -112,10 +112,10 @@ instance (Arbitrary nodeId
instance
(
Arbitrary
hyperdata
instance
(
Arbitrary
hyperdata
,
Arbitrary
nodeId
,
Arbitrary
nodeId
,
Arbitrary
nodeTypeI
d
,
Arbitrary
hasDBi
d
,
Arbitrary
userId
,
Arbitrary
userId
,
Arbitrary
nodeParentId
,
Arbitrary
nodeParentId
)
=>
Arbitrary
(
NodePolySearch
nodeId
nodeTypeI
d
userId
nodeParentId
)
=>
Arbitrary
(
NodePolySearch
nodeId
hasDBi
d
userId
nodeParentId
NodeName
UTCTime
hyperdata
(
Maybe
TSVector
))
where
NodeName
UTCTime
hyperdata
(
Maybe
TSVector
))
where
--arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
--arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
arbitrary
=
NodeSearch
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
arbitrary
=
NodeSearch
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
...
...
src/Gargantext/Database/Query/Facet.hs
View file @
b5c9a011
...
@@ -52,9 +52,9 @@ import Test.QuickCheck (elements)
...
@@ -52,9 +52,9 @@ import Test.QuickCheck (elements)
import
Test.QuickCheck.Arbitrary
import
Test.QuickCheck.Arbitrary
import
qualified
Opaleye.Internal.Unpackspec
()
import
qualified
Opaleye.Internal.Unpackspec
()
import
Gargantext.Core
import
Gargantext.Core.Types
import
Gargantext.Core.Types
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
,
wellNamedSchema
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
,
wellNamedSchema
)
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Query.Filter
import
Gargantext.Database.Query.Filter
import
Gargantext.Database.Query.Join
(
leftJoin5
)
import
Gargantext.Database.Query.Join
(
leftJoin5
)
...
@@ -232,13 +232,13 @@ instance Arbitrary OrderBy
...
@@ -232,13 +232,13 @@ instance Arbitrary OrderBy
-- TODO-SECURITY check
-- TODO-SECURITY check
--{-
--{-
runViewAuthorsDoc
::
ContactId
->
IsTrash
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Cmd
err
[
FacetDoc
]
runViewAuthorsDoc
::
HasDBid
NodeType
=>
ContactId
->
IsTrash
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Cmd
err
[
FacetDoc
]
runViewAuthorsDoc
cId
t
o
l
order
=
runOpaQuery
$
filterWith
o
l
order
$
viewAuthorsDoc
cId
t
ntId
runViewAuthorsDoc
cId
t
o
l
order
=
runOpaQuery
$
filterWith
o
l
order
$
viewAuthorsDoc
cId
t
ntId
where
where
ntId
=
NodeDocument
ntId
=
NodeDocument
-- TODO add delete ?
-- TODO add delete ?
viewAuthorsDoc
::
ContactId
->
IsTrash
->
NodeType
->
Query
FacetDocRead
viewAuthorsDoc
::
HasDBid
NodeType
=>
ContactId
->
IsTrash
->
NodeType
->
Query
FacetDocRead
viewAuthorsDoc
cId
_
nt
=
proc
()
->
do
viewAuthorsDoc
cId
_
nt
=
proc
()
->
do
(
doc
,(
_
,(
_
,(
_
,
contact'
))))
<-
queryAuthorsDoc
-<
()
(
doc
,(
_
,(
_
,(
_
,
contact'
))))
<-
queryAuthorsDoc
-<
()
...
@@ -248,7 +248,7 @@ viewAuthorsDoc cId _ nt = proc () -> do
...
@@ -248,7 +248,7 @@ viewAuthorsDoc cId _ nt = proc () -> do
-}
-}
restrict
-<
_node_id
contact'
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
_node_id
contact'
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
_node_typename
doc
.==
(
pgInt4
$
nodeTypeI
d
nt
)
restrict
-<
_node_typename
doc
.==
(
pgInt4
$
hasDBi
d
nt
)
returnA
-<
FacetDoc
(
_node_id
doc
)
returnA
-<
FacetDoc
(
_node_id
doc
)
(
_node_date
doc
)
(
_node_date
doc
)
...
@@ -279,7 +279,8 @@ queryAuthorsDoc = leftJoin5 queryNodeTable queryNodeNodeNgramsTable queryNgramsT
...
@@ -279,7 +279,8 @@ queryAuthorsDoc = leftJoin5 queryNodeTable queryNodeNodeNgramsTable queryNgramsT
------------------------------------------------------------------------
------------------------------------------------------------------------
-- TODO-SECURITY check
-- TODO-SECURITY check
runViewDocuments
::
CorpusId
runViewDocuments
::
HasDBid
NodeType
=>
CorpusId
->
IsTrash
->
IsTrash
->
Maybe
Offset
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
Limit
...
@@ -289,14 +290,14 @@ runViewDocuments :: CorpusId
...
@@ -289,14 +290,14 @@ runViewDocuments :: CorpusId
runViewDocuments
cId
t
o
l
order
query
=
do
runViewDocuments
cId
t
o
l
order
query
=
do
runOpaQuery
$
filterWith
o
l
order
sqlQuery
runOpaQuery
$
filterWith
o
l
order
sqlQuery
where
where
ntId
=
nodeTypeI
d
NodeDocument
ntId
=
hasDBi
d
NodeDocument
sqlQuery
=
viewDocuments
cId
t
ntId
query
sqlQuery
=
viewDocuments
cId
t
ntId
query
runCountDocuments
::
CorpusId
->
IsTrash
->
Maybe
Text
->
Cmd
err
Int
runCountDocuments
::
HasDBid
NodeType
=>
CorpusId
->
IsTrash
->
Maybe
Text
->
Cmd
err
Int
runCountDocuments
cId
t
mQuery
=
do
runCountDocuments
cId
t
mQuery
=
do
runCountOpaQuery
sqlQuery
runCountOpaQuery
sqlQuery
where
where
sqlQuery
=
viewDocuments
cId
t
(
nodeTypeI
d
NodeDocument
)
mQuery
sqlQuery
=
viewDocuments
cId
t
(
hasDBi
d
NodeDocument
)
mQuery
viewDocuments
::
CorpusId
viewDocuments
::
CorpusId
...
...
src/Gargantext/Database/Query/Table/NgramsPostag.hs
View file @
b5c9a011
...
@@ -25,6 +25,8 @@ import Gargantext.Prelude
...
@@ -25,6 +25,8 @@ import Gargantext.Prelude
import
qualified
Database.PostgreSQL.Simple
as
PGS
import
qualified
Database.PostgreSQL.Simple
as
PGS
type
NgramsPostagInsert
=
(
Int
type
NgramsPostagInsert
=
(
Int
,
Int
,
Int
,
Text
,
Text
...
@@ -34,6 +36,7 @@ type NgramsPostagInsert = ( Int
...
@@ -34,6 +36,7 @@ type NgramsPostagInsert = ( Int
,
Int
,
Int
)
)
insertNgramsPostag
::
[
NgramsPostagInsert
]
->
Cmd
err
[
NgramIds
]
insertNgramsPostag
::
[
NgramsPostagInsert
]
->
Cmd
err
[
NgramIds
]
insertNgramsPostag
ns
=
runPGSQuery
queryInsertNgramsPostag
(
PGS
.
Only
$
Values
fields
ns
)
insertNgramsPostag
ns
=
runPGSQuery
queryInsertNgramsPostag
(
PGS
.
Only
$
Values
fields
ns
)
where
where
...
...
src/Gargantext/Database/Query/Table/Node.hs
View file @
b5c9a011
...
@@ -32,8 +32,8 @@ import Database.PostgreSQL.Simple.SqlQQ (sql)
...
@@ -32,8 +32,8 @@ import Database.PostgreSQL.Simple.SqlQQ (sql)
import
Opaleye
hiding
(
FromField
)
import
Opaleye
hiding
(
FromField
)
import
Prelude
hiding
(
null
,
id
,
map
,
sum
)
import
Prelude
hiding
(
null
,
id
,
map
,
sum
)
import
Gargantext.Core
import
Gargantext.Core.Types
import
Gargantext.Core.Types
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Hyperdata.Default
import
Gargantext.Database.Admin.Types.Hyperdata.Default
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
...
@@ -73,7 +73,7 @@ selectNodesWith' parentId maybeNodeType = proc () -> do
...
@@ -73,7 +73,7 @@ selectNodesWith' parentId maybeNodeType = proc () -> do
row
@
(
Node
_
_
typeId
_
parentId'
_
_
_
)
<-
queryNodeTable
-<
()
row
@
(
Node
_
_
typeId
_
parentId'
_
_
_
)
<-
queryNodeTable
-<
()
restrict
-<
parentId'
.==
(
pgNodeId
parentId
)
restrict
-<
parentId'
.==
(
pgNodeId
parentId
)
let
typeId'
=
maybe
0
nodeTypeI
d
maybeNodeType
let
typeId'
=
maybe
0
hasDBi
d
maybeNodeType
restrict
-<
if
typeId'
>
0
restrict
-<
if
typeId'
>
0
then
typeId
.==
(
pgInt4
(
typeId'
::
Int
))
then
typeId
.==
(
pgInt4
(
typeId'
::
Int
))
...
@@ -119,7 +119,7 @@ getClosestParentIdByType nId nType = do
...
@@ -119,7 +119,7 @@ getClosestParentIdByType nId nType = do
result
<-
runPGSQuery
query
(
nId
,
0
::
Int
)
result
<-
runPGSQuery
query
(
nId
,
0
::
Int
)
case
result
of
case
result
of
[
DPS
.
Only
parentId
,
DPS
.
Only
pTypename
]
->
do
[
DPS
.
Only
parentId
,
DPS
.
Only
pTypename
]
->
do
if
nodeTypeI
d
nType
==
pTypename
then
if
hasDBi
d
nType
==
pTypename
then
pure
$
Just
$
NodeId
parentId
pure
$
Just
$
NodeId
parentId
else
else
getClosestParentIdByType
(
NodeId
parentId
)
nType
getClosestParentIdByType
(
NodeId
parentId
)
nType
...
@@ -164,7 +164,7 @@ getNodesWithType nt _ = runOpaQuery $ selectNodesWithType nt
...
@@ -164,7 +164,7 @@ getNodesWithType nt _ = runOpaQuery $ selectNodesWithType nt
selectNodesWithType
::
NodeType
->
Query
NodeRead
selectNodesWithType
::
NodeType
->
Query
NodeRead
selectNodesWithType
nt'
=
proc
()
->
do
selectNodesWithType
nt'
=
proc
()
->
do
row
@
(
Node
_
_
tn
_
_
_
_
_
)
<-
queryNodeTable
-<
()
row
@
(
Node
_
_
tn
_
_
_
_
_
)
<-
queryNodeTable
-<
()
restrict
-<
tn
.==
(
pgInt4
$
nodeTypeI
d
nt'
)
restrict
-<
tn
.==
(
pgInt4
$
hasDBi
d
nt'
)
returnA
-<
row
returnA
-<
row
getNodesIdWithType
::
HasNodeError
err
=>
NodeType
->
Cmd
err
[
NodeId
]
getNodesIdWithType
::
HasNodeError
err
=>
NodeType
->
Cmd
err
[
NodeId
]
...
@@ -175,7 +175,7 @@ getNodesIdWithType nt = do
...
@@ -175,7 +175,7 @@ getNodesIdWithType nt = do
selectNodesIdWithType
::
NodeType
->
Query
(
Column
PGInt4
)
selectNodesIdWithType
::
NodeType
->
Query
(
Column
PGInt4
)
selectNodesIdWithType
nt
=
proc
()
->
do
selectNodesIdWithType
nt
=
proc
()
->
do
row
@
(
Node
_
_
tn
_
_
_
_
_
)
<-
queryNodeTable
-<
()
row
@
(
Node
_
_
tn
_
_
_
_
_
)
<-
queryNodeTable
-<
()
restrict
-<
tn
.==
(
pgInt4
$
nodeTypeI
d
nt
)
restrict
-<
tn
.==
(
pgInt4
$
hasDBi
d
nt
)
returnA
-<
_node_id
row
returnA
-<
_node_id
row
------------------------------------------------------------------------
------------------------------------------------------------------------
...
@@ -228,7 +228,7 @@ node nodeType name hyperData parentId userId =
...
@@ -228,7 +228,7 @@ node nodeType name hyperData parentId userId =
Nothing
Nothing
(
pgJSONB
$
cs
$
encode
hyperData
)
(
pgJSONB
$
cs
$
encode
hyperData
)
where
where
typeId
=
nodeTypeI
d
nodeType
typeId
=
hasDBi
d
nodeType
-------------------------------
-------------------------------
insertNodes
::
[
NodeWrite
]
->
Cmd
err
Int64
insertNodes
::
[
NodeWrite
]
->
Cmd
err
Int64
...
@@ -242,7 +242,7 @@ insertNodes' ns = mkCmd $ \conn -> runInsert_ conn
...
@@ -242,7 +242,7 @@ insertNodes' ns = mkCmd $ \conn -> runInsert_ conn
ns' :: [NodeWrite]
ns' :: [NodeWrite]
ns' = map (\(Node i t u p n d h)
ns' = map (\(Node i t u p n d h)
-> Node (pgNodeId <$> i)
-> Node (pgNodeId <$> i)
(pgInt4 $
nodeTypeId
t)
(pgInt4 $
hasDBid
t)
(pgInt4 u)
(pgInt4 u)
(pgNodeId <$> p)
(pgNodeId <$> p)
(pgStrictText n)
(pgStrictText n)
...
@@ -266,7 +266,7 @@ insertNodesWithParentR pid ns = insertNodesR (set node_parentId (pgNodeId <$> pi
...
@@ -266,7 +266,7 @@ insertNodesWithParentR pid ns = insertNodesR (set node_parentId (pgNodeId <$> pi
-- needs a Temporary type between Node' and NodeWriteT
-- needs a Temporary type between Node' and NodeWriteT
node2table
::
UserId
->
Maybe
ParentId
->
Node'
->
NodeWrite
node2table
::
UserId
->
Maybe
ParentId
->
Node'
->
NodeWrite
node2table
uid
pid
(
Node'
nt
txt
v
[]
)
=
Node
Nothing
Nothing
(
pgInt4
$
nodeTypeI
d
nt
)
(
pgInt4
uid
)
(
fmap
pgNodeId
pid
)
(
pgStrictText
txt
)
Nothing
(
pgStrictJSONB
$
cs
$
encode
v
)
node2table
uid
pid
(
Node'
nt
txt
v
[]
)
=
Node
Nothing
Nothing
(
pgInt4
$
hasDBi
d
nt
)
(
pgInt4
uid
)
(
fmap
pgNodeId
pid
)
(
pgStrictText
txt
)
Nothing
(
pgStrictJSONB
$
cs
$
encode
v
)
node2table
_
_
(
Node'
_
_
_
_
)
=
panic
"node2table: should not happen, Tree insert not implemented yet"
node2table
_
_
(
Node'
_
_
_
_
)
=
panic
"node2table: should not happen, Tree insert not implemented yet"
...
...
src/Gargantext/Database/Query/Table/Node/Children.hs
View file @
b5c9a011
...
@@ -18,8 +18,8 @@ module Gargantext.Database.Query.Table.Node.Children
...
@@ -18,8 +18,8 @@ module Gargantext.Database.Query.Table.Node.Children
import
Control.Arrow
(
returnA
)
import
Control.Arrow
(
returnA
)
import
Data.Proxy
import
Data.Proxy
import
Gargantext.Core
import
Gargantext.Core.Types
import
Gargantext.Core.Types
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataDocument
,
HyperdataContact
)
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataDocument
,
HyperdataContact
)
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
import
Gargantext.Database.Query.Filter
import
Gargantext.Database.Query.Filter
...
@@ -30,23 +30,23 @@ import Protolude
...
@@ -30,23 +30,23 @@ import Protolude
-- TODO getAllTableDocuments
-- TODO getAllTableDocuments
getAllDocuments
::
ParentId
->
Cmd
err
(
TableResult
(
Node
HyperdataDocument
))
getAllDocuments
::
HasDBid
NodeType
=>
ParentId
->
Cmd
err
(
TableResult
(
Node
HyperdataDocument
))
getAllDocuments
pId
=
getAllChildren
pId
(
Proxy
::
Proxy
HyperdataDocument
)
getAllDocuments
pId
=
getAllChildren
pId
(
Proxy
::
Proxy
HyperdataDocument
)
(
Just
NodeDocument
)
(
Just
NodeDocument
)
-- TODO getAllTableContacts
-- TODO getAllTableContacts
getAllContacts
::
ParentId
->
Cmd
err
(
TableResult
(
Node
HyperdataContact
))
getAllContacts
::
HasDBid
NodeType
=>
ParentId
->
Cmd
err
(
TableResult
(
Node
HyperdataContact
))
getAllContacts
pId
=
getAllChildren
pId
(
Proxy
::
Proxy
HyperdataContact
)
getAllContacts
pId
=
getAllChildren
pId
(
Proxy
::
Proxy
HyperdataContact
)
(
Just
NodeContact
)
(
Just
NodeContact
)
getAllChildren
::
JSONB
a
getAllChildren
::
(
JSONB
a
,
HasDBid
NodeType
)
=>
ParentId
=>
ParentId
->
proxy
a
->
proxy
a
->
Maybe
NodeType
->
Maybe
NodeType
->
Cmd
err
(
NodeTableResult
a
)
->
Cmd
err
(
NodeTableResult
a
)
getAllChildren
pId
p
maybeNodeType
=
getChildren
pId
p
maybeNodeType
Nothing
Nothing
getAllChildren
pId
p
maybeNodeType
=
getChildren
pId
p
maybeNodeType
Nothing
Nothing
getChildren
::
JSONB
a
getChildren
::
(
JSONB
a
,
HasDBid
NodeType
)
=>
ParentId
=>
ParentId
->
proxy
a
->
proxy
a
->
Maybe
NodeType
->
Maybe
NodeType
...
@@ -66,14 +66,15 @@ getChildren pId _ maybeNodeType maybeOffset maybeLimit = do
...
@@ -66,14 +66,15 @@ getChildren pId _ maybeNodeType maybeOffset maybeLimit = do
where
where
query
=
selectChildren
pId
maybeNodeType
query
=
selectChildren
pId
maybeNodeType
selectChildren
::
ParentId
selectChildren
::
HasDBid
NodeType
=>
ParentId
->
Maybe
NodeType
->
Maybe
NodeType
->
Query
NodeRead
->
Query
NodeRead
selectChildren
parentId
maybeNodeType
=
proc
()
->
do
selectChildren
parentId
maybeNodeType
=
proc
()
->
do
row
@
(
Node
nId
_
typeName
_
parent_id
_
_
_
)
<-
queryNodeTable
-<
()
row
@
(
Node
nId
_
typeName
_
parent_id
_
_
_
)
<-
queryNodeTable
-<
()
(
NodeNode
n1id
n2id
_
_
)
<-
queryNodeNodeTable
-<
()
(
NodeNode
n1id
n2id
_
_
)
<-
queryNodeNodeTable
-<
()
let
nodeType
=
maybe
0
nodeTypeI
d
maybeNodeType
let
nodeType
=
maybe
0
hasDBi
d
maybeNodeType
restrict
-<
typeName
.==
pgInt4
nodeType
restrict
-<
typeName
.==
pgInt4
nodeType
restrict
-<
(
.||
)
(
parent_id
.==
(
pgNodeId
parentId
))
restrict
-<
(
.||
)
(
parent_id
.==
(
pgNodeId
parentId
))
...
...
src/Gargantext/Database/Query/Table/Node/Document/Insert.hs
View file @
b5c9a011
...
@@ -69,7 +69,7 @@ import Database.PostgreSQL.Simple.SqlQQ
...
@@ -69,7 +69,7 @@ import Database.PostgreSQL.Simple.SqlQQ
import
Database.PostgreSQL.Simple.ToField
(
toField
,
Action
{-, ToField-}
)
import
Database.PostgreSQL.Simple.ToField
(
toField
,
Action
{-, ToField-}
)
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
GHC.Generics
(
Generic
)
import
GHC.Generics
(
Generic
)
import
Gargantext.
Database.Admin.Config
(
nodeTypeId
)
import
Gargantext.
Core
(
HasDBid
(
hasDBid
)
)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
{-, formatPGSQuery-}
)
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
{-, formatPGSQuery-}
)
...
@@ -91,20 +91,20 @@ import Database.PostgreSQL.Simple (formatQuery)
...
@@ -91,20 +91,20 @@ import Database.PostgreSQL.Simple (formatQuery)
-- ParentId : folder ID which is parent of the inserted documents
-- ParentId : folder ID which is parent of the inserted documents
-- Administrator of the database has to create a uniq index as following SQL command:
-- Administrator of the database has to create a uniq index as following SQL command:
-- `create unique index on nodes (typename, parent_id, (hyperdata ->> 'uniqId'));`
-- `create unique index on nodes (typename, parent_id, (hyperdata ->> 'uniqId'));`
insertDb
::
InsertDb
a
=>
UserId
->
ParentId
->
[
a
]
->
Cmd
err
[
ReturnId
]
insertDb
::
(
InsertDb
a
,
HasDBid
NodeType
)
=>
UserId
->
ParentId
->
[
a
]
->
Cmd
err
[
ReturnId
]
insertDb
u
p
=
runPGSQuery
queryInsert
.
Only
.
Values
fields
.
map
(
insertDb'
u
p
)
insertDb
u
p
=
runPGSQuery
queryInsert
.
Only
.
Values
fields
.
map
(
insertDb'
u
p
)
where
where
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
inputSqlTypes
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
inputSqlTypes
class
InsertDb
a
class
InsertDb
a
where
where
insertDb'
::
UserId
->
ParentId
->
a
->
[
Action
]
insertDb'
::
HasDBid
NodeType
=>
UserId
->
ParentId
->
a
->
[
Action
]
instance
InsertDb
HyperdataDocument
instance
InsertDb
HyperdataDocument
where
where
insertDb'
u
p
h
=
[
toField
(
""
::
Text
)
insertDb'
u
p
h
=
[
toField
(
""
::
Text
)
,
toField
$
nodeTypeI
d
NodeDocument
,
toField
$
hasDBi
d
NodeDocument
,
toField
u
,
toField
u
,
toField
p
,
toField
p
,
toField
$
maybe
"No Title"
(
DT
.
take
255
)
(
_hd_title
h
)
,
toField
$
maybe
"No Title"
(
DT
.
take
255
)
(
_hd_title
h
)
...
@@ -115,7 +115,7 @@ instance InsertDb HyperdataDocument
...
@@ -115,7 +115,7 @@ instance InsertDb HyperdataDocument
instance
InsertDb
HyperdataContact
instance
InsertDb
HyperdataContact
where
where
insertDb'
u
p
h
=
[
toField
(
""
::
Text
)
insertDb'
u
p
h
=
[
toField
(
""
::
Text
)
,
toField
$
nodeTypeI
d
NodeContact
,
toField
$
hasDBi
d
NodeContact
,
toField
u
,
toField
u
,
toField
p
,
toField
p
,
toField
$
maybe
"Contact"
(
DT
.
take
255
)
(
Just
"Name"
)
-- (_hc_name h)
,
toField
$
maybe
"Contact"
(
DT
.
take
255
)
(
Just
"Name"
)
-- (_hc_name h)
...
@@ -217,13 +217,13 @@ secret :: Text
...
@@ -217,13 +217,13 @@ secret :: Text
secret
=
"Database secret to change"
secret
=
"Database secret to change"
instance
(
AddUniqId
a
,
ToJSON
a
)
=>
AddUniqId
(
Node
a
)
instance
(
AddUniqId
a
,
ToJSON
a
,
HasDBid
NodeType
)
=>
AddUniqId
(
Node
a
)
where
where
addUniqId
(
Node
nid
_
t
u
p
n
d
h
)
=
Node
nid
hashId
t
u
p
n
d
h
addUniqId
(
Node
nid
_
t
u
p
n
d
h
)
=
Node
nid
hashId
t
u
p
n
d
h
where
where
hashId
=
Just
$
"
\\
x"
<>
(
hash
$
DT
.
concat
params
)
hashId
=
Just
$
"
\\
x"
<>
(
hash
$
DT
.
concat
params
)
params
=
[
secret
params
=
[
secret
,
cs
$
show
$
nodeTypeI
d
NodeDocument
,
cs
$
show
$
hasDBi
d
NodeDocument
,
n
,
n
,
cs
$
show
p
,
cs
$
show
p
,
cs
$
encode
h
,
cs
$
encode
h
...
@@ -235,7 +235,7 @@ instance (AddUniqId a, ToJSON a) => AddUniqId (Node a)
...
@@ -235,7 +235,7 @@ instance (AddUniqId a, ToJSON a) => AddUniqId (Node a)
where
where
hashId = "\\x" <> (hash $ DT.concat params)
hashId = "\\x" <> (hash $ DT.concat params)
params = [ secret
params = [ secret
, cs $ show $
nodeTypeI
d NodeDocument
, cs $ show $
hasDBi
d NodeDocument
, n
, n
, cs $ show p
, cs $ show p
, cs $ encode h
, cs $ encode h
...
@@ -272,10 +272,10 @@ maybeText = maybe (DT.pack "") identity
...
@@ -272,10 +272,10 @@ maybeText = maybe (DT.pack "") identity
class
ToNode
a
class
ToNode
a
where
where
-- TODO Maybe NodeId
-- TODO Maybe NodeId
toNode
::
UserId
->
ParentId
->
a
->
Node
a
toNode
::
HasDBid
NodeType
=>
UserId
->
ParentId
->
a
->
Node
a
instance
ToNode
HyperdataDocument
where
instance
ToNode
HyperdataDocument
where
toNode
u
p
h
=
Node
0
Nothing
(
nodeTypeI
d
NodeDocument
)
u
(
Just
p
)
n
date
h
toNode
u
p
h
=
Node
0
Nothing
(
hasDBi
d
NodeDocument
)
u
(
Just
p
)
n
date
h
where
where
n
=
maybe
"No Title"
(
DT
.
take
255
)
(
_hd_title
h
)
n
=
maybe
"No Title"
(
DT
.
take
255
)
(
_hd_title
h
)
date
=
jour
y
m
d
date
=
jour
y
m
d
...
@@ -285,7 +285,7 @@ instance ToNode HyperdataDocument where
...
@@ -285,7 +285,7 @@ instance ToNode HyperdataDocument where
-- TODO better Node
-- TODO better Node
instance
ToNode
HyperdataContact
where
instance
ToNode
HyperdataContact
where
toNode
u
p
h
=
Node
0
Nothing
(
nodeTypeI
d
NodeContact
)
u
(
Just
p
)
"Contact"
date
h
toNode
u
p
h
=
Node
0
Nothing
(
hasDBi
d
NodeContact
)
u
(
Just
p
)
"Contact"
date
h
where
where
date
=
jour
2020
01
01
date
=
jour
2020
01
01
...
...
src/Gargantext/Database/Query/Table/Node/Select.hs
View file @
b5c9a011
...
@@ -18,21 +18,21 @@ import Control.Arrow (returnA)
...
@@ -18,21 +18,21 @@ import Control.Arrow (returnA)
import
Opaleye
import
Opaleye
import
Protolude
import
Protolude
import
Gargantext.Core
import
Gargantext.Core.Types
import
Gargantext.Core.Types
import
Gargantext.Core.Types.Individu
(
Username
)
import
Gargantext.Core.Types.Individu
(
Username
)
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Schema.User
import
Gargantext.Database.Schema.User
import
Gargantext.Database.Query.Table.User
import
Gargantext.Database.Query.Table.User
selectNodesWithUsername
::
NodeType
->
Username
->
Cmd
err
[
NodeId
]
selectNodesWithUsername
::
HasDBid
NodeType
=>
NodeType
->
Username
->
Cmd
err
[
NodeId
]
selectNodesWithUsername
nt
u
=
runOpaQuery
(
q
u
)
selectNodesWithUsername
nt
u
=
runOpaQuery
(
q
u
)
where
where
q
u'
=
proc
()
->
do
q
u'
=
proc
()
->
do
(
n
,
usrs
)
<-
join'
-<
()
(
n
,
usrs
)
<-
join'
-<
()
restrict
-<
user_username
usrs
.==
(
toNullable
$
pgStrictText
u'
)
restrict
-<
user_username
usrs
.==
(
toNullable
$
pgStrictText
u'
)
restrict
-<
_node_typename
n
.==
(
pgInt4
$
nodeTypeI
d
nt
)
restrict
-<
_node_typename
n
.==
(
pgInt4
$
hasDBi
d
nt
)
returnA
-<
_node_id
n
returnA
-<
_node_id
n
join'
::
Query
(
NodeRead
,
UserReadNull
)
join'
::
Query
(
NodeRead
,
UserReadNull
)
...
...
src/Gargantext/Database/Query/Table/NodeNode.hs
View file @
b5c9a011
...
@@ -43,9 +43,9 @@ import qualified Database.PostgreSQL.Simple as PGS (Query, Only(..))
...
@@ -43,9 +43,9 @@ import qualified Database.PostgreSQL.Simple as PGS (Query, Only(..))
import
qualified
Opaleye
as
O
import
qualified
Opaleye
as
O
import
Opaleye
import
Opaleye
import
Gargantext.Core
import
Gargantext.Core.Types
import
Gargantext.Core.Types
import
Gargantext.Database.Schema.NodeNode
import
Gargantext.Database.Schema.NodeNode
import
Gargantext.Database.Admin.Config
(
nodeTypeId
)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Schema.Node
...
@@ -85,7 +85,7 @@ getNodeNodeWith pId _ maybeNodeType = runOpaQuery query
...
@@ -85,7 +85,7 @@ getNodeNodeWith pId _ maybeNodeType = runOpaQuery query
row@(Node nId typeName _ parent_id _ _ _) <- queryNodeTable -< ()
row@(Node nId typeName _ parent_id _ _ _) <- queryNodeTable -< ()
(NodeNode _ n1id n2id _ _) <- queryNodeNodeTable -< ()
(NodeNode _ n1id n2id _ _) <- queryNodeNodeTable -< ()
let nodeType = maybe 0
nodeTypeI
d maybeNodeType
let nodeType = maybe 0
hasDBi
d maybeNodeType
restrict -< typeName .== pgInt4 nodeType
restrict -< typeName .== pgInt4 nodeType
restrict -< (.||) (parent_id .== (pgNodeId parentId))
restrict -< (.||) (parent_id .== (pgNodeId parentId))
...
@@ -145,46 +145,46 @@ nodeNodesCategory inputData = map (\(PGS.Only a) -> a)
...
@@ -145,46 +145,46 @@ nodeNodesCategory inputData = map (\(PGS.Only a) -> a)
|]
|]
------------------------------------------------------------------------
------------------------------------------------------------------------
selectCountDocs
::
CorpusId
->
Cmd
err
Int
selectCountDocs
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
Int
selectCountDocs
cId
=
runCountOpaQuery
(
queryCountDocs
cId
)
selectCountDocs
cId
=
runCountOpaQuery
(
queryCountDocs
cId
)
where
where
queryCountDocs
cId'
=
proc
()
->
do
queryCountDocs
cId'
=
proc
()
->
do
(
n
,
nn
)
<-
joinInCorpus
-<
()
(
n
,
nn
)
<-
joinInCorpus
-<
()
restrict
-<
nn
^.
nn_node1_id
.==
(
toNullable
$
pgNodeId
cId'
)
restrict
-<
nn
^.
nn_node1_id
.==
(
toNullable
$
pgNodeId
cId'
)
restrict
-<
nn
^.
nn_category
.>=
(
toNullable
$
pgInt4
1
)
restrict
-<
nn
^.
nn_category
.>=
(
toNullable
$
pgInt4
1
)
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
nodeTypeI
d
NodeDocument
)
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
hasDBi
d
NodeDocument
)
returnA
-<
n
returnA
-<
n
-- | TODO use UTCTime fast
-- | TODO use UTCTime fast
selectDocsDates
::
CorpusId
->
Cmd
err
[
Text
]
selectDocsDates
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
[
Text
]
selectDocsDates
cId
=
map
(
head'
"selectDocsDates"
.
splitOn
"-"
)
selectDocsDates
cId
=
map
(
head'
"selectDocsDates"
.
splitOn
"-"
)
<$>
catMaybes
<$>
catMaybes
<$>
map
(
view
hd_publication_date
)
<$>
map
(
view
hd_publication_date
)
<$>
selectDocs
cId
<$>
selectDocs
cId
selectDocs
::
CorpusId
->
Cmd
err
[
HyperdataDocument
]
selectDocs
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
[
HyperdataDocument
]
selectDocs
cId
=
runOpaQuery
(
queryDocs
cId
)
selectDocs
cId
=
runOpaQuery
(
queryDocs
cId
)
queryDocs
::
CorpusId
->
O
.
Query
(
Column
PGJsonb
)
queryDocs
::
HasDBid
NodeType
=>
CorpusId
->
O
.
Query
(
Column
PGJsonb
)
queryDocs
cId
=
proc
()
->
do
queryDocs
cId
=
proc
()
->
do
(
n
,
nn
)
<-
joinInCorpus
-<
()
(
n
,
nn
)
<-
joinInCorpus
-<
()
restrict
-<
nn
^.
nn_node1_id
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
nn
^.
nn_node1_id
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
nn
^.
nn_category
.>=
(
toNullable
$
pgInt4
1
)
restrict
-<
nn
^.
nn_category
.>=
(
toNullable
$
pgInt4
1
)
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
nodeTypeI
d
NodeDocument
)
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
hasDBi
d
NodeDocument
)
returnA
-<
view
(
node_hyperdata
)
n
returnA
-<
view
(
node_hyperdata
)
n
selectDocNodes
::
CorpusId
->
Cmd
err
[
Node
HyperdataDocument
]
selectDocNodes
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
[
Node
HyperdataDocument
]
selectDocNodes
cId
=
runOpaQuery
(
queryDocNodes
cId
)
selectDocNodes
cId
=
runOpaQuery
(
queryDocNodes
cId
)
queryDocNodes
::
CorpusId
->
O
.
Query
NodeRead
queryDocNodes
::
HasDBid
NodeType
=>
CorpusId
->
O
.
Query
NodeRead
queryDocNodes
cId
=
proc
()
->
do
queryDocNodes
cId
=
proc
()
->
do
(
n
,
nn
)
<-
joinInCorpus
-<
()
(
n
,
nn
)
<-
joinInCorpus
-<
()
restrict
-<
nn
^.
nn_node1_id
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
nn
^.
nn_node1_id
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
nn
^.
nn_category
.>=
(
toNullable
$
pgInt4
1
)
restrict
-<
nn
^.
nn_category
.>=
(
toNullable
$
pgInt4
1
)
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
nodeTypeI
d
NodeDocument
)
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
hasDBi
d
NodeDocument
)
returnA
-<
n
returnA
-<
n
joinInCorpus
::
O
.
Query
(
NodeRead
,
NodeNodeReadNull
)
joinInCorpus
::
O
.
Query
(
NodeRead
,
NodeNodeReadNull
)
...
@@ -201,13 +201,13 @@ joinOn1 = leftJoin queryNodeTable queryNodeNodeTable cond
...
@@ -201,13 +201,13 @@ joinOn1 = leftJoin queryNodeTable queryNodeNodeTable cond
------------------------------------------------------------------------
------------------------------------------------------------------------
selectPublicNodes
::
(
Hyperdata
a
,
QueryRunnerColumnDefault
PGJsonb
a
)
selectPublicNodes
::
HasDBid
NodeType
=>
(
Hyperdata
a
,
QueryRunnerColumnDefault
PGJsonb
a
)
=>
Cmd
err
[(
Node
a
,
Maybe
Int
)]
=>
Cmd
err
[(
Node
a
,
Maybe
Int
)]
selectPublicNodes
=
runOpaQuery
(
queryWithType
NodeFolderPublic
)
selectPublicNodes
=
runOpaQuery
(
queryWithType
NodeFolderPublic
)
queryWithType
::
NodeType
->
O
.
Query
(
NodeRead
,
Column
(
Nullable
PGInt4
))
queryWithType
::
HasDBid
NodeType
=>
NodeType
->
O
.
Query
(
NodeRead
,
Column
(
Nullable
PGInt4
))
queryWithType
nt
=
proc
()
->
do
queryWithType
nt
=
proc
()
->
do
(
n
,
nn
)
<-
joinOn1
-<
()
(
n
,
nn
)
<-
joinOn1
-<
()
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
nodeTypeI
d
nt
)
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
hasDBi
d
nt
)
returnA
-<
(
n
,
nn
^.
nn_node2_id
)
returnA
-<
(
n
,
nn
^.
nn_node2_id
)
src/Gargantext/Database/Query/Tree.hs
View file @
b5c9a011
...
@@ -46,9 +46,9 @@ import Database.PostgreSQL.Simple
...
@@ -46,9 +46,9 @@ import Database.PostgreSQL.Simple
import
Database.PostgreSQL.Simple.SqlQQ
import
Database.PostgreSQL.Simple.SqlQQ
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Core
import
Gargantext.Core.Types.Main
(
NodeTree
(
..
),
Tree
(
..
))
import
Gargantext.Core.Types.Main
(
NodeTree
(
..
),
Tree
(
..
))
import
Gargantext.Database.Admin.Config
(
fromNodeTypeId
,
nodeTypeId
,
fromNodeTypeId
)
import
Gargantext.Database.Admin.Config
hiding
(
nodeTypes
)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
)
import
Gargantext.Database.Prelude
(
Cmd
,
runPGSQuery
)
import
Gargantext.Database.Query.Table.NodeNode
(
getNodeNode
)
import
Gargantext.Database.Query.Table.NodeNode
(
getNodeNode
)
...
@@ -153,16 +153,16 @@ updateTree nts fun r = do
...
@@ -153,16 +153,16 @@ updateTree nts fun r = do
sharedTreeUpdate
::
HasTreeError
err
=>
UpdateTree
err
sharedTreeUpdate
::
HasTreeError
err
=>
UpdateTree
err
sharedTreeUpdate
p
nt
n
=
dbTree
n
nt
sharedTreeUpdate
p
nt
n
=
dbTree
n
nt
<&>
map
(
\
n'
->
if
(
view
dt_nodeId
n'
)
==
n
<&>
map
(
\
n'
->
if
(
view
dt_nodeId
n'
)
==
n
-- && elem (from
NodeTypeI
d $ _dt_typeId n') [NodeGraph]
-- && elem (from
DBi
d $ _dt_typeId n') [NodeGraph]
-- && not (elem (from
NodeTypeI
d $ _dt_typeId n') [NodeFile])
-- && not (elem (from
DBi
d $ _dt_typeId n') [NodeFile])
then
set
dt_parentId
(
Just
p
)
n'
then
set
dt_parentId
(
Just
p
)
n'
else
n'
)
else
n'
)
publicTreeUpdate
::
HasTreeError
err
=>
UpdateTree
err
publicTreeUpdate
::
HasTreeError
err
=>
UpdateTree
err
publicTreeUpdate
p
nt
n
=
dbTree
n
nt
publicTreeUpdate
p
nt
n
=
dbTree
n
nt
<&>
map
(
\
n'
->
if
_dt_nodeId
n'
==
n
<&>
map
(
\
n'
->
if
_dt_nodeId
n'
==
n
-- && (from
NodeTypeI
d $ _dt_typeId n') /= NodeGraph
-- && (from
DBi
d $ _dt_typeId n') /= NodeGraph
-- && not (elem (from
NodeTypeI
d $ _dt_typeId n') [NodeFile])
-- && not (elem (from
DBi
d $ _dt_typeId n') [NodeFile])
then
set
dt_parentId
(
Just
p
)
n'
then
set
dt_parentId
(
Just
p
)
n'
else
n'
)
else
n'
)
...
@@ -178,7 +178,7 @@ findNodesWithType :: RootId -> [NodeType] -> [NodeType] -> Cmd err [DbTreeNode]
...
@@ -178,7 +178,7 @@ findNodesWithType :: RootId -> [NodeType] -> [NodeType] -> Cmd err [DbTreeNode]
findNodesWithType
root
target
through
=
findNodesWithType
root
target
through
=
filter
isInTarget
<$>
dbTree
root
through
filter
isInTarget
<$>
dbTree
root
through
where
where
isInTarget
n
=
List
.
elem
(
from
NodeTypeI
d
$
view
dt_typeId
n
)
isInTarget
n
=
List
.
elem
(
from
DBi
d
$
view
dt_typeId
n
)
$
List
.
nub
$
target
<>
through
$
List
.
nub
$
target
<>
through
------------------------------------------------------------------------
------------------------------------------------------------------------
...
...
src/Gargantext/Database/Query/Tree/Root.hs
View file @
b5c9a011
...
@@ -15,11 +15,12 @@ module Gargantext.Database.Query.Tree.Root
...
@@ -15,11 +15,12 @@ module Gargantext.Database.Query.Tree.Root
import
Control.Arrow
(
returnA
)
import
Control.Arrow
(
returnA
)
import
Data.Either
(
Either
,
fromLeft
,
fromRight
)
import
Data.Either
(
Either
,
fromLeft
,
fromRight
)
import
Gargantext.Core
import
Gargantext.Core.Types.Individu
(
User
(
..
))
import
Gargantext.Core.Types.Individu
(
User
(
..
))
import
Gargantext.Core.Types.Main
(
CorpusName
)
import
Gargantext.Core.Types.Main
(
CorpusName
)
import
Gargantext.Database.Action.Node
import
Gargantext.Database.Action.Node
import
Gargantext.Database.Action.User
(
getUserId
,
getUsername
)
import
Gargantext.Database.Action.User
(
getUserId
,
getUsername
)
import
Gargantext.Database.Admin.Config
(
nodeTypeId
,
userMaster
)
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataUser
)
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataUser
)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
(
Cmd
,
runOpaQuery
)
import
Gargantext.Database.Prelude
(
Cmd
,
runOpaQuery
)
...
@@ -118,21 +119,21 @@ selectRoot :: User -> Query NodeRead
...
@@ -118,21 +119,21 @@ selectRoot :: User -> Query NodeRead
selectRoot
(
UserName
username
)
=
proc
()
->
do
selectRoot
(
UserName
username
)
=
proc
()
->
do
row
<-
queryNodeTable
-<
()
row
<-
queryNodeTable
-<
()
users
<-
queryUserTable
-<
()
users
<-
queryUserTable
-<
()
restrict
-<
_node_typename
row
.==
(
pgInt4
$
nodeTypeI
d
NodeUser
)
restrict
-<
_node_typename
row
.==
(
pgInt4
$
hasDBi
d
NodeUser
)
restrict
-<
user_username
users
.==
(
pgStrictText
username
)
restrict
-<
user_username
users
.==
(
pgStrictText
username
)
restrict
-<
_node_userId
row
.==
(
user_id
users
)
restrict
-<
_node_userId
row
.==
(
user_id
users
)
returnA
-<
row
returnA
-<
row
selectRoot
(
UserDBId
uid
)
=
proc
()
->
do
selectRoot
(
UserDBId
uid
)
=
proc
()
->
do
row
<-
queryNodeTable
-<
()
row
<-
queryNodeTable
-<
()
restrict
-<
_node_typename
row
.==
(
pgInt4
$
nodeTypeI
d
NodeUser
)
restrict
-<
_node_typename
row
.==
(
pgInt4
$
hasDBi
d
NodeUser
)
restrict
-<
_node_userId
row
.==
(
pgInt4
uid
)
restrict
-<
_node_userId
row
.==
(
pgInt4
uid
)
returnA
-<
row
returnA
-<
row
selectRoot
(
RootId
nid
)
=
selectRoot
(
RootId
nid
)
=
proc
()
->
do
proc
()
->
do
row
<-
queryNodeTable
-<
()
row
<-
queryNodeTable
-<
()
restrict
-<
_node_typename
row
.==
(
pgInt4
$
nodeTypeI
d
NodeUser
)
restrict
-<
_node_typename
row
.==
(
pgInt4
$
hasDBi
d
NodeUser
)
restrict
-<
_node_id
row
.==
(
pgNodeId
nid
)
restrict
-<
_node_id
row
.==
(
pgNodeId
nid
)
returnA
-<
row
returnA
-<
row
selectRoot
UserPublic
=
panic
{-nodeError $ NodeError-}
"[G.D.Q.T.Root.selectRoot] No root for Public"
selectRoot
UserPublic
=
panic
{-nodeError $ NodeError-}
"[G.D.Q.T.Root.selectRoot] No root for Public"
src/Gargantext/Database/Schema/NgramsPostag.hs
View file @
b5c9a011
...
@@ -22,7 +22,9 @@ module Gargantext.Database.Schema.NgramsPostag
...
@@ -22,7 +22,9 @@ module Gargantext.Database.Schema.NgramsPostag
import
Control.Lens
import
Control.Lens
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Gargantext.Core
import
Gargantext.Database.Schema.Prelude
import
Gargantext.Database.Schema.Prelude
import
Gargantext.API.Ngrams.Types
import
Gargantext.Prelude
import
Gargantext.Prelude
import
qualified
Database.PostgreSQL.Simple
as
PGS
import
qualified
Database.PostgreSQL.Simple
as
PGS
...
@@ -33,7 +35,7 @@ data NgramsPostagPoly id
...
@@ -33,7 +35,7 @@ data NgramsPostagPoly id
ngrams_id
ngrams_id
lemm_id
lemm_id
score
score
=
NgramsPostag
DB
{
_ngramsPostag_id
::
!
id
=
NgramsPostag
Poly
{
_ngramsPostag_id
::
!
id
,
_ngramsPostag_lang_id
::
!
lang_id
,
_ngramsPostag_lang_id
::
!
lang_id
,
_ngramsPostag_algo_id
::
!
algo_id
,
_ngramsPostag_algo_id
::
!
algo_id
,
_ngramsPostag_postag
::
!
postag
,
_ngramsPostag_postag
::
!
postag
...
@@ -43,9 +45,18 @@ data NgramsPostagPoly id
...
@@ -43,9 +45,18 @@ data NgramsPostagPoly id
}
deriving
(
Show
)
}
deriving
(
Show
)
------------------------------------------------------------------------
------------------------------------------------------------------------
data
PosTag
=
PosTag
{
unPosTag
::
Text
}
|
NER
{
unNER
::
Text
}
-- TODO
------------------------------------------------------------------------
type
NgramsPostag
=
NgramsPostagPoly
(
Maybe
Int
)
Lang
PostTagAlgo
(
Maybe
PosTag
)
NgramsTerm
NgramsTerm
(
Maybe
Int
)
type
NgramsPostagDB
=
NgramsPostagPoly
(
Maybe
Int
)
Int
Int
(
Maybe
Text
)
Int
Int
Int
type
NgramsPostagDB
=
NgramsPostagPoly
(
Maybe
Int
)
Int
Int
(
Maybe
Text
)
Int
Int
Int
------------------------------------------------------------------------
type
NgramsPosTagWrite
=
NgramsPostagPoly
(
Maybe
(
Column
PGInt4
))
type
NgramsPosTagWrite
=
NgramsPostagPoly
(
Maybe
(
Column
PGInt4
))
(
Column
PGInt4
)
(
Column
PGInt4
)
(
Column
PGInt4
)
(
Column
PGInt4
)
...
@@ -72,7 +83,7 @@ type NgramsPosTagReadNull = NgramsPostagPoly (Column (Nullable PGInt4))
...
@@ -72,7 +83,7 @@ type NgramsPosTagReadNull = NgramsPostagPoly (Column (Nullable PGInt4))
makeLenses
''
N
gramsPostagPoly
makeLenses
''
N
gramsPostagPoly
instance
PGS
.
ToRow
NgramsPostagDB
where
instance
PGS
.
ToRow
NgramsPostagDB
where
toRow
(
NgramsPostag
DB
f0
f1
f2
f3
f4
f5
f6
)
=
[
toField
f0
toRow
(
NgramsPostag
Poly
f0
f1
f2
f3
f4
f5
f6
)
=
[
toField
f0
,
toField
f1
,
toField
f1
,
toField
f2
,
toField
f2
,
toField
f3
,
toField
f3
...
...
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