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
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
Christian Merten
haskell-gargantext
Commits
21e3b7ca
Commit
21e3b7ca
authored
Aug 29, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[REST] Adding Graph api end point.
parent
40463188
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
12 deletions
+54
-12
API.hs
src/Gargantext/API.hs
+5
-0
Node.hs
src/Gargantext/API/Node.hs
+13
-0
Graph.hs
src/Gargantext/Viz/Graph.hs
+22
-1
Matrice.hs
src/Gargantext/Viz/Graph/Distances/Matrice.hs
+14
-11
No files found.
src/Gargantext/API.hs
View file @
21e3b7ca
...
...
@@ -68,6 +68,7 @@ import Gargantext.API.FrontEnd (FrontEndAPI, frontEndServer)
import
Gargantext.API.Node
(
Roots
,
roots
,
NodeAPI
,
nodeAPI
,
NodesAPI
,
nodesAPI
,
GraphAPI
,
graphAPI
)
import
Gargantext.API.Count
(
CountAPI
,
count
,
Query
)
import
Gargantext.API.Search
(
SearchAPI
,
search
,
SearchQuery
)
...
...
@@ -215,6 +216,9 @@ type GargAPI =
-- Corpus endpoint
:<|>
"search"
:>
Summary
"Search endpoint"
:>
ReqBody
'[
J
SON
]
SearchQuery
:>
SearchAPI
:<|>
"graph"
:>
Summary
"Graph endpoint"
:>
Capture
"id"
Int
:>
GraphAPI
-- :<|> "scraper" :> WithCallbacks ScraperAPI
...
...
@@ -242,6 +246,7 @@ server env = do
:<|>
nodesAPI
conn
:<|>
count
:<|>
search
conn
:<|>
graphAPI
conn
-- :<|> orchestrator
where
conn
=
env
^.
env_conn
...
...
src/Gargantext/API/Node.hs
View file @
21e3b7ca
...
...
@@ -45,6 +45,11 @@ import Gargantext.Database.Node ( getNodesWithParentId
import
Gargantext.Database.Facet
(
FacetDoc
,
getDocFacet
,
FacetChart
)
-- Graph
import
Gargantext.TextFlow
import
Gargantext.Viz.Graph
(
Graph
)
import
Gargantext.Core
(
Lang
(
..
))
import
Gargantext.Text.Terms
(
TermType
(
..
))
-------------------------------------------------------------------
-------------------------------------------------------------------
-- | Node API Types management
...
...
@@ -101,6 +106,12 @@ roots conn = liftIO (putStrLn ( "/user" :: Text) >> getNodesWithParentId conn 0
:<|>
pure
(
panic
"not implemented yet"
)
:<|>
pure
(
panic
"not implemented yet"
)
type
GraphAPI
=
Get
'[
J
SON
]
Graph
graphAPI
::
Connection
->
NodeId
->
Server
GraphAPI
graphAPI
_
_
=
liftIO
$
textFlow
(
Mono
EN
)
(
Contexts
contextText
)
nodeAPI
::
Connection
->
NodeId
->
Server
NodeAPI
nodeAPI
conn
id
=
liftIO
(
putStrLn
(
"/node"
::
Text
)
>>
getNode
conn
id
)
:<|>
deleteNode'
conn
id
...
...
@@ -110,6 +121,8 @@ nodeAPI conn id = liftIO (putStrLn ("/node" :: Text) >> getNode co
-- :<|> upload
-- :<|> query
nodesAPI
::
Connection
->
[
NodeId
]
->
Server
NodesAPI
nodesAPI
conn
ids
=
deleteNodes'
conn
ids
...
...
src/Gargantext/Viz/Graph.hs
View file @
21e3b7ca
...
...
@@ -16,6 +16,7 @@ Portability : POSIX
module
Gargantext.Viz.Graph
where
------------------------------------------------------------------------
import
GHC.IO
(
FilePath
)
import
GHC.Generics
(
Generic
)
import
Data.Aeson.TH
(
deriveJSON
)
...
...
@@ -23,19 +24,26 @@ import qualified Data.Aeson as DA
import
Data.ByteString.Lazy
as
DBL
(
readFile
,
writeFile
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
,
pack
)
import
qualified
Text.Read
as
T
import
qualified
Data.Text
as
T
import
Data.Map.Strict
(
Map
)
import
qualified
Data.Map.Strict
as
M
import
Data.Swagger
(
ToSchema
)
import
Gargantext.Prelude
import
Gargantext.Core.Types
(
Label
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
)
import
Data.Graph.Clustering.Louvain.CplusPlus
(
LouvainNode
(
..
))
import
Test.QuickCheck.Arbitrary
(
Arbitrary
,
arbitrary
)
import
Test.QuickCheck
(
elements
)
------------------------------------------------------------------------
data
TypeNode
=
Terms
|
Unknown
deriving
(
Show
,
Generic
)
...
...
@@ -67,6 +75,19 @@ data Graph = Graph { graph_nodes :: [Node]
}
deriving
(
Show
,
Generic
)
$
(
deriveJSON
(
unPrefix
"graph_"
)
''
G
raph
)
-- | Intances for Swagger documentation
instance
ToSchema
Node
instance
ToSchema
TypeNode
instance
ToSchema
Attributes
instance
ToSchema
Edge
instance
ToSchema
Graph
-- | Intances for the mack
instance
Arbitrary
Graph
where
arbitrary
=
elements
$
[
Graph
{
graph_nodes
=
[
Node
{
node_size
=
4
,
node_type
=
Terms
,
node_id
=
pack
"0"
,
node_label
=
pack
"animal"
,
node_attributes
=
Attributes
{
clust_default
=
0
}},
Node
{
node_size
=
3
,
node_type
=
Terms
,
node_id
=
pack
"1"
,
node_label
=
pack
"bird"
,
node_attributes
=
Attributes
{
clust_default
=
0
}},
Node
{
node_size
=
2
,
node_type
=
Terms
,
node_id
=
pack
"2"
,
node_label
=
pack
"boy"
,
node_attributes
=
Attributes
{
clust_default
=
1
}},
Node
{
node_size
=
2
,
node_type
=
Terms
,
node_id
=
pack
"3"
,
node_label
=
pack
"dog"
,
node_attributes
=
Attributes
{
clust_default
=
0
}},
Node
{
node_size
=
2
,
node_type
=
Terms
,
node_id
=
pack
"4"
,
node_label
=
pack
"girl"
,
node_attributes
=
Attributes
{
clust_default
=
1
}},
Node
{
node_size
=
4
,
node_type
=
Terms
,
node_id
=
pack
"5"
,
node_label
=
pack
"human body"
,
node_attributes
=
Attributes
{
clust_default
=
1
}},
Node
{
node_size
=
3
,
node_type
=
Terms
,
node_id
=
pack
"6"
,
node_label
=
pack
"object"
,
node_attributes
=
Attributes
{
clust_default
=
2
}},
Node
{
node_size
=
2
,
node_type
=
Terms
,
node_id
=
pack
"7"
,
node_label
=
pack
"pen"
,
node_attributes
=
Attributes
{
clust_default
=
2
}},
Node
{
node_size
=
2
,
node_type
=
Terms
,
node_id
=
pack
"8"
,
node_label
=
pack
"table"
,
node_attributes
=
Attributes
{
clust_default
=
2
}}],
graph_edges
=
[
Edge
{
edge_source
=
pack
"0"
,
edge_target
=
pack
"0"
,
edge_weight
=
1.0
,
edge_id
=
pack
"0"
},
Edge
{
edge_source
=
pack
"1"
,
edge_target
=
pack
"0"
,
edge_weight
=
1.0
,
edge_id
=
pack
"1"
},
Edge
{
edge_source
=
pack
"1"
,
edge_target
=
pack
"1"
,
edge_weight
=
1.0
,
edge_id
=
pack
"2"
},
Edge
{
edge_source
=
pack
"2"
,
edge_target
=
pack
"2"
,
edge_weight
=
1.0
,
edge_id
=
pack
"3"
},
Edge
{
edge_source
=
pack
"2"
,
edge_target
=
pack
"5"
,
edge_weight
=
1.0
,
edge_id
=
pack
"4"
},
Edge
{
edge_source
=
pack
"3"
,
edge_target
=
pack
"0"
,
edge_weight
=
1.0
,
edge_id
=
pack
"5"
},
Edge
{
edge_source
=
pack
"3"
,
edge_target
=
pack
"1"
,
edge_weight
=
1.0
,
edge_id
=
pack
"6"
},
Edge
{
edge_source
=
pack
"3"
,
edge_target
=
pack
"3"
,
edge_weight
=
1.0
,
edge_id
=
pack
"7"
},
Edge
{
edge_source
=
pack
"4"
,
edge_target
=
pack
"4"
,
edge_weight
=
1.0
,
edge_id
=
pack
"8"
},
Edge
{
edge_source
=
pack
"4"
,
edge_target
=
pack
"5"
,
edge_weight
=
1.0
,
edge_id
=
pack
"9"
},
Edge
{
edge_source
=
pack
"5"
,
edge_target
=
pack
"5"
,
edge_weight
=
1.0
,
edge_id
=
pack
"10"
},
Edge
{
edge_source
=
pack
"6"
,
edge_target
=
pack
"6"
,
edge_weight
=
1.0
,
edge_id
=
pack
"11"
},
Edge
{
edge_source
=
pack
"7"
,
edge_target
=
pack
"6"
,
edge_weight
=
1.0
,
edge_id
=
pack
"12"
},
Edge
{
edge_source
=
pack
"7"
,
edge_target
=
pack
"7"
,
edge_weight
=
1.0
,
edge_id
=
pack
"13"
},
Edge
{
edge_source
=
pack
"8"
,
edge_target
=
pack
"6"
,
edge_weight
=
1.0
,
edge_id
=
pack
"14"
},
Edge
{
edge_source
=
pack
"8"
,
edge_target
=
pack
"7"
,
edge_weight
=
1.0
,
edge_id
=
pack
"15"
},
Edge
{
edge_source
=
pack
"8"
,
edge_target
=
pack
"8"
,
edge_weight
=
1.0
,
edge_id
=
pack
"16"
}]}]
-----------------------------------------------------------
-- Old Gargantext Version
...
...
src/Gargantext/Viz/Graph/Distances/Matrice.hs
View file @
21e3b7ca
...
...
@@ -117,7 +117,6 @@ matProba r mat = zipWith (/) mat (matSum r mat)
diag
::
Elt
e
=>
Acc
(
Matrix
e
)
->
Acc
(
Vector
e
)
diag
m
=
backpermute
(
indexTail
(
shape
m
))
(
lift1
(
\
(
Z
:.
x
)
->
(
Z
:.
x
:.
(
x
::
Exp
Int
))))
m
-- | Divide by the Diagonal of the matrix
--
-- >>> run $ divByDiag 3 (use $ matrix 3 ([1..] :: [Double]))
...
...
@@ -209,21 +208,25 @@ conditional' m = (run $ ie $ map fromIntegral $ use m, run $ sg $ map fromIntegr
-- Distributional measure is a relative measure which depends on the
-- selected list, it represents structural equivalence.
--
-- The distributional measure
\[P_c\]
of @i@ and @j@ terms is: \[
-- The distributional measure
P(c)
of @i@ and @j@ terms is: \[
-- S_{MI} = \frac {\sum_{k \neq i,j ; MI_{ik} >0}^{} \min(MI_{ik},
-- MI_{jk})}{\sum_{k \neq i,j ; MI_{ik}}^{}} \]
--
-- Mutual information
-- \[S{MI}({i},{j}) = \log(\frac{C{ij}}{E{ij}})\]
-- \[S
_
{MI}({i},{j}) = \log(\frac{C{ij}}{E{ij}})\]
--
-- Number of cooccurrences of @i@ and @j@ in the same context of text
-- \[C{ij}\]
--
-- The expected value of the cooccurrences
-- \[E_{ij} = \frac {S_{i} S_{j}} {N}\]
-- The expected value of the cooccurrences @i@ and @j@ (given a map list of size @n@)
-- \[E_{ij}^{m} = \frac {S_{i} S_{j}} {N_{m}}\]
--
-- Total cooccurrences of term @i@ given a map list of size @m@
-- \[S_{i} = \sum_{j, j \neq i}^{m} S_{ij}\]
--
-- Total cooccurrences of terms given a map list of size @m@
-- \[N_{m} = \sum_{i,i \neq i}^{m} \sum_{j, j \neq j}^{m} S_{ij}\]
--
-- Total cooccurrences of @i@ term
-- \[N_{i} = \sum_{i}^{} S_{i}\]
distributional
::
Matrix
Int
->
Matrix
Double
distributional
m
=
run
$
matMiniMax
$
ri
(
map
fromIntegral
$
use
m
)
where
...
...
@@ -232,17 +235,17 @@ distributional m = run $ matMiniMax $ ri (map fromIntegral $ use m)
ri
mat
=
zipWith
(
/
)
mat1
mat2
where
mat1
=
matSum
n
$
zipWith
min
(
mi
mat
)
(
mi
$
transpose
mat
)
mat1
=
matSum
n
$
zipWith
min
(
s_mi
mat
)
(
s_
mi
$
transpose
mat
)
mat2
=
matSum
n
mat
mi
m'
=
zipWith
(
\
a
b
->
max
(
log
$
a
/
b
)
0
)
m'
s_mi
m'
=
zipWith
(
\
a
b
->
log
(
a
/
b
)
)
m'
$
zipWith
(
/
)
(
crossProduct
m'
)
(
total
m'
)
total
m''
=
replicate
(
constant
(
Z
:.
n
:.
n
))
$
fold
(
+
)
0
$
fold
(
+
)
0
m''
n
=
dim
m
n
=
dim
m
crossProduct
m'''
=
zipWith
(
*
)
(
cross
m'''
)
(
cross
(
transpose
m'''
))
cross
mat
=
zipWith
(
-
)
(
matSum
n
mat
)
(
mat
)
cross
mat
=
zipWith
(
-
)
(
matSum
n
mat
)
(
mat
)
-----------------------------------------------------------------------
-----------------------------------------------------------------------
...
...
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