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