Commit 296ae91d authored by PkSM3's avatar PkSM3

[UPDATE] for stop-list, but not yet

parent 6f0fe49e
...@@ -111,10 +111,16 @@ class NgramEdit(APIView): ...@@ -111,10 +111,16 @@ class NgramEdit(APIView):
node_mapList = get_or_create_node(nodetype='MapList', corpus=corpus ) node_mapList = get_or_create_node(nodetype='MapList', corpus=corpus )
results = session.query(NodeNgram).filter(NodeNgram.node_id==node_mapList.id ).all() results = session.query(NodeNgram).filter(NodeNgram.node_id==node_mapList.id ).all()
ngram_2del = [int(i) for i in ngram_ids.split('+')] 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() 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: for map_node in ngram_2del_:
session.delete(map_node) session.delete(map_node)
session.commit() 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 = = = = ] # [ = = = = / del from map-list = = = = ]
return Response(None, 204) return Response(None, 204)
...@@ -193,3 +199,5 @@ class Document(APIView): ...@@ -193,3 +199,5 @@ class Document(APIView):
'id': node.id 'id': node.id
} }
return Response(data) return Response(data)
...@@ -75,7 +75,15 @@ from rest_framework.decorators import api_view ...@@ -75,7 +75,15 @@ from rest_framework.decorators import api_view
class List(APIView): 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): class Ngrams(APIView):
...@@ -117,7 +125,6 @@ class Ngrams(APIView): ...@@ -117,7 +125,6 @@ class Ngrams(APIView):
group_by.append(Cvalue.score) group_by.append(Cvalue.score)
results.append('cvalue') results.append('cvalue')
if 'specificity' in request.GET['score']: if 'specificity' in request.GET['score']:
Spec = aliased(NodeNodeNgram) Spec = aliased(NodeNodeNgram)
spec_id = get_or_create_node(nodetype='Specificity', corpus=corpus).id spec_id = get_or_create_node(nodetype='Specificity', corpus=corpus).id
...@@ -196,6 +203,23 @@ class Ngrams(APIView): ...@@ -196,6 +203,23 @@ class Ngrams(APIView):
total = ngrams_query.count() 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 formatted result
return JsonHttpResponse({ return JsonHttpResponse({
'pagination': { 'pagination': {
...@@ -203,20 +227,7 @@ class Ngrams(APIView): ...@@ -203,20 +227,7 @@ class Ngrams(APIView):
'limit': limit, 'limit': limit,
'total': total, 'total': total,
}, },
'data': [ 'data': output,
{
'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]
],
}) })
def post(self , request , node_id ): def post(self , request , node_id ):
...@@ -232,10 +243,10 @@ class Group(APIView): ...@@ -232,10 +243,10 @@ class Group(APIView):
Groups can be synonyms, a cathegory or ngrams groups with stems or lems. 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):
node_id = int(node_id) node_id = int(node_id)
corpus = session.query(Node).filter(Node.id==node_id).first() corpus = session.query(Node).filter(Node.id==node_id).first()
group = get_or_create_node(corpus=corpus, nodetype='Group') group = get_or_create_node(corpus=corpus, nodetype='Group')
return(group.id) return(group.id)
def get(self, request, corpus_id): def get(self, request, corpus_id):
# query ngrams # query ngrams
......
...@@ -22,7 +22,7 @@ urlpatterns = patterns('', ...@@ -22,7 +22,7 @@ urlpatterns = patterns('',
url(r'node/(\d+)/ngrams/keep$', ngrams.Keep.as_view()), 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/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/(?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()),
#url(r'nodes/(\d+)/children/hyperdata$', api.NodesChildrenMetatadata.as_view()), #url(r'nodes/(\d+)/children/hyperdata$', api.NodesChildrenMetatadata.as_view()),
......
...@@ -891,9 +891,44 @@ function SearchFilters( elem ) { ...@@ -891,9 +891,44 @@ function SearchFilters( elem ) {
} }
if( MODE == "filter_stop-list") { if( MODE == "filter_stop-list") {
console.clear()
console.log("ngrams_stop:") if(Object.keys(ngrams_stop).length<1) {
console.log( {} ) 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 ) { ...@@ -910,12 +945,31 @@ function getIDFromURL( item ) {
return pageurl[cid+1]; 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 = = = = = = = = = = ] // [ = = = = = = = = = = INIT = = = = = = = = = = ]
var corpus_id = getIDFromURL( "corpus" ) var corpus_id = getIDFromURL( "corpus" )
var url1=window.location.origin+"/api/node/"+corpus_id+"/ngrams/group", var url1=window.location.origin+"/api/node/"+corpus_id+"/ngrams/group",
url2=window.location.origin+"/api/node/"+corpus_id+"/ngrams/keep", url2=window.location.origin+"/api/node/"+corpus_id+"/ngrams/keep",
url3=window.location.href+"/ngrams.json"; url3=window.location.href+"/ngrams.json";
var ngrams_groups, ngrams_map, ngrams_data; var ngrams_groups = {}, ngrams_map = {}, ngrams_stop = {} , ngrams_data = {};
$.when( $.when(
$.ajax({ $.ajax({
type: "GET", type: "GET",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment