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
3de1405d
Commit
3de1405d
authored
Dec 10, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] clean version for mines.paristech
parent
8229e21b
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
182 additions
and
37 deletions
+182
-37
urls.py
gargantext_web/urls.py
+2
-1
views.py
gargantext_web/views.py
+18
-1
group.py
ngram/group.py
+5
-3
NgramsExtractor.py
parsing/NgramsExtractors/NgramsExtractor.py
+2
-2
TurboNgramsExtractor.py
parsing/NgramsExtractors/TurboNgramsExtractor.py
+2
-2
ngrams.py
rest_v1_0/ngrams.py
+20
-12
NGrams_dyna_chart_and_table.js
static/js/NGrams_dyna_chart_and_table.js
+12
-4
menu.html
templates/corpus/menu.html
+83
-2
terms.html
templates/corpus/terms.html
+3
-7
explorer.html
templates/explorer.html
+1
-1
views.py
tests/ngramstable/views.py
+34
-2
No files found.
gargantext_web/urls.py
View file @
3de1405d
...
...
@@ -103,7 +103,8 @@ urlpatterns = patterns('',
url
(
r'^tests/'
,
include
(
'tests.urls'
)),
url
(
r'^project/(\d+)/corpus/(\d+)/terms$'
,
samtest
.
get_ngrams
),
url
(
r'^api/corpus/(\d+)$'
,
samtest
.
get_corpus_state
),
url
(
r'^test_cores$'
,
samtest
.
get_cores
)
url
(
r'^test_cores$'
,
samtest
.
get_cores
),
url
(
r'^get_groups$'
,
samtest
.
get_groups
)
)
...
...
gargantext_web/views.py
View file @
3de1405d
...
...
@@ -345,7 +345,8 @@ def corpus(request, project_id, 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
]
# [ getting workflow status ] #
the_query
=
""" SELECT hyperdata FROM node_node WHERE id=
%
d """
%
(
int
(
corpus_id
)
)
cursor
=
connection
.
cursor
()
try
:
...
...
@@ -353,6 +354,21 @@ def corpus(request, project_id, corpus_id):
processing
=
cursor
.
fetchone
()[
0
][
"Processing"
]
except
:
processing
=
"Error"
# [ / getting workflow status ] #
# [ how many groups ? ] #
nb_groups
=
0
the_query
=
""" SELECT group_id FROM auth_user_groups WHERE user_id=
%
d """
%
(
int
(
request
.
user
.
id
)
)
cursor
=
connection
.
cursor
()
try
:
cursor
.
execute
(
the_query
)
results
=
cursor
.
fetchall
()
nb_groups
=
len
(
results
)
except
:
pass
# [ / how many groups ? ] #
html
=
t
.
render
(
Context
({
'debug'
:
settings
.
DEBUG
,
...
...
@@ -363,6 +379,7 @@ def corpus(request, project_id, corpus_id):
'processing'
:
processing
,
# 'documents': documents,\
'number'
:
number
,
'nb_groups'
:
nb_groups
,
'view'
:
"documents"
}))
...
...
ngram/group.py
View file @
3de1405d
...
...
@@ -116,7 +116,10 @@ def compute_groups(corpus, limit_inf=None, limit_sup=None, how='Stem'):
for
key
in
mainform_dict
.
keys
():
miam_to_insert
.
add
((
miam_node
.
id
,
mainform_dict
[
key
],
1
))
try
:
miam_to_insert
.
add
((
miam_node
.
id
,
mainform_dict
[
key
],
1
))
except
:
pass
try
:
ids
=
ids_dict
[
key
]
...
...
@@ -125,9 +128,8 @@ def compute_groups(corpus, limit_inf=None, limit_sup=None, how='Stem'):
for
ngram_id
in
ids
:
if
ngram_id
!=
mainform_dict
[
key
]:
group_to_insert
.
add
((
node_group
.
id
,
mainform_dict
[
key
],
ngram_id
,
1
))
except
e
xception
as
e
:
except
E
xception
as
e
:
print
(
e
)
print
(
group
[
stem
])
#print(ids_dict[stem])
...
...
parsing/NgramsExtractors/NgramsExtractor.py
View file @
3de1405d
from
..Taggers
import
Turbo
Tagger
from
..Taggers
import
Nltk
Tagger
import
nltk
...
...
@@ -21,7 +21,7 @@ class NgramsExtractor:
self
.
stop
()
def
start
(
self
):
self
.
tagger
=
Turbo
Tagger
()
self
.
tagger
=
Nltk
Tagger
()
def
stop
(
self
):
pass
...
...
parsing/NgramsExtractors/TurboNgramsExtractor.py
View file @
3de1405d
from
.NgramsExtractor
import
NgramsExtractor
from
..Taggers
import
Turbo
Tagger
from
..Taggers
import
Nltk
Tagger
class
TurboNgramsExtractor
(
NgramsExtractor
):
def
start
(
self
):
self
.
tagger
=
Turbo
Tagger
()
self
.
tagger
=
Nltk
Tagger
()
rest_v1_0/ngrams.py
View file @
3de1405d
...
...
@@ -108,10 +108,12 @@ class List(APIView):
def
get
(
self
,
request
,
corpus_id
,
list_name
):
if
not
request
.
user
.
is_authenticated
():
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
request
.
user
.
id
,
Node
.
id
==
corpus_id
)
.
first
()
if
corpus
==
None
:
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
start_
=
time
.
time
()
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
corpus_id
)
.
first
()
list_name
=
list_name
.
title
()
+
"List"
node_list
=
get_or_create_node
(
nodetype
=
list_name
,
corpus
=
corpus
)
nodes_ngrams
=
session
.
query
(
NodeNgram
.
ngram_id
)
.
filter
(
NodeNgram
.
node_id
==
node_list
.
id
)
.
all
()
...
...
@@ -143,11 +145,13 @@ class Ngrams(APIView):
http://localhost:8000/api/node/1444485/ngrams?format=json&score=tfidf,occs
'''
def
get
(
self
,
request
,
node_id
):
# query ngrams
if
not
request
.
user
.
is_authenticated
():
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
request
.
user
.
id
,
Node
.
id
==
node_id
)
.
first
()
if
corpus
==
None
:
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
start_
=
time
.
time
()
ParentNode
=
aliased
(
Node
)
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
node_id
)
.
first
()
group_by
=
[]
results
=
[
'id'
,
'terms'
]
...
...
@@ -319,15 +323,19 @@ class Group(APIView):
REST API to manage groups of Ngrams
Groups can be synonyms, a cathegory or ngrams groups with stems or lems.
'''
def
get_group_id
(
self
,
node_id
):
def
get_group_id
(
self
,
node_id
,
user_id
):
node_id
=
int
(
node_id
)
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
node_id
)
.
first
()
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user_id
,
Node
.
id
==
node_id
)
.
first
()
if
corpus
==
None
:
return
None
group
=
get_or_create_node
(
corpus
=
corpus
,
nodetype
=
'Group'
)
return
(
group
.
id
)
def
get
(
self
,
request
,
corpus_id
):
# query ngrams
group_id
=
self
.
get_group_id
(
corpus_id
)
if
not
request
.
user
.
is_authenticated
():
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
group_id
=
self
.
get_group_id
(
corpus_id
,
request
.
user
.
id
)
if
group_id
==
None
:
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
#api/node/$corpus_id/ngrams?ngram_id=12
# ngram_id = 1 #request.GET.get('ngram_id', False)
# ngram_id = int(node_id)
...
...
@@ -395,7 +403,7 @@ class Group(APIView):
# input validation
input
=
validate
(
request
.
DATA
,
{
'data'
:
{
'source'
:
int
,
'target'
:
list
}})
group_id
=
get_group_id
(
corpus_id
)
group_id
=
get_group_id
(
corpus_id
,
request
.
user
.
id
)
for
data
in
input
[
'data'
]:
...
...
@@ -424,7 +432,7 @@ class Group(APIView):
for
subform
in
group_new
[
mainform
]:
gdict
.
append
(
subform
)
GDict
.
append
(
gdict
)
existing_group_id
=
self
.
get_group_id
(
corpus_id
)
existing_group_id
=
self
.
get_group_id
(
corpus_id
,
request
.
user
.
id
)
grouped_ngrams
=
(
session
.
query
(
NodeNgramNgram
)
.
filter
(
NodeNgramNgram
.
node_id
==
existing_group_id
)
...
...
static/js/NGrams_dyna_chart_and_table.js
View file @
3de1405d
...
...
@@ -538,13 +538,18 @@ function SelectAll( box ) {
MyTable
.
data
(
'dynatable'
).
dom
.
update
();
}
function
SaveGlobalChanges
(
elem
)
{
function
SaveGlobalChanges
(
delete_
)
{
console
.
log
(
"iterating over global stop words:"
)
$
(
'.globalstopwords'
).
each
(
function
(
i
,
obj
)
{
console
.
log
(
obj
)
$
(
'.globalstopwords'
).
each
(
function
()
{
console
.
log
(
$
(
this
).
data
(
"id"
)
)
});
console
.
log
(
" - - - - -"
)
console
.
log
(
elem
)
console
.
log
(
"delete: "
+
delete_
)
if
(
!
delete_
)
{
// SaveLocalChanges()
}
else
{
}
}
function
SaveGlobalChanges_Form
(
nodes2del
)
{
...
...
@@ -1082,6 +1087,9 @@ var NGrams = {
}
$
(
"#corpusdisplayer"
).
hide
()
if
(
$
(
"#share_button"
).
length
==
0
)
{
$
(
"#ImportList"
).
remove
()
}
var
url
=
[
...
...
templates/corpus/menu.html
View file @
3de1405d
...
...
@@ -48,6 +48,9 @@
{% if number == 0 %}
<a
class=
"btn btn-primary btn-lg"
role=
"button"
href=
"/admin/documents/corpus/{{ corpus.id }}/"
>
Add documents
</a></p>
{% endif %}
{% if nb_groups != None and nb_groups > 0 %}
<a
style=
"visibility: hidden;"
id=
"share_button"
class=
"btn btn-primary btn-lg"
role=
"button"
>
Share!!!
</a></p>
{% endif %}
</div>
</div>
...
...
@@ -117,6 +120,47 @@
</div>
</div>
<div
id=
"sharemodal"
class=
"modal fade"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-hidden=
"true"
>
×
</button>
<h3
class=
"modal-title"
>
Share this Corpus with your Groups
</h3>
</div>
<div
class=
"modal-body form-horizontal"
>
<h4>
List of available groups:
</h4>
<div
id=
"groups_list"
>
here show the groups
</div>
<div
class=
"modal-footer"
>
<button
id=
"closesharemodal"
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Close
</button>
<button
id=
"send_share"
type=
"button"
class=
"btn btn-primary"
>
Share
</button>
</div>
</div>
</div>
</div>
</div>
<style>
label
{
padding
:
10px
;
margin
:
0
0
10px
;
display
:
block
;
}
label
:hover
{
background
:
#eee
;
cursor
:
pointer
;
}
</style>
<script
type=
"text/javascript"
>
function
gotoexplorer
(
elem
)
{
...
...
@@ -139,7 +183,6 @@
// url_ += "&start=" + start__.getFullYear() + "&end="+end__.getFullYear();
}
return
window
.
open
(
url_
,
'_blank'
);
}
var
refresh_time
=
10000
//ms
...
...
@@ -162,7 +205,6 @@
});
}
if
(
$
(
"#process_state"
).
text
()
==
"0"
)
{
// workflow : finished!
}
else
{
...
...
@@ -170,6 +212,45 @@
}
function
get_groups
()
{
console
.
log
(
"IN get_groups()!"
)
var
url_
=
"/get_groups"
$
.
ajax
({
type
:
"GET"
,
url
:
url_
,
dataType
:
"json"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
var
_content
=
""
for
(
var
i
in
data
)
{
var
g_id
=
data
[
i
][
0
]
,
g_name
=
data
[
i
][
1
]
_content
+=
'<label><input name="groups" data-id="'
+
g_id
+
'" type="checkbox" /> '
+
g_name
+
'</label>'
}
$
(
"#groups_list"
).
html
(
_content
)
},
error
:
function
(
exception
)
{
console
.
log
(
"exception!:"
+
exception
.
status
)
}
});
}
if
(
$
(
"#share_button"
).
length
>
0
)
{
$
(
"#share_button"
).
click
(
function
()
{
get_groups
()
$
(
"#sharemodal"
).
modal
(
"show"
);
});
$
(
"#send_share"
).
click
(
function
()
{
$
(
'input[name=groups]:checked'
).
each
(
function
()
{
console
.
log
(
$
(
this
).
data
(
"id"
)
);
});
});
}
</script>
...
...
templates/corpus/terms.html
View file @
3de1405d
...
...
@@ -113,7 +113,7 @@ input[type=radio] + label {
}
input
[
type
=
radio
]
:checked
+
label
{
background-image
:
none
;
background-image
:
none
;
outline
:
0
;
-webkit-box-shadow
:
inset
0
2px
4px
rgba
(
0
,
0
,
0
,
0.15
),
0
1px
2px
rgba
(
0
,
0
,
0
,
0.05
);
-moz-box-shadow
:
inset
0
2px
4px
rgba
(
0
,
0
,
0
,
0.15
),
0
1px
2px
rgba
(
0
,
0
,
0
,
0.05
);
...
...
@@ -291,8 +291,8 @@ input[type=radio]:checked + label {
-->
<div
class=
"modal-footer"
>
<button
onclick=
"SaveGlobalChanges(
this.id
)"
id=
"nope"
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
No
</button>
<button
onclick=
"SaveGlobalChanges(t
his.id
)"
id=
"yep"
type=
"button"
class=
"btn btn-primary"
>
Yes
</button>
<button
onclick=
"SaveGlobalChanges(
false
)"
id=
"nope"
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
No
</button>
<button
onclick=
"SaveGlobalChanges(t
rue
)"
id=
"yep"
type=
"button"
class=
"btn btn-primary"
>
Yes
</button>
</div>
...
...
@@ -309,10 +309,6 @@ input[type=radio]:checked + label {
<div
id=
"filter_search"
style=
"visibility:hidden"
>
<span
style=
"font-size:70%;"
>
<input
title=
"Search in Titles"
type=
"checkbox"
checked
onclick=
"return false"
>
TI
</input>
<input
title=
"Search in Abstracts"
type=
"checkbox"
>
AB
</input>
</span>
<select
id=
"example-single-optgroups"
onchange=
"SearchFilters(this);"
>
<!-- <optgroup label=""> -->
<option
id=
"filter_all"
value=
"filter_all"
>
All
</option>
...
...
templates/explorer.html
View file @
3de1405d
...
...
@@ -324,7 +324,7 @@
<div
id=
"tab-container-top"
class=
'tab-container'
style=
"display: none;"
>
<ul
class=
'etabs'
>
<li
id=
"tabmed"
class=
'tab active'
><a
href=
"#tabs3"
>
Medline
Pubs
</a></li>
<li
id=
"tabmed"
class=
'tab active'
><a
href=
"#tabs3"
>
Pubs
</a></li>
<li
id=
"tabgps"
class=
'tab'
><a
href=
"#tabs3"
></a></li>
</ul>
...
...
tests/ngramstable/views.py
View file @
3de1405d
...
...
@@ -77,7 +77,6 @@ def get_ngrams(request , project_id , corpus_id ):
myamlist_type_id
=
cache
.
NodeType
[
'MiamList'
]
.
id
miamlist
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
request
.
user
.
id
,
Node
.
parent_id
==
corpus_id
,
Node
.
type_id
==
myamlist_type_id
)
.
first
()
t
the_query
=
""" SELECT hyperdata FROM node_node WHERE id=
%
d """
%
(
int
(
corpus_id
)
)
cursor
=
connection
.
cursor
()
try
:
...
...
@@ -86,6 +85,18 @@ def get_ngrams(request , project_id , corpus_id ):
except
:
processing
=
"Error"
# [ how many groups ? ] #
nb_groups
=
0
the_query
=
""" SELECT group_id FROM auth_user_groups WHERE user_id=
%
d """
%
(
int
(
request
.
user
.
id
)
)
cursor
=
connection
.
cursor
()
try
:
cursor
.
execute
(
the_query
)
results
=
cursor
.
fetchall
()
nb_groups
=
len
(
results
)
except
:
pass
# [ / how many groups ? ] #
html
=
t
.
render
(
Context
({
'debug'
:
settings
.
DEBUG
,
'user'
:
request
.
user
,
...
...
@@ -94,6 +105,7 @@ def get_ngrams(request , project_id , corpus_id ):
'corpus'
:
corpus
,
'processing'
:
processing
,
'number'
:
number
,
'nb_groups'
:
nb_groups
,
'list_id'
:
miamlist
.
id
,
}))
...
...
@@ -186,4 +198,24 @@ def get_corpus_state( request , corpus_id ):
finally
:
connection
.
close
()
# processing = corpus.hyperdata['Processing']
return
JsonHttpResponse
(
processing
)
\ No newline at end of file
return
JsonHttpResponse
(
processing
)
def
get_groups
(
request
):
if
not
request
.
user
.
is_authenticated
():
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
results
=
[]
the_query
=
""" SELECT auth_user_groups.group_id, auth_group.name
\
FROM auth_user_groups,auth_group
\
WHERE auth_user_groups.user_id=
%
d
\
AND auth_user_groups.group_id=auth_group.id """
%
(
int
(
request
.
user
.
id
)
)
cursor
=
connection
.
cursor
()
try
:
cursor
.
execute
(
the_query
)
results
=
cursor
.
fetchall
()
except
:
pass
return
JsonHttpResponse
(
results
)
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