dbis-functional-dependencies 0.0.7__tar.gz → 1.0.0__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 (32) hide show
  1. dbis_functional_dependencies-1.0.0/PKG-INFO +178 -0
  2. dbis_functional_dependencies-1.0.0/README.md +153 -0
  3. dbis_functional_dependencies-1.0.0/pyproject.toml +46 -0
  4. dbis_functional_dependencies-1.0.0/src/dbis_functional_dependencies/BCNF.py +1761 -0
  5. dbis_functional_dependencies-1.0.0/src/dbis_functional_dependencies/fdcheck.py +113 -0
  6. {dbis-functional-dependencies-0.0.7/functional_dependencies → dbis_functional_dependencies-1.0.0/src/dbis_functional_dependencies}/fds.py +14 -10
  7. dbis_functional_dependencies-1.0.0/src/dbis_functional_dependencies/fdsbase.py +207 -0
  8. dbis_functional_dependencies-1.0.0/src/dbis_functional_dependencies.egg-info/PKG-INFO +178 -0
  9. dbis_functional_dependencies-1.0.0/src/dbis_functional_dependencies.egg-info/SOURCES.txt +21 -0
  10. dbis_functional_dependencies-1.0.0/src/dbis_functional_dependencies.egg-info/requires.txt +15 -0
  11. dbis_functional_dependencies-1.0.0/src/dbis_functional_dependencies.egg-info/top_level.txt +1 -0
  12. dbis_functional_dependencies-1.0.0/tests/test_bcnf.py +1233 -0
  13. dbis_functional_dependencies-1.0.0/tests/test_bitplan.py +77 -0
  14. dbis_functional_dependencies-1.0.0/tests/test_cheung.py +68 -0
  15. dbis_functional_dependencies-1.0.0/tests/test_dbis.py +138 -0
  16. dbis_functional_dependencies-1.0.0/tests/test_fdfromdata.py +68 -0
  17. dbis_functional_dependencies-1.0.0/tests/test_fds.py +96 -0
  18. dbis_functional_dependencies-1.0.0/tests/test_fdsbase.py +43 -0
  19. dbis_functional_dependencies-1.0.0/tests/test_tum.py +29 -0
  20. dbis-functional-dependencies-0.0.7/PKG-INFO +0 -23
  21. dbis-functional-dependencies-0.0.7/README.md +0 -7
  22. dbis-functional-dependencies-0.0.7/dbis_functional_dependencies.egg-info/PKG-INFO +0 -23
  23. dbis-functional-dependencies-0.0.7/dbis_functional_dependencies.egg-info/SOURCES.txt +0 -12
  24. dbis-functional-dependencies-0.0.7/dbis_functional_dependencies.egg-info/top_level.txt +0 -1
  25. dbis-functional-dependencies-0.0.7/functional_dependencies/BCNF.py +0 -619
  26. dbis-functional-dependencies-0.0.7/functional_dependencies/fdcheck.py +0 -96
  27. dbis-functional-dependencies-0.0.7/functional_dependencies/fdsbase.py +0 -194
  28. dbis-functional-dependencies-0.0.7/setup.py +0 -36
  29. {dbis-functional-dependencies-0.0.7 → dbis_functional_dependencies-1.0.0}/LICENSE +0 -0
  30. {dbis-functional-dependencies-0.0.7 → dbis_functional_dependencies-1.0.0}/setup.cfg +0 -0
  31. {dbis-functional-dependencies-0.0.7/functional_dependencies → dbis_functional_dependencies-1.0.0/src/dbis_functional_dependencies}/__init__.py +0 -0
  32. {dbis-functional-dependencies-0.0.7 → dbis_functional_dependencies-1.0.0/src}/dbis_functional_dependencies.egg-info/dependency_links.txt +0 -0
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.1
2
+ Name: dbis-functional-dependencies
3
+ Version: 1.0.0
4
+ Summary: RWTH Aachen Computer Science i5/dbis assets for Lecture Datenbanken und Informationssysteme
5
+ Author-email: DBIS i5 RWTH Aachen <dbis-vl@dbis.rwth-aachen.de>
6
+ Project-URL: Homepage, https://git.rwth-aachen.de/i5/teaching/dbis/dbis-functional-dependencies
7
+ Classifier: Programming Language :: Python :: 3.10
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: graphviz~=0.20
13
+ Requires-Dist: networkx~=2.7
14
+ Requires-Dist: numpy~=1.26
15
+ Requires-Dist: sphinx~=7.2
16
+ Requires-Dist: sphinxcontrib-apidoc~=0.4
17
+ Requires-Dist: functional-dependencies~=1.3
18
+ Requires-Dist: build~=1.0
19
+ Requires-Dist: pylodstorage~=0.4.11
20
+ Provides-Extra: test
21
+ Requires-Dist: black==23.12.1; extra == "test"
22
+ Provides-Extra: build
23
+ Requires-Dist: twine==4.*; extra == "build"
24
+ Requires-Dist: build==1.*; extra == "build"
25
+
26
+ # DBIS Functional Dependencies
27
+
28
+ Functional Dependencies and Normal Forms for Relational Databases
29
+
30
+ [![PyPI Status](https://img.shields.io/pypi/v/dbis-functional-dependencies.svg)](https://pypi.python.org/pypi/dbis-functional-dependencies/)
31
+ [![pypi](https://img.shields.io/pypi/pyversions/dbis-functional-dependencies)](https://pypi.org/project/dbis-functional-dependencies/)
32
+ [![License](https://img.shields.io/pypi/l/dbis-functional-dependencies)](https://www.apache.org/licenses/LICENSE-2.0)
33
+ [![Pipeline Status](https://git.rwth-aachen.de/i5/teaching/dbis/dbis-functional-dependencies/badges/main/pipeline.svg)](https://git.rwth-aachen.de/i5/teaching/dbis/dbis-functional-dependencies/-/packages)
34
+
35
+ This library provides a Python implementation of the [synthesis algorithm](https://de.wikipedia.org/wiki/Synthesealgorithmus) and decomposition algorithm according to the DBIS lecture. For more background and application of functional dependencies and the algorithms, see [Doku-FunctionalDependencies](https://git.rwth-aachen.de/i5/teaching/dbis-jupyter/dbis-ss-2023-test/-/blob/main/doku/Doku-FunctionalDependencies.ipynb).
36
+
37
+ # Features
38
+ - Create sets of Functional dependencies (FDSets).
39
+ - Calculate candidate keys of an FDSet.
40
+ - Calculate attribute closure of an attribute or set of attributes.
41
+ - Test whether an FDSet is in 2NF, 3NF or BCNF.
42
+ - Execute the synthesis algorithm to transform the FDSet into 3NF.
43
+ - Execute the decomposition algorithm to transform the FDSet into BCNF.
44
+ - Generate the closure $F^+$ of an FDSet $F$.
45
+ - Generate true/false questions w.r.t. synthesis and decomposition algorithm.
46
+
47
+ # Installation
48
+ Install via pip:
49
+ ```bash
50
+ pip install dbis-functional-dependencies
51
+ ```
52
+
53
+ # Usage
54
+ ### Creating an FDSet
55
+ Create a new instance of `FunctionalDependencySet`. The set of attributes is passed as parameter.
56
+ ```python
57
+ fdset = FunctionalDependencySet('ABCDE')
58
+ ```
59
+ You can add more attributes later by using the `add_attribute` function.
60
+ ```python
61
+ fdset.add_attribute('F')
62
+ ```
63
+ Add dependencies with the `add_dependency` function ...
64
+ ```python
65
+ fdset.add_dependency("AC", "DE")
66
+ fdset.add_dependency("DEF", "B")
67
+ fdset.add_dependency("B", "D")
68
+ ```
69
+ ... or remove them with the `remove_dependency` function.
70
+ ```python
71
+ fdset.remove_dependency("B", "D")
72
+ ```
73
+
74
+ Printing an FDSet shows the dependencies in a more readable form.
75
+ ```python
76
+ print(f"{fdset}")
77
+ ```
78
+
79
+ ### Attribute closure and candidate keys
80
+ Calculate the attribute closure of one or multiple attributes.
81
+ ```python
82
+ closureA = fdset.get_attr_closure('A')
83
+ closureAC = fdset.get_attr_closure('AC')
84
+ ```
85
+
86
+ Calculate all candidate keys.
87
+ ```python
88
+ ckeys = fdset.find_candidate_keys()
89
+ ```
90
+
91
+ ### Check for normal forms
92
+ Since we only work with schemas (no actual values for the attributes), we assume that a corresponding database is in 1NF.
93
+
94
+ Check whether the FDSet is in 2NF, 3NF or BCNF.
95
+ ```python
96
+ is2NF = fdset.is2NF()
97
+ is3NF = fdset.is3NF()
98
+ isBCNF = fdset.isBCNF()
99
+ ```
100
+
101
+ ### Execute the synthesis algorithm
102
+ Execute the synthesis algorithm on an FDSet to generate a corresponding list of FDSets in 3NF.
103
+ ```python
104
+ fdslist = fdset.synthesize()
105
+ ```
106
+ The algorithm performs the following steps:
107
+
108
+ 0. Find the candidate keys.
109
+ 1. Calculate the canonical cover.
110
+ - left reduction
111
+ - right reduction
112
+ - remove dependencies with empty rhs
113
+ - combine dependencies with same lhs
114
+ 2. Create a new relation for every dependency in the canonical cover.
115
+ 3. Create the optional key scheme if no candidate key is included in the attribute set of one of the relations of step 2.
116
+ 4. Remove subset relations.
117
+
118
+ You receive additional information on the steps of the algorithm by toggling the parameter `verbose`.
119
+ ```python
120
+ fdslist = fdset.synthesize(vebose=True)
121
+ ```
122
+ Alternatively, you can also execute the single steps with the following functions:
123
+ ```python
124
+ fdset_step.canonical_cover()
125
+ fdslist_step = fdset_step.create_new_fdsets()
126
+ fdslist_step_with_key = FunctionalDependencySet.create_optional_key_scheme(self, ckeys, fdslist_step)
127
+ reduced_fdslist_step = FunctionalDependencySet.remove_subset_relations(self, fdslist_step_with_key)
128
+ ```
129
+ The verbose option exists for all steps.
130
+
131
+ ### Execute the decomposition algorithm
132
+ Execute the decomposition algorithm on an FDSet to generate a corresponding decomposition of FDSets in BCNF.
133
+ ```python
134
+ fdslist = fdset.decompose2()
135
+ ```
136
+ Before performing the actual algorithm, the the closure of the FDSet is calculated.
137
+
138
+ ### Closure of an FDSet
139
+ Calculate the closure $F^+$ of an FDSet $F$.
140
+ ```python
141
+ fdset.completeFDsetToClosure()
142
+ ```
143
+ This function just adds dependencies with all subset combinations of the attribute set with their corresponding closures on the rhs of the dependency, so that no implicit dependency is missed by the decomposition algorithm.
144
+
145
+ ### Exercise generator
146
+ Generate true/false statements based on the different steps of the algorithms.
147
+ ```python
148
+ fdslist = fdset.synthesize(genEx=True)
149
+ ```
150
+ The `genEx` option is available for the following functions:
151
+ * `find_candidate_keys`
152
+ * `synthesize`
153
+ * `canonical_cover`
154
+ * `left_reduction`
155
+ * `right_reduction`
156
+ * `remove_empty_fds`
157
+ * `combine_fds`
158
+ * `create_new_fdsets`
159
+ * `create_optional_key_scheme`
160
+ * `remove_subset_relations`
161
+ * `decompose2`
162
+
163
+ ### Checking results against expected
164
+ Checks a given calculated step of an FDSet during the synthesis algorithm (according to the DBIS lecture) for correctness.
165
+ ```python
166
+ original = fdset.copy()
167
+ fdset.left_reduction()
168
+ original.isCorrectLeftReduction(fdset)
169
+ ```
170
+ For this purpose, the following functions exist:
171
+ * `isCorrectLeftReduction`
172
+ * `isCorrectRightReduction`
173
+ * `isCorrectRemovingEmptyFDs`
174
+ * `isCorrectCombinationOfDependencies`
175
+ * `isCorrectCanonicalCover`
176
+ * `isCorrectCreationOfNewFDS`
177
+
178
+ These functions are called on the FDSet with all steps before already calculated on it.
@@ -0,0 +1,153 @@
1
+ # DBIS Functional Dependencies
2
+
3
+ Functional Dependencies and Normal Forms for Relational Databases
4
+
5
+ [![PyPI Status](https://img.shields.io/pypi/v/dbis-functional-dependencies.svg)](https://pypi.python.org/pypi/dbis-functional-dependencies/)
6
+ [![pypi](https://img.shields.io/pypi/pyversions/dbis-functional-dependencies)](https://pypi.org/project/dbis-functional-dependencies/)
7
+ [![License](https://img.shields.io/pypi/l/dbis-functional-dependencies)](https://www.apache.org/licenses/LICENSE-2.0)
8
+ [![Pipeline Status](https://git.rwth-aachen.de/i5/teaching/dbis/dbis-functional-dependencies/badges/main/pipeline.svg)](https://git.rwth-aachen.de/i5/teaching/dbis/dbis-functional-dependencies/-/packages)
9
+
10
+ This library provides a Python implementation of the [synthesis algorithm](https://de.wikipedia.org/wiki/Synthesealgorithmus) and decomposition algorithm according to the DBIS lecture. For more background and application of functional dependencies and the algorithms, see [Doku-FunctionalDependencies](https://git.rwth-aachen.de/i5/teaching/dbis-jupyter/dbis-ss-2023-test/-/blob/main/doku/Doku-FunctionalDependencies.ipynb).
11
+
12
+ # Features
13
+ - Create sets of Functional dependencies (FDSets).
14
+ - Calculate candidate keys of an FDSet.
15
+ - Calculate attribute closure of an attribute or set of attributes.
16
+ - Test whether an FDSet is in 2NF, 3NF or BCNF.
17
+ - Execute the synthesis algorithm to transform the FDSet into 3NF.
18
+ - Execute the decomposition algorithm to transform the FDSet into BCNF.
19
+ - Generate the closure $F^+$ of an FDSet $F$.
20
+ - Generate true/false questions w.r.t. synthesis and decomposition algorithm.
21
+
22
+ # Installation
23
+ Install via pip:
24
+ ```bash
25
+ pip install dbis-functional-dependencies
26
+ ```
27
+
28
+ # Usage
29
+ ### Creating an FDSet
30
+ Create a new instance of `FunctionalDependencySet`. The set of attributes is passed as parameter.
31
+ ```python
32
+ fdset = FunctionalDependencySet('ABCDE')
33
+ ```
34
+ You can add more attributes later by using the `add_attribute` function.
35
+ ```python
36
+ fdset.add_attribute('F')
37
+ ```
38
+ Add dependencies with the `add_dependency` function ...
39
+ ```python
40
+ fdset.add_dependency("AC", "DE")
41
+ fdset.add_dependency("DEF", "B")
42
+ fdset.add_dependency("B", "D")
43
+ ```
44
+ ... or remove them with the `remove_dependency` function.
45
+ ```python
46
+ fdset.remove_dependency("B", "D")
47
+ ```
48
+
49
+ Printing an FDSet shows the dependencies in a more readable form.
50
+ ```python
51
+ print(f"{fdset}")
52
+ ```
53
+
54
+ ### Attribute closure and candidate keys
55
+ Calculate the attribute closure of one or multiple attributes.
56
+ ```python
57
+ closureA = fdset.get_attr_closure('A')
58
+ closureAC = fdset.get_attr_closure('AC')
59
+ ```
60
+
61
+ Calculate all candidate keys.
62
+ ```python
63
+ ckeys = fdset.find_candidate_keys()
64
+ ```
65
+
66
+ ### Check for normal forms
67
+ Since we only work with schemas (no actual values for the attributes), we assume that a corresponding database is in 1NF.
68
+
69
+ Check whether the FDSet is in 2NF, 3NF or BCNF.
70
+ ```python
71
+ is2NF = fdset.is2NF()
72
+ is3NF = fdset.is3NF()
73
+ isBCNF = fdset.isBCNF()
74
+ ```
75
+
76
+ ### Execute the synthesis algorithm
77
+ Execute the synthesis algorithm on an FDSet to generate a corresponding list of FDSets in 3NF.
78
+ ```python
79
+ fdslist = fdset.synthesize()
80
+ ```
81
+ The algorithm performs the following steps:
82
+
83
+ 0. Find the candidate keys.
84
+ 1. Calculate the canonical cover.
85
+ - left reduction
86
+ - right reduction
87
+ - remove dependencies with empty rhs
88
+ - combine dependencies with same lhs
89
+ 2. Create a new relation for every dependency in the canonical cover.
90
+ 3. Create the optional key scheme if no candidate key is included in the attribute set of one of the relations of step 2.
91
+ 4. Remove subset relations.
92
+
93
+ You receive additional information on the steps of the algorithm by toggling the parameter `verbose`.
94
+ ```python
95
+ fdslist = fdset.synthesize(vebose=True)
96
+ ```
97
+ Alternatively, you can also execute the single steps with the following functions:
98
+ ```python
99
+ fdset_step.canonical_cover()
100
+ fdslist_step = fdset_step.create_new_fdsets()
101
+ fdslist_step_with_key = FunctionalDependencySet.create_optional_key_scheme(self, ckeys, fdslist_step)
102
+ reduced_fdslist_step = FunctionalDependencySet.remove_subset_relations(self, fdslist_step_with_key)
103
+ ```
104
+ The verbose option exists for all steps.
105
+
106
+ ### Execute the decomposition algorithm
107
+ Execute the decomposition algorithm on an FDSet to generate a corresponding decomposition of FDSets in BCNF.
108
+ ```python
109
+ fdslist = fdset.decompose2()
110
+ ```
111
+ Before performing the actual algorithm, the the closure of the FDSet is calculated.
112
+
113
+ ### Closure of an FDSet
114
+ Calculate the closure $F^+$ of an FDSet $F$.
115
+ ```python
116
+ fdset.completeFDsetToClosure()
117
+ ```
118
+ This function just adds dependencies with all subset combinations of the attribute set with their corresponding closures on the rhs of the dependency, so that no implicit dependency is missed by the decomposition algorithm.
119
+
120
+ ### Exercise generator
121
+ Generate true/false statements based on the different steps of the algorithms.
122
+ ```python
123
+ fdslist = fdset.synthesize(genEx=True)
124
+ ```
125
+ The `genEx` option is available for the following functions:
126
+ * `find_candidate_keys`
127
+ * `synthesize`
128
+ * `canonical_cover`
129
+ * `left_reduction`
130
+ * `right_reduction`
131
+ * `remove_empty_fds`
132
+ * `combine_fds`
133
+ * `create_new_fdsets`
134
+ * `create_optional_key_scheme`
135
+ * `remove_subset_relations`
136
+ * `decompose2`
137
+
138
+ ### Checking results against expected
139
+ Checks a given calculated step of an FDSet during the synthesis algorithm (according to the DBIS lecture) for correctness.
140
+ ```python
141
+ original = fdset.copy()
142
+ fdset.left_reduction()
143
+ original.isCorrectLeftReduction(fdset)
144
+ ```
145
+ For this purpose, the following functions exist:
146
+ * `isCorrectLeftReduction`
147
+ * `isCorrectRightReduction`
148
+ * `isCorrectRemovingEmptyFDs`
149
+ * `isCorrectCombinationOfDependencies`
150
+ * `isCorrectCanonicalCover`
151
+ * `isCorrectCreationOfNewFDS`
152
+
153
+ These functions are called on the FDSet with all steps before already calculated on it.
@@ -0,0 +1,46 @@
1
+ [project]
2
+ name="dbis-functional-dependencies"
3
+ version='1.0.0'
4
+ description="RWTH Aachen Computer Science i5/dbis assets for Lecture Datenbanken und Informationssysteme"
5
+
6
+ authors = [
7
+ { name = "DBIS i5 RWTH Aachen", email = "dbis-vl@dbis.rwth-aachen.de" }
8
+ ]
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ classifiers = [
12
+ "Programming Language :: Python :: 3.10",
13
+ "Programming Language :: Python :: 3.11"
14
+ ]
15
+
16
+ dependencies = [
17
+ "graphviz~=0.20",
18
+ "networkx~=2.7",
19
+ "numpy~=1.26",
20
+ "sphinx~=7.2",
21
+ "sphinxcontrib-apidoc~=0.4",
22
+ "functional-dependencies~=1.3",
23
+ "build~=1.0",
24
+ "pylodstorage~=0.4.11"
25
+ ]
26
+
27
+ [project.optional-dependencies]
28
+ test = [
29
+ "black==23.12.1"
30
+ ]
31
+ build = [
32
+ "twine==4.*",
33
+ "build==1.*"
34
+ ]
35
+
36
+
37
+ [project.urls]
38
+ "Homepage" = "https://git.rwth-aachen.de/i5/teaching/dbis/dbis-functional-dependencies"
39
+
40
+ [options]
41
+ include_package_data = true
42
+ exclude = ["examples"]
43
+
44
+ [build-system]
45
+ requires = ["setuptools>=42"]
46
+ build-backend = "setuptools.build_meta"