Commit 99e007f0 authored by delanoe's avatar delanoe

[FIX] fix merge with Rom push.

parent 8d1b3767
......@@ -177,3 +177,46 @@ class CorpusFacet(APIView):
# // if subfield not in corpus.aggs:
# // corpus.aggs[subfield] = xcounts
return (xcounts, total)
class CorpusGraph(APIView):
'''
Generate a graph
'''
def get(self, request, node_id):
# check that the node is a corpus
# ? faster from cache than: corpus = session.query(Node)...
corpus = cache.Node[node_id]
if corpus.typename != 'CORPUS':
raise ValidationException(
"Only nodes of type CORPUS can accept facet queries" +
" (but this node has type %s)..." % corpus.typename
)
else:
self.corpus = corpus
# check that the hyperfield parameter makes sense
_facet_available_subfields = [
'journal', 'publication_year', 'rubrique',
'language_iso2', 'language_iso3', 'language_name'
]
parameters = get_parameters(request)
# validate() triggers an info message if subfield not in range
parameters = validate(parameters, {'type': dict, 'items': {
'hyperfield': {'type': str, 'range': _facet_available_subfields}
}})
subfield = parameters['hyperfield']
# do_cooc
# do_distance
# response
return JsonHttpResponse({
'doc_count' : total,
'by': { subfield: xcounts }
})
......@@ -5,8 +5,8 @@ from . import ngramlists
urlpatterns = [
url(r'^nodes$', nodes.NodeListResource.as_view()),
url(r'^nodes/(\d+)$', nodes.NodeResource.as_view()),
url(r'^nodes$' , nodes.NodeListResource.as_view()),
url(r'^nodes/(\d+)$' , nodes.NodeResource.as_view()),
url(r'^nodes/(\d+)/facets$', nodes.CorpusFacet.as_view()),
......@@ -22,4 +22,6 @@ urlpatterns = [
# - an optional grouplist
# aka lexical model
url(r'^ngramlists/family$', ngramlists.ListFamily.as_view()),
url(r'^nodes/(\d+)/graph$' , nodes.CorpusGraph.as_view()),
]
......@@ -74,3 +74,32 @@ def docs_by_journals(request, project_id, corpus_id):
'view': 'journals'
},
)
@requires_auth
def graph(request, project_id, corpus_id):
'''
Graph
'''
# we pass our corpus
corpus = cache.Node[corpus_id]
# and the project just for project.id in corpusBannerTop
project = cache.Node[project_id]
# rendered page : journals.html
return render(
template_name = 'pages/corpora/journals.html',
request = request,
context = {
'debug': settings.DEBUG,
'date': datetime.now(),
'project': project,
'corpus' : corpus,
'view': 'journals'
},
)
from django.conf.urls import url
from . import main, auth
from . import projects, corpora, terms
from . import projects, corpora, terms, explorer
urlpatterns = [
......@@ -28,4 +28,8 @@ urlpatterns = [
# terms table for the corpus
url(r'^projects/(\d+)/corpora/(\d+)/terms/?$', terms.ngramtable),
# graph explorer
url(r'^projects/(\d+)/corpora/(\d+)/graph/?$', explorer.graph),
]
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