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
35f1f480
Commit
35f1f480
authored
Nov 06, 2015
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] simple score for cooc.
parent
6cfb53e5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
12 deletions
+12
-12
cooccurrences.py
analysis/cooccurrences.py
+6
-6
functions.py
analysis/functions.py
+2
-2
graph.py
rest_v1_0/graph.py
+4
-4
No files found.
analysis/cooccurrences.py
View file @
35f1f480
...
...
@@ -18,7 +18,7 @@ def do_cooc(corpus=None
,
start
=
None
,
end
=
None
,
limit
=
1000
,
isMonopartite
=
True
,
apax
=
1
):
,
hapax
=
3
):
'''
Compute the cooccurence matrix and save it, returning NodeNgramNgram.node_id
For the moment list of paramters are not supported because, lists need to
...
...
@@ -68,12 +68,13 @@ def do_cooc(corpus=None
doc_id
=
cache
.
NodeType
[
'Document'
]
.
id
NodeNgramX
=
aliased
(
NodeNgram
)
cooc_score
=
func
.
count
(
NodeNgramX
.
node_id
)
.
label
(
'cooc_score'
)
#cooc_score = func.sqrt(func.sum(NodeNgramX.weight * NodeNgramY.weight)).label('cooc_score')
#print([n for n in test_query])
if
isMonopartite
:
NodeNgramX
=
aliased
(
NodeNgram
)
NodeNgramY
=
aliased
(
NodeNgram
)
cooc_score
=
func
.
sum
(
NodeNgramX
.
weight
+
NodeNgramY
.
weight
)
.
label
(
'cooc_score'
)
#cooc_score = func.sqrt(func.sum(NodeNgramX.weight * NodeNgramY.weight)).label('cooc_score')
cooc_query
=
(
session
.
query
(
NodeNgramX
.
ngram_id
,
NodeNgramY
.
ngram_id
,
cooc_score
)
.
join
(
Node
,
Node
.
id
==
NodeNgramX
.
node_id
)
...
...
@@ -82,7 +83,6 @@ def do_cooc(corpus=None
)
else
:
NodeNgramY
=
aliased
(
NodeNgram
)
cooc_score
=
func
.
sqrt
(
func
.
sum
(
NodeHyperdataNgram
.
score
)
*
func
.
sum
(
NodeNgramY
.
weight
))
.
label
(
'cooc_score'
)
cooc_query
=
(
session
.
query
(
NodeHyperdataNgram
.
ngram_id
,
NodeNgramY
.
ngram_id
,
cooc_score
)
.
join
(
Node
,
Node
.
id
==
NodeHyperdataNgram
.
node_id
)
...
...
@@ -151,7 +151,7 @@ def do_cooc(corpus=None
# Cooc is symetric, take only the main cooccurrences and cut at the limit
cooc_query
=
cooc_query
.
filter
(
NodeNgramX
.
ngram_id
<
NodeNgramY
.
ngram_id
)
cooc_query
=
cooc_query
.
having
(
cooc_score
>
apax
)
cooc_query
=
cooc_query
.
having
(
cooc_score
>
h
apax
)
if
isMonopartite
:
cooc_query
=
cooc_query
.
group_by
(
NodeNgramX
.
ngram_id
,
NodeNgramY
.
ngram_id
)
...
...
analysis/functions.py
View file @
35f1f480
...
...
@@ -117,7 +117,7 @@ def get_cooc(request=None, corpus=None
,
field1
=
'ngrams'
,
field2
=
'ngrams'
,
cooc_id
=
None
,
type
=
'node_link'
,
size
=
1000
,
start
=
None
,
end
=
None
,
apax
=
1
,
h
apax
=
1
):
'''
get_ccoc : to compute the graph.
...
...
@@ -140,7 +140,7 @@ def get_cooc(request=None, corpus=None
#cooc_id = get_or_create_node(nodetype='Cooccurrence', corpus=corpus).id
cooc_id
=
do_cooc
(
corpus
=
corpus
,
field1
=
"ngrams"
,
field2
=
"ngrams"
,
miam_id
=
miam_id
,
group_id
=
group_id
,
stop_id
=
stop_id
,
limit
=
size
,
isMonopartite
=
True
,
start
=
start
,
end
=
end
,
apax
=
apax
)
,
isMonopartite
=
True
,
start
=
start
,
end
=
end
,
hapax
=
h
apax
)
G
,
partition
,
ids
,
weight
=
do_distance
(
cooc_id
,
field1
=
"ngrams"
,
field2
=
"ngrams"
,
isMonopartite
=
True
)
...
...
rest_v1_0/graph.py
View file @
35f1f480
...
...
@@ -21,21 +21,21 @@ class Graph(APIView):
format_
=
request
.
GET
.
get
(
'format'
,
'json'
)
type_
=
request
.
GET
.
get
(
'type'
,
'node_link'
)
apax
=
request
.
GET
.
get
(
'
apax'
,
1
)
hapax
=
request
.
GET
.
get
(
'h
apax'
,
1
)
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
corpus_id
)
.
first
()
accepted_field1
=
[
'ngrams'
,
'journal'
,
'source'
,
'authors'
]
accepted_field2
=
[
'ngrams'
,]
options
=
[
'start'
,
'end'
,
'apax'
]
options
=
[
'start'
,
'end'
,
'
h
apax'
]
if
field1
in
accepted_field1
:
if
field2
in
accepted_field2
:
if
start
is
not
None
and
end
is
not
None
:
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
start
=
start
,
end
=
end
,
apax
=
apax
)
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
start
=
start
,
end
=
end
,
hapax
=
h
apax
)
else
:
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
apax
=
apax
)
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
hapax
=
h
apax
)
if
format_
==
'json'
:
return
JsonHttpResponse
(
data
)
else
:
...
...
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