1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::error::Error;
use std::fmt;
pub use crate::api::API;
pub struct Extractor {
api: API
}
impl Extractor {
pub fn new(url: &str) -> Extractor {
Extractor {
api: API::new(url)
}
}
pub async fn extract(&self, queue: &Vec<Question>, texts: &Vec<&str>) -> Answers {
let params = json!({"queue": queue, "texts": texts});
Ok(self.api.post("extract", ¶ms).await?.json().await?)
}
}
pub type Answers = Result<Vec<Answer>, Box<dyn Error>>;
#[derive(Debug, Serialize)]
pub struct Question {
pub name: String,
pub query: String,
pub question: String,
pub snippet: bool
}
#[derive(Debug, Deserialize)]
pub struct Answer {
pub name: String,
pub answer: String
}
impl fmt::Display for Answer {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} {}", self.name, self.answer)
}
}