Skip to content

Commit

Permalink
topConceptbottomConcept
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 17, 2024
1 parent d595053 commit e353e46
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
修复 `generateConcepts`
修复 `generateConcepts` -- `topConcept``bottomConcept` 是特殊的

`concept-graph/` -- 从 `generateConcepts` 生成有向图

Expand Down
10 changes: 10 additions & 0 deletions src/concept/bottomConcept.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Context } from "../context/Context.js"
import type { Concept } from "./Concept.js"

export function bottomConcept(context: Context): Concept {
return {
context,
extent: new Set(),
intent: context.attributes,
}
}
2 changes: 2 additions & 0 deletions src/concept/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./assertSameContext.js"
export * from "./bottomConcept.js"
export * from "./closureAttributes.js"
export * from "./closureEntities.js"
export * from "./Concept.js"
Expand All @@ -10,3 +11,4 @@ export * from "./conceptMeet.js"
export * from "./createConceptSet.js"
export * from "./isExtent.js"
export * from "./isIntent.js"
export * from "./topConcept.js"
10 changes: 10 additions & 0 deletions src/concept/topConcept.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Context } from "../context/Context.js"
import type { Concept } from "./Concept.js"

export function topConcept(context: Context): Concept {
return {
context,
extent: context.entities,
intent: new Set(),
}
}
22 changes: 13 additions & 9 deletions src/context/commonEntities.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { setIsSupersetOf } from "../utils/Set.js"
import type { Attribute, Context, Entity } from "./index.js"
import { setIntersection } from "../utils/Set.js"
import {
entitiesOf,
type Attribute,
type Context,
type Entity,
} from "./index.js"

export function commonEntities(
context: Context,
inputAttributes: ReadonlySet<Attribute> | ReadonlyArray<Attribute>,
): ReadonlySet<Entity> {
inputAttributes = new Set(inputAttributes)

const resultEntities = new Set<Entity>()
for (const [keyEntity, foundAttributes] of context.entityAttributeIndex) {
if (setIsSupersetOf(foundAttributes, inputAttributes)) {
resultEntities.add(keyEntity)
}
let resultEntities = context.entities
for (const inputAttribute of inputAttributes) {
resultEntities = setIntersection(
resultEntities,
entitiesOf(context, inputAttribute),
)
}

return resultEntities
Expand Down

0 comments on commit e353e46

Please sign in to comment.