-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #488 from YuukiToriyama/main
chimei-ruiju.orgへの対応: main(v0.1.21)との差分を取り込み
- Loading branch information
Showing
14 changed files
with
750 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct LatLng { | ||
/// 緯度 | ||
latitude: f64, | ||
/// 軽度 | ||
longitude: f64, | ||
pub(crate) latitude: f64, | ||
/// 経度 | ||
pub(crate) longitude: f64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//! 🚧 Experimental module 🚧 | ||
//! | ||
//! This module contains unstable functions. | ||
//! | ||
//! Please note that these functions may be removed or changed disruptively without any announcement. | ||
//! | ||
//! If you are eager to use this module, please enable `experimental` feature flag. | ||
|
||
mod parse_with_geolonia; | ||
pub mod parser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
use crate::api::AsyncApi; | ||
use crate::domain::common::token::Token; | ||
use crate::experimental::parser::Parser; | ||
use crate::tokenizer::Tokenizer; | ||
|
||
impl Parser { | ||
#[inline] | ||
pub(crate) async fn parse_with_geolonia(&self, address: &str) -> Vec<Token> { | ||
let geolonia_api = AsyncApi::default(); | ||
let tokenizer = Tokenizer::new(address); | ||
|
||
// 都道府県名の検出 | ||
let (prefecture, tokenizer) = match tokenizer.read_prefecture() { | ||
Ok(found) => found, | ||
Err(not_found) => { | ||
if self.options.verbose { | ||
log::error!("都道府県名の検出に失敗しました") | ||
} | ||
return not_found.tokens; | ||
} | ||
}; | ||
|
||
// 市区町村名の検出 | ||
let prefecture_master = match geolonia_api | ||
.get_prefecture_master(prefecture.name_ja()) | ||
.await | ||
{ | ||
Ok(result) => result, | ||
Err(error) => { | ||
if self.options.verbose { | ||
log::error!("{}", error.error_message) | ||
} | ||
return tokenizer.finish().tokens; | ||
} | ||
}; | ||
let (city_name, tokenizer) = match tokenizer.read_city(&prefecture_master.cities) { | ||
Ok(found) => found, | ||
Err(not_found) => { | ||
if self.options.correct_incomplete_city_names { | ||
match not_found.read_city_with_county_name_completion(&prefecture_master.cities) | ||
{ | ||
Ok(result) => result, | ||
Err(not_found) => { | ||
if self.options.verbose { | ||
log::error!("市区町村名の検出に失敗しました") | ||
} | ||
return not_found.tokens; | ||
} | ||
} | ||
} else { | ||
if self.options.verbose { | ||
log::error!("市区町村名の検出に失敗しました") | ||
} | ||
return not_found.finish().tokens; | ||
} | ||
} | ||
}; | ||
|
||
// 町名の検出 | ||
let city_master = match geolonia_api | ||
.get_city_master(prefecture.name_ja(), &city_name) | ||
.await | ||
{ | ||
Ok(result) => result, | ||
Err(error) => { | ||
if self.options.verbose { | ||
log::error!("{}", error.error_message) | ||
} | ||
return tokenizer.finish().tokens; | ||
} | ||
}; | ||
let (_, tokenizer) = | ||
match tokenizer.read_town(city_master.towns.iter().map(|x| x.name.clone()).collect()) { | ||
Ok(found) => found, | ||
Err(not_found) => { | ||
if self.options.verbose { | ||
log::error!("町名の検出に失敗しました") | ||
} | ||
return not_found.tokens; | ||
} | ||
}; | ||
|
||
tokenizer.finish().tokens | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::domain::common::token::{City, Prefecture, Token, Town}; | ||
use crate::experimental::parser::{DataSource, Parser, ParserOptions}; | ||
|
||
#[tokio::test] | ||
async fn 都道府県名が誤っている場合() { | ||
let parser = Parser { | ||
options: ParserOptions { | ||
data_source: DataSource::Geolonia, | ||
correct_incomplete_city_names: false, | ||
verbose: false, | ||
}, | ||
}; | ||
let result = parser | ||
.parse_with_geolonia("奈川県横浜市磯子区洋光台3-10-3") | ||
.await; | ||
assert_eq!( | ||
result, | ||
vec![Token::Rest("奈川県横浜市磯子区洋光台3-10-3".to_string())] | ||
) | ||
} | ||
|
||
#[tokio::test] | ||
async fn 市区町村名が誤っている場合() { | ||
let parser = Parser { | ||
options: ParserOptions { | ||
data_source: DataSource::Geolonia, | ||
correct_incomplete_city_names: false, | ||
verbose: false, | ||
}, | ||
}; | ||
let result = parser | ||
.parse_with_geolonia("神奈川県横浜県磯子市洋光台3-10-3") | ||
.await; | ||
assert_eq!( | ||
result, | ||
vec![ | ||
Token::Prefecture(Prefecture { | ||
prefecture_name: "神奈川県".to_string(), | ||
representative_point: None, | ||
}), | ||
Token::Rest("横浜県磯子市洋光台3-10-3".to_string()) | ||
] | ||
) | ||
} | ||
|
||
#[tokio::test] | ||
async fn 町名が誤っている場合() { | ||
let parser = Parser { | ||
options: ParserOptions { | ||
data_source: DataSource::Geolonia, | ||
correct_incomplete_city_names: false, | ||
verbose: false, | ||
}, | ||
}; | ||
let result = parser | ||
.parse_with_geolonia("神奈川県横浜市磯子区陽光台3-10-3") | ||
.await; | ||
assert_eq!( | ||
result, | ||
vec![ | ||
Token::Prefecture(Prefecture { | ||
prefecture_name: "神奈川県".to_string(), | ||
representative_point: None, | ||
}), | ||
Token::City(City { | ||
city_name: "横浜市磯子区".to_string(), | ||
representative_point: None, | ||
}), | ||
Token::Rest("陽光台3-10-3".to_string()) | ||
] | ||
) | ||
} | ||
|
||
#[tokio::test] | ||
async fn パースに成功した場合() { | ||
let parser = Parser { | ||
options: ParserOptions { | ||
data_source: DataSource::Geolonia, | ||
correct_incomplete_city_names: false, | ||
verbose: false, | ||
}, | ||
}; | ||
let result = parser | ||
.parse_with_geolonia("神奈川県横浜市磯子区洋光台3-10-3") | ||
.await; | ||
assert_eq!( | ||
result, | ||
vec![ | ||
Token::Prefecture(Prefecture { | ||
prefecture_name: "神奈川県".to_string(), | ||
representative_point: None, | ||
}), | ||
Token::City(City { | ||
city_name: "横浜市磯子区".to_string(), | ||
representative_point: None, | ||
}), | ||
Token::Town(Town { | ||
town_name: "洋光台三丁目".to_string(), | ||
representative_point: None, | ||
}), | ||
Token::Rest("10-3".to_string()) | ||
] | ||
) | ||
} | ||
} |
Oops, something went wrong.