BudouX Swift implementation.
BudouX is the machine learning powered line break organizer tool.
The original BudouX uses HTML markup to ensure that clauses are broken properly. BudouX.swift inserts a U+2060
(word joiner) and a U+200B
(zero width space) between each character and clause to ensure that Cocoa's UI component to do the line breaking properly.
Here is a sample project in this repository "Example.swiftpm".
CLI tool budoux-swift
contains in this repository as well.
You can get a list of phrases by feeding a sentence to the parser.
import BudouX
// Load Default Japanese Parser
let parser = Parser()
// Parse
print(parser.parse("ăăȘăă«ćŻăæ·»ăæć
端ăźăăŻăăăžăŒă"))
// ["ăăȘăă«", "ćŻăæ·»ă", "æć
端ăź", "ăăŻăăăžăŒă"]
You can also translate an Swift's String
with word joiners and zero width spaces for semantic line breaks.
import BudouX
// Load Default Japanese Parser
let parser = Parser()
let sample = "ăăȘăă«ćŻăæ·»ăæć
端ăźăăŻăăăžăŒă"
print(parser.translate(sentence: sample))
// ăâ ăȘâ ăâ ă«âćŻâ ăâ æ·»â ăâæâ ć
â 端â ăźâăâ ăŻâ ăâ ăâ ăžâ ăŒâ ă
Here's a convinience String extension method as well.
import BudouX
let sample = "ăăȘăă«ćŻăæ·»ăæć
端ăźăăŻăăăžăŒă"
print(sample.budouxed())
// ăâ ăȘâ ăâ ă«âćŻâ ăâ æ·»â ăâæâ ć
â 端â ăźâăâ ăŻâ ăâ ăâ ăžâ ăŒâ ă
If you need a function which translate an HTML string by wrapping phrases with non-breaking markup. Here's a support package for it.
griffin-stewie/HTMLBudouX.swift
SwiftUI.Text
You can also use methods for SwiftUI's Text
in iOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, and watchOS 6.0+.
import SwiftUI
import BudouX
struct ContentView: View {
static let content = "ăăźă€ăŒăăăŒăŽă©ăźăăăšăăŁăéąšăć€ă§ăćșă«ć·ăăăăă€éăăăăăă€ăăăæŁźă§éŁŸăăăăąăȘăŒăȘćžăéć€ăźăăăăăČăăèăźæłąă"
let swiftuiText: SwiftUI.Text = Text(content)
let budouxText: SwiftUI.Text = BudouXText(content)
var body: some View {
VStack {
swiftuiText
budouxText
}
.multilineTextAlignment(.center)
}
}
Support Swift Package Manager only. There are no plans to support other package management tools at this time.
package.append(
.package(url: "https://github.com/griffin-stewie/BudouX.swift", from: "0.7.0")
)
package.targets.append(
.target(name: "Foo", dependencies: [
.productItem(name: "BudouX", package: "BudouX.swift")
])
)
For this package maintainer, run following command to update Sources/BudouX/Data/JaKNBCModel.swift
and Sources/BudouX/Data/UnicodeBlocks.swift
from original BudouX.
make generate_data
link |
Stars: 44 |
Last commit: 5 weeks ago |
The implementation is now equivalent to the original BudouX v0.5.1.
Full Changelog: https://github.com/griffin-stewie/BudouX.swift/compare/v0.6.0...v0.7.0
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics