Skip to content

Commit 47641ad

Browse files
committed
allow properties to be ignored by redundancy check script
1 parent f1f36b4 commit 47641ad

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

databases/catdat/schema/004_category-properties.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ CREATE TABLE category_property_assignments (
2828
reason TEXT NOT NULL CHECK (length(reason) > 0),
2929
is_deduced INTEGER NOT NULL DEFAULT FALSE
3030
CHECK (is_deduced in (TRUE, FALSE)),
31+
check_redundancy INTEGER NOT NULL DEFAULT TRUE
32+
CHECK (check_redundancy in (TRUE, FALSE)),
3133
UNIQUE (category_id, property_id),
3234
FOREIGN KEY (category_id) REFERENCES categories (id) ON DELETE CASCADE,
3335
FOREIGN KEY (property_id) REFERENCES category_properties (id) ON DELETE CASCADE

databases/catdat/scripts/categories.utils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,27 @@ export function get_next_implication_for_contradiction(
230230
}
231231
return null
232232
}
233+
234+
/**
235+
* Returns a dictionary mapping a category to the set of its assigned
236+
* properties (satisfied or unsatisfied) that should not be checked
237+
* by the redundancy check script.
238+
*/
239+
export function get_ignored_redundant_properties(db: Database) {
240+
const rows = db
241+
.prepare(
242+
`SELECT category_id, property_id
243+
FROM category_property_assignments
244+
WHERE check_redundancy = FALSE`,
245+
)
246+
.all() as { category_id: string; property_id: string }[]
247+
248+
const grouped: Record<string, Set<string>> = {}
249+
250+
for (const row of rows) {
251+
grouped[row.category_id] ??= new Set()
252+
grouped[row.category_id].add(row.property_id)
253+
}
254+
255+
return grouped
256+
}

databases/catdat/scripts/redundancies.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { get_client } from './shared'
22
import {
33
get_all_assignments,
44
get_categories,
5+
get_ignored_redundant_properties,
56
get_next_implication,
67
get_next_implication_for_contradiction,
78
get_normalized_category_implications,
@@ -30,13 +31,15 @@ function check_redundant_category_property_assignments() {
3031
const implications = get_normalized_category_implications(db)
3132
const categories = get_categories(db)
3233
const assignments = get_all_assignments(db, categories)
34+
const ignore_dict = get_ignored_redundant_properties(db)
3335

3436
let redundancy_count = 0
3537

3638
for (const category of categories) {
3739
const redundant_satisfied_property = get_redundant_satisfied_property(
3840
assignments[category.id].satisfied.non_deduced,
3941
implications,
42+
ignore_dict[category.id],
4043
)
4144

4245
if (redundant_satisfied_property) {
@@ -56,6 +59,7 @@ function check_redundant_category_property_assignments() {
5659
all_satisfied_properties,
5760
assignments[category.id].unsatisfied.non_deduced,
5861
implications,
62+
ignore_dict[category.id],
5963
)
6064

6165
if (redundant_unsatisfied_property) {
@@ -104,8 +108,10 @@ function get_deduced_satisfied_properties(
104108
function get_redundant_satisfied_property(
105109
satisfied_properties: Set<string>,
106110
implications: NormalizedCategoryImplication[],
111+
ignored: Set<string> = new Set(),
107112
) {
108113
for (const p of [...satisfied_properties]) {
114+
if (ignored.has(p)) continue
109115
satisfied_properties.delete(p)
110116
const deduced_properties = get_deduced_satisfied_properties(
111117
satisfied_properties,
@@ -161,8 +167,10 @@ function get_redundant_unsatisfied_property(
161167
satisfied_properties: Set<string>,
162168
unsatisfied_properties: Set<string>,
163169
implications: NormalizedCategoryImplication[],
170+
ignored: Set<string> = new Set(),
164171
) {
165172
for (const p of [...unsatisfied_properties]) {
173+
if (ignored.has(p)) continue
166174
unsatisfied_properties.delete(p)
167175
const deduced_properties = get_deduced_unsatisfied_properties(
168176
satisfied_properties,

0 commit comments

Comments
 (0)