Commit 56ccef86 authored by delanoe's avatar delanoe

[FIX] Graph generation ok, totally in ORM, sqlalchemy.

parent ef4ecd5a
...@@ -53,11 +53,11 @@ def cooc(corpus=None ...@@ -53,11 +53,11 @@ def cooc(corpus=None
NodeNgramX = aliased(NodeNgram) NodeNgramX = aliased(NodeNgram)
NodeNgramY = aliased(NodeNgram) NodeNgramY = aliased(NodeNgram)
cooc_score = func.sqrt(func.sum(NodeNgramX.weight) * func.sum(NodeNgramY.weight)).label('cooc_score')
doc_id = cache.NodeType['Document'].id doc_id = cache.NodeType['Document'].id
cooc_query = (session.query(NodeNgramX.ngram_id, NodeNgramY.ngram_id, cooc_query = (session.query(NodeNgramX.ngram_id, NodeNgramY.ngram_id, cooc_score)
func.sqrt(func.sum(NodeNgramX.weight) * func.sum(NodeNgramY.weight)))
.join(Node, Node.id == NodeNgramX.node_id) .join(Node, Node.id == NodeNgramX.node_id)
.join(NodeNgramY, NodeNgramY.node_id == Node.id) .join(NodeNgramY, NodeNgramY.node_id == Node.id)
.filter(Node.parent_id==corpus.id, Node.type_id==doc_id) .filter(Node.parent_id==corpus.id, Node.type_id==doc_id)
...@@ -109,11 +109,12 @@ def cooc(corpus=None ...@@ -109,11 +109,12 @@ def cooc(corpus=None
# Cooc is symetric, take only the main cooccurrences and cut at the limit # Cooc is symetric, take only the main cooccurrences and cut at the limit
cooc_query = (cooc_query cooc_query = (cooc_query
.filter(NodeNgramX.ngram_id < NodeNgramY.ngram_id) .filter(NodeNgramX.ngram_id < NodeNgramY.ngram_id)
.having(cooc_score > 1)
.group_by(NodeNgramX.ngram_id, NodeNgramY.ngram_id) .group_by(NodeNgramX.ngram_id, NodeNgramY.ngram_id)
.order_by(desc(func.count())) .order_by(desc('cooc_score'))
#.limit(limit) #.limit(50)
) )
matrix = WeightedMatrix(cooc_query) matrix = WeightedMatrix(cooc_query)
......
...@@ -229,10 +229,10 @@ def get_cooc(request=None, corpus=None, cooc_id=None, type='node_link', size=siz ...@@ -229,10 +229,10 @@ def get_cooc(request=None, corpus=None, cooc_id=None, type='node_link', size=siz
#print(n) #print(n)
#print(m) #print(m)
nodes_included = 333 #int(round(size/20,0)) nodes_included = 100 #int(round(size/20,0))
#nodes_excluded = int(round(size/10,0)) #nodes_excluded = int(round(size/10,0))
nodes_specific = 333 #int(round(size/10,0)) nodes_specific = 50 #int(round(size/10,0))
#nodes_generic = int(round(size/10,0)) #nodes_generic = int(round(size/10,0))
# TODO user the included score for the node size # TODO user the included score for the node size
...@@ -267,6 +267,8 @@ def get_cooc(request=None, corpus=None, cooc_id=None, type='node_link', size=siz ...@@ -267,6 +267,8 @@ def get_cooc(request=None, corpus=None, cooc_id=None, type='node_link', size=siz
G.remove_nodes_from(nodes_to_remove) G.remove_nodes_from(nodes_to_remove)
uG = G.to_undirected() uG = G.to_undirected()
partition = best_partition(uG) partition = best_partition(uG)
print("Density of the graph:", nx.density(G))
except: except:
print("-" * 30) print("-" * 30)
PrintException() PrintException()
......
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