Skip to content

Commit 69f165a

Browse files
committed
refactoring of scripts
1 parent 411f8bb commit 69f165a

21 files changed

Lines changed: 392 additions & 387 deletions

databases/catdat/scripts/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const PLURALS = {
55
functor: 'functors',
66
} as const
77

8+
// TODO: integrate this into schema
89
export const STRUCTURE_MAPS = [
910
['source', 'functor', 'category'],
1011
['target', 'functor', 'category'],

databases/catdat/scripts/deduce-implications.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { STRUCTURE_MAPS, STRUCTURES_WITH_DUALS, type StructureType } from './config'
2-
import { are_equal_sets, get_client, parse_json_set } from './utils/helpers'
2+
import { are_equal_sets, parse_json_set } from './utils/helpers'
3+
import { get_client } from './utils/db'
34

45
const db = get_client()
56

@@ -24,9 +25,9 @@ export function create_dualized_implications(type: StructureType) {
2425
assumptions: string
2526
conclusions: string
2627
dual_assumptions: string
28+
dual_conclusions: string
2729
dual_source_assumptions: string
2830
dual_target_assumptions: string
29-
dual_conclusions: string
3031
}
3132
>(
3233
`SELECT
@@ -42,22 +43,22 @@ export function create_dualized_implications(type: StructureType) {
4243
) AS dual_assumptions,
4344
(
4445
SELECT json_group_array(p.dual_property_id)
45-
FROM source_assumptions a
46+
FROM conclusions a
4647
LEFT JOIN properties p ON p.id = a.property_id
4748
WHERE a.implication_id = i.id
48-
) AS dual_source_assumptions,
49+
) AS dual_conclusions,
4950
(
5051
SELECT json_group_array(p.dual_property_id)
51-
FROM target_assumptions a
52+
FROM source_assumptions a
5253
LEFT JOIN properties p ON p.id = a.property_id
5354
WHERE a.implication_id = i.id
54-
) AS dual_target_assumptions,
55+
) AS dual_source_assumptions,
5556
(
5657
SELECT json_group_array(p.dual_property_id)
57-
FROM conclusions a
58+
FROM target_assumptions a
5859
LEFT JOIN properties p ON p.id = a.property_id
5960
WHERE a.implication_id = i.id
60-
) AS dual_conclusions
61+
) AS dual_target_assumptions
6162
FROM implications_view i
6263
WHERE i.type = ? AND i.is_deduced = FALSE`,
6364
)
@@ -92,7 +93,7 @@ export function create_dualized_implications(type: StructureType) {
9293
VALUES (?, ?, ?, ?)
9394
`)
9495

95-
const mapped_assumption_inserts = {
96+
const associated_assumption_inserts = {
9697
source: source_assumption_insert,
9798
target: target_assumption_insert,
9899
}
@@ -124,7 +125,7 @@ export function create_dualized_implications(type: StructureType) {
124125

125126
count++
126127

127-
const mapped_dual_assumptions = {
128+
const associated_dual_assumptions = {
128129
source: dual_source_assumptions,
129130
target: dual_target_assumptions,
130131
}
@@ -149,8 +150,8 @@ export function create_dualized_implications(type: StructureType) {
149150
const [name, from, to] = map
150151
if (from !== type) continue
151152

152-
for (const assumption of mapped_dual_assumptions[name] ?? []) {
153-
mapped_assumption_inserts[name].run(dual_id, assumption, type, to)
153+
for (const assumption of associated_dual_assumptions[name] ?? []) {
154+
associated_assumption_inserts[name].run(dual_id, assumption, type, to)
154155
}
155156
}
156157
}
@@ -169,7 +170,9 @@ export function create_self_dual_implications(type: StructureType) {
169170

170171
const relevant_props = db
171172
.prepare<[StructureType], { id: string; dual: string }>(
172-
`SELECT id, dual_property_id AS dual
173+
`SELECT
174+
id,
175+
dual_property_id AS dual
173176
FROM properties
174177
WHERE
175178
type = ?
@@ -180,17 +183,20 @@ export function create_self_dual_implications(type: StructureType) {
180183
.all(type)
181184

182185
const implication_insert = db.prepare(`
183-
INSERT INTO implications (id, type, proof, is_deduced)
186+
INSERT INTO implications
187+
(id, type, proof, is_deduced)
184188
VALUES (?, ?, 'This holds by self-duality.', TRUE)
185189
`)
186190

187191
const assumption_insert = db.prepare(`
188-
INSERT INTO assumptions (implication_id, property_id, type)
192+
INSERT INTO assumptions
193+
(implication_id, property_id, type)
189194
VALUES (?, ?, ?)
190195
`)
191196

192197
const conclusion_insert = db.prepare(`
193-
INSERT INTO conclusions (implication_id, property_id, type)
198+
INSERT INTO conclusions
199+
(implication_id, property_id, type)
194200
VALUES (?, ?, ?)
195201
`)
196202

databases/catdat/scripts/deduce-special-morphisms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { get_client } from './utils/helpers'
1+
import { get_client } from './utils/db'
22

33
const db = get_client()
44

databases/catdat/scripts/deduce-special-objects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { get_client } from './utils/helpers'
1+
import { get_client } from './utils/db'
22

33
const db = get_client()
44

databases/catdat/scripts/deduce-structure-properties.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
*/
55

66
import { type Database, SqliteError } from 'better-sqlite3'
7-
import { get_client, is_subset } from './utils/helpers'
7+
import { is_subset } from './utils/helpers'
8+
import { get_client } from './utils/db'
89
import {
9-
get_structures,
1010
get_properties_dict,
1111
get_property_assignments,
12-
is_dual_structure,
13-
type StructureMeta,
1412
type PropertyMeta,
15-
} from './utils/deduction'
13+
} from './utils/properties'
1614
import {
1715
get_contradiction_string,
1816
get_normalized_implications,
1917
get_proof_string,
2018
NormalizedImplication,
2119
} from './utils/implications'
2220
import { STRUCTURES_WITH_DUALS, type StructureType } from './config'
21+
import { get_structures, is_dual_structure, type StructureMeta } from './utils/structures'
2322

2423
/**
2524
* Returns the set of satisfied properties that can be deduced from a set
@@ -389,9 +388,8 @@ function delete_deduced_properties(db: Database, type: StructureType) {
389388
}
390389

391390
/**
392-
* --- MAIN FUNCTION ---
393-
* Deduce properties of structures from given ones
394-
* by using the list of implications.
391+
* Main function: Deduce properties of structures from given ones
392+
* by using the stored implications.
395393
*/
396394
export function deduce_properties_for_structures(type: StructureType) {
397395
console.info(`\n--- Deduce ${type} properties ---`)

databases/catdat/scripts/proof-length.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type StructureType } from './config'
2-
import { get_client } from './utils/helpers'
2+
import { get_client } from './utils/db'
33

44
const db = get_client()
55

databases/catdat/scripts/redundancies.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import { get_client } from './utils/helpers'
1+
import { get_client } from './utils/db'
22
import {
33
get_deduced_satisfied_properties,
44
get_deduced_unsatisfied_properties,
55
} from './deduce-structure-properties'
6-
import {
7-
get_property_assignments_by_deduction,
8-
get_structures,
9-
StructureMeta,
10-
} from './utils/deduction'
6+
import { get_property_assignments_by_deduction } from './utils/properties'
117
import type { StructureType } from './config'
128
import {
139
get_normalized_implications,
1410
type NormalizedImplication,
1511
} from './utils/implications'
12+
import { get_structures } from './utils/structures'
1613

1714
const db = get_client()
1815

@@ -37,7 +34,7 @@ function check_redundant_property_assignments(type: StructureType) {
3734

3835
const implications = get_normalized_implications(db, type)
3936

40-
const structures: StructureMeta[] = get_structures(db, type)
37+
const structures = get_structures(db, type)
4138

4239
const assignments = get_property_assignments_by_deduction(db, structures, type)
4340
const ignore_dict = get_ignored_redundant_assignments(type)

databases/catdat/scripts/restrict-functor-properties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { get_client } from './utils/helpers'
1+
import { get_client } from './utils/db'
22

33
const db = get_client()
44

databases/catdat/scripts/seed.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'node:path'
2-
import { get_client, seed_file, seed_files } from './utils/helpers'
2+
import { seed_file, seed_files } from './utils/seed.helpers'
3+
import { get_client } from './utils/db'
34
import type {
45
CategoryYaml,
56
ConfigYaml,
@@ -8,7 +9,7 @@ import type {
89
PropertyEntry,
910
StructureYaml,
1011
PropertyYaml,
11-
} from './seed.types'
12+
} from './utils/seed.types'
1213
import { create_schema_hash, get_saved_schema_hash } from './utils/schema'
1314
import { PLURALS, STRUCTURE_MAPS, type StructureType } from './config'
1415

databases/catdat/scripts/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
3-
import { get_client } from './utils/helpers'
3+
import { get_client } from './utils/db'
44
import { create_schema_hash, write_schema_hash } from './utils/schema'
55

66
const schema_folder = path.resolve('databases', 'catdat', 'schema')

0 commit comments

Comments
 (0)