-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples_3.py
45 lines (39 loc) · 1.38 KB
/
examples_3.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
# -*- coding: utf-8 -*-
"""
Author: Gaurav Sahu, 10:00 16th January, 2018
Contains usage examples for the contexts module.
1. Given a list of object-attribute relations,
- compute formal concepts
- compute intent and extent
- generate concept-lattice from concepts
"""
import concept_context as cnct
import time
if __name__ == '__main__':
# a simple object-attribute relation illustration using toy-example of
# Star Alliance Airlines data mapping airlines with their destinations
relation = []
# Air Canada relation
relation += [('T1', 'b'), ('T1', 'd')]
# Air New zealand relation
relation += [('T2', 'b'), ('T2', 'e')]
relation += [('T3', 'c')]
relation += [('T4', 'a'), ('T4', 'b'), ('T4', 'c')]
relation += [('T5', 'd')]
relation += [('T6', 'b'), ('T6', 'c')]
relation += [('T7', 'e')]
concepts = cnct.formalConcepts(relation)
start = time.clock()
concepts.computeLattice()
print("Triangles example")
print(concepts)
concepts.computeCanonicalBasis(epsilon=0.3, delta=0.4, basis_type='pac')
for impl in concepts.canonical_basis:
print(impl)
print(time.clock() - start)
# write to a dot file
# Note: use linux command dot starAlliance.dot -Tpng -o starAlliance.png
# to convert the dot file to png
# dotfile = open('triangles.dot', "w")
# concepts.dotPrint(dotfile)
# dotfile.close()