8
8
9
9
def covering_edges (concept_list , context ):
10
10
"""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
+ """
12
68
Objects = context ._Objects
13
69
Properties = context ._Properties
14
70
@@ -17,9 +73,9 @@ def covering_edges(concept_list, context):
17
73
for extent , intent in concept_index .items ():
18
74
candidate_counter = dict .fromkeys (concept_index , 0 )
19
75
20
- property_candidates = Properties .supremum - intent
76
+ property_candidates = Properties .fromint ( Properties . supremum & ~ intent )
21
77
22
- for atom in Properties . fromint ( property_candidates ) .atoms ():
78
+ for atom in property_candidates .atoms ():
23
79
extent_candidate = Objects .fromint (extent & atom .prime ())
24
80
intent_candidate = concept_index [extent_candidate ]
25
81
candidate_counter [extent_candidate ] += 1
0 commit comments