Skip to content

Commit

Permalink
generateConcepts(context)
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 6, 2024
1 parent b12176f commit f303423
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# context

`generateConcepts(context)`
`generateConcepts` test

# lattice

Expand Down
24 changes: 24 additions & 0 deletions src/context/generateConcepts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
conceptFromAttributes,
conceptFromEntities,
conceptJoin,
createConceptSet,
type Concept,
} from "../concept/index.js"
Expand All @@ -8,11 +10,33 @@ import type { Context } from "./index.js"
export function generateConcepts(context: Context): Array<Concept> {
const targets = createConceptSet()
const results = createConceptSet()

for (const entity of context.entities) {
const entityConcept = conceptFromEntities(context, [entity])
targets.add(entityConcept)
results.add(entityConcept)
}

for (const attribute of context.attributes) {
const attributeConcept = conceptFromAttributes(context, [attribute])
targets.add(attributeConcept)
results.add(attributeConcept)
}

while (true) {
const first = targets.representatives.shift()
if (first === undefined) {
break
}

for (const target of targets.representatives) {
const concept = conceptJoin(first, target)
if (!results.has(concept)) {
targets.add(concept)
results.add(concept)
}
}
}

return results.representatives
}

0 comments on commit f303423

Please sign in to comment.