@@ -15,6 +15,10 @@ type CategoryMeta = {
1515 dual_category_id : string | null
1616}
1717
18+ /**
19+ * Deduce properties of categories from given ones
20+ * by using the list of implications.
21+ */
1822export async function deduce_category_properties ( db : Client ) {
1923 const tx = await db . transaction ( )
2024
@@ -53,6 +57,20 @@ export async function deduce_category_properties(db: Client) {
5357 }
5458}
5559
60+ /**
61+ * Implications have the form:
62+ *
63+ * P_1 + ... + P_n ----> Q_1 + ... + Q_m
64+ *
65+ * or
66+ *
67+ * P_1 + ... + P_n <---> Q_1 + ... + Q_m
68+ *
69+ * This function decomposes them into normalized implications,
70+ * which have the form:
71+ *
72+ * P_1 + ... + P_n ----> Q
73+ */
5674async function get_normalized_category_implications (
5775 tx : Transaction ,
5876) : Promise < NormalizedCategoryImplication [ ] > {
@@ -113,6 +131,9 @@ async function get_normalized_category_implications(
113131 return implications
114132}
115133
134+ /**
135+ * Returns the list of categories saved in the database.
136+ */
116137async function get_categories ( tx : Transaction ) {
117138 const res = await tx . execute ( `
118139 SELECT id, name, dual_category_id
@@ -121,6 +142,10 @@ async function get_categories(tx: Transaction) {
121142 return res . rows as unknown as CategoryMeta [ ]
122143}
123144
145+ /**
146+ * Clears all the deduced properties.
147+ * This runs before the deduction starts.
148+ */
124149async function delete_deduced_category_properties ( tx : Transaction , category_id : string ) {
125150 await tx . execute ( {
126151 sql : `
@@ -131,6 +156,10 @@ async function delete_deduced_category_properties(tx: Transaction, category_id:
131156 } )
132157}
133158
159+ /**
160+ * Returns the list of properties that are satisfied or unsatisfied
161+ * for a given category.
162+ */
134163async function get_decided_properties (
135164 tx : Transaction ,
136165 category_id : string ,
@@ -148,6 +177,10 @@ async function get_decided_properties(
148177 return new Set ( res . rows . map ( ( row ) => row . property_id ) as string [ ] )
149178}
150179
180+ /**
181+ * Deduce satisfied properties for a given category from given ones
182+ * by using the list of normalized implications.
183+ */
151184async function deduce_satisfied_category_properties (
152185 tx : Transaction ,
153186 category_id : string ,
@@ -208,6 +241,10 @@ async function deduce_satisfied_category_properties(
208241 )
209242}
210243
244+ /**
245+ * Deduce unsatisfied properties for a given category from given ones
246+ * by using the satisfied properties and the list of normalized implications.
247+ */
211248async function deduce_unsatisfied_category_properties (
212249 tx : Transaction ,
213250 category_id : string ,
@@ -287,6 +324,10 @@ async function deduce_unsatisfied_category_properties(
287324 )
288325}
289326
327+ /**
328+ * Assign dual properties to dual categories:
329+ * If C has property P, then C^op has property P^op (if defined).
330+ */
290331async function deduce_dual_category_properties ( tx : Transaction , category : CategoryMeta ) {
291332 const res = await tx . execute ( {
292333 sql : `
0 commit comments