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
86c289b4
Commit
86c289b4
authored
May 29, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] ngrams-table progress
parent
b004fb6f
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
737 additions
and
8 deletions
+737
-8
urls.py
gargantext_web/urls.py
+2
-1
views.py
gargantext_web/views.py
+62
-6
dyna_chart_and_table.js
static/js/dyna_chart_and_table.js
+2
-1
test_dyna_chart_and_table.js
static/js/test_dyna_chart_and_table.js
+671
-0
No files found.
gargantext_web/urls.py
View file @
86c289b4
...
...
@@ -78,7 +78,8 @@ urlpatterns = patterns('',
url
(
r'^tests/project/(\d+)/ISTEXquery/go$'
,
pubmedscrapper
.
testISTEX
),
url
(
r'^tests/paginator/corpus/(\d+)/$'
,
views
.
newpaginatorJSON
),
url
(
r'^tests/move2trash/$'
,
views
.
move_to_trash_multiple
),
url
(
r'^project/(\d+)/corpus/(\d+)/ngrams$'
,
views
.
test_ngrams
)
url
(
r'^project/(\d+)/corpus/(\d+)/ngrams$'
,
views
.
get_ngrams
),
url
(
r'^project/(\d+)/corpus/(\d+)/ngrams/ngrams.json$'
,
views
.
test_ngrams
)
)
...
...
gargantext_web/views.py
View file @
86c289b4
...
...
@@ -255,6 +255,43 @@ def projects(request):
'projects'
:
projects
})
def
get_ngrams
(
request
,
project_id
,
corpus_id
):
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/login/?next=
%
s'
%
request
.
path
)
try
:
offset
=
int
(
project_id
)
offset
=
int
(
corpus_id
)
except
ValueError
:
raise
Http404
()
t
=
get_template
(
'tests/ngrams.html'
)
user
=
cache
.
User
[
request
.
user
.
username
]
.
id
date
=
datetime
.
datetime
.
now
()
project
=
cache
.
Node
[
int
(
project_id
)]
corpus
=
cache
.
Node
[
int
(
corpus_id
)]
type_doc_id
=
cache
.
NodeType
[
'Document'
]
.
id
number
=
session
.
query
(
func
.
count
(
Node
.
id
))
.
filter
(
Node
.
parent_id
==
corpus_id
,
Node
.
type_id
==
type_doc_id
)
.
all
()[
0
][
0
]
try
:
processing
=
corpus
.
hyperdata
[
'Processing'
]
except
Exception
as
error
:
print
(
error
)
processing
=
0
html
=
t
.
render
(
Context
({
'debug'
:
settings
.
DEBUG
,
'user'
:
user
,
'date'
:
date
,
'project'
:
project
,
'corpus'
:
corpus
,
'processing'
:
processing
,
'number'
:
number
,
}))
return
HttpResponse
(
html
)
def
test_ngrams
(
request
,
project_id
,
corpus_id
):
results
=
[
"hola"
,
"mundo"
]
...
...
@@ -314,13 +351,14 @@ def test_ngrams(request , project_id, corpus_id ):
NgramOccs
=
session
.
query
(
Node_Ngram
)
.
filter
(
Node_Ngram
.
node_id
==
doc
.
id
)
.
all
()
for
ngram
in
NgramOccs
:
if
ngram
.
ngram_id
not
in
Ngrams_Scores
:
Ngrams_Scores
[
ngram
.
ngram_id
]
=
{
Ngrams_Scores
[
ngram
.
ngram_id
]
=
{}
Ngrams_Scores
[
ngram
.
ngram_id
][
"scores"
]
=
{
"occ_sum"
:
0.0
,
"occ_uniq"
:
0.0
,
"tfidf_sum"
:
0.0
}
Ngrams_Scores
[
ngram
.
ngram_id
][
"occ_sum"
]
+=
ngram
.
weight
Ngrams_Scores
[
ngram
.
ngram_id
][
"occ_uniq"
]
+=
1
Ngrams_Scores
[
ngram
.
ngram_id
][
"
scores"
][
"
occ_sum"
]
+=
ngram
.
weight
Ngrams_Scores
[
ngram
.
ngram_id
][
"
scores"
][
"
occ_uniq"
]
+=
1
# print("\t" , ngram.ngram_id , "\t" , ngram.weight )
## Getting the Effective nro de OCCS / >##
...
...
@@ -343,7 +381,7 @@ def test_ngrams(request , project_id, corpus_id ):
NgramTFIDF
=
session
.
query
(
NodeNodeNgram
)
.
filter
(
NodeNodeNgram
.
nodex_id
==
corpus_id
)
.
all
()
for
ngram
in
NgramTFIDF
:
Ngrams_Scores
[
ngram
.
ngram_id
][
"tfidf_sum"
]
+=
ngram
.
score
Ngrams_Scores
[
ngram
.
ngram_id
][
"
scores"
][
"
tfidf_sum"
]
+=
ngram
.
score
# print( "docid:", ngram.nodey_id , ngram.ngram_id , ngram.score)
...
...
@@ -360,10 +398,28 @@ def test_ngrams(request , project_id, corpus_id ):
# id | nodex_id | nodey_id | ngram_id | score
ngrams_ids
=
Ngrams_Scores
.
keys
()
Metrics
=
{
"ngrams"
:[],
"scores"
:
{
"nb_docs"
:
len
(
documents
),
"nb_ngrams"
:
len
(
ngrams_ids
)
}
}
return
JsonHttpResponse
(
results
)
query
=
session
.
query
(
Ngram
)
.
filter
(
Ngram
.
id
.
in_
(
ngrams_ids
))
ngrams_data
=
query
.
all
()
for
ngram
in
ngrams_data
:
Ngrams_Scores
[
ngram
.
id
][
"name"
]
=
ngram
.
terms
Ngrams_Scores
[
ngram
.
id
][
"id"
]
=
ngram
.
id
Metrics
[
"ngrams"
]
.
append
(
Ngrams_Scores
[
ngram
.
id
]
)
return
JsonHttpResponse
(
Metrics
)
...
...
static/js/dyna_chart_and_table.js
View file @
86c289b4
...
...
@@ -359,7 +359,8 @@ function ulWriter(rowIndex, record, columns, cellWriter) {
.
renderHorizontalGridLines
(
true
)
.
brushOn
(
false
)
.
compose
([
dc
.
lineChart
(
moveChart
).
group
(
indexAvgByMonthGroup
)
dc
.
lineChart
(
moveChart
)
.
group
(
indexAvgByMonthGroup
)
.
valueAccessor
(
function
(
d
)
{
return
d
.
value
.
avg
;
})
...
...
static/js/test_dyna_chart_and_table.js
0 → 100644
View file @
86c289b4
This diff is collapsed.
Click to expand it.
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