Commit 8715a750 authored by delanoe's avatar delanoe

Merge branch 'samuel' into unstable

parents 9b970abf 7eac6741
......@@ -99,7 +99,7 @@ class Ngrams(APIView):
'''
REST application to manage ngrams
Example :
http://localhost:8000/api/node/1444485/ngrams?format=json&score=tfidf,occurrences
http://localhost:8000/api/node/1444485/ngrams?format=json&score=tfidf,occs
'''
def get(self, request, node_id):
# query ngrams
......@@ -134,9 +134,9 @@ class Ngrams(APIView):
# )
# for i in ngrams_query:
# print(i)
if 'occurrences' in the_score:
occurrences = func.sum(Node_Ngram.weight).label('occurrences')
ngrams_query = (ngrams_query.add_column(occurrences))
if 'occs' in the_score:
occs = func.sum(Node_Ngram.weight).label('occs')
ngrams_query = (ngrams_query.add_column(occs))
results.append('occurences')
if 'tfidf' in the_score:
......@@ -170,8 +170,8 @@ class Ngrams(APIView):
results.append('specificity')
order_query = request.GET.get('order', False)
if order_query == 'occurrences':
ngrams_query = ngrams_query.order_by(desc(occurrences))
if order_query == 'occs':
ngrams_query = ngrams_query.order_by(desc(occs))
elif order_query == 'cvalue':
ngrams_query = ngrams_query.order_by(desc(Cvalue.score))
elif order_query == 'tfidf':
......@@ -241,18 +241,18 @@ class Ngrams(APIView):
output = []
for ngram in ngrams_query[offset : offset+limit]:
info = {}
info = { "scores":{} }
try: info["id"] = ngram.id
except: pass
try: info["terms"] = ngram.terms
try: info["name"] = ngram.terms
except: pass
try: info["occurrences"] = ngram.occurrences
try: info["scores"]["occ_uniq"] = ngram.occs
except: pass
try: info["tfidf"] = ngram.tfidf
try: info["scores"]["tfidf"] = ngram.tfidf
except: pass
try: info["cvalue"] = ngram.cvalue
try: info["scores"]["cvalue"] = ngram.cvalue
except: pass
try: info["specificity"] = ngram.specificity
try: info["scores"]["specificity"] = ngram.specificity
except: pass
output.append( info )
......@@ -344,7 +344,7 @@ class Group(APIView):
# print(i)
ngrams = [int(i) for i in list(groups["nodes"].keys())]
groups["nodes"] = get_occtfidf( ngrams , request.user.id , corpus_id , "Group")
# groups["nodes"] = get_occtfidf( ngrams , request.user.id , corpus_id , "Group")
return JsonHttpResponse(groups)
......
......@@ -880,11 +880,12 @@ function getIDFromURL( item ) {
}
// [ = = = = = = = = = = INIT = = = = = = = = = = ]
// http://localhost:8000/api/node/84592/ngrams?format=json&score=tfidf,occs&list=miam
var corpus_id = getIDFromURL( "corpus" )
var url0=window.location.origin+"/api/node/"+corpus_id+"/ngrams/list/stop",
var url0=window.location.origin+"/api/node/"+corpus_id+"/ngrams?format=json&score=tfidf,occs&list=stop&limit=999999",
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";
url2=window.location.origin+"/api/node/"+corpus_id+"/ngrams?format=json&score=tfidf,occs&list=map&limit=999999",
url3=window.location.origin+"/api/node/"+corpus_id+"/ngrams?format=json&score=tfidf,occs&list=miam&limit=999999";
var NGrams = {
"group" : {},
"stop" : {},
......@@ -899,7 +900,11 @@ $.when(
type: "GET",
url: url0,
dataType: "json",
success : function(data, textStatus, jqXHR) { NGrams["stop"] = data },
success : function(data, textStatus, jqXHR) {
for(var i in data.data) {
NGrams["stop"][data.data[i].id] = data.data[i]
}
},
error: function(exception) {
console.log("first ajax, exception!: "+exception.status)
}
......@@ -908,7 +913,9 @@ $.when(
type: "GET",
url: url1,
dataType: "json",
success : function(data, textStatus, jqXHR) { NGrams["group"] = data },
success : function(data, textStatus, jqXHR) {
NGrams["group"] = data
},
error: function(exception) {
console.log("first ajax, exception!: "+exception.status)
}
......@@ -917,7 +924,11 @@ $.when(
type: "GET",
url: url2,
dataType: "json",
success : function(data, textStatus, jqXHR) { NGrams["map"] = data },
success : function(data, textStatus, jqXHR) {
for(var i in data.data) {
NGrams["map"][data.data[i].id] = data.data[i]
}
},
error: function(exception) {
console.log("first ajax, exception!: "+exception.status)
}
......@@ -926,7 +937,18 @@ $.when(
type: "GET",
url: url3,
dataType: "json",
success : function(data, textStatus, jqXHR) { NGrams["main"] = data },
success : function(data, textStatus, jqXHR) {
NGrams["main"] = {
"ngrams": data.data,
"scores": {
"initial":"occ_uniq",
"nb_docs":data.data.length,
"orig_nb_ngrams":1,
"nb_ngrams":data.data.length,
}
}
},
error: function(exception) {
console.log("second ajax, exception!: "+exception.status)
}
......@@ -963,7 +985,6 @@ $.when(
}
}
// Building the Score-Selector //NGrams["scores"]
var FirstScore = NGrams["main"].scores.initial
var possible_scores = Object.keys( NGrams["main"].ngrams[0].scores );
......
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