use crate::dictionary::dictionary_candidate::{CompletionCandidate, DictionaryCandidate};
use crate::dictionary::CompositeKey;
#[derive(Debug, Clone)]
pub struct Candidate {
pub(crate) midashi: String,
pub(crate) strict_okuri: Option<String>,
pub(crate) okuri: bool,
pub(crate) kouho_text: String,
pub(crate) annotation: Option<String>,
pub(crate) output: String,
}
impl Default for Candidate {
fn default() -> Self {
Candidate {
midashi: "エラー".to_string(),
strict_okuri: None,
okuri: false,
kouho_text: "エラー".to_string(),
annotation: None,
output: "エラー".to_string(),
}
}
}
impl PartialEq for Candidate {
fn eq(&self, other: &Self) -> bool {
if self.midashi.eq(&other.midashi) && self.kouho_text.eq(&other.kouho_text) {
return true;
}
false
}
}
impl Candidate {
pub(crate) fn new(
midashi: String,
strict_okuri: Option<String>,
okuri: bool,
kouho_text: String,
annotation: Option<String>,
output: String,
) -> Self {
Candidate {
midashi,
strict_okuri,
okuri,
kouho_text,
annotation,
output,
}
}
pub(in crate::dictionary) fn from_dictionary_candidate(
composite_key: &CompositeKey,
dictionary_cand: &DictionaryCandidate,
) -> Self {
Self {
midashi: composite_key.get_dict_key(),
strict_okuri: composite_key.get_okuri().to_owned(),
okuri: composite_key.has_okuri(),
kouho_text: dictionary_cand.kouho_text.to_owned(),
annotation: dictionary_cand.annotation.to_owned(),
output: dictionary_cand.kouho_text.to_owned(),
}
}
pub(in crate::dictionary) fn from_completion_candidate(
completion_candidate: &CompletionCandidate,
) -> Self {
Self {
midashi: completion_candidate.midashi.to_string(),
strict_okuri: completion_candidate.okuri.to_owned(),
okuri: completion_candidate.okuri.is_some(),
kouho_text: completion_candidate.kouho_text.to_owned(),
annotation: completion_candidate.annotation.to_owned(),
output: completion_candidate.kouho_text.to_owned(),
}
}
}