Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
d32032f2
Commit
d32032f2
authored
Sep 30, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[GRAPH] Retrieve cooccurrences if computed already.
parent
5e84408a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
8 deletions
+12
-8
cooccurrences.py
graph/cooccurrences.py
+12
-8
No files found.
graph/cooccurrences.py
View file @
d32032f2
...
...
@@ -20,7 +20,7 @@ def filterMatrix(matrix, mapList_id, groupList_id):
return
cooc
@
shared_task
def
computeGraph
(
corpus_id
=
None
,
cooc_id
=
None
def
computeGraph
(
corpus_id
=
None
,
cooc_id
=
None
,
field1
=
'ngrams'
,
field2
=
'ngrams'
,
start
=
None
,
end
=
None
,
mapList_id
=
None
,
groupList_id
=
None
...
...
@@ -30,7 +30,7 @@ def computeGraph( corpus_id=None, cooc_id=None
,
save_on_db
=
True
,
reset
=
True
):
print
(
"GRAPH# ... Computing cooccurrences."
)
print
(
"GRAPH
# ... Computing cooccurrences."
)
(
cooc_id
,
cooc_matrix
)
=
countCooccurrences
(
corpus_id
=
corpus_id
,
cooc_id
=
cooc_id
,
field1
=
field1
,
field2
=
field2
,
start
=
start
,
end
=
end
...
...
@@ -39,19 +39,19 @@ def computeGraph( corpus_id=None, cooc_id=None
,
distance
=
distance
,
bridgeness
=
bridgeness
,
save_on_db
=
True
)
print
(
"GRAPH#
%
d ... Cooccurrences computed."
%
(
cooc_id
))
print
(
"GRAPH
#
%
d ... Cooccurrences computed."
%
(
cooc_id
))
print
(
"GRAPH
#
%
d ... Clustering with distance
%
s
."
%
(
cooc_id
,
distance
))
print
(
"GRAPH
#
%
d ... Clustering with
%
s distance
."
%
(
cooc_id
,
distance
))
G
,
partition
,
ids
,
weight
=
clusterByDistances
(
cooc_matrix
,
field1
=
"ngrams"
,
field2
=
"ngrams"
,
distance
=
distance
)
print
(
"GRAPH#
%
d ... Filtering by bridgeness
%
d."
%
(
cooc_id
,
bridgeness
))
print
(
"GRAPH
#
%
d ... Filtering by bridgeness
%
d."
%
(
cooc_id
,
bridgeness
))
data
=
filterByBridgeness
(
G
,
partition
,
ids
,
weight
,
bridgeness
,
"node_link"
,
field1
,
field2
)
print
(
"GRAPH#
%
d ... Saving Graph in hyperdata as json."
%
cooc_id
)
print
(
"GRAPH
#
%
d ... Saving Graph in hyperdata as json."
%
cooc_id
)
node
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
cooc_id
)
.
first
()
if
node
.
hyperdata
.
get
(
distance
,
None
)
is
None
:
...
...
@@ -62,11 +62,11 @@ def computeGraph( corpus_id=None, cooc_id=None
node
.
save_hyperdata
()
session
.
commit
()
print
(
"GRAPH#
%
d ... Returning data as json."
%
cooc_id
)
print
(
"GRAPH
#
%
d ... Returning data as json."
%
cooc_id
)
return
data
def
countCooccurrences
(
corpus_id
=
None
,
cooc_id
=
None
def
countCooccurrences
(
corpus_id
=
None
,
cooc_id
=
None
,
field1
=
'ngrams'
,
field2
=
'ngrams'
,
start
=
None
,
end
=
None
,
mapList_id
=
None
,
groupList_id
=
None
...
...
@@ -119,6 +119,10 @@ def countCooccurrences( corpus_id=None, cooc_id=None
cooc_id
=
coocNode
.
id
else
:
cooc_id
=
int
(
cooc_id
[
0
])
else
:
print
(
"GRAPH #
%
s ... Loading cooccurrences computed already."
%
cooc_id
)
cooc
=
session
.
query
(
NodeNgramNgram
.
ngram1_id
,
NodeNgramNgram
.
ngram2_id
,
NodeNgramNgram
.
weight
)
.
filter
(
NodeNgramNgram
.
node_id
==
cooc_id
)
.
all
()
return
(
int
(
cooc_id
),
WeightedMatrix
(
cooc
))
if
reset
==
True
:
session
.
query
(
NodeNgramNgram
)
.
filter
(
NodeNgramNgram
.
node_id
==
cooc_id
)
.
delete
()
...
...
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