parattice

Crates.ioparattice
lib.rsparattice
version0.2.2
sourcesrc
created_at2020-06-22 06:39:02.934906
updated_at2020-06-22 10:17:31.638178
descriptionRecursive paraphrase lattice generator
homepage
repositoryhttps://github.com/chrovis/parattice/
max_upload_size
id256562
size77,753
Koichi Akabe (vbkaisetsu)

documentation

README

parattice: Recursive paraphrase lattice generator 🔄

This library takes a sentence and a paraphrase corpus, recursively finds paraphrases based on the corpus, expands the given sentence, and generates a paraphrase lattice.

This library also provides a method to search a phrase in the paraphrase lattice.

Example

This example generates a paraphrase lattice and searches a phrase in the generated lattice.

use parattice::Lattice;
use parattice::LatticeKMP;
use parattice::PaRattice;

// initialization
let paradict = vec![
    vec![
        vec!["blood", "stem", "cell"],
        vec!["造血", "幹", "細胞"],
        vec!["hematopoietic", "stem", "cell"],
    ],
    vec![
        vec!["造血", "幹", "細胞", "移植"],
        vec!["hematopoietic", "stem", "cell", "transplantation"],
    ],
    vec![vec!["stem", "cell"], vec!["幹", "細胞"]],
    vec![
        vec!["幹", "細胞", "移植"],
        vec!["rescue", "transplant"],
        vec!["stem", "cell", "rescue"],
    ],
    vec![vec!["rescue"], vec!["救命"]],
    vec![vec!["blood"], vec!["血液"]],
];
let parattice = PaRattice::new(paradict);

// lattice generation
let words = vec!["造血", "幹", "細胞", "移植"];
let lattice = parattice.get_lattice(&words, true, 2);

// dump a generated lattice
println!(lattice.dump_dot(true));

// serialization & deserialization
let bytes = lattice.to_bytes();
let new_lattice = Lattice::new_from_bytes(&bytes);

// search
let kmp = LatticeKMP::new(vec!["幹", "細胞"]);
let results = kmp.search(&new_lattice);
for result in &results {
    for edge in result {
        print!("({}, {}) ", edge.0, edge.1);
    }
    println!();
    let s = lattice.get_trunk_span(result.clone());
    for edge in &s {
        print!("({}, {}) ", edge.0, edge.1);
    }
    println!("\n===========");
}

Patents

License

Copyright 2020 Xcoo, Inc.

Licensed under the Apache License, Version 2.0.

Commit count: 7

cargo fmt