ripple-down-rules 0.5.94__tar.gz → 0.5.96__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 (152) hide show
  1. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/PKG-INFO +1 -1
  2. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/__init__.py +1 -1
  3. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/datastructures/callable_expression.py +7 -1
  4. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/datastructures/dataclasses.py +1 -1
  5. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/rdr.py +21 -7
  6. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/rules.py +19 -0
  7. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/utils.py +21 -9
  8. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules.egg-info/PKG-INFO +1 -1
  9. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_is_a_robot/physical_object_is_a_robot_output__scrdr.py +5 -1
  10. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_is_a_robot/physical_object_is_a_robot_output__scrdr_defs.py +4 -3
  11. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_is_a_robot/physical_object_is_a_robot_rdr.py +2 -2
  12. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_is_a_robot/rdr_metadata/datasets_physical_object_is_a_robot.json +10 -4
  13. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_select_objects_that_are_parts_of_robot/physical_object_select_objects_that_are_parts_of_robot_output__mcrdr.py +3 -3
  14. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_select_objects_that_are_parts_of_robot/physical_object_select_objects_that_are_parts_of_robot_output__mcrdr_defs.py +3 -3
  15. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_select_objects_that_are_parts_of_robot/physical_object_select_objects_that_are_parts_of_robot_rdr.py +2 -2
  16. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_select_objects_that_are_parts_of_robot/rdr_metadata/datasets_physical_object_select_objects_that_are_parts_of_robot.json +2 -0
  17. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/.github/workflows/build_and_deploy_doc.yml +0 -0
  18. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/.github/workflows/ci.yml +0 -0
  19. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/.github/workflows/publish-to-test-pypi.yml +0 -0
  20. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/.gitignore +0 -0
  21. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/.idea/shelf/Uncommitted_changes_before_Checkout_at_2_4_25,_6_32_PM_[Changes]/shelved.patch +0 -0
  22. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/.idea/shelf/Uncommitted_changes_before_Checkout_at_2_4_25,_6_32_PM_[Changes]1/shelved.patch +0 -0
  23. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/LICENSE +0 -0
  24. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/README.md +0 -0
  25. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/doc/_config.yml +0 -0
  26. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/doc/_toc.yml +0 -0
  27. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/doc/bibliography.md +0 -0
  28. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/doc/intro.md +0 -0
  29. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/doc/references.bib +0 -0
  30. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/doc/requirements.txt +0 -0
  31. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/examples/__init__.py +0 -0
  32. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/examples/animal_species.py +0 -0
  33. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/examples/part_containment_rdr/__init__.py +0 -0
  34. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/examples/part_containment_rdr/rdr_metadata/part_containment_rdr.json +0 -0
  35. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/examples/part_containment_rdr/robot_contained_objects_mcrdr.py +0 -0
  36. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/examples/part_containment_rdr/robot_contained_objects_mcrdr_defs.py +0 -0
  37. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/examples/part_containment_rdr/robot_rdr.py +0 -0
  38. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/examples/relational_example.py +0 -0
  39. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/images/scrdr.dot +0 -0
  40. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/images/scrdr.png +0 -0
  41. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/images/thinking_pr2.jpg +0 -0
  42. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/pyproject.toml +0 -0
  43. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/pytest.ini +0 -0
  44. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/requirements-dev-ci.txt +0 -0
  45. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/requirements-dev.txt +0 -0
  46. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/requirements-gui.txt +0 -0
  47. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/requirements-viz.txt +0 -0
  48. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/requirements.txt +0 -0
  49. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_mcrdr_extra.dot +0 -0
  50. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_mcrdr_extra.png +0 -0
  51. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_mcrdr_stop_only.dot +0 -0
  52. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_mcrdr_stop_only.png +0 -0
  53. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_mcrdr_stop_plus_rule.dot +0 -0
  54. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_mcrdr_stop_plus_rule.png +0 -0
  55. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_scrdr.dot +0 -0
  56. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_scrdr.png +0 -0
  57. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_scrdr_2.dot +0 -0
  58. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_scrdr_2.png +0 -0
  59. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_scrdr_3.dot +0 -0
  60. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/complete_scrdr_3.png +0 -0
  61. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/grdr_Habitat.dot +0 -0
  62. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/grdr_Habitat.png +0 -0
  63. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/grdr_Species.dot +0 -0
  64. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/grdr_Species.png +0 -0
  65. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/mcrdr_extra.dot +0 -0
  66. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/mcrdr_extra.png +0 -0
  67. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/mcrdr_extra_classify.dot +0 -0
  68. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/mcrdr_extra_classify.png +0 -0
  69. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/mcrdr_stop_plus_rule_combined.dot +0 -0
  70. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/mcrdr_stop_plus_rule_combined.png +0 -0
  71. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/partial_mcrdr_extra.dot +0 -0
  72. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/partial_mcrdr_extra.png +0 -0
  73. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/relational_scrdr_classify.dot +0 -0
  74. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/results/relational_scrdr_classify.png +0 -0
  75. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/setup.cfg +0 -0
  76. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/datastructures/__init__.py +0 -0
  77. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/datastructures/case.py +0 -0
  78. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/datastructures/enums.py +0 -0
  79. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/experts.py +0 -0
  80. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/helpers.py +0 -0
  81. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/rdr_decorators.py +0 -0
  82. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/start-code-server.sh +0 -0
  83. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/user_interface/__init__.py +0 -0
  84. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/user_interface/gui.py +0 -0
  85. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/user_interface/ipython_custom_shell.py +0 -0
  86. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/user_interface/object_diagram.py +0 -0
  87. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/user_interface/prompt.py +0 -0
  88. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules/user_interface/template_file_creator.py +0 -0
  89. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules.egg-info/SOURCES.txt +0 -0
  90. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules.egg-info/dependency_links.txt +0 -0
  91. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules.egg-info/requires.txt +0 -0
  92. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/src/ripple_down_rules.egg-info/top_level.txt +0 -0
  93. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/__init__.py +0 -0
  94. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/conf/__init__.py +0 -0
  95. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/conf/world/__init__.py +0 -0
  96. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/conf/world/base_config.py +0 -0
  97. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/conf/world/handles_and_containers.py +0 -0
  98. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/conftest.py +0 -0
  99. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/datasets.py +0 -0
  100. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/factories/__init__.py +0 -0
  101. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/factories/world/__init__.py +0 -0
  102. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/factories/world/handles_and_containers.py +0 -0
  103. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/correct_drawer_rdr_expert_answers_fit.json +0 -0
  104. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/drawer_cabinet_expert_answers_fit.json +0 -0
  105. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/grdr_expert_answers_classify.json +0 -0
  106. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/grdr_expert_answers_fit.json +0 -0
  107. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/grdr_expert_answers_fit_extra.json +0 -0
  108. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/grdr_expert_answers_fit_no_targets.json +0 -0
  109. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_expert_answers_classify.json +0 -0
  110. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_expert_answers_fit_no_targets.json +0 -0
  111. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_expert_answers_stop_only_fit.json +0 -0
  112. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_extra_expert_answers_classify.json +0 -0
  113. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_extra_expert_answers_fit.json +0 -0
  114. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_multi_line_expert_answers_fit.json +0 -0
  115. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_stop_only_answers_fit.json +0 -0
  116. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_stop_plus_rule_answers_fit.json +0 -0
  117. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_stop_plus_rule_combined_expert_answers_fit.json +0 -0
  118. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mcrdr_stop_plus_rule_expert_answers_fit.json +0 -0
  119. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/mutagenic_expert_answers.json +0 -0
  120. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/relational_scrdr_expert_answers_classify.json +0 -0
  121. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/scrdr_expert_answers_classify.json +0 -0
  122. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/scrdr_expert_answers_fit.json +0 -0
  123. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/scrdr_expert_answers_fit_no_targets.json +0 -0
  124. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/scrdr_multi_line_expert_answers_fit.json +0 -0
  125. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_expert_answers/scrdr_world_expert_answers_fit.json +0 -0
  126. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_generated_rdrs/__init__.py +0 -0
  127. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_helpers/__init__.py +0 -0
  128. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_helpers/helpers.py +0 -0
  129. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_helpers/object_diagram_case_query.png +0 -0
  130. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_helpers/object_diagram_person.png +0 -0
  131. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_json_serialization.py +0 -0
  132. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_object_diagram.py +0 -0
  133. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_on_mutagenic.py +0 -0
  134. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_rdr.py +0 -0
  135. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_rdr_alchemy.py +0 -0
  136. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_rdr_decorators.py +0 -0
  137. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_rdr_helpers_rdrs.py +0 -0
  138. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_rdr_world/__init__.py +0 -0
  139. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_rdr_world/conftest.py +0 -0
  140. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_rdr_world/test_rdr_world.py +0 -0
  141. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_relational_rdr.py +0 -0
  142. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_relational_rdr_alchemy.py +0 -0
  143. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_is_a_robot/__init__.py +0 -0
  144. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_results/datasets_physical_object_select_objects_that_are_parts_of_robot/__init__.py +0 -0
  145. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_sql_model.py +0 -0
  146. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_template_file_creator.py +0 -0
  147. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_user_interface/__init__.py +0 -0
  148. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_user_interface/test_ipython.py +0 -0
  149. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_user_interface/test_ipython_copilot.py +0 -0
  150. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_user_interface/test_prompt.py +0 -0
  151. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_user_interface/test_qt_gui_inline.py +0 -0
  152. {ripple_down_rules-0.5.94 → ripple_down_rules-0.5.96}/test/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.5.94
3
+ Version: 0.5.96
4
4
  Summary: Implements the various versions of Ripple Down Rules (RDR) for knowledge representation and reasoning.
5
5
  Author-email: Abdelrhman Bassiouny <abassiou@uni-bremen.de>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,4 +1,4 @@
1
- __version__ = "0.5.94"
1
+ __version__ = "0.5.96"
2
2
 
3
3
  import logging
4
4
  logger = logging.Logger("rdr")
@@ -267,10 +267,16 @@ class CallableExpression(SubclassJSONSerializer):
267
267
 
268
268
  @classmethod
269
269
  def _from_json(cls, data: Dict[str, Any]) -> CallableExpression:
270
+ scope = {}
271
+ for k, v in data['scope'].items():
272
+ try:
273
+ scope[k] = get_type_from_string(v)
274
+ except ModuleNotFoundError:
275
+ pass
270
276
  return cls(user_input=data["user_input"],
271
277
  conclusion_type=tuple(get_type_from_string(t) for t in data["conclusion_type"])
272
278
  if data["conclusion_type"] else None,
273
- scope={k: get_type_from_string(v) for k, v in data["scope"].items()},
279
+ scope=scope,
274
280
  conclusion=SubclassJSONSerializer.from_json(data["conclusion"]),
275
281
  mutually_exclusive=data["mutually_exclusive"])
276
282
 
@@ -139,7 +139,7 @@ class CaseQuery:
139
139
  attribute_types_str = f"Union[{', '.join([t.__name__ for t in self.core_attribute_type])}]"
140
140
  else:
141
141
  attribute_types_str = self.core_attribute_type[0].__name__
142
- if list in self.attribute_type:
142
+ if all(t in self.attribute_type for t in [list, set]) and len(self.core_attribute_type) > 2:
143
143
  return f"List[{attribute_types_str}]"
144
144
  else:
145
145
  return attribute_types_str
@@ -4,6 +4,7 @@ import importlib
4
4
  import os
5
5
  from abc import ABC, abstractmethod
6
6
  from copy import copy
7
+ from types import NoneType
7
8
 
8
9
  from ripple_down_rules.datastructures.dataclasses import CaseFactoryMetaData
9
10
  from . import logger
@@ -144,7 +145,7 @@ class RippleDownRules(SubclassJSONSerializer, ABC):
144
145
  try:
145
146
  rdr.update_from_python(model_dir, package_name=package_name)
146
147
  rdr.to_json_file(json_file)
147
- except (FileNotFoundError, ValueError) as e:
148
+ except (FileNotFoundError, ValueError, SyntaxError) as e:
148
149
  logger.warning(f"Could not load the python file for the model {model_name} from {model_dir}. "
149
150
  f"Make sure the file exists and is valid.")
150
151
  rdr.save(save_dir=load_dir, model_name=model_name, package_name=package_name)
@@ -546,6 +547,8 @@ class RDRWithCodeWriter(RippleDownRules, ABC):
546
547
  main_types = set()
547
548
  main_types.add(self.case_type)
548
549
  main_types.update(make_set(self.conclusion_type))
550
+ main_types.update({Union, Optional})
551
+ defs_types.add(Union)
549
552
  main_types.update({Case, create_case})
550
553
  main_types = main_types.difference(defs_types)
551
554
  return main_types, defs_types, cases_types
@@ -689,9 +692,8 @@ class SingleClassRDR(RDRWithCodeWriter):
689
692
 
690
693
  def _write_to_python(self, model_dir: str, package_name: Optional[str] = None):
691
694
  super()._write_to_python(model_dir, package_name=package_name)
692
- if self.default_conclusion is not None:
693
- with open(model_dir + f"/{self.generated_python_file_name}.py", "a") as f:
694
- f.write(f"{' ' * 4}else:\n{' ' * 8}return {self.default_conclusion}\n")
695
+ with open(model_dir + f"/{self.generated_python_file_name}.py", "a") as f:
696
+ f.write(f"{' ' * 4}else:\n{' ' * 8}return {self.default_conclusion}\n")
695
697
 
696
698
  def write_rules_as_source_code_to_file(self, rule: SingleClassRule, filename: str, parent_indent: str = "",
697
699
  defs_file: Optional[str] = None, cases_file: Optional[str] = None,
@@ -719,7 +721,19 @@ class SingleClassRDR(RDRWithCodeWriter):
719
721
 
720
722
  @property
721
723
  def conclusion_type_hint(self) -> str:
722
- return self.conclusion_type[0].__name__
724
+ all_types = set(list(self.conclusion_type) + [type(self.default_conclusion)])
725
+ if NoneType in all_types:
726
+ return f"Optional[{', '.join([t.__name__ for t in all_types if t is not NoneType])}]"
727
+ return f"Union[{', '.join([t.__name__ for t in all_types])}]"
728
+
729
+ def _get_types_to_import(self) -> Tuple[Set[Type], Set[Type], Set[Type]]:
730
+ main_types, def_types, case_types = super()._get_types_to_import()
731
+ main_types.add(type(self.default_conclusion))
732
+ def_types.add(type(self.default_conclusion))
733
+ if self.default_conclusion is None:
734
+ main_types.add(Optional)
735
+ def_types.add(Optional)
736
+ return main_types, def_types, case_types
723
737
 
724
738
  @property
725
739
  def conclusion_type(self) -> Tuple[Type]:
@@ -857,8 +871,8 @@ class MultiClassRDR(RDRWithCodeWriter):
857
871
 
858
872
  def _get_types_to_import(self) -> Tuple[Set[Type], Set[Type], Set[Type]]:
859
873
  main_types, defs_types, cases_types = super()._get_types_to_import()
860
- main_types.update({Set, Union, make_set})
861
- defs_types.add(Union)
874
+ main_types.update({Set, make_set})
875
+ defs_types.update({List, Set})
862
876
  return main_types, defs_types, cases_types
863
877
 
864
878
  def update_start_rule(self, case_query: CaseQuery, expert: Expert):
@@ -4,6 +4,7 @@ import logging
4
4
  import re
5
5
  from abc import ABC, abstractmethod
6
6
  from pathlib import Path
7
+ from types import NoneType
7
8
  from uuid import uuid4
8
9
 
9
10
  from anytree import NodeMixin
@@ -162,6 +163,22 @@ class Rule(NodeMixin, SubclassJSONSerializer, ABC):
162
163
  # use regex to replace the function name
163
164
  new_function_name = f"def conclusion_{self.uid}"
164
165
  conclusion_lines[0] = re.sub(r"def (\w+)", new_function_name, conclusion_lines[0])
166
+ # add type hint
167
+ if len(self.conclusion.conclusion_type) == 1:
168
+ hint = self.conclusion.conclusion_type[0].__name__
169
+ else:
170
+ if (all(t in self.conclusion.conclusion_type for t in [list, set])
171
+ and len(self.conclusion.conclusion_type) > 2):
172
+ type_names = [t.__name__ for t in self.conclusion.conclusion_type if t not in [list, set]]
173
+ hint = f"List[{', '.join(type_names)}]"
174
+ else:
175
+ if NoneType in self.conclusion.conclusion_type:
176
+ type_names = [t.__name__ for t in self.conclusion.conclusion_type if t is not NoneType]
177
+ hint = f"Optional[{', '.join(type_names)}]"
178
+ else:
179
+ type_names = [t.__name__ for t in self.conclusion.conclusion_type]
180
+ hint = f"Union[{', '.join(type_names)}]"
181
+ conclusion_lines[0] = conclusion_lines[0].replace("):", f") -> {hint}:")
165
182
  func_call = f"{parent_indent} return {new_function_name.replace('def ', '')}(case)\n"
166
183
  return "\n".join(conclusion_lines).strip(' '), func_call
167
184
  else:
@@ -184,6 +201,8 @@ class Rule(NodeMixin, SubclassJSONSerializer, ABC):
184
201
  # use regex to replace the function name
185
202
  new_function_name = f"def conditions_{self.uid}"
186
203
  conditions_lines[0] = re.sub(r"def (\w+)", new_function_name, conditions_lines[0])
204
+ # add type hint
205
+ conditions_lines[0] = conditions_lines[0].replace('):', ') -> bool:')
187
206
  def_code = "\n".join(conditions_lines)
188
207
  with open(defs_file, 'a') as f:
189
208
  f.write(def_code.strip() + "\n\n\n")
@@ -851,15 +851,11 @@ def get_relative_import(target_file_path, imported_module_path: Optional[str] =
851
851
  # Convert path to Python import format
852
852
  rel_parts = [part.replace('..', '.') for part in Path(rel_path).parts]
853
853
  rel_parts = rel_parts if rel_parts else ['']
854
- # dot_parts = [part for part in rel_parts if part == '.']
855
- # non_dot_parts = [part for part in rel_parts if part != '.']
854
+ dot_parts = [part for part in rel_parts if part == '.']
855
+ non_dot_parts = [part for part in rel_parts if part != '.'] + [imported_path.stem]
856
856
 
857
-
858
- # Join the parts and add the module name
859
- # joined_parts = "".join(dot_parts) + ".".join(non_dot_parts) + f".{imported_path.stem}"
860
- joined_parts = "." + "".join(rel_parts)
861
- joined_parts += imported_path.stem if joined_parts.endswith(".") else f".{imported_path.stem}"
862
- # joined_parts = f".{joined_parts}" if not joined_parts.startswith(".") else joined_parts
857
+ # Join the parts
858
+ joined_parts = "." + "".join(dot_parts) + ".".join(non_dot_parts)
863
859
 
864
860
  return joined_parts
865
861
 
@@ -922,10 +918,14 @@ def get_imports_from_types(type_objs: Iterable[Type],
922
918
  name = type(tp).__qualname__
923
919
  else:
924
920
  continue
921
+ if name == "NoneType":
922
+ module = "types"
925
923
  if module is None or module == 'builtins' or module.startswith('_')\
926
924
  or module in sys.builtin_module_names or module in excluded_modules or "<" in module \
927
925
  or name in exclueded_names:
928
926
  continue
927
+ if module == "typing":
928
+ module = "typing_extensions"
929
929
  module_to_types[module].append(name)
930
930
  except AttributeError:
931
931
  continue
@@ -1055,7 +1055,19 @@ def get_type_from_string(type_path: str):
1055
1055
  :param type_path: The path to the type.
1056
1056
  """
1057
1057
  module_path, class_name = type_path.rsplit(".", 1)
1058
- module = importlib.import_module(module_path)
1058
+ try:
1059
+ module = importlib.import_module(module_path)
1060
+ except ModuleNotFoundError:
1061
+ module_path_parts = module_path.split(".")
1062
+ idx = -1
1063
+ while True:
1064
+ try:
1065
+ module = importlib.import_module('.'.join(module_path_parts[:idx]))
1066
+ break
1067
+ except ModuleNotFoundError:
1068
+ idx -= 1
1069
+ if abs(idx) > len(module_path_parts):
1070
+ raise
1059
1071
  if module == builtins and class_name == 'NoneType':
1060
1072
  return type(None)
1061
1073
  return getattr(module, class_name)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.5.94
3
+ Version: 0.5.96
4
4
  Summary: Implements the various versions of Ripple Down Rules (RDR) for knowledge representation and reasoning.
5
5
  Author-email: Abdelrhman Bassiouny <abassiou@uni-bremen.de>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,4 +1,6 @@
1
1
  from ripple_down_rules.datastructures.case import Case, create_case
2
+ from types import NoneType
3
+ from typing_extensions import Optional
2
4
  from .physical_object_is_a_robot_output__scrdr_defs import *
3
5
 
4
6
 
@@ -7,9 +9,11 @@ conclusion_type = (bool,)
7
9
  mutually_exclusive = True
8
10
 
9
11
 
10
- def classify(case: Dict, **kwargs) -> bool:
12
+ def classify(case: Dict, **kwargs) -> Optional[bool]:
11
13
  if not isinstance(case, Case):
12
14
  case = create_case(case, max_recursion_idx=3)
13
15
 
14
16
  if conditions_226969243620390858682731042391766665817(case):
15
17
  return conclusion_226969243620390858682731042391766665817(case)
18
+ else:
19
+ return None
@@ -1,15 +1,16 @@
1
- from typing import Dict
1
+ from types import NoneType
2
2
  from ...datasets import PhysicalObject, Robot
3
+ from typing_extensions import Dict, Optional, Union
3
4
 
4
5
 
5
- def conditions_226969243620390858682731042391766665817(case):
6
+ def conditions_226969243620390858682731042391766665817(case) -> bool:
6
7
  def conditions_for_physical_object_is_a_robot(self_: PhysicalObject, output_: bool) -> bool:
7
8
  """Get conditions on whether it's possible to conclude a value for PhysicalObject_is_a_robot.output_ of type ."""
8
9
  return True
9
10
  return conditions_for_physical_object_is_a_robot(**case)
10
11
 
11
12
 
12
- def conclusion_226969243620390858682731042391766665817(case):
13
+ def conclusion_226969243620390858682731042391766665817(case) -> bool:
13
14
  def physical_object_is_a_robot(self_: PhysicalObject, output_: bool) -> bool:
14
15
  """Get possible value(s) for PhysicalObject_is_a_robot.output_ of type ."""
15
16
  return isinstance(self_, Robot)
@@ -1,6 +1,6 @@
1
- from typing import Any, Dict
2
- from ripple_down_rules.helpers import general_rdr_classify
1
+ from typing_extensions import Any, Dict
3
2
  from ripple_down_rules.datastructures.case import Case, create_case
3
+ from ripple_down_rules.helpers import general_rdr_classify
4
4
  from . import physical_object_is_a_robot_output__scrdr as output__classifier
5
5
 
6
6
  classifiers_dict = dict()
@@ -12,9 +12,12 @@
12
12
  "builtins.bool"
13
13
  ],
14
14
  "scope": {
15
- "Dict": "typing.Dict",
16
15
  "PhysicalObject": "test.datasets.PhysicalObject",
17
- "Robot": "test.datasets.Robot"
16
+ "Robot": "test.datasets.Robot",
17
+ "NoneType": "builtins.NoneType",
18
+ "Dict": "typing.Dict",
19
+ "Optional": "typing.Optional",
20
+ "Union": "typing.Union"
18
21
  },
19
22
  "conclusion": {
20
23
  "_type": "builtins.NoneType",
@@ -29,9 +32,12 @@
29
32
  "builtins.bool"
30
33
  ],
31
34
  "scope": {
32
- "Dict": "typing.Dict",
33
35
  "PhysicalObject": "test.datasets.PhysicalObject",
34
- "Robot": "test.datasets.Robot"
36
+ "Robot": "test.datasets.Robot",
37
+ "NoneType": "builtins.NoneType",
38
+ "Dict": "typing.Dict",
39
+ "Optional": "typing.Optional",
40
+ "Union": "typing.Union"
35
41
  },
36
42
  "conclusion": {
37
43
  "_type": "builtins.NoneType",
@@ -1,11 +1,11 @@
1
- from ripple_down_rules.utils import make_set
2
- from typing import Set, Union
1
+ from typing_extensions import Optional, Set
3
2
  from ripple_down_rules.datastructures.case import Case, create_case
3
+ from ripple_down_rules.utils import make_set
4
4
  from .physical_object_select_objects_that_are_parts_of_robot_output__mcrdr_defs import *
5
5
 
6
6
 
7
7
  attribute_name = 'output_'
8
- conclusion_type = (set, PhysicalObject, list,)
8
+ conclusion_type = (set, list, PhysicalObject,)
9
9
  mutually_exclusive = False
10
10
 
11
11
 
@@ -1,15 +1,15 @@
1
- from typing import Dict, List, Union
1
+ from typing_extensions import Dict, List, Set, Union
2
2
  from ...datasets import PhysicalObject, Robot
3
3
 
4
4
 
5
- def conditions_164855806603893754507167918997373216146(case):
5
+ def conditions_164855806603893754507167918997373216146(case) -> bool:
6
6
  def conditions_for_physical_object_select_objects_that_are_parts_of_robot(self_: PhysicalObject, objects: List[PhysicalObject], robot: Robot, output_: PhysicalObject) -> bool:
7
7
  """Get conditions on whether it's possible to conclude a value for PhysicalObject_select_objects_that_are_parts_of_robot.output_ of type PhysicalObject."""
8
8
  return robot is not None
9
9
  return conditions_for_physical_object_select_objects_that_are_parts_of_robot(**case)
10
10
 
11
11
 
12
- def conclusion_164855806603893754507167918997373216146(case):
12
+ def conclusion_164855806603893754507167918997373216146(case) -> List[PhysicalObject]:
13
13
  def physical_object_select_objects_that_are_parts_of_robot(self_: PhysicalObject, objects: List[PhysicalObject], robot: Robot, output_: PhysicalObject) -> List[PhysicalObject]:
14
14
  """Get possible value(s) for PhysicalObject_select_objects_that_are_parts_of_robot.output_ of type PhysicalObject."""
15
15
  robot_parts = [obj for obj in objects if obj in robot.parts]
@@ -1,6 +1,6 @@
1
- from typing import Any, Dict
2
- from ripple_down_rules.helpers import general_rdr_classify
1
+ from typing_extensions import Any, Dict
3
2
  from ripple_down_rules.datastructures.case import Case, create_case
3
+ from ripple_down_rules.helpers import general_rdr_classify
4
4
  from . import physical_object_select_objects_that_are_parts_of_robot_output__mcrdr as output__classifier
5
5
 
6
6
  classifiers_dict = dict()
@@ -14,6 +14,7 @@
14
14
  "scope": {
15
15
  "Dict": "typing.Dict",
16
16
  "List": "typing.List",
17
+ "Set": "typing.Set",
17
18
  "Union": "typing.Union",
18
19
  "PhysicalObject": "test.datasets.PhysicalObject",
19
20
  "Robot": "test.datasets.Robot"
@@ -35,6 +36,7 @@
35
36
  "scope": {
36
37
  "Dict": "typing.Dict",
37
38
  "List": "typing.List",
39
+ "Set": "typing.Set",
38
40
  "Union": "typing.Union",
39
41
  "PhysicalObject": "test.datasets.PhysicalObject",
40
42
  "Robot": "test.datasets.Robot"