Skip to content

Commit be4d2b5

Browse files
committed
抽出 entitiesOf
1 parent 6608884 commit be4d2b5

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
抽出 `entitiesOf`
2-
31
修复 `commonAttributes` -- 应该是交集不是并集
42

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

src/context/attributesOf.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Attribute, Context, Entity } from "./Context.js"
22

3-
export function attributesOf(context: Context, entity: Entity): Set<Attribute> {
3+
export function attributesOf(
4+
context: Context,
5+
entity: Entity,
6+
): ReadonlySet<Attribute> {
47
const attributes = context.entityAttributeIndex.get(entity)
58
if (attributes === undefined) {
69
return new Set()

src/context/entitiesOf.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Attribute, Context, Entity } from "./Context.js"
2+
import { attributesOf } from "./attributesOf.js"
3+
4+
export function entitiesOf(
5+
context: Context,
6+
attribute: Attribute,
7+
): ReadonlySet<Entity> {
8+
const entities = new Set<Entity>()
9+
for (const entity of context.entities) {
10+
if (attributesOf(context, entity).has(attribute)) {
11+
entities.add(entity)
12+
}
13+
}
14+
15+
return entities
16+
}

src/context/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export * from "./attributesOf.js"
2-
// export * from "./entitiesOf.js"
32
export * from "./commonAttributes.js"
43
export * from "./commonEntities.js"
54
export * from "./Context.js"
65
export * from "./createContextFromCrossTable.js"
76
export * from "./CrossTable.js"
7+
export * from "./entitiesOf.js"
88
export * from "./entityHasAttribute.js"

0 commit comments

Comments
 (0)