Skip to content

Commit

Permalink
utils/QuotientSet
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 6, 2024
1 parent 12ff482 commit 387b450
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
35 changes: 18 additions & 17 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# learn

回顾 lattice 书,看看还函数需要加什么 API
实现 lattice 书中的 "from theory to practice"
读 rudolf wille 的原始论文和书
`utils/QuotientSet.test`

# context

`generateAllConcepts(context)`
`generateNewConcepts(context)`
`generateConcepts(context)`

如何处理对 context 的修改?

- 由于 concept 包含 context,
所以 context 必须是 immutable 的,
所以对 context 的修改必须是 functional 的。
# learn

- 增加与删除 entity 或 attribute;
- 修改某个 entity 和 attribute 的关系。
实现 lattice 书中的 "from theory to practice"

# lattice

实现 concept 之间的序关系

lessGeneral
moreGeneral
- lessGeneral
- moreGeneral

`buildLattice(context)`

# later
# optimize

`Context` -- use double index `entityAttributeIndex` and `attributeEntityIndex`

# editing context

如何处理对 context 的修改?

- 由于 concept 包含 context,
所以 context 必须是 immutable 的,
所以对 context 的修改必须是 functional 的。

- 增加与删除 entity 或 attribute;
- 修改某个 entity 和 attribute 的关系。
8 changes: 8 additions & 0 deletions src/context/generateConcepts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Concept } from "../concept/index.js"
import type { Context } from "./index.js"

export function generateConcepts(context: Context): Array<Concept> {
const targets: Array<Concept> = []
const results: Array<Concept> = []
return results
}
1 change: 1 addition & 0 deletions src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./Context.js"
export * from "./createContextFromCrossTable.js"
export * from "./CrossTable.js"
export * from "./entityHasAttribute.js"
export * from "./generateConcepts.js"
38 changes: 38 additions & 0 deletions src/utils/QuotientSet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export type QuotientSetOpitons<T> = {
equal: (x: T, y: T) => boolean
}

export class QuotientSet<T> {
representatives: Array<T>
equal: (x: T, y: T) => boolean

constructor(options: QuotientSetOpitons<T>) {
this.representatives = []
this.equal = options.equal
}

has(x: T): boolean {
const found = this.representatives.find((y) => this.equal(x, y))
if (found === undefined) return false
else return true
}

add(x: T): this {
const found = this.representatives.find((y) => this.equal(x, y))
if (found === undefined) {
this.representatives.push(x)
}

return this
}

delete(x: T): boolean {
const foundIndex = this.representatives.findIndex((y) => this.equal(x, y))
if (foundIndex === -1) {
return false
}

this.representatives.splice(foundIndex, 1)
return true
}
}

0 comments on commit 387b450

Please sign in to comment.