Skip to content

Commit e4bbc29

Browse files
committed
Clean code and add docstest
1 parent a78ea2c commit e4bbc29

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

concepts/algorithms/covering_edges.py

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,63 @@
88

99
def covering_edges(concept_list, context):
1010
"""Yield mapping edge as ``((extent, intent), (lower_extent, lower_intent))``
11-
pairs (concept and it's lower neighbor) from ``context`` and ``concept_list``"""
11+
pairs (concept and it's lower neighbor) from ``context`` and ``concept_list``
12+
13+
Example:
14+
>>> from concepts import make_context
15+
>>> from concepts.concepts import ConceptList, Concept
16+
17+
>>> context = make_context('''
18+
... |0|1|2|3|4|5|
19+
... A|X|X|X| | | |
20+
... B|X| |X|X|X|X|
21+
... C|X|X| | |X| |
22+
... D| |X|X| | | |''')
23+
24+
>>> concepts = [('ABCD', ''),
25+
... ('ABC', '0'),
26+
... ('AC', '01'),
27+
... ('A', '012'),
28+
... ('', '012345'),
29+
... ('C', '014'),
30+
... ('AB', '02'),
31+
... ('B', '02345'),
32+
... ('BC', '04'),
33+
... ('ACD', '1'),
34+
... ('AD', '12'),
35+
... ('ABD', '2')]
36+
37+
>>> concept_list = ConceptList.frompairs(
38+
... map(lambda c: (context._Objects.frommembers(c[0]),
39+
... context._Properties.frommembers(c[1])),
40+
... concepts))
41+
42+
>>> edges = covering_edges(concept_list, context)
43+
44+
>>> [(''.join(concept[0].members()), # doctest: +NORMALIZE_WHITESPACE
45+
... ''.join(lower[0].members()))
46+
... for concept, lower in edges]
47+
[('ABCD', 'ABC'),
48+
('ABCD', 'ACD'),
49+
('ABCD', 'ABD'),
50+
('ABC', 'AC'),
51+
('ABC', 'AB'),
52+
('ABC', 'BC'),
53+
('AC', 'A'),
54+
('AC', 'C'),
55+
('A', ''),
56+
('C', ''),
57+
('AB', 'A'),
58+
('AB', 'B'),
59+
('B', ''),
60+
('BC', 'C'),
61+
('BC', 'B'),
62+
('ACD', 'AC'),
63+
('ACD', 'AD'),
64+
('AD', 'A'),
65+
('ABD', 'AB'),
66+
('ABD', 'AD')]
67+
"""
1268
Objects = context._Objects
1369
Properties = context._Properties
1470

@@ -17,9 +73,9 @@ def covering_edges(concept_list, context):
1773
for extent, intent in concept_index.items():
1874
candidate_counter = dict.fromkeys(concept_index, 0)
1975

20-
property_candidates = Properties.supremum - intent
76+
property_candidates = Properties.fromint(Properties.supremum & ~intent)
2177

22-
for atom in Properties.fromint(property_candidates).atoms():
78+
for atom in property_candidates.atoms():
2379
extent_candidate = Objects.fromint(extent & atom.prime())
2480
intent_candidate = concept_index[extent_candidate]
2581
candidate_counter[extent_candidate] += 1

0 commit comments

Comments
 (0)