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
296ae91d
Commit
296ae91d
authored
Nov 16, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] for stop-list, but not yet
parent
6f0fe49e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
27 deletions
+100
-27
views.py
annotations/views.py
+10
-2
ngrams.py
rest_v1_0/ngrams.py
+31
-20
urls.py
rest_v1_0/urls.py
+1
-1
NGrams_dyna_chart_and_table.js
static/js/NGrams_dyna_chart_and_table.js
+58
-4
No files found.
annotations/views.py
View file @
296ae91d
...
...
@@ -111,10 +111,16 @@ class NgramEdit(APIView):
node_mapList
=
get_or_create_node
(
nodetype
=
'MapList'
,
corpus
=
corpus
)
results
=
session
.
query
(
NodeNgram
)
.
filter
(
NodeNgram
.
node_id
==
node_mapList
.
id
)
.
all
()
ngram_2del
=
[
int
(
i
)
for
i
in
ngram_ids
.
split
(
'+'
)]
ngram_2del
=
session
.
query
(
NodeNgram
)
.
filter
(
NodeNgram
.
node_id
==
node_mapList
.
id
,
NodeNgram
.
ngram_id
.
in_
(
ngram_2del
)
)
.
all
()
for
map_node
in
ngram_2del
:
ngram_2del
_
=
session
.
query
(
NodeNgram
)
.
filter
(
NodeNgram
.
node_id
==
node_mapList
.
id
,
NodeNgram
.
ngram_id
.
in_
(
ngram_2del
)
)
.
all
()
for
map_node
in
ngram_2del
_
:
session
.
delete
(
map_node
)
session
.
commit
()
node_stopList
=
get_or_create_node
(
nodetype
=
'StopList'
,
corpus
=
corpus
)
for
ngram_id
in
ngram_2del
:
stop_node
=
NodeNgram
(
weight
=
1.0
,
ngram_id
=
ngram_id
,
node_id
=
node_stopList
.
id
)
session
.
add
(
stop_node
)
session
.
commit
()
# [ = = = = / del from map-list = = = = ]
return
Response
(
None
,
204
)
...
...
@@ -193,3 +199,5 @@ class Document(APIView):
'id'
:
node
.
id
}
return
Response
(
data
)
rest_v1_0/ngrams.py
View file @
296ae91d
...
...
@@ -75,7 +75,15 @@ from rest_framework.decorators import api_view
class
List
(
APIView
):
pass
def
get
(
self
,
request
,
corpus_id
,
list_name
):
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
corpus_id
)
.
first
()
list_name
=
list_name
.
title
()
+
"List"
node_mapList
=
get_or_create_node
(
nodetype
=
list_name
,
corpus
=
corpus
)
nodes_in_map
=
session
.
query
(
NodeNgram
)
.
filter
(
NodeNgram
.
node_id
==
node_mapList
.
id
)
.
all
()
results
=
{}
for
node
in
nodes_in_map
:
results
[
node
.
ngram_id
]
=
True
return
JsonHttpResponse
(
results
)
class
Ngrams
(
APIView
):
...
...
@@ -117,7 +125,6 @@ class Ngrams(APIView):
group_by
.
append
(
Cvalue
.
score
)
results
.
append
(
'cvalue'
)
if
'specificity'
in
request
.
GET
[
'score'
]:
Spec
=
aliased
(
NodeNodeNgram
)
spec_id
=
get_or_create_node
(
nodetype
=
'Specificity'
,
corpus
=
corpus
)
.
id
...
...
@@ -196,6 +203,23 @@ class Ngrams(APIView):
total
=
ngrams_query
.
count
()
output
=
[]
for
ngram
in
ngrams_query
[
offset
:
offset
+
limit
]:
info
=
{}
try
:
info
[
"id"
]
=
ngram
.
id
except
:
pass
try
:
info
[
"terms"
]
=
ngram
.
terms
except
:
pass
try
:
info
[
"tfidf"
]
=
ngram
.
tfidf
except
:
pass
try
:
info
[
"cvalue"
]
=
ngram
.
cvalue
except
:
pass
try
:
info
[
"specificity"
]
=
ngram
.
specificity
except
:
pass
output
.
append
(
info
)
# return formatted result
return
JsonHttpResponse
({
'pagination'
:
{
...
...
@@ -203,20 +227,7 @@ class Ngrams(APIView):
'limit'
:
limit
,
'total'
:
total
,
},
'data'
:
[
{
'id'
:
ngram
.
id
,
'terms'
:
ngram
.
terms
,
'tfidf'
:
ngram
.
tfidf
,
'cvalue'
:
ngram
.
cvalue
}
for
ngram
in
ngrams_query
[
offset
:
offset
+
limit
]
# TODO : dict comprehension in list comprehension :
# results = ['id', 'terms']
# { x : eval('ngram.' + x) for x in results
# } for ngram in ngrams_query[offset : offset+limit]
],
'data'
:
output
,
})
def
post
(
self
,
request
,
node_id
):
...
...
@@ -232,10 +243,10 @@ class Group(APIView):
Groups can be synonyms, a cathegory or ngrams groups with stems or lems.
'''
def
get_group_id
(
self
,
node_id
):
node_id
=
int
(
node_id
)
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
node_id
)
.
first
()
group
=
get_or_create_node
(
corpus
=
corpus
,
nodetype
=
'Group'
)
return
(
group
.
id
)
node_id
=
int
(
node_id
)
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
node_id
)
.
first
()
group
=
get_or_create_node
(
corpus
=
corpus
,
nodetype
=
'Group'
)
return
(
group
.
id
)
def
get
(
self
,
request
,
corpus_id
):
# query ngrams
...
...
rest_v1_0/urls.py
View file @
296ae91d
...
...
@@ -22,7 +22,7 @@ urlpatterns = patterns('',
url
(
r'node/(\d+)/ngrams/keep$'
,
ngrams
.
Keep
.
as_view
()),
# url(r'node/(?P<list_id>[0-9]+)/ngrams/keep/(?P<ngram_ids>[0-9,\+]+)+$' , ngrams.Keep.as_view()),
url
(
r'node/(?P<list_id>[0-9]+)/ngrams/(?P<ngram_ids>[0-9,\+]+)+$'
,
views
.
NgramEdit
.
as_view
()),
url
(
r'node/(
\d+)/ngrams/list
$'
,
ngrams
.
List
.
as_view
()),
url
(
r'node/(
?P<corpus_id>[0-9]+)/ngrams/list/(?P<list_name>\w+)
$'
,
ngrams
.
List
.
as_view
()),
#url(r'nodes/(\d+)/children/hyperdata$', api.NodesChildrenMetatadata.as_view()),
#url(r'nodes/(\d+)/children/hyperdata$', api.NodesChildrenMetatadata.as_view()),
...
...
static/js/NGrams_dyna_chart_and_table.js
View file @
296ae91d
...
...
@@ -891,9 +891,44 @@ function SearchFilters( elem ) {
}
if
(
MODE
==
"filter_stop-list"
)
{
console
.
clear
()
console
.
log
(
"ngrams_stop:"
)
console
.
log
(
{}
)
if
(
Object
.
keys
(
ngrams_stop
).
length
<
1
)
{
var
corpus_id
=
getIDFromURL
(
"corpus"
)
var
someurl
=
window
.
location
.
origin
+
"/api/node/"
+
corpus_id
+
"/ngrams/list/stop"
;
$
.
ajax
({
type
:
"GET"
,
url
:
someurl
,
dataType
:
"json"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
console
.
clear
()
console
.
log
(
"ngrams_stop:"
)
console
.
log
(
data
)
ngrams_stop
=
data
var
sub_ngrams_data
=
{
"ngrams"
:[],
"scores"
:
$
.
extend
({},
ngrams_data
.
scores
)
}
for
(
var
r
in
ngrams_data
.
ngrams
)
{
if
(
ngrams_stop
[
ngrams_data
.
ngrams
[
r
].
id
]
)
{
sub_ngrams_data
[
"ngrams"
].
push
(
ngrams_data
.
ngrams
[
r
]
)
}
}
},
error
:
function
(
exception
)
{
console
.
log
(
"second ajax, exception!: "
+
exception
.
status
)
}
})
}
else
{
var
sub_ngrams_data
=
{
"ngrams"
:[],
"scores"
:
$
.
extend
({},
ngrams_data
.
scores
)
}
for
(
var
r
in
ngrams_data
.
ngrams
)
{
if
(
ngrams_stop
[
ngrams_data
.
ngrams
[
r
].
id
]
)
{
sub_ngrams_data
[
"ngrams"
].
push
(
ngrams_data
.
ngrams
[
r
]
)
}
}
}
}
}
...
...
@@ -910,12 +945,31 @@ function getIDFromURL( item ) {
return
pageurl
[
cid
+
1
];
}
var
StopList
=
{}
function
test_getlist
(
list_name
)
{
// node/(?P<corpus_id>[0-9]+)/ngrams/list/(?P<list_name>\w+)
var
corpus_id
=
getIDFromURL
(
"corpus"
)
var
someurl
=
window
.
location
.
origin
+
"/api/node/"
+
corpus_id
+
"/ngrams/list/"
+
list_name
;
$
.
ajax
({
type
:
"GET"
,
url
:
someurl
,
dataType
:
"json"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
console
.
log
(
data
)
StopList
=
data
},
error
:
function
(
exception
)
{
console
.
log
(
"second ajax, exception!: "
+
exception
.
status
)
}
})
}
// [ = = = = = = = = = = INIT = = = = = = = = = = ]
var
corpus_id
=
getIDFromURL
(
"corpus"
)
var
url1
=
window
.
location
.
origin
+
"/api/node/"
+
corpus_id
+
"/ngrams/group"
,
url2
=
window
.
location
.
origin
+
"/api/node/"
+
corpus_id
+
"/ngrams/keep"
,
url3
=
window
.
location
.
href
+
"/ngrams.json"
;
var
ngrams_groups
,
ngrams_map
,
ngrams_data
;
var
ngrams_groups
=
{},
ngrams_map
=
{},
ngrams_stop
=
{}
,
ngrams_data
=
{}
;
$
.
when
(
$
.
ajax
({
type
:
"GET"
,
...
...
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