Skip to content

Commit f303423

Browse files
committed
generateConcepts(context)
1 parent b12176f commit f303423

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# context
22

3-
`generateConcepts(context)`
3+
`generateConcepts` test
44

55
# lattice
66

src/context/generateConcepts.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {
2+
conceptFromAttributes,
23
conceptFromEntities,
4+
conceptJoin,
35
createConceptSet,
46
type Concept,
57
} from "../concept/index.js"
@@ -8,11 +10,33 @@ import type { Context } from "./index.js"
810
export function generateConcepts(context: Context): Array<Concept> {
911
const targets = createConceptSet()
1012
const results = createConceptSet()
13+
1114
for (const entity of context.entities) {
1215
const entityConcept = conceptFromEntities(context, [entity])
1316
targets.add(entityConcept)
1417
results.add(entityConcept)
1518
}
1619

20+
for (const attribute of context.attributes) {
21+
const attributeConcept = conceptFromAttributes(context, [attribute])
22+
targets.add(attributeConcept)
23+
results.add(attributeConcept)
24+
}
25+
26+
while (true) {
27+
const first = targets.representatives.shift()
28+
if (first === undefined) {
29+
break
30+
}
31+
32+
for (const target of targets.representatives) {
33+
const concept = conceptJoin(first, target)
34+
if (!results.has(concept)) {
35+
targets.add(concept)
36+
results.add(concept)
37+
}
38+
}
39+
}
40+
1741
return results.representatives
1842
}

0 commit comments

Comments
 (0)