Skip to content

Commit

Permalink
抽出 entitiesOf
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 17, 2024
1 parent 6608884 commit be4d2b5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
抽出 `entitiesOf`

修复 `commonAttributes` -- 应该是交集不是并集

`concept-graph/` -- 从 `generateConcepts` 生成有向图
Expand Down
5 changes: 4 additions & 1 deletion src/context/attributesOf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Attribute, Context, Entity } from "./Context.js"

export function attributesOf(context: Context, entity: Entity): Set<Attribute> {
export function attributesOf(
context: Context,
entity: Entity,
): ReadonlySet<Attribute> {
const attributes = context.entityAttributeIndex.get(entity)
if (attributes === undefined) {
return new Set()
Expand Down
16 changes: 16 additions & 0 deletions src/context/entitiesOf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Attribute, Context, Entity } from "./Context.js"
import { attributesOf } from "./attributesOf.js"

export function entitiesOf(
context: Context,
attribute: Attribute,
): ReadonlySet<Entity> {
const entities = new Set<Entity>()
for (const entity of context.entities) {
if (attributesOf(context, entity).has(attribute)) {
entities.add(entity)
}
}

return entities
}
2 changes: 1 addition & 1 deletion src/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * from "./attributesOf.js"
// export * from "./entitiesOf.js"
export * from "./commonAttributes.js"
export * from "./commonEntities.js"
export * from "./Context.js"
export * from "./createContextFromCrossTable.js"
export * from "./CrossTable.js"
export * from "./entitiesOf.js"
export * from "./entityHasAttribute.js"

0 comments on commit be4d2b5

Please sign in to comment.