conceptflow 0.6.2__tar.gz → 0.6.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. {conceptflow-0.6.2/src/conceptflow.egg-info → conceptflow-0.6.3}/PKG-INFO +3 -1
  2. {conceptflow-0.6.2 → conceptflow-0.6.3}/pyproject.toml +5 -0
  3. conceptflow-0.6.3/src/conceptflow/_version.py +1 -0
  4. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/core/context.py +14 -2
  5. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/io/formats.py +22 -1
  6. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/validation/input.py +22 -14
  7. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/dimflux_layout.py +2 -2
  8. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/nested.py +31 -7
  9. {conceptflow-0.6.2 → conceptflow-0.6.3/src/conceptflow.egg-info}/PKG-INFO +3 -1
  10. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow.egg-info/SOURCES.txt +11 -0
  11. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow.egg-info/requires.txt +2 -0
  12. conceptflow-0.6.3/tests/test_backend_consistency.py +270 -0
  13. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_browser.py +89 -0
  14. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_context_handling.py +17 -0
  15. conceptflow-0.6.3/tests/test_cross_library.py +345 -0
  16. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_dimflux_layout.py +16 -0
  17. conceptflow-0.6.3/tests/test_feature_matrix.py +414 -0
  18. conceptflow-0.6.3/tests/test_properties_core.py +934 -0
  19. conceptflow-0.6.3/tests/test_properties_drawing.py +130 -0
  20. conceptflow-0.6.3/tests/test_properties_estimators.py +180 -0
  21. conceptflow-0.6.3/tests/test_properties_input.py +228 -0
  22. conceptflow-0.6.3/tests/test_properties_io_nested.py +370 -0
  23. conceptflow-0.6.3/tests/test_properties_scaling.py +244 -0
  24. conceptflow-0.6.3/tests/test_reproducibility.py +244 -0
  25. conceptflow-0.6.3/tests/test_sklearn_workflows.py +210 -0
  26. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_validation_input.py +37 -0
  27. conceptflow-0.6.2/src/conceptflow/_version.py +0 -1
  28. {conceptflow-0.6.2 → conceptflow-0.6.3}/LICENSE +0 -0
  29. {conceptflow-0.6.2 → conceptflow-0.6.3}/README.md +0 -0
  30. {conceptflow-0.6.2 → conceptflow-0.6.3}/setup.cfg +0 -0
  31. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/__init__.py +0 -0
  32. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/_deprecation.py +0 -0
  33. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/__init__.py +0 -0
  34. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/_bitset.py +0 -0
  35. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/_membership.py +0 -0
  36. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/_registry.py +0 -0
  37. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/derivation.py +0 -0
  38. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/enumeration.py +0 -0
  39. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/generators.py +0 -0
  40. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/hasse.py +0 -0
  41. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/implications.py +0 -0
  42. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/order.py +0 -0
  43. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/algorithms/reduction.py +0 -0
  44. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/cluster/__init__.py +0 -0
  45. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/cluster/concept_lattice.py +0 -0
  46. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/core/__init__.py +0 -0
  47. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/core/concept.py +0 -0
  48. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/core/incomplete_context.py +0 -0
  49. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/core/lattice.py +0 -0
  50. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/core/many_valued_context.py +0 -0
  51. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/core/operations.py +0 -0
  52. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/core/scale_measures.py +0 -0
  53. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/__init__.py +0 -0
  54. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/_loaders.py +0 -0
  55. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/README.md +0 -0
  56. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/animals_en.cxt +0 -0
  57. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/binary_relations_en.cxt +0 -0
  58. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_de.cxt +0 -0
  59. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_en.cxt +0 -0
  60. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/driveconcepts_de.cxt +0 -0
  61. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/driveconcepts_en.cxt +0 -0
  62. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/famous_animals_en.cxt +0 -0
  63. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/forum_romanum_en.cxt +0 -0
  64. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/livingbeings_de.cxt +0 -0
  65. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/livingbeings_en.cxt +0 -0
  66. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/missmarple_de.cxt +0 -0
  67. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/missmarple_en.cxt +0 -0
  68. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/music_en.cxt +0 -0
  69. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/newzealand_en.cxt +0 -0
  70. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/officesupplies_de.cxt +0 -0
  71. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/officesupplies_en.cxt +0 -0
  72. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/planets_en.cxt +0 -0
  73. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/seasoningplanner_de.cxt +0 -0
  74. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/tealady.cxt +0 -0
  75. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/triangles_en.cxt +0 -0
  76. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository.json +0 -0
  77. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/decomposition/__init__.py +0 -0
  78. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/decomposition/bipartite.py +0 -0
  79. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/decomposition/boolean_factorization.py +0 -0
  80. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/decomposition/ordinal_factorization.py +0 -0
  81. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/exploration/__init__.py +0 -0
  82. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/exploration/builder.py +0 -0
  83. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/exploration/combinations.py +0 -0
  84. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/exploration/view.py +0 -0
  85. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/feature_extraction/__init__.py +0 -0
  86. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/feature_extraction/concept_encoder.py +0 -0
  87. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/io/__init__.py +0 -0
  88. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/io/cxt.py +0 -0
  89. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/metrics/__init__.py +0 -0
  90. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/metrics/drawing_quality.py +0 -0
  91. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/metrics/measures.py +0 -0
  92. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/metrics/rules.py +0 -0
  93. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/preprocessing/__init__.py +0 -0
  94. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/preprocessing/conceptual_scaler.py +0 -0
  95. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/preprocessing/scales.py +0 -0
  96. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/quality.py +0 -0
  97. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/rules/__init__.py +0 -0
  98. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/rules/implication_basis.py +0 -0
  99. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/rules/outlier_detector.py +0 -0
  100. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/validation/__init__.py +0 -0
  101. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/__init__.py +0 -0
  102. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/_checks.py +0 -0
  103. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/_clearance.py +0 -0
  104. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/_text.py +0 -0
  105. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/d3_backend.py +0 -0
  106. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/graph_data.py +0 -0
  107. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/graphviz.py +0 -0
  108. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/html_figure.py +0 -0
  109. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/lattice_plot.py +0 -0
  110. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/layered_layout.py +0 -0
  111. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/static.py +0 -0
  112. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow/visualization/tikz.py +0 -0
  113. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow.egg-info/dependency_links.txt +0 -0
  114. {conceptflow-0.6.2 → conceptflow-0.6.3}/src/conceptflow.egg-info/top_level.txt +0 -0
  115. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_algorithm_registry.py +0 -0
  116. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_audit_regressions.py +0 -0
  117. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_boolean_factorization.py +0 -0
  118. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_check_estimator.py +0 -0
  119. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_cluster_estimator.py +0 -0
  120. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_concept.py +0 -0
  121. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_concept_encoder.py +0 -0
  122. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_conceptual_scaler.py +0 -0
  123. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_context_operations.py +0 -0
  124. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_cxt_io.py +0 -0
  125. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_d3_backend.py +0 -0
  126. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_datasets.py +0 -0
  127. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_derivation.py +0 -0
  128. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_docs_examples.py +0 -0
  129. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_drawing_quality.py +0 -0
  130. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_enumeration.py +0 -0
  131. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_exploration.py +0 -0
  132. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_formal_context.py +0 -0
  133. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_generators.py +0 -0
  134. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_graph_data.py +0 -0
  135. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_hasse.py +0 -0
  136. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_html_figure.py +0 -0
  137. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_implication_basis_estimator.py +0 -0
  138. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_implications.py +0 -0
  139. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_incomplete_context.py +0 -0
  140. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_lattice.py +0 -0
  141. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_lattice_navigation.py +0 -0
  142. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_layout_and_graphviz.py +0 -0
  143. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_many_valued_context.py +0 -0
  144. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_measures.py +0 -0
  145. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_metrics.py +0 -0
  146. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_nested_combinations.py +0 -0
  147. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_nested_levels.py +0 -0
  148. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_nested_visualization.py +0 -0
  149. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_oracles.py +0 -0
  150. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_ord2factor.py +0 -0
  151. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_ordinal_factorization.py +0 -0
  152. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_patch_0_3_1.py +0 -0
  153. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_public_api.py +0 -0
  154. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_quality.py +0 -0
  155. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_reduction.py +0 -0
  156. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_review_fixes.py +0 -0
  157. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_scale_measures.py +0 -0
  158. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_scales.py +0 -0
  159. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_sklearn_compatibility.py +0 -0
  160. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_static_figures.py +0 -0
  161. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_tikz.py +0 -0
  162. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_visualization_options.py +0 -0
  163. {conceptflow-0.6.2 → conceptflow-0.6.3}/tests/test_workflows.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conceptflow
3
- Version: 0.6.2
3
+ Version: 0.6.3
4
4
  Summary: A scikit-learn compatible Formal Concept Analysis framework.
5
5
  Author-email: Anurag Sharma <sharma@cs.uni-kassel.de>
6
6
  License-Expression: BSD-3-Clause
@@ -35,6 +35,8 @@ Provides-Extra: dev
35
35
  Requires-Dist: scikit-learn>=1.6; extra == "dev"
36
36
  Requires-Dist: pytest; extra == "dev"
37
37
  Requires-Dist: pytest-cov; extra == "dev"
38
+ Requires-Dist: hypothesis; extra == "dev"
39
+ Requires-Dist: concepts; extra == "dev"
38
40
  Requires-Dist: ruff; extra == "dev"
39
41
  Dynamic: license-file
40
42
 
@@ -54,6 +54,11 @@ dev = [
54
54
  "scikit-learn>=1.6",
55
55
  "pytest",
56
56
  "pytest-cov",
57
+ # Property-based tests (tests/test_properties_*.py).
58
+ "hypothesis",
59
+ # Results compared with another FCA library (tests/test_cross_library.py;
60
+ # fcapy and caspailleur come with DimFlux).
61
+ "concepts",
57
62
  "ruff",
58
63
  ]
59
64
 
@@ -0,0 +1 @@
1
+ __version__ = "0.6.3"
@@ -88,6 +88,18 @@ def _check_unique_names(names: tuple[str, ...], kind: str) -> None:
88
88
  )
89
89
 
90
90
 
91
+ def as_cell_array(data) -> np.ndarray:
92
+ """
93
+ ``np.asarray(data)``, except that a list mixing numbers and strings keeps
94
+ each cell as it is: NumPy would turn it into strings ([2, "x"] becomes
95
+ ["2", "x"]), and the string "2" is not a cross while the number 2 is.
96
+ """
97
+ array = np.asarray(data)
98
+ if array.dtype.kind in "US" and not isinstance(data, np.ndarray):
99
+ array = np.asarray(data, dtype=object)
100
+ return array
101
+
102
+
91
103
  def _cross_table(data) -> np.ndarray:
92
104
  """
93
105
  Convert incidence data to a boolean cross table, cell by cell:
@@ -105,7 +117,7 @@ def _cross_table(data) -> np.ndarray:
105
117
  """
106
118
  if scipy.sparse.issparse(data):
107
119
  data = data.toarray()
108
- raw = np.asarray(data)
120
+ raw = as_cell_array(data)
109
121
 
110
122
  if raw.dtype == bool:
111
123
  # Copy, so later changes to the caller's array cannot alter a frozen
@@ -240,7 +252,7 @@ class FormalContext:
240
252
  """
241
253
  if scipy.sparse.issparse(data):
242
254
  data = data.toarray()
243
- array = np.asarray(data)
255
+ array = as_cell_array(data)
244
256
 
245
257
  if array.ndim != 2:
246
258
  raise ValueError("Formal context data must be two-dimensional.")
@@ -39,6 +39,17 @@ def context_to_json(context: FormalContext) -> str:
39
39
  return json.dumps(data, ensure_ascii=False)
40
40
 
41
41
 
42
+ def _json_names(value, what: str) -> list:
43
+ """Object or attribute names from JSON: a list of strings or numbers."""
44
+ if not isinstance(value, list) or not all(
45
+ isinstance(name, (str, int, float)) and not isinstance(name, bool) for name in value
46
+ ):
47
+ raise ValueError(
48
+ f"The JSON context's {what} must be a list of names, got {str(value)[:60]}."
49
+ )
50
+ return value
51
+
52
+
42
53
  def context_from_json(text: str) -> FormalContext:
43
54
  """Parse a context from FCART/fcapy JSON or the plain dict layout."""
44
55
  data = json.loads(text)
@@ -53,7 +64,15 @@ def context_from_json(text: str) -> FormalContext:
53
64
  f"The JSON context has no {exc.args[0]!r} entry: expected the "
54
65
  'FCART/fcapy layout or {"objects", "attributes", "incidence"}.'
55
66
  ) from None
56
- return FormalContext(objects=objects, attributes=attributes, incidence=incidence)
67
+ if not isinstance(incidence, list):
68
+ raise ValueError(
69
+ f"The JSON context's incidence must be a list of rows, got {str(incidence)[:60]}."
70
+ )
71
+ return FormalContext(
72
+ objects=_json_names(objects, "objects"),
73
+ attributes=_json_names(attributes, "attributes"),
74
+ incidence=incidence,
75
+ )
57
76
 
58
77
  try:
59
78
  header, body = data
@@ -66,6 +85,8 @@ def context_from_json(text: str) -> FormalContext:
66
85
  '{"objects", "attributes", "incidence"}.'
67
86
  ) from exc
68
87
 
88
+ objects = _json_names(objects, "objects")
89
+ attributes = _json_names(attributes, "attributes")
69
90
  if len(rows) != len(objects):
70
91
  raise ValueError(
71
92
  f"The JSON context names {len(objects)} objects but has {len(rows)} rows."
@@ -9,7 +9,7 @@ import pandas as pd
9
9
  from scipy import sparse
10
10
 
11
11
  from conceptflow.core import FormalContext, IncompleteContext
12
- from conceptflow.core.context import _cross_table
12
+ from conceptflow.core.context import _cross_table, as_cell_array
13
13
 
14
14
  _UNKNOWN_HINT = (
15
15
  "Binary-context estimators need complete data. Choose a completion with "
@@ -52,7 +52,7 @@ def check_binary_context_input(X) -> FormalContext:
52
52
  if sparse.issparse(X):
53
53
  array = X.toarray()
54
54
  else:
55
- array = np.asarray(X)
55
+ array = as_cell_array(X)
56
56
 
57
57
  if np.iscomplexobj(array):
58
58
  raise ValueError("Complex data not supported")
@@ -61,20 +61,28 @@ def check_binary_context_input(X) -> FormalContext:
61
61
  array = array.astype(object)
62
62
 
63
63
  if array.dtype == object:
64
- # Try to coerce to numeric — raises TypeError with sklearn-compatible
65
- # message if elements cannot be converted (e.g. dicts, arbitrary objects).
66
- try:
67
- array = array.astype(float)
68
- except ValueError:
64
+ cells = array.ravel().tolist()
65
+ if any(cell is pd.NA for cell in cells) or pd.isna(array).any():
66
+ raise ValueError(
67
+ "Input contains NaN: missing entries. If empty cells mean "
68
+ '"no cross", pass FormalContext.from_array(X) instead.'
69
+ )
70
+ if any(isinstance(cell, complex) for cell in cells):
71
+ raise ValueError("Complex data not supported")
72
+ if any(
73
+ isinstance(cell, (float, np.floating)) and not np.isfinite(cell) for cell in cells
74
+ ):
75
+ raise ValueError("Input contains infinity or a value too large.")
76
+ if any(isinstance(cell, (str, bytes)) for cell in cells):
69
77
  # Strings such as "x" / ".": read cell by cell, as FormalContext
70
- # does (unknown spellings raise a ValueError naming the value).
71
- # Empty cells are still rejected, as for numeric input.
72
- if pd.isna(array).any():
73
- raise ValueError(
74
- "Input contains NaN: missing entries. If empty cells mean "
75
- '"no cross", pass FormalContext.from_array(X) instead.'
76
- ) from None
78
+ # and DataFrames are, so "2" or "1.5" are refused whatever the
79
+ # other cells hold (unknown spellings raise a ValueError naming
80
+ # the value).
77
81
  array = _cross_table(array)
82
+ else:
83
+ # Numbers: raises TypeError with scikit-learn's message for
84
+ # anything else (e.g. dicts, arbitrary objects).
85
+ array = array.astype(float)
78
86
 
79
87
  if array.ndim != 2:
80
88
  raise ValueError(
@@ -157,12 +157,12 @@ def lattice_to_graph_data_dimflux(
157
157
 
158
158
  # DimFlux needs at least two concepts, and for exactly two it returns
159
159
  # (almost) the same point twice: draw those by hand, top above bottom
160
- # (screen coordinates, y grows downwards).
160
+ # (DimFlux coordinates, y grows upwards; flipped below).
161
161
  if lattice.n_concepts < 2:
162
162
  coordinates = {concept.extent: np.zeros(2) for concept in lattice.concepts}
163
163
  elif lattice.n_concepts == 2:
164
164
  coordinates = {
165
- concept.extent: np.array([0.0, 0.0 if concept == lattice.top() else 1.0])
165
+ concept.extent: np.array([0.0, 1.0 if concept == lattice.top() else 0.0])
166
166
  for concept in lattice.concepts
167
167
  }
168
168
  else:
@@ -125,10 +125,22 @@ def _inner_template_data(
125
125
  {"source": e.source, "target": e.target}
126
126
  for e in inner_gd.edges
127
127
  ],
128
+ "orientation": _orientation(template_view.lattice),
128
129
  "gamma_by_name": gamma_by_name,
129
130
  }
130
131
 
131
132
 
133
+ def _orientation(lattice) -> dict[str, str]:
134
+ """
135
+ The nodes the page puts straight above each other (top above bottom) to
136
+ turn a DimFlux drawing upright. Given explicitly because a view entered
137
+ by a click shows the template with the extents cut down to the outer
138
+ concept's objects, where the largest and smallest extents are no longer
139
+ unique; it must be turned like the template drawn inside the bubble.
140
+ """
141
+ return {"top": lattice.top().stable_id(), "bottom": lattice.bottom().stable_id()}
142
+
143
+
132
144
  def debug_filled_pairs(view: ExplorationView) -> None:
133
145
  """
134
146
  Print a mathematical verification report of the subdirect product filling.
@@ -696,6 +708,8 @@ def _nested_data(
696
708
  "inner_template": next_inner_template,
697
709
  "nodes": child_nodes,
698
710
  "edges": inner_template["edges"],
711
+ # Drawn at the angle of the preview inside the bubble.
712
+ "orientation": inner_template["orientation"],
699
713
  "metadata": {
700
714
  "context_size": (node.metadata["extent_size"], 0),
701
715
  "n_concepts": len(inner_template["nodes"]),
@@ -746,6 +760,7 @@ def _nested_data(
746
760
  "scale_names": list(view.scale_names),
747
761
  "nodes": nodes,
748
762
  "edges": edges,
763
+ "orientation": _orientation(view.lattice),
749
764
  "inner_template": inner_template,
750
765
  "metadata": {
751
766
  "context_size": (
@@ -1151,10 +1166,15 @@ function closestDistance(nodes) {{
1151
1166
  return best;
1152
1167
  }}
1153
1168
 
1154
- function computeTransform(nodes, targetWidth, targetHeight, padding) {{
1155
- const topNode = nodes.reduce((best, d) =>
1169
+ // `orientation` ({{top, bottom}} node ids) says which nodes go straight above
1170
+ // each other; a view entered by a click uses its template's, so it is drawn
1171
+ // at the angle of the preview (its extents are cut down to the objects of
1172
+ // the outer concept, so the largest and smallest are not unique there).
1173
+ function computeTransform(nodes, targetWidth, targetHeight, padding, orientation) {{
1174
+ const byId = new Map(nodes.map(d => [d.id, d]));
1175
+ const topNode = byId.get(orientation?.top) ?? nodes.reduce((best, d) =>
1156
1176
  extentSize(d) > extentSize(best) ? d : best, nodes[0]);
1157
- const bottomNode = nodes.reduce((best, d) =>
1177
+ const bottomNode = byId.get(orientation?.bottom) ?? nodes.reduce((best, d) =>
1158
1178
  extentSize(d) < extentSize(best) ? d : best, nodes[0]);
1159
1179
 
1160
1180
  const bx = bottomNode.x ?? 0;
@@ -1323,7 +1343,9 @@ function drawTemplatePreview(parentGroup, innerTemplate, filledInner, radius, sh
1323
1343
  const innerSize = radius * 1.55;
1324
1344
  const padding = Math.min(8, innerSize / 6);
1325
1345
 
1326
- const transform = computeTransform(innerTemplate.nodes, innerSize, innerSize, padding);
1346
+ const transform = computeTransform(
1347
+ innerTemplate.nodes, innerSize, innerSize, padding, innerTemplate.orientation
1348
+ );
1327
1349
 
1328
1350
  const childGroup = parentGroup
1329
1351
  .append("g")
@@ -1371,7 +1393,9 @@ function drawChildPreview(parentGroup, childData, radius) {{
1371
1393
  const innerSize = radius * 1.35;
1372
1394
  const padding = Math.min(8, innerSize / 6);
1373
1395
 
1374
- const transform = computeTransform(childData.nodes, innerSize, innerSize, padding);
1396
+ const transform = computeTransform(
1397
+ childData.nodes, innerSize, innerSize, padding, childData.orientation
1398
+ );
1375
1399
 
1376
1400
  const childGroup = parentGroup
1377
1401
  .append("g")
@@ -1418,7 +1442,7 @@ function drawView(size) {{
1418
1442
 
1419
1443
  const transform = computeTransform(
1420
1444
  viewData.nodes, size.width, size.height,
1421
- Math.min(100, size.width / 6, size.height / 6)
1445
+ Math.min(100, size.width / 6, size.height / 6), viewData.orientation
1422
1446
  );
1423
1447
  const nodeById = new Map(viewData.nodes.map(d => [d.id, d]));
1424
1448
 
@@ -1483,7 +1507,7 @@ function drawView(size) {{
1483
1507
 
1484
1508
  // Draw inner template preview (subdirect decomposition) or plain child preview.
1485
1509
  // Attr labels shown only in the top outer node's bubble (largest extent).
1486
- const topOuterId = viewData.nodes.reduce((best, d) =>
1510
+ const topOuterId = viewData.orientation?.top ?? viewData.nodes.reduce((best, d) =>
1487
1511
  extentSize(d) > extentSize(best) ? d : best, viewData.nodes[0]).id;
1488
1512
 
1489
1513
  if (showChildPreviews) {{
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conceptflow
3
- Version: 0.6.2
3
+ Version: 0.6.3
4
4
  Summary: A scikit-learn compatible Formal Concept Analysis framework.
5
5
  Author-email: Anurag Sharma <sharma@cs.uni-kassel.de>
6
6
  License-Expression: BSD-3-Clause
@@ -35,6 +35,8 @@ Provides-Extra: dev
35
35
  Requires-Dist: scikit-learn>=1.6; extra == "dev"
36
36
  Requires-Dist: pytest; extra == "dev"
37
37
  Requires-Dist: pytest-cov; extra == "dev"
38
+ Requires-Dist: hypothesis; extra == "dev"
39
+ Requires-Dist: concepts; extra == "dev"
38
40
  Requires-Dist: ruff; extra == "dev"
39
41
  Dynamic: license-file
40
42
 
@@ -96,6 +96,7 @@ src/conceptflow/visualization/static.py
96
96
  src/conceptflow/visualization/tikz.py
97
97
  tests/test_algorithm_registry.py
98
98
  tests/test_audit_regressions.py
99
+ tests/test_backend_consistency.py
99
100
  tests/test_boolean_factorization.py
100
101
  tests/test_browser.py
101
102
  tests/test_check_estimator.py
@@ -105,6 +106,7 @@ tests/test_concept_encoder.py
105
106
  tests/test_conceptual_scaler.py
106
107
  tests/test_context_handling.py
107
108
  tests/test_context_operations.py
109
+ tests/test_cross_library.py
108
110
  tests/test_cxt_io.py
109
111
  tests/test_d3_backend.py
110
112
  tests/test_datasets.py
@@ -114,6 +116,7 @@ tests/test_docs_examples.py
114
116
  tests/test_drawing_quality.py
115
117
  tests/test_enumeration.py
116
118
  tests/test_exploration.py
119
+ tests/test_feature_matrix.py
117
120
  tests/test_formal_context.py
118
121
  tests/test_generators.py
119
122
  tests/test_graph_data.py
@@ -135,13 +138,21 @@ tests/test_oracles.py
135
138
  tests/test_ord2factor.py
136
139
  tests/test_ordinal_factorization.py
137
140
  tests/test_patch_0_3_1.py
141
+ tests/test_properties_core.py
142
+ tests/test_properties_drawing.py
143
+ tests/test_properties_estimators.py
144
+ tests/test_properties_input.py
145
+ tests/test_properties_io_nested.py
146
+ tests/test_properties_scaling.py
138
147
  tests/test_public_api.py
139
148
  tests/test_quality.py
140
149
  tests/test_reduction.py
150
+ tests/test_reproducibility.py
141
151
  tests/test_review_fixes.py
142
152
  tests/test_scale_measures.py
143
153
  tests/test_scales.py
144
154
  tests/test_sklearn_compatibility.py
155
+ tests/test_sklearn_workflows.py
145
156
  tests/test_static_figures.py
146
157
  tests/test_tikz.py
147
158
  tests/test_validation_input.py
@@ -10,6 +10,8 @@ python-sat>=1.8.dev30
10
10
  scikit-learn>=1.6
11
11
  pytest
12
12
  pytest-cov
13
+ hypothesis
14
+ concepts
13
15
  ruff
14
16
 
15
17
  [docs]
@@ -0,0 +1,270 @@
1
+ """
2
+ The backends draw the same diagram.
3
+
4
+ For one drawing, the interactive page (d3), matplotlib, TikZ and Graphviz
5
+ must show the same nodes, edges and labels, with each attribute at its
6
+ attribute concept and each object at its object concept (reduced
7
+ labelling, from the definition), shortened to the same ``max_label_items``
8
+ names; and matplotlib and TikZ must put the nodes where ``layout_positions``
9
+ says. For nested diagrams, matplotlib and TikZ show the same labels, and each
10
+ object is labelled once, inside its outer object concept, at its inner
11
+ object concept.
12
+ """
13
+
14
+ import collections
15
+ import json
16
+ import math
17
+ import re
18
+
19
+ import numpy as np
20
+ import pandas as pd
21
+ import pytest
22
+
23
+ pytest.importorskip("hypothesis")
24
+
25
+ from hypothesis import given # noqa: E402
26
+ from hypothesis import strategies as st # noqa: E402
27
+
28
+ from conceptflow import ( # noqa: E402
29
+ ConceptLattice,
30
+ ExplorationBuilder,
31
+ FormalContext,
32
+ ManyValuedContext, # noqa: E402
33
+ )
34
+ from conceptflow.preprocessing import ( # noqa: E402
35
+ ConceptualScaler,
36
+ ContranominalScale,
37
+ NominalScale,
38
+ ThresholdScale,
39
+ )
40
+ from conceptflow.visualization import ( # noqa: E402
41
+ graph_data_to_tikz,
42
+ lattice_to_dot,
43
+ lattice_to_graph_data,
44
+ layered_layout,
45
+ layout_positions,
46
+ nested_data_to_tikz,
47
+ render_graph_data_html,
48
+ render_lattice_matplotlib,
49
+ render_nested_matplotlib,
50
+ )
51
+ from conceptflow.visualization.nested import exploration_view_to_nested_data # noqa: E402
52
+ from tests.property_helpers import incidences # noqa: E402
53
+
54
+ LETTERS = "qwertyuiopasdfgh"
55
+
56
+
57
+ @st.composite
58
+ def lattices(draw):
59
+ incidence = draw(incidences(min_objects=1, max_objects=6, min_attributes=1,
60
+ max_attributes=6))
61
+ g, m = incidence.shape
62
+ names = draw(st.lists(st.text(LETTERS, min_size=1, max_size=3), min_size=g + m,
63
+ max_size=g + m, unique=True), label="names")
64
+ context = FormalContext.from_array(incidence, [f"O{n}" for n in names[:g]],
65
+ [f"A{n}" for n in names[g:]])
66
+ min_support = draw(st.sampled_from([None, None, 2]), label="min_support")
67
+ return ConceptLattice.from_context(context, min_support=min_support)
68
+
69
+
70
+ def joined(names, max_items):
71
+ names = sorted(names)
72
+ if max_items is not None and len(names) > max_items:
73
+ names = [*names[:max_items], f"+{len(names) - max_items}"]
74
+ return ", ".join(names)
75
+
76
+
77
+ def expected_labels(lattice, max_items):
78
+ """node index -> (attribute text, object text), from the definition."""
79
+ context = lattice.context
80
+ attributes = collections.defaultdict(list)
81
+ objects = collections.defaultdict(list)
82
+ position = {c.extent: i for i, c in enumerate(lattice.concepts)}
83
+ for m, name in enumerate(context.attributes):
84
+ extent = context.attribute_derivation([m])
85
+ if extent in position: # mu(m) is drawn
86
+ attributes[position[extent]].append(name)
87
+ for g, name in enumerate(context.objects):
88
+ extent = context.attribute_derivation(context.object_derivation([g]))
89
+ if extent in position: # gamma(g) is drawn (not below an iceberg)
90
+ objects[position[extent]].append(name)
91
+ return {
92
+ i: (joined(attributes[i], max_items), joined(objects[i], max_items))
93
+ for i in range(lattice.n_concepts)
94
+ }
95
+
96
+
97
+ def similar(points, other, tolerance=1e-6):
98
+ """Whether ``other`` is ``points`` moved and uniformly scaled (no rotation)."""
99
+ keys = list(points)
100
+ a = np.array([points[k] for k in keys], dtype=float)
101
+ b = np.array([other[k] for k in keys], dtype=float)
102
+ a, b = a - a.mean(axis=0), b - b.mean(axis=0)
103
+ size_a, size_b = np.abs(a).max(), np.abs(b).max()
104
+ if size_a < 1e-12 or size_b < 1e-12:
105
+ return size_a < 1e-12 and size_b < 1e-12
106
+ return np.allclose(a / size_a, b / size_b, atol=tolerance)
107
+
108
+
109
+ @given(lattices(), st.sampled_from([None, 1, 2, 6]), st.floats(0, 2 * math.pi))
110
+ def test_every_backend_shows_the_same_labels_and_positions(lattice, max_items, angle):
111
+ import matplotlib
112
+
113
+ matplotlib.use("Agg")
114
+ import matplotlib.pyplot as plt
115
+
116
+ expected = expected_labels(lattice, max_items)
117
+ graph_data = layered_layout(lattice_to_graph_data(lattice))
118
+ if not lattice.is_iceberg and lattice.n_concepts > 1:
119
+ # Stored at an angle, as DimFlux layouts are: drawn upright.
120
+ from dataclasses import replace
121
+
122
+ cos_a, sin_a = math.cos(angle), math.sin(angle)
123
+ graph_data = replace(
124
+ graph_data, metadata={**graph_data.metadata, "layout": "custom"},
125
+ nodes=[replace(n, x=cos_a * n.x - sin_a * n.y, y=sin_a * n.x + cos_a * n.y)
126
+ for n in graph_data.nodes],
127
+ )
128
+ index = {n.node_id: i for i, n in enumerate(graph_data.nodes)}
129
+ assert [n.concept for n in graph_data.nodes] == list(lattice.concepts)
130
+ positions = layout_positions(graph_data)
131
+ drawn = {index[n.node_id]: positions[frozenset(n.metadata["extent"])]
132
+ for n in graph_data.nodes}
133
+ edges = {(index[e.source], index[e.target]) for e in graph_data.edges}
134
+
135
+ # The interactive page.
136
+ html = render_graph_data_html(graph_data, max_label_items=max_items)
137
+ page = json.loads(re.search(r"const graphData = (.*?);\n", html).group(1))
138
+ assert {i: (node["attribute_text"], node["object_text"])
139
+ for i, node in enumerate(page["nodes"])} == expected
140
+ assert {(index[e["source"]], index[e["target"]]) for e in page["edges"]} == edges
141
+
142
+ # matplotlib: nodes where layout_positions says, labels at their nodes.
143
+ figure = render_lattice_matplotlib(graph_data, max_label_items=max_items)
144
+ ax = figure.axes[0]
145
+ points = {tuple(np.round(p, 6)) for p in ax.collections[1].get_offsets()}
146
+ assert points == {tuple(np.round(p, 6)) for p in drawn.values()}
147
+ at_point = {tuple(np.round(p, 6)): i for i, p in drawn.items()}
148
+ shown = collections.defaultdict(list)
149
+ for text in ax.texts:
150
+ shown[at_point[tuple(np.round(text.xy, 6))]].append(text.get_text())
151
+ plt.close(figure)
152
+ for i, (attributes, objects) in expected.items():
153
+ assert sorted(shown.get(i, [])) == sorted(t for t in (attributes, objects) if t), i
154
+
155
+ # TikZ: the same labels, nodes placed like layout_positions.
156
+ tikz = graph_data_to_tikz(graph_data, max_label_items=max_items)
157
+ nodes = re.findall(r"\\node\[concept(.*?)\] \((\w+)\) at \(([-\d.]+), ([-\d.]+)\)", tikz)
158
+ assert len(nodes) == lattice.n_concepts
159
+ tikz_points = {}
160
+ for options, name, x, y in nodes:
161
+ i = index[name]
162
+ tikz_points[i] = (float(x), float(y))
163
+ attributes = re.search(r"\[attr\]above:\{(.*?)\}\}", options)
164
+ objects = re.search(r"\[obj\]below:\{(.*?)\}\}", options)
165
+ assert (attributes.group(1) if attributes else "",
166
+ objects.group(1) if objects else "") == expected[i], name
167
+ assert similar(drawn, tikz_points, tolerance=1e-3) # TikZ rounds coordinates
168
+
169
+ # Graphviz lays the lattice out itself; the labels and edges are the same.
170
+ dot = lattice_to_dot(lattice, max_label_items=max_items)
171
+ for i in range(lattice.n_concepts):
172
+ line = re.search(rf"^ c{i}( \[xlabel=<(.*)>\])?;$", dot, re.MULTILINE)
173
+ fonts = dict(re.findall(r'<FONT COLOR="(#\w+)">(.*?)</FONT>', line.group(2) or ""))
174
+ assert (fonts.get("#1f4e79", ""), fonts.get("#333333", "")) == expected[i], i
175
+ position = {c: i for i, c in enumerate(lattice.concepts)}
176
+ dot_edges = {tuple(int(x) for x in pair) for pair in re.findall(r"c(\d+) -> c(\d+)", dot)}
177
+ assert dot_edges == {(position[a], position[b]) for a, b in lattice.edges}
178
+
179
+
180
+ # ---------------------------------------------------------------------------
181
+ # Nested diagrams
182
+ # ---------------------------------------------------------------------------
183
+
184
+
185
+ @st.composite
186
+ def nested_views(draw):
187
+ n = draw(st.integers(1, 8), label="objects")
188
+ rng = np.random.default_rng(draw(st.integers(0, 2**32 - 1), label="seed"))
189
+ data = pd.DataFrame(
190
+ {"color": rng.choice(["red", "blue", "green"], n),
191
+ "size": rng.choice([10.0, 40.0, 80.0], n),
192
+ "shape": rng.choice(["round", "square"], n)},
193
+ index=[f"o{i}" for i in range(n)],
194
+ )
195
+ builder = ExplorationBuilder(ManyValuedContext.from_dataframe(data))
196
+ root = builder.root("color", [NominalScale("color")])
197
+ inner = draw(st.sampled_from(["none", "top", "all"]), label="inner views")
198
+ inner_scales = draw(st.sampled_from([[ThresholdScale("size", [33, 66])],
199
+ [ContranominalScale("shape")]]), label="inner")
200
+ if inner == "top":
201
+ builder.expand(root, root.lattice.top(), "inner", inner_scales)
202
+ elif inner == "all":
203
+ builder.expand_all(root, scales=inner_scales)
204
+ return data, root, inner, inner_scales
205
+
206
+
207
+ def matplotlib_labels(data, **options):
208
+ import matplotlib
209
+
210
+ matplotlib.use("Agg")
211
+ import matplotlib.pyplot as plt
212
+
213
+ figure = render_nested_matplotlib(data, **options)
214
+ texts = sorted(text.get_text() for text in figure.axes[0].texts)
215
+ plt.close(figure)
216
+ return texts
217
+
218
+
219
+ @given(nested_views(), st.sampled_from([None, 1, 3]), st.booleans())
220
+ def test_nested_backends_show_the_same_labels(view, max_items, objects):
221
+ _, root, _, _ = view
222
+ data = exploration_view_to_nested_data(root, timeout_ms=50)
223
+ options = {"max_label_items": max_items, "show_object_labels": objects}
224
+ tikz = nested_data_to_tikz(data, **options)
225
+ tikz_texts = sorted(re.findall(r"\\node\[(?:attr|obj), (?:above|below)\] at .*? \{(.*)\};",
226
+ tikz))
227
+ assert matplotlib_labels(data, **options) == tikz_texts
228
+
229
+
230
+ @given(nested_views())
231
+ def test_static_nested_figures_label_each_object_once_at_its_place(view):
232
+ from conceptflow.visualization.static import _nested_geometry
233
+
234
+ data_frame, root, inner, inner_scales = view
235
+ data = exploration_view_to_nested_data(root, timeout_ms=50)
236
+ tikz = nested_data_to_tikz(data, show_object_labels=True, max_label_items=None)
237
+ outer_context = root.context
238
+ outer_index = {node["id"]: k for k, node in enumerate(data["nodes"])}
239
+ outer_intent = {k: frozenset(node["metadata"]["intent"])
240
+ for k, node in enumerate(data["nodes"])}
241
+ places = {}
242
+ for match in re.finditer(r"\\node\[obj, below\] at \((\w+)\.south\) \{(.*)\};", tikz):
243
+ for name in match.group(2).split(", "):
244
+ assert name not in places, f"{name} labelled twice"
245
+ places[name] = match.group(1)
246
+ assert sorted(places) == sorted(data_frame.index)
247
+
248
+ geometry = _nested_geometry(data)
249
+ for name, place in places.items():
250
+ g = outer_context.objects.index(name)
251
+ own_outer = frozenset(outer_context.attributes[j]
252
+ for j in outer_context.object_derivation([g]))
253
+ if geometry["template"] is None:
254
+ k = int(place[1:])
255
+ assert place.startswith("o") and outer_intent[k] == own_outer, (name, place)
256
+ continue
257
+ k, j = (int(part) for part in place[1:].split("x"))
258
+ assert outer_intent[k] == own_outer, (name, place)
259
+ # The inner node: the object's own intent in the inner scale.
260
+ inner_context = ConceptualScaler(scales=inner_scales, output="context").fit_transform(
261
+ data_frame
262
+ )
263
+ own_inner = frozenset(inner_context.attributes[m]
264
+ for m in inner_context.object_derivation([g]))
265
+ node = data["nodes"][k]
266
+ inner_ids = list(geometry["inner_places"][node["id"]])
267
+ template = {n["id"]: frozenset(n["intent"])
268
+ for n in geometry["template"]["nodes"]}
269
+ assert template[inner_ids[j]] == own_inner, (name, place)
270
+ assert outer_index # the figure has outer nodes