Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Przemyslaw Kaminski
haskell-gargantext
Commits
6fcad8ff
Commit
6fcad8ff
authored
Nov 21, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DB] SQL queries for ngrams table.
parent
2adb8ebd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
3 deletions
+93
-3
Flow.hs
src/Gargantext/Database/Flow.hs
+9
-2
Ngrams.hs
src/Gargantext/Database/Ngrams.hs
+84
-1
No files found.
src/Gargantext/Database/Flow.hs
View file @
6fcad8ff
...
@@ -51,7 +51,7 @@ type UserId = Int
...
@@ -51,7 +51,7 @@ type UserId = Int
type
RootId
=
Int
type
RootId
=
Int
type
CorpusId
=
Int
type
CorpusId
=
Int
flowDatabase
::
FileFormat
->
FilePath
->
CorpusName
->
IO
Int
--flowDatabase :: FileFormat -> FilePath -> CorpusName -> Cmd
Int
flowDatabase
ff
fp
cName
=
do
flowDatabase
ff
fp
cName
=
do
-- Corus Flow
-- Corus Flow
...
@@ -92,7 +92,11 @@ flowDatabase ff fp cName = do
...
@@ -92,7 +92,11 @@ flowDatabase ff fp cName = do
listId2
<-
runCmd'
$
listFlow
masterUserId
corpusId
indexedNgrams
listId2
<-
runCmd'
$
listFlow
masterUserId
corpusId
indexedNgrams
printDebug
"list id : "
listId2
printDebug
"list id : "
listId2
(
_
,
_
,
corpusId2
)
<-
subFlow
"user1"
cName
(
userId
,
_
,
corpusId2
)
<-
subFlow
"user1"
cName
userListId
<-
runCmd'
$
listFlowUser
userId
corpusId2
printDebug
"UserList : "
userListId
inserted
<-
runCmd'
$
add
corpusId2
(
map
reId
ids
)
inserted
<-
runCmd'
$
add
corpusId2
(
map
reId
ids
)
printDebug
"Inserted : "
(
length
inserted
)
printDebug
"Inserted : "
(
length
inserted
)
...
@@ -219,6 +223,9 @@ listFlow uId cId ngs = do
...
@@ -219,6 +223,9 @@ listFlow uId cId ngs = do
pure
lId
pure
lId
listFlowUser
::
UserId
->
CorpusId
->
Cmd
[
Int
]
listFlowUser
uId
cId
=
mkList
cId
uId
------------------------------------------------------------------------
------------------------------------------------------------------------
groupNgramsBy
::
(
NgramsT
NgramsIndexed
->
NgramsT
NgramsIndexed
->
Maybe
(
NgramsIndexed
,
NgramsIndexed
))
groupNgramsBy
::
(
NgramsT
NgramsIndexed
->
NgramsT
NgramsIndexed
->
Maybe
(
NgramsIndexed
,
NgramsIndexed
))
...
...
src/Gargantext/Database/Ngrams.hs
View file @
6fcad8ff
...
@@ -87,7 +87,7 @@ ngramsTypeId Terms = 4
...
@@ -87,7 +87,7 @@ ngramsTypeId Terms = 4
type
NgramsTerms
=
Text
type
NgramsTerms
=
Text
type
NgramsId
=
Int
type
NgramsId
=
Int
type
Size
=
Int
type
Size
=
Int
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | TODO put it in Gargantext.Text.Ngrams
-- | TODO put it in Gargantext.Text.Ngrams
...
@@ -169,3 +169,86 @@ queryInsertNgrams = [sql|
...
@@ -169,3 +169,86 @@ queryInsertNgrams = [sql|
FROM input_rows
FROM input_rows
JOIN ngrams c USING (terms); -- columns of unique index
JOIN ngrams c USING (terms); -- columns of unique index
|]
|]
-- | Ngrams Table
data
NgramsTableParam
=
NgramsTableParam
{
_nt_listId
::
Int
,
_nt_corpusId
::
Int
,
_nt_typeNode
::
Int
,
_nt_typeNgrams
::
Int
}
type
NgramsTableParamUser
=
NgramsTableParam
type
NgramsTableParamMaster
=
NgramsTableParam
data
NgramsTableData
=
NgramsTableData
{
_ntd_terms
::
Text
,
_ntd_n
::
Int
,
_ntd_ngramsType
::
Int
,
_ntd_weight
::
Double
}
deriving
(
Show
)
getTableNgrams
::
NgramsTableParamUser
->
NgramsTableParamMaster
->
Cmd
[(
Text
,
Int
,
Int
,
Double
)]
getTableNgrams
(
NgramsTableParam
ul
uc
utn
utg
)
(
NgramsTableParam
ml
mc
mtn
mtg
)
=
mkCmd
$
\
conn
->
DPS
.
query
conn
querySelectTableNgrams
(
ul
,
uc
,
utn
,
utg
,
ml
,
mc
,
mtn
,
mtg
)
querySelectTableNgrams
::
DPS
.
Query
querySelectTableNgrams
=
[
sql
|
WITH tableUser AS (select ngs.terms, ngs.n, nn1.ngrams_type,nn2.weight FROM ngrams ngs
JOIN nodes_ngrams nn1 ON nn1.ngram_id = ngs.id
JOIN nodes_ngrams nn2 ON nn2.ngram_id = ngs.id
JOIN nodes n ON n.id = nn2.node_id
WHERE nn1.node_id = ? -- User listId
AND n.parent_id = ? -- User CorpusId or AnnuaireId
AND n.typename = ? -- both type of childs (Documents or Contacts)
AND nn2.ngrams_type = ? -- both type of ngrams (Authors or Terms?)
), tableMaster AS (select ngs.terms, ngs.n, nn1.ngrams_type,nn2.weight FROM ngrams ngs
JOIN nodes_ngrams nn1 ON nn1.ngram_id = ngs.id
JOIN nodes_ngrams nn2 ON nn2.ngram_id = ngs.id
JOIN nodes n ON n.id = nn2.node_id
WHERE nn1.node_id = ? -- Master listId
AND n.parent_id = ? -- Master CorpusId or AnnuaireId
AND n.typename = ? -- both type of childs (Documents or Contacts)
AND nn2.ngrams_type = ? -- both type of ngrams (Authors or Terms?)
)
SELECT COALESCE(tu.terms,tm.terms) AS terms
, COALESCE(tu.n,tm.n) AS n
, COALESCE(tu.ngrams_type,tm.ngrams_type) AS ngrams_type
, COALESCE(tu.weight,tm.weight) AS weight
FROM tableUser tu RIGHT JOIN tableMaster tm ON tu.terms = tm.terms;
|]
type
ListIdUser
=
Int
type
ListIdMaster
=
Int
getNgramsGroup
::
ListIdUser
->
ListIdMaster
->
Cmd
[(
Text
,
Text
)]
getNgramsGroup
lu
lm
=
mkCmd
$
\
conn
->
DPS
.
query
conn
querySelectNgramsGroup
(
lu
,
lm
)
querySelectNgramsGroup
::
DPS
.
Query
querySelectNgramsGroup
=
[
sql
|
WITH groupUser AS (
SELECT n1.terms AS t1, n2.terms AS t2 FROM nodes_ngrams_ngrams nnn
JOIN ngrams n1 ON n1.id = nnn.ngram1_id
JOIN ngrams n2 ON n2.id = nnn.ngram2_id
WHERE
nnn.node_id = ? -- User listId
),
groupMaster AS (
SELECT n1.terms AS t1, n2.terms AS t2 FROM nodes_ngrams_ngrams nnn
JOIN ngrams n1 ON n1.id = nnn.ngram1_id
JOIN ngrams n2 ON n2.id = nnn.ngram2_id
WHERE
nnn.node_id = ? -- Master listId
)
SELECT COALESCE(gu.t1,gm.t1) AS ngram1_id
, COALESCE(gu.t2,gm.t2) AS ngram2_id
FROM groupUser gu RIGHT JOIN groupMaster gm ON gu.t1 = gm.t1
|]
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