Skip to content

Commit 492fe99

Browse files
committed
定义 generateConceptSetByJoin 然后 generateConceptSet 调用它
1 parent 1849ba5 commit 492fe99

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
定义 `generateConceptSetByJoin` 然后 `generateConceptSet` 调用它
21
定义 `generateConceptSetByMeet` 然后测试两种计算方式相等
32

43
# learn

src/lattice/generateConceptSet.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
1-
import { conceptJoin, type Concept } from "../concept/index.js"
1+
import { type Concept } from "../concept/index.js"
22
import type { Context } from "../context/index.js"
33
import type { QuotientSet } from "../utils/QuotientSet.js"
4-
import { generateAttributeConceptSet } from "./generateAttributeConceptSet.js"
5-
import { generateEntityConceptSet } from "./generateEntityConceptSet.js"
4+
import { generateConceptSetByJoin } from "./generateConceptSetByJoin.js"
65

76
export function generateConceptSet(context: Context): QuotientSet<Concept> {
8-
const targets = generateEntityConceptSet(context)
9-
const results = generateAttributeConceptSet(context).union(targets)
10-
11-
while (true) {
12-
const first = targets.representatives.shift()
13-
if (first === undefined) {
14-
break
15-
}
16-
17-
for (const target of targets.representatives) {
18-
const concept = conceptJoin(first, target)
19-
if (!results.has(concept)) {
20-
targets.add(concept)
21-
results.add(concept)
22-
}
23-
}
24-
}
25-
26-
return results
7+
return generateConceptSetByJoin(context)
278
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { conceptJoin, 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 generateConceptSetByJoin(
8+
context: Context,
9+
): QuotientSet<Concept> {
10+
const targets = generateEntityConceptSet(context)
11+
const results = generateAttributeConceptSet(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 = conceptJoin(first, target)
21+
if (!results.has(concept)) {
22+
targets.add(concept)
23+
results.add(concept)
24+
}
25+
}
26+
}
27+
28+
return results
29+
}

0 commit comments

Comments
 (0)