forked from amitKr85/project_student_allocation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_graph_from_lattice.py
67 lines (52 loc) · 2.21 KB
/
extract_graph_from_lattice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from concepts import Context
import graphviz
SORTKEYS = [lambda c: c.index]
NAME_GETTERS = [lambda c: 'c%d' % c.index]
def show_graph(lattice, filename=None, directory=None, render=False, view=False, **kwargs):
# """Return graphviz source for visualizing the lattice graph."""
# dot = graphviz.Digraph(
# name=lattice.__class__.__name__,
# comment=repr(lattice),
# filename=filename,
# directory=directory,
# node_attr=dict(shape='circle', width='.25', style='filled', label=''),
# edge_attr=dict(dir='none', labeldistance='1.5', minlen='2'),
# **kwargs
# )
sortkey = SORTKEYS[0]
node_name = NAME_GETTERS[0]
nodecount = 0
edgecount = 0
for concept in lattice._concepts:
name = node_name(concept)
nodecount+=1
# dot.node(name)
print("for node =",name)
if concept.objects:
# dot.edge(name, name, headlabel=' '.join(concept.objects),labelangle='270', color='transparent')
print("objects >",' | '.join(concept.objects))
if concept.properties:
# dot.edge(name, name, taillabel=' '.join(concept.properties), labelangle='90', color='transparent')
print("properties >",' | '.join(concept.properties))
# dot.edges((name, node_name(c)) for c in sorted(concept.lower_neighbors, key=sortkey))
print("edges :")
for i in sorted(concept.lower_neighbors,key=sortkey):
print(name,"->",node_name(i))
edgecount+=1
print()
print("nodes:",nodecount,"edges:",edgecount)
# if render or view:
# dot.render(view=view) # pragma: no cover
# return dot
# c = Context.fromfile("test_files/tech_formal_context.csv",frmat="csv")
c = Context.fromfile("test_files/student_formal_context.csv",frmat="csv")
# max_e_len = 0
# for e,i in c.lattice:
# if len(e) > max_e_len:
# max_e_len = len(e)
for i,exin in enumerate(c.lattice):
extent,intent = exin
print("c"+str(i),">",extent,"\t->",intent)
#
# c.lattice.graphviz(view=True,filename="temp_show.pdf")
# show_graph(c.lattice,filename="temp_show.pdf",directory="output_trees",view=True)