A MoonBit-native bilingual paragraph and sentence alignment toolkit with dynamic-programming based matching and a practical CLI.
moon check
moon test///|
test "basic alignment" {
let report = @moonalign.align(
"MoonBit favors maintainable tooling.\n", "MoonBit 强调可维护的工具链。\n",
)
inspect(report.pairs.length(), content="1")
inspect(report.pairs[0].move_kind, content="1-1")
}///|
let documents = @moonalign.synthetic_corpus(10)
///|
let results = @moonalign.align_corpus(documents)
///|
let summary = @moonalign.summarize_corpus(results)
///|
let review = @moonalign.make_review_queue(results[0])moon run cmd/main -- \
--source-text "MoonBit favors stable tooling. MoonAlign builds corpora." \
--target-text "MoonBit 强调稳定工具链。MoonAlign 用来构建语料。" \
--mode sentence \
--format json| 参数 | 说明 |
|---|---|
| --source-text <text> | 源语言文本 |
| --target-text <text> | 目标语言文本 |
| --mode sentence\|paragraph | 句子级或段落级切分,默认 sentence |
| --format json\|tsv | JSON 或 TSV 输出,默认 json |
| --benchmark | 运行内置离线基准并输出 JSON 指标 |
| --help | 显示帮助 |
moon run --target wasm-gc cmd/main -- --benchmarksource / target text
│
▼
normalization and segmentation
│
▼
weighted text units ─────── lexical anchors
│ │
└──────── dynamic programming alignment
│
▼
alignment report and metrics
│
┌──────────────────┼──────────────────┐
▼ ▼ ▼
JSON/TSV quality gate review queue| 数据集 | Precision | Recall | F1 | 覆盖率 |
|---|---|---|---|---|
| tatoeba-eng-cmn-short | 0.2500 | 0.2222 | 0.2353 | 1.0000 |
| tatoeba-eng-cmn-merge | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
moon fmt --check
moon check --target all --deny-warn
moon test --target wasm-gc --deny-warn
moon test --target native --deny-warn
moon infopub struct AlignOptions {
segment_mode : SegmentMode
max_fan_out : Int
join_penalty : Double
deviation_penalty : Double
min_sentence_chars : Int
preserve_paragraphs : Bool
} derive(Debug)pub struct AlignmentQuality {
source_units : Int
target_units : Int
aligned_pairs : Int
exact_one_to_one : Int
merged_pairs : Int
anchored_pairs : Int
source_coverage : Double
target_coverage : Double
mean_confidence : Double
monotonicity : Double
score : Double
issues : Array[QualityIssue]
} derive(ToJson, Debug)pub struct AnchorOptions {
min_token_length : Int
include_numbers : Bool
include_urls : Bool
include_identifiers : Bool
case_sensitive : Bool
max_anchors_per_unit : Int
} derive(Debug)pub struct BenchmarkResult {
name : String
metrics : AlignmentMetrics
warnings : Array[String]
} derive(ToJson, Debug)fn CorpusDocument::with_metadata(document : CorpusDocument, key~ : String, value~ : String) -> CorpusDocumentpub struct CorpusResult {
id : String
report : AlignmentReport
quality : AlignmentQuality
} derive(ToJson, Debug)pub struct QualityGate {
min_source_coverage : Double
min_target_coverage : Double
min_mean_confidence : Double
min_quality_score : Double
max_warning_count : Int
} derive(Debug)pub struct ReviewItem {
document_id : String
pair_index : Int
label : ReviewLabel
confidence : Double
reason : String
anchors : Int
} derive(ToJson, Debug)pub struct ReviewQueue {
items : Array[ReviewItem]
accepted : Int
needs_review : Int
rejected : Int
} derive(ToJson, Debug)fn align_texts(source_text : String, target_text : String, options? : AlignOptions) -> AlignmentReportfn align_units(source_units : Array[TextUnit], target_units : Array[TextUnit], options? : AlignOptions) -> AlignmentReportfn align_with_mode(source_text : String, target_text : String, mode? : SegmentMode) -> AlignmentReportfn gold_pair(source_start~ : Int, source_end~ : Int, target_start~ : Int, target_end~ : Int) -> GoldPairfn match_anchors(source_units : Array[TextUnit], target_units : Array[TextUnit], options? : AnchorOptions) -> Array[LexicalAnchor]fn quality_issue(code~ : String, severity~ : String, message~ : String, source_unit? : Int, target_unit? : Int) -> QualityIssueA MoonBit-native bilingual paragraph and sentence alignment toolkit with dynamic-programming based matching and a practical CLI.