mod cedex;
pub(crate) mod france;
mod phonemicize;
use once_cell::sync::Lazy;
use super::{Boost, FieldSpec, Profile};
use crate::doc::Document;
use crate::text::{Synonyms, Token};
pub use phonemicize::phonemicize;
pub(crate) const SYNONYMS_SOURCE: &str = include_str!("synonyms.txt");
static SYNONYMS: Lazy<Synonyms> = Lazy::new(|| Synonyms::parse(SYNONYMS_SOURCE));
pub(crate) const FIELDS: &[FieldSpec] = &[
FieldSpec {
key: "name",
boost: Boost::Const(4.0),
required: true,
},
FieldSpec::new("street"),
FieldSpec {
key: "postcode",
boost: Boost::ByType {
doc_type: "municipality",
matched: 1.2,
otherwise: 1.0,
},
required: false,
},
FieldSpec::new("city"),
FieldSpec::new("context"),
FieldSpec::new("citycode"),
];
const FILTERS: &[&str] = &["source", "type", "citycode", "postcode"];
pub struct FrProfile {
_private: (),
}
impl FrProfile {
pub fn new() -> Self {
Self { _private: () }
}
}
impl Default for FrProfile {
fn default() -> Self {
Self::new()
}
}
impl Profile for FrProfile {
fn name(&self) -> &'static str {
"fr"
}
fn version(&self) -> u32 {
3
}
fn min_score(&self) -> f64 {
0.3
}
fn min_limit(&self) -> usize {
10
}
fn fields(&self) -> &[FieldSpec] {
FIELDS
}
fn filters(&self) -> &[&'static str] {
FILTERS
}
fn synonyms(&self) -> Option<&Synonyms> {
Some(&SYNONYMS)
}
fn process_query(&self, query: &str) -> String {
let query = france::extract_address(query);
let query = france::clean_query(&query);
france::remove_leading_zeros(&query)
}
fn postal(&self, query: &str) -> Option<super::Postal> {
cedex::postal(query)
}
fn process_tokens(&self, tokens: Vec<Token>) -> Vec<Token> {
let tokens = france::glue_ordinal(tokens);
let tokens: Vec<Token> = tokens.into_iter().map(france::fold_ordinal).collect();
let tokens = france::flag_housenumber(tokens);
let tokens = SYNONYMS.apply(tokens);
tokens
.into_iter()
.map(|t| t.with_value(phonemicize(&t.value)))
.collect()
}
fn make_labels(&self, doc: &Document, housenumber: Option<&str>) -> Vec<String> {
france::make_labels(doc, housenumber)
}
}