secure the api calling for the phonemizer service
This commit is contained in:
parent
3ba26023d0
commit
f14f90c141
|
@ -4,7 +4,6 @@ use autofeur::save::Save;
|
||||||
use kdam::tqdm;
|
use kdam::tqdm;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
/// Generates the DB file foe easy usage.
|
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let mut save = Save::default();
|
let mut save = Save::default();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use std::{env, ops::Add};
|
use std::{
|
||||||
|
env::{self, VarError},
|
||||||
|
ops::Add,
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use hypher::hyphenate;
|
use hypher::hyphenate;
|
||||||
|
@ -7,14 +10,13 @@ use itertools::Itertools;
|
||||||
use crate::save::Save;
|
use crate::save::Save;
|
||||||
|
|
||||||
async fn call_inference_service(word: &str) -> anyhow::Result<String> {
|
async fn call_inference_service(word: &str) -> anyhow::Result<String> {
|
||||||
let server: Result<String, anyhow::Error> =
|
let server: String = env::var("PHONEMIZER")
|
||||||
env::var("PHONEMIZER").or_else(|_| Ok("http://localhost:8000/".to_string()));
|
.or_else(|_| Ok::<String, VarError>("http://localhost:8000/".to_string()))
|
||||||
Ok(
|
.unwrap();
|
||||||
reqwest::get(format!("{}?grapheme={}", server.unwrap(), word))
|
|
||||||
.await?
|
let url = reqwest::Url::parse_with_params(&server, &[("grapheme", word)])?;
|
||||||
.text()
|
|
||||||
.await?,
|
Ok(reqwest::get(url).await?.text().await?)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Save<'_> {
|
impl Save<'_> {
|
||||||
|
@ -77,7 +79,7 @@ impl Save<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// we finally just need to compute the end of the word which matches the sound
|
// we finally just need to compute the end of the word which matches the sound
|
||||||
let found = completed_syllabes.drain(i+1..).join("");
|
let found = completed_syllabes.drain(i + 1..).join("");
|
||||||
println!("{} is equivalent to {}", completion, found);
|
println!("{} is equivalent to {}", completion, found);
|
||||||
|
|
||||||
Ok(format!("{} ({})", found, word))
|
Ok(format!("{} ({})", found, word))
|
||||||
|
|
|
@ -13,7 +13,6 @@ pub struct TrieNode<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TrieNode<'a> {
|
impl<'a> TrieNode<'a> {
|
||||||
// Create new node
|
|
||||||
pub fn new<'b>(is_final: bool) -> TrieNode<'b> {
|
pub fn new<'b>(is_final: bool) -> TrieNode<'b> {
|
||||||
TrieNode {
|
TrieNode {
|
||||||
is_final,
|
is_final,
|
||||||
|
|
Loading…
Reference in a new issue