File tree Expand file tree Collapse file tree 4 files changed +62
-2
lines changed Expand file tree Collapse file tree 4 files changed +62
-2
lines changed Original file line number Diff line number Diff line change 1
- 定义 ` generateConceptSetByMeet ` 然后测试两种计算方式相等
2
-
3
1
# learn
4
2
5
3
回顾《Restructuring lattice theory》笔记
Original file line number Diff line number Diff line change
1
+ import assert from "node:assert"
2
+ import test from "node:test"
3
+ import { createContextFromCrossTable } from "../context/createContextFromCrossTable.js"
4
+ import { planets } from "../examples/planets.js"
5
+ import { waterbodies } from "../examples/waterbodies.js"
6
+ import { generateConceptSetByJoin } from "./generateConceptSetByJoin.js"
7
+ import { generateConceptSetByMeet } from "./generateConceptSetByMeet.js"
8
+
9
+ test ( "by join and meet are the same -- planets" , ( ) => {
10
+ const context = createContextFromCrossTable ( planets )
11
+
12
+ assert (
13
+ generateConceptSetByJoin ( context ) . isEqualTo (
14
+ generateConceptSetByMeet ( context ) ,
15
+ ) ,
16
+ )
17
+ } )
18
+
19
+ test ( "by join and meet are the same -- waterbodies" , ( ) => {
20
+ const context = createContextFromCrossTable ( waterbodies )
21
+
22
+ assert (
23
+ generateConceptSetByJoin ( context ) . isEqualTo (
24
+ generateConceptSetByMeet ( context ) ,
25
+ ) ,
26
+ )
27
+ } )
Original file line number Diff line number Diff line change
1
+ import { conceptMeet , type Concept } from "../concept/index.js"
2
+ import type { Context } from "../context/index.js"
3
+ import type { QuotientSet } from "../utils/QuotientSet.js"
4
+ import { generateAttributeConceptSet } from "./generateAttributeConceptSet.js"
5
+ import { generateEntityConceptSet } from "./generateEntityConceptSet.js"
6
+
7
+ export function generateConceptSetByMeet (
8
+ context : Context ,
9
+ ) : QuotientSet < Concept > {
10
+ const targets = generateAttributeConceptSet ( context )
11
+ const results = generateEntityConceptSet ( context ) . union ( targets )
12
+
13
+ while ( true ) {
14
+ const first = targets . representatives . shift ( )
15
+ if ( first === undefined ) {
16
+ break
17
+ }
18
+
19
+ for ( const target of targets . representatives ) {
20
+ const concept = conceptMeet ( first , target )
21
+ if ( ! results . has ( concept ) ) {
22
+ targets . add ( concept )
23
+ results . add ( concept )
24
+ }
25
+ }
26
+ }
27
+
28
+ return results
29
+ }
Original file line number Diff line number Diff line change @@ -52,4 +52,10 @@ export class QuotientSet<T> {
52
52
for ( const x of this . representatives ) if ( that . has ( x ) ) newSet . add ( x )
53
53
return newSet
54
54
}
55
+
56
+ isEqualTo ( that : QuotientSet < T > ) : boolean {
57
+ if ( this . equal !== that . equal ) return false
58
+
59
+ return this . union ( that ) . size === this . size
60
+ }
55
61
}
You can’t perform that action at this time.
0 commit comments