Commit f74f25ee authored by Administrator's avatar Administrator

[FEAT] From nodelink to docs.

parent be75f405
......@@ -146,6 +146,7 @@ def get_cooc(request=None, corpus_id=None, cooc_id=None, type='node_link', n=150
from analysis.louvain import best_partition
matrix = defaultdict(lambda : defaultdict(float))
ids = dict()
labels = dict()
weight = dict()
......@@ -161,9 +162,13 @@ def get_cooc(request=None, corpus_id=None, cooc_id=None, type='node_link', n=150
cooccurrence_node = Node.objects.filter(type=type_cooc, parent=corpus).first()
for cooccurrence in NodeNgramNgram.objects.filter(node=cooccurrence_node):
ids[cooccurrence.ngramx.terms] = cooccurrence.ngramx.id
ids[cooccurrence.ngramy.terms] = cooccurrence.ngramy.id
labels[cooccurrence.ngramx.id] = cooccurrence.ngramx.terms
labels[cooccurrence.ngramy.id] = cooccurrence.ngramy.terms
matrix[cooccurrence.ngramx.id][cooccurrence.ngramy.id] = cooccurrence.score
matrix[cooccurrence.ngramy.id][cooccurrence.ngramx.id] = cooccurrence.score
......@@ -200,6 +205,7 @@ def get_cooc(request=None, corpus_id=None, cooc_id=None, type='node_link', n=150
#node,type(labels[node])
G.node[node]['label'] = node
G.node[node]['name'] = node
G.node[node]['pk'] = ids[str(node)]
G.node[node]['size'] = weight[node]
G.node[node]['group'] = partition[node]
G.add_edge(node, "cluster " + str(partition[node]), weight=3)
......
......@@ -537,7 +537,16 @@ def tfidf(request, corpus_id, ngram_id):
ngram = Ngram.objects.get(id=ngram_id)
node_node_ngrams = NodeNodeNgram.objects.filter(nodex=corpus, ngram=ngram).order_by('-score')
tfidf_list = [ dict(id=x.nodey.id, title=x.nodey.metadata['title']) for x in node_node_ngrams]
# only for tests
# TODO add test if metadata present
tfidf_list = [ dict(
id=x.nodey.id,
title=x.nodey.metadata['title'],
publication_date=x.nodey.metadata['publication_date'],
journal=x.nodey.metadata['journal'],
abstract=x.nodey.metadata['abstract'])
for x in node_node_ngrams]
data = json.dumps(tfidf_list)
return JsonHttpResponse(data)
......
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