Skip to content

Commit

Permalink
Porting changes from Lukhnos Liu's Gramambular 2. (#74)
Browse files Browse the repository at this point in the history
* Also using MIT in lieu of MIT-NTL.
  • Loading branch information
ShikiSuen authored Aug 7, 2022
1 parent 0af1710 commit 26b5462
Show file tree
Hide file tree
Showing 21 changed files with 1,236 additions and 1,540 deletions.
34 changes: 18 additions & 16 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
MIT License

1. The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Copyright (c) 2022 and onwards Lukhnos Liu // The author of the C++ "Gramambular 2".
Swiftified by (c) 2022 and onwards The vChewing Project (MIT License).

2. No trademark license is granted to use the trade names, trademarks, service
marks, or product names of Contributor, except as required to fulfill notice
requirements above.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ MegrezTests.swift 檔案內的 SimpleLM 可以作為範例。
這裡只講幾個常用函式:

- 游標位置 `compositor.cursorIndex` 是可以賦值與取值的動態變數,且會在賦值內容為超出位置範圍的數值時自動修正。初期值為 0。
- `compositor.insertReading("gao1")` 可以在當前的游標位置插入讀音「gao1」。
- `compositor.dropReading(direction: .front)` 的作用是:朝著往文字輸入方向、砍掉一個與游標相鄰的讀音。反之,`dropReading(direction: .rear)` 則朝著與文字輸入方向相反的方向、砍掉一個與游標相鄰的讀音。
- `compositor.insertKey("gao1")` 可以在當前的游標位置插入讀音「gao1」。
- `compositor.dropKey(direction: .front)` 的作用是:朝著往文字輸入方向、砍掉一個與游標相鄰的讀音。反之,`dropKey(direction: .rear)` 則朝著與文字輸入方向相反的方向、砍掉一個與游標相鄰的讀音。
- 在威注音的術語體系當中,「文字輸入方向」為向前(Front)、與此相反的方向為向後(Rear)。
- `compositor.fixNodeWithCandidate(.init(key: "讀音", value: "候選字"), at: 游標位置)` 用來根據輸入法選中的候選字詞、據此更新當前游標位置選中的候選字詞節點當中的候選字詞。
- `compositor.overrideCandidate(.init(key: "讀音", value: "候選字"), at: 游標位置, overrideType: 覆寫模式)` 用來根據輸入法選中的候選字詞、據此更新當前游標位置選中的候選字詞節點當中的候選字詞。

輸入完內容之後,可以聲明一個用來接收結果的變數:

Expand All @@ -96,15 +96,15 @@ MegrezTests.swift 是輸入了很多內容之後再 walk 的。實際上一款
walk 之後的取值的方法及利用方法可以有很多種。這裡有其中的一個:

```swift
var composed: [String] = walked.map(\.node.currentPair.value)
var composed: [String] = walked.map(\.value)
print(composed)
```

類似於:

```swift
for phrase in walked {
composed.append(phrase.node.currentKeyValue.value)
composed.append(phrase.value)
}
print(composed)
```
Expand All @@ -118,7 +118,6 @@ walk 之後的取值的方法及利用方法可以有很多種。這裡有其中

## 著作權 (Credits)

- Swiftified and further development by (c) 2022 and onwards The vChewing Project (MIT-NTL License).
- Swiftified and further development by (c) 2022 and onwards The vChewing Project (MIT License).
- Swift programmer: Shiki Suen
- C++ migration review: Hiraku Wong
- Was initially rebranded from (c) Lukhnos Liu's C++ library "Gramambular" (MIT License).
- Was initially rebranded from (c) Lukhnos Liu's C++ library "Gramambular 2" (MIT License).
40 changes: 17 additions & 23 deletions Sources/Megrez/0_Megrez.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
// Swiftified by (c) 2022 and onwards The vChewing Project (MIT-NTL License).
// Rebranded from (c) Lukhnos Liu's C++ library "Gramambular" (MIT License).
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
// Swiftified by (c) 2022 and onwards The vChewing Project (MIT License).
// Rebranded from (c) Lukhnos Liu's C++ library "Gramambular 2" (MIT License).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)

1. The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
/// The namespace for this package.
public enum Megrez {
public typealias KeyValuePaired = Compositor.Candidate // 相容性措施。
}

2. No trademark license is granted to use the trade names, trademarks, service
marks, or product names of Contributor, except as required to fulfill notice
requirements above.
// 著作權聲明:
// 除了 Megrez 專有的修改與實作以外,該套件所有程式邏輯來自於 Gramambular、算法歸 Lukhnos Liu 所有。
// 天權星引擎(Megrez Compositor)僅僅是將 Gramambular 用 Swift 重寫之後繼續開發的結果而已。

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// 術語:

/// The namespace for this package.
public enum Megrez {}
// Grid: 節軌
// Walk: 爬軌
// Node: 節點
// SpanLength: 節幅
// Span: 幅位
Loading

0 comments on commit 26b5462

Please sign in to comment.