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
158
Issues
158
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
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
21f8b2e0
Commit
21f8b2e0
authored
Sep 11, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TextFlow] grouping fun
parent
23ef92fa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
41 deletions
+53
-41
List.hs
src/Gargantext/Core/Text/List.hs
+41
-37
Types.hs
src/Gargantext/Core/Types.hs
+1
-3
Main.hs
src/Gargantext/Core/Types/Main.hs
+10
-0
NgramsByNode.hs
src/Gargantext/Database/Action/Metrics/NgramsByNode.hs
+1
-1
No files found.
src/Gargantext/Core/Text/List.hs
View file @
21f8b2e0
...
...
@@ -21,7 +21,7 @@ import Gargantext.API.Ngrams (NgramsElement, mkNgramsElement, RootParent(..), mS
-- import Gargantext.API.Ngrams.Tools (getCoocByNgrams', Diagonal(..))
import
Gargantext.Core
(
Lang
(
..
))
import
Gargantext.Core.Types
(
ListType
(
..
),
MasterCorpusId
,
UserCorpusId
,
Ordering
(
..
))
import
Gargantext.Database.Action.Metrics.NgramsByNode
(
{-ngramsGroup,-}
getNodesByNgramsUser
,
groupNodesByNgramsWith
)
import
Gargantext.Database.Action.Metrics.NgramsByNode
(
ngramsGroup
,
getNodesByNgramsUser
,
groupNodesByNgramsWith
)
import
Gargantext.Database.Action.Metrics.TFICF
(
getTficf
)
import
Gargantext.Core.Text.Metrics.TFICF
(
sortTficf
)
import
Gargantext.Database.Prelude
(
Cmd
)
...
...
@@ -98,10 +98,10 @@ buildNgramsTermsList :: Lang
->
UserCorpusId
->
MasterCorpusId
->
Cmd
err
(
Map
NgramsType
[
NgramsElement
])
buildNgramsTermsList
_l
_n
_
m
s
uCid
mCid
=
do
buildNgramsTermsList
l
n
m
s
uCid
mCid
=
do
candidates
<-
sortTficf
Up
<$>
getTficf
uCid
mCid
NgramsTerms
printDebug
"head candidates"
(
List
.
take
10
$
candidates
)
printDebug
"tail candidates"
(
List
.
take
10
$
List
.
reverse
$
candidates
)
--
printDebug "head candidates" (List.take 10 $ candidates)
--
printDebug "tail candidates" (List.take 10 $ List.reverse $ candidates)
let
(
candidatesHead
,
candidatesTail0
)
=
List
.
splitAt
3
candidates
...
...
@@ -113,43 +113,47 @@ buildNgramsTermsList _l _n _m s uCid mCid = do
ngs
=
List
.
concat
$
map
toNgramsElement
$
map
(
\
(
lt
,
(
t
,
d
))
->
(
lt
,
((
t
,
(
d
,
Set
.
singleton
t
)))))
termList
$
groupStems
$
map
(
\
(
listType
,
(
t
,
d
))
->
(
ngramsGroup
l
n
m
t
,
GroupedText
listType
t
d
Set
.
empty
)
)
termList
pure
$
Map
.
fromList
[(
NgramsTerms
,
ngs
)]
toTermList
::
Int
->
Int
->
(
a
->
Bool
)
->
[
a
]
->
[(
ListType
,
a
)]
toTermList
_
_
_
[]
=
[]
toTermList
a
b
stop
ns
=
-- trace ("computing toTermList") $
map
(
toGargList
stop
CandidateTerm
)
xs
<>
map
(
toGargList
stop
MapTerm
)
ys
<>
toTermList
a
b
stop
zs
type
Group
=
Lang
->
Int
->
Int
->
Text
->
Text
type
Stem
=
Text
type
Label
=
Text
data
GroupedText
=
GroupedText
{
_gt_listType
::
ListType
,
_gt_label
::
Label
,
_gt_score
::
Double
,
_gt_group
::
Set
Text
}
groupStems
::
[(
Stem
,
GroupedText
)]
->
[
GroupedText
]
groupStems
=
Map
.
elems
.
Map
.
fromListWith
grouping
where
grouping
(
GroupedText
lt1
label1
score1
group1
)
(
GroupedText
lt2
label2
score2
group2
)
|
score1
>=
score2
=
GroupedText
lt
label1
score1
(
Set
.
insert
label2
gr
)
|
otherwise
=
GroupedText
lt
label2
score2
(
Set
.
insert
label1
gr
)
where
lt
=
lt1
<>
lt2
gr
=
Set
.
union
group1
group2
toNgramsElement
::
GroupedText
->
[
NgramsElement
]
toNgramsElement
(
GroupedText
listType
label
_
setNgrams
)
=
[
parentElem
]
<>
childrenElems
where
xs
=
take
a
ns
xz
=
drop
a
ns
ys
=
take
b
xz
zs
=
drop
b
xz
toNgramsElement
::
(
ListType
,
(
Text
,
(
Double
,
Set
Text
)))
->
[
NgramsElement
]
toNgramsElement
(
listType
,
(
_stem
,
(
_score
,
setNgrams
)))
=
case
Set
.
toList
setNgrams
of
[]
->
[]
(
parent
:
children
)
->
[
parentElem
]
<>
childrenElems
where
parentElem
=
mkNgramsElement
parent
listType
Nothing
(
mSetFromList
children
)
childrenElems
=
map
(
\
t
->
mkNgramsElement
t
listType
(
Just
$
RootParent
parent
parent
)
(
mSetFromList
[]
)
)
children
parent
=
label
children
=
Set
.
toList
setNgrams
parentElem
=
mkNgramsElement
parent
listType
Nothing
(
mSetFromList
children
)
childrenElems
=
map
(
\
t
->
mkNgramsElement
t
listType
(
Just
$
RootParent
parent
parent
)
(
mSetFromList
[]
)
)
children
toGargList
::
(
b
->
Bool
)
->
ListType
->
b
->
(
ListType
,
b
)
...
...
src/Gargantext/Core/Types.hs
View file @
21f8b2e0
...
...
@@ -126,10 +126,8 @@ instance Semigroup TokenTag where
instance
Monoid
TokenTag
where
mempty
=
TokenTag
[]
empty
Nothing
Nothing
mappend
t1
t2
=
(
<>
)
t1
t2
mconcat
=
foldl
mappend
mempty
-- mappend t1 t2 = (<>) t1 t2
class
HasInvalidError
e
where
...
...
src/Gargantext/Core/Types/Main.hs
View file @
21f8b2e0
...
...
@@ -23,6 +23,7 @@ import Data.Either (Either(..))
import
Data.Eq
(
Eq
())
import
Data.Map
(
fromList
,
lookup
)
import
Data.Monoid
((
<>
))
import
Data.Semigroup
(
Semigroup
(
..
))
import
Data.Swagger
import
Data.Text
(
Text
,
unpack
)
import
GHC.Generics
(
Generic
)
...
...
@@ -61,6 +62,15 @@ instance ToParamSchema ListType
instance
Arbitrary
ListType
where
arbitrary
=
elements
[
minBound
..
maxBound
]
instance
Semigroup
ListType
where
MapTerm
<>
_
=
MapTerm
_
<>
MapTerm
=
MapTerm
CandidateTerm
<>
_
=
CandidateTerm
_
<>
CandidateTerm
=
CandidateTerm
StopTerm
<>
StopTerm
=
StopTerm
instance
FromHttpApiData
ListType
where
parseUrlPiece
=
Right
.
read
.
unpack
...
...
src/Gargantext/Database/Action/Metrics/NgramsByNode.hs
View file @
21f8b2e0
...
...
@@ -66,7 +66,7 @@ countNodesByNgramsWith f m = (total, m')
where
total
=
fromIntegral
$
Set
.
size
$
Set
.
unions
$
elems
m
m'
=
Map
.
map
(
swap
.
second
(
fromIntegral
.
Set
.
size
))
$
groupNodesByNgramsWith
f
m
$
groupNodesByNgramsWith
f
m
groupNodesByNgramsWith
::
(
Text
->
Text
)
...
...
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