geocoder_core/profile/fr/
mod.rs1pub(crate) mod france;
9mod phonemicize;
10
11use once_cell::sync::Lazy;
12
13use super::{Boost, FieldSpec, Profile};
14use crate::doc::Document;
15use crate::text::{Synonyms, Token};
16
17pub use phonemicize::phonemicize;
18
19pub(crate) const SYNONYMS_SOURCE: &str = include_str!("synonyms.txt");
21
22static SYNONYMS: Lazy<Synonyms> = Lazy::new(|| Synonyms::parse(SYNONYMS_SOURCE));
23
24pub(crate) const FIELDS: &[FieldSpec] = &[
26 FieldSpec {
27 key: "name",
28 boost: Boost::Const(4.0),
29 required: true,
30 },
31 FieldSpec::new("street"),
32 FieldSpec {
33 key: "postcode",
34 boost: Boost::ByType {
35 doc_type: "municipality",
36 matched: 1.2,
37 otherwise: 1.0,
38 },
39 required: false,
40 },
41 FieldSpec::new("city"),
42 FieldSpec::new("context"),
43 FieldSpec::new("citycode"),
44];
45
46const FILTERS: &[&str] = &["source", "type", "citycode", "postcode"];
47
48pub struct FrProfile {
49 _private: (),
50}
51
52impl FrProfile {
53 pub fn new() -> Self {
54 Self { _private: () }
55 }
56}
57
58impl Default for FrProfile {
59 fn default() -> Self {
60 Self::new()
61 }
62}
63
64impl Profile for FrProfile {
65 fn name(&self) -> &'static str {
66 "fr"
67 }
68
69 fn version(&self) -> u32 {
70 3
71 }
72
73 fn min_score(&self) -> f64 {
74 0.3
75 }
76
77 fn min_limit(&self) -> usize {
80 10
81 }
82
83 fn fields(&self) -> &[FieldSpec] {
84 FIELDS
85 }
86
87 fn filters(&self) -> &[&'static str] {
88 FILTERS
89 }
90
91 fn synonyms(&self) -> Option<&Synonyms> {
92 Some(&SYNONYMS)
93 }
94
95 fn process_query(&self, query: &str) -> String {
97 let query = france::extract_address(query);
98 let query = france::clean_query(&query);
99 france::remove_leading_zeros(&query)
100 }
101
102 fn process_tokens(&self, tokens: Vec<Token>) -> Vec<Token> {
105 let tokens = france::glue_ordinal(tokens);
106 let tokens: Vec<Token> = tokens.into_iter().map(france::fold_ordinal).collect();
107 let tokens = france::flag_housenumber(tokens);
108 let tokens = SYNONYMS.apply(tokens);
109 tokens
110 .into_iter()
111 .map(|t| t.with_value(phonemicize(&t.value)))
112 .collect()
113 }
114
115 fn make_labels(&self, doc: &Document, housenumber: Option<&str>) -> Vec<String> {
116 france::make_labels(doc, housenumber)
117 }
118}