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
34078f1c
Commit
34078f1c
authored
May 06, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Intersection of graph: go for tests on dev for feedbacks.
parent
e5a4d658
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
18 deletions
+31
-18
intersection.py
graphExplorer/intersection.py
+25
-10
urls.py
graphExplorer/urls.py
+2
-5
extras_explorerjs.js
static/js/graphExplorer/extras_explorerjs.js
+4
-3
No files found.
graphExplorer/intersection.py
View file @
34078f1c
from
gargantext.models
import
Node
,
Ngram
,
NodeNgram
,
NodeNgramNgram
,
\
from
gargantext.models
import
Node
,
Ngram
,
NodeNgram
,
NodeNgramNgram
,
\
NodeHyperdata
,
HyperdataKey
HyperdataKey
from
gargantext.util.db
import
session
,
aliased
,
bulk_insert
,
func
from
gargantext.util.db
import
session
,
aliased
,
bulk_insert
,
func
from
gargantext.util.lists
import
WeightedMatrix
,
UnweightedList
,
Translations
from
gargantext.util.lists
import
WeightedMatrix
,
UnweightedList
,
Translations
from
gargantext.util.http
import
JsonHttpResponse
from
gargantext.util.http
import
JsonHttpResponse
from
sqlalchemy
import
desc
,
asc
,
or_
,
and_
from
sqlalchemy
import
desc
,
asc
,
or_
,
and_
import
datetime
import
datetime
def
getCorpusIntersection
(
request
,
corpuses_ids
):
def
intersection
(
request
,
corpuses_ids
,
measure
=
'cooc'
):
FinalDict
=
False
FinalDict
=
False
if
request
.
method
==
'POST'
and
"nodeids"
in
request
.
POST
and
len
(
request
.
POST
[
"nodeids"
])
>
0
:
if
request
.
method
==
'POST'
and
"nodeids"
in
request
.
POST
and
len
(
request
.
POST
[
"nodeids"
])
>
0
:
...
@@ -48,11 +48,10 @@ def getCorpusIntersection(request , corpuses_ids):
...
@@ -48,11 +48,10 @@ def getCorpusIntersection(request , corpuses_ids):
ngrams_data
=
(
session
.
query
(
NodeNgramNgram
)
ngrams_data
=
(
session
.
query
(
NodeNgramNgram
)
.
filter
(
NodeNgramNgram
.
node_id
==
cooc_ids
[
0
]
.
filter
(
NodeNgramNgram
.
node_id
==
cooc_ids
[
0
]
,
or_
(
,
or_
(
NodeNgramNgram
.
ngram1_id
.
in_
(
node_ids
)
NodeNgramNgram
.
ngram1_id
.
in_
(
node_ids
)
,
NodeNgramNgram
.
ngram2_id
.
in_
(
node_ids
)
,
NodeNgramNgram
.
ngram2_id
.
in_
(
node_ids
)
)
)
)
)
.
group_by
(
NodeNgramNgram
)
.
group_by
(
NodeNgramNgram
)
.
all
()
.
all
()
)
)
...
@@ -66,10 +65,13 @@ def getCorpusIntersection(request , corpuses_ids):
...
@@ -66,10 +65,13 @@ def getCorpusIntersection(request , corpuses_ids):
n1
=
e
[
0
]
n1
=
e
[
0
]
n2
=
e
[
1
]
n2
=
e
[
1
]
# print( G[n1][n2]["weight"] , "\t", n1,",",n2 )
# print( G[n1][n2]["weight"] , "\t", n1,",",n2 )
if
n1
not
in
Coocs
:
if
n1
not
in
Coocs
:
Coocs
[
n1
]
=
0
Coocs
[
n1
]
=
0
if
n2
not
in
Coocs
:
if
n2
not
in
Coocs
:
Coocs
[
n2
]
=
0
Coocs
[
n2
]
=
0
Coocs
[
n1
]
+=
G
[
n1
][
n2
][
"weight"
]
Coocs
[
n1
]
+=
G
[
n1
][
n2
][
"weight"
]
Coocs
[
n2
]
+=
G
[
n1
][
n2
][
"weight"
]
Coocs
[
n2
]
+=
G
[
n1
][
n2
][
"weight"
]
...
@@ -79,7 +81,6 @@ def getCorpusIntersection(request , corpuses_ids):
...
@@ -79,7 +81,6 @@ def getCorpusIntersection(request , corpuses_ids):
Coocs_1
,
G_1
=
get_score
(
corpuses_ids
[
1
]
)
Coocs_1
,
G_1
=
get_score
(
corpuses_ids
[
1
]
)
FinalDict
=
{}
FinalDict
=
{}
measure
=
'cooc'
if
measure
==
'jacquard'
:
if
measure
==
'jacquard'
:
for
node
in
node_ids
:
for
node
in
node_ids
:
...
@@ -95,7 +96,7 @@ def getCorpusIntersection(request , corpuses_ids):
...
@@ -95,7 +96,7 @@ def getCorpusIntersection(request , corpuses_ids):
else
:
else
:
FinalDict
[
node
]
=
0
FinalDict
[
node
]
=
0
elif
measure
==
'
cooc
'
:
elif
measure
==
'
degree
'
:
for
node
in
node_ids
:
for
node
in
node_ids
:
if
node
in
G_1
.
nodes
()
and
node
in
G_0
.
nodes
():
if
node
in
G_1
.
nodes
()
and
node
in
G_0
.
nodes
():
score_0
=
Coocs_0
[
node
]
/
G_0
.
degree
(
node
)
score_0
=
Coocs_0
[
node
]
/
G_0
.
degree
(
node
)
...
@@ -108,6 +109,20 @@ def getCorpusIntersection(request , corpuses_ids):
...
@@ -108,6 +109,20 @@ def getCorpusIntersection(request , corpuses_ids):
else
:
else
:
FinalDict
[
node
]
=
0
FinalDict
[
node
]
=
0
elif
measure
==
'cooc'
:
for
node
in
node_ids
:
if
node
in
G_1
.
nodes
()
and
node
in
G_0
.
nodes
():
#FinalDict[node] = Coocs_1[node] / Coocs_0[node]
FinalDict
[
node
]
=
Coocs_0
[
node
]
/
Coocs_1
[
node
]
elif
node
in
G_0
.
nodes
()
and
node
not
in
G_1
.
nodes
()
:
FinalDict
[
node
]
=
0.0
elif
node
not
in
G_0
.
nodes
()
and
node
in
G_1
.
nodes
()
:
FinalDict
[
node
]
=
0.0
else
:
FinalDict
[
node
]
=
0
print
(
FinalDict
)
print
(
FinalDict
)
#print(node,score)
#print(node,score)
# Getting AVG-COOC of each ngram that exists in the cooc-matrix of the compared-corpus.
# Getting AVG-COOC of each ngram that exists in the cooc-matrix of the compared-corpus.
...
...
graphExplorer/urls.py
View file @
34078f1c
from
django.conf.urls
import
patterns
,
url
from
django.conf.urls
import
patterns
,
url
#from graphExplorer import views
from
graphExplorer.intersection
import
getCorpusIntersection
# Module "Graph Explorer"
# Module "Graph Explorer"
from
graphExplorer.rest
import
Graph
from
graphExplorer.rest
import
Graph
from
graphExplorer.views
import
explorer
from
graphExplorer.views
import
explorer
from
graphExplorer.intersection
import
getCorpusI
ntersection
from
graphExplorer.intersection
import
i
ntersection
# TODO : factor urls
# TODO : factor urls
...
@@ -15,7 +12,7 @@ from graphExplorer.intersection import getCorpusIntersection
...
@@ -15,7 +12,7 @@ from graphExplorer.intersection import getCorpusIntersection
# ^explorer/$corpus_id/data.json
# ^explorer/$corpus_id/data.json
# ^explorer/$corpus_id/intersection
# ^explorer/$corpus_id/intersection
urlpatterns
=
[
url
(
r'^explorer/intersection/(\w+)$'
,
getCorpusI
ntersection
)
urlpatterns
=
[
url
(
r'^explorer/intersection/(\w+)$'
,
i
ntersection
)
,
url
(
r'^projects/(\d+)/corpora/(\d+)/explorer$'
,
explorer
)
,
url
(
r'^projects/(\d+)/corpora/(\d+)/explorer$'
,
explorer
)
,
url
(
r'^projects/(\d+)/corpora/(\d+)/graph$'
,
Graph
.
as_view
())
,
url
(
r'^projects/(\d+)/corpora/(\d+)/graph$'
,
Graph
.
as_view
())
,
url
(
r'^projects/(\d+)/corpora/(\d+)/node_link.json$'
,
Graph
.
as_view
())
,
url
(
r'^projects/(\d+)/corpora/(\d+)/node_link.json$'
,
Graph
.
as_view
())
...
...
static/js/graphExplorer/extras_explorerjs.js
View file @
34078f1c
...
@@ -887,11 +887,12 @@ function GetUserPortfolio() {
...
@@ -887,11 +887,12 @@ function GetUserPortfolio() {
var
sel_p_id
=
selected
[
0
],
sel_c_id
=
selected
[
1
]
var
sel_p_id
=
selected
[
0
],
sel_c_id
=
selected
[
1
]
var
html_selection
=
""
var
html_selection
=
""
html_selection
+=
'<center>You are comparing<br><span class="glyphicon glyphicon-hand-down" aria-hidden="true"></span></center>'
+
"
\n
"
html_selection
+=
'<center>You are comparing
:
<br><span class="glyphicon glyphicon-hand-down" aria-hidden="true"></span></center>'
+
"
\n
"
html_selection
+=
'<center>'
html_selection
+=
'<center>'
html_selection
+=
'(
'
+
portfolio
[
sel_p_id
]
+
'
) '
html_selection
+=
'(
current graph
) '
html_selection
+=
'<span class="glyphicon glyphicon-resize-horizontal" aria-hidden="true"></span>'
html_selection
+=
'<span class="glyphicon glyphicon-resize-horizontal" aria-hidden="true"></span>'
html_selection
+=
' ('
+
portfolio
[
sel_c_id
]
+
')'
html_selection
+=
' ('
+
portfolio
[
sel_p_id
]
+
' / '
+
portfolio
[
sel_c_id
]
+
')'
// html_selection += ' (' + portfolio[sel_p_id] + '/' + sel_c_id + portfolio[sel_c_id] + ')'
html_selection
+=
'</center><br>'
+
"
\n
"
html_selection
+=
'</center><br>'
+
"
\n
"
$
(
"#selected_corpus"
).
html
(
html_selection
)
$
(
"#selected_corpus"
).
html
(
html_selection
)
...
...
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