-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.py
100 lines (94 loc) · 4.49 KB
/
examples.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*- 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 += [('Air Canada', 'Latin America'), ('Air Canada', 'Europe'),
('Air Canada', 'Canada'), ('Air Canada', 'Asia Pacific'),
('Air Canada', 'Middle East'), ('Air Canada', 'Africa'),
('Air Canada', 'Mexico'), ('Air Canada', 'Caribbean'),
('Air Canada', 'United States')]
# Air New zealand relation
relation += [('Air New Zealand', 'Europe'),
('Air New Zealand', 'Asia Pacific'),
('Air New Zealand', 'United States')]
# All Nippon Airways relation
relation += [('All Nippon Airways', 'Europe'),
('All Nippon Airways', 'Asia Pacific'),
('All Nippon Airways', 'United States')]
# Ansett Australia relation
relation += [('Ansett Australia', 'Asia Pacific')]
# The Australian Airlines Group
relation += [('The Austrian Airlines Group', 'Europe'),
('The Austrian Airlines Group', 'Canada'),
('The Austrian Airlines Group', 'Asia Pacific'),
('The Austrian Airlines Group', 'Middle East'),
('The Austrian Airlines Group', 'Africa'),
('The Austrian Airlines Group', 'United States')]
# British Midland relation
relation += [('British Midland', 'Europe')]
# Lufthansa relation
relation += [('Lufthansa', 'Latin America '), ('Lufthansa', 'Europe'),
('Lufthansa', 'Canada'), ('Lufthansa', 'Asia Pacific'),
('Lufthansa', 'Middle East'), ('Lufthansa', 'Africa'),
('Lufthansa', 'Mexico'), ('Lufthansa', 'United States')]
# Mexicana relation
relation += [('Mexicana', 'Latin America'), ('Mexicana', 'Canada'),
('Mexicana', 'Mexico'), ('Mexicana', 'Caribbean'),
('Mexicana', 'United States')]
# Scandinavian Airlines relation
relation += [('Scandinavian Airlines', 'Latin America'),
('Scandinavian Airlines', 'Europe'),
('Scandinavian Airlines', 'Asia Pacific'),
('Scandinavian Airlines', 'Africa'),
('Scandinavian Airlines', 'United States')]
# Singapore Airlines relation
relation += [('Singapore Airlines', 'Europe'),
('Singapore Airlines', 'Canada'),
('Singapore Airlines', 'Asia Pacific'),
('Singapore Airlines', 'Middle East'),
('Singapore Airlines', 'Africa'),
('Singapore Airlines', 'United States')]
# Thai Airways International
relation += [('Thai Airways International', 'Latin America'),
('Thai Airways International', 'Europe'),
('Thai Airways International', 'Asia Pacific'),
('Thai Airways International', 'Caribbean'),
('Thai Airways International', 'United States')]
# United Airlines relation
relation += [('United Airlines', 'Latin America'),
('United Airlines', 'Europe'),
('United Airlines', 'Canada'),
('United Airlines', 'Asia Pacific'),
('United Airlines', 'Mexico'),
('United Airlines', 'Caribbean'),
('United Airlines', 'United States')]
# VARIG relation
relation += [('VARIG', 'Latin America'), ('VARIG', 'Europe'),
('VARIG', 'Asia Pacific'), ('VARIG', 'Africa'),
('VARIG', 'Mexico'), ('VARIG', 'United States')]
start = time.clock()
concepts = cnct.formalConcepts(relation)
concepts.computeLattice()
print("Star Alliance Airlines example")
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('starAlliance.dot', "w")
# concepts.dotPrint(dotfile)
# dotfile.close()