From cf889a62e8667fd7c438bc03385f5aed786b4a96 Mon Sep 17 00:00:00 2001 From: ToriChan Date: Mon, 4 Nov 2024 12:13:14 +0900 Subject: [PATCH 01/12] =?UTF-8?q?Token=E3=81=AE=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF:=20`Token::Town`=E3=81=AB=E6=A0=BC=E7=B4=8D?= =?UTF-8?q?=E3=81=99=E3=82=8B=E5=80=A4=E3=81=AE=E5=9E=8B=E3=82=92`Town`?= =?UTF-8?q?=E3=81=8B=E3=82=89`String`=E3=81=AB=E5=A4=89=E6=9B=B4=20(#500)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update: #498: `Token::Town`に格納する値の型を`Town`から`String`に変更 * update: #498: 構造体`Town`を削除 --- core/src/domain/common/token.rs | 20 ++++------------ .../experimental/parse_with_chimeiruiju.rs | 7 ++---- core/src/experimental/parse_with_geolonia.rs | 7 ++---- core/src/experimental/parser.rs | 24 +++++++------------ core/src/parser.rs | 2 +- core/src/tokenizer/read_town.rs | 10 ++------ 6 files changed, 20 insertions(+), 50 deletions(-) diff --git a/core/src/domain/common/token.rs b/core/src/domain/common/token.rs index a53107b7..45afc88a 100644 --- a/core/src/domain/common/token.rs +++ b/core/src/domain/common/token.rs @@ -6,7 +6,7 @@ use std::cmp::Ordering::{Equal, Greater, Less}; pub enum Token { Prefecture(Prefecture), City(City), - Town(Town), + Town(String), Rest(String), } @@ -53,19 +53,13 @@ pub(crate) struct City { pub(crate) representative_point: Option, } -#[derive(Debug, PartialEq, Clone)] -pub(crate) struct Town { - pub(crate) town_name: String, - pub(crate) representative_point: Option, -} - pub(crate) fn append_token(tokens: &[Token], token: Token) -> Vec { [tokens.to_owned(), vec![token]].concat() } #[cfg(test)] mod tests { - use crate::domain::common::token::{City, Prefecture, Token, Town}; + use crate::domain::common::token::{City, Prefecture, Token}; #[test] fn sort_token_vector() { @@ -79,10 +73,7 @@ mod tests { prefecture_name: "東京都".to_string(), representative_point: None, }), - Token::Town(Town { - town_name: "貫井北町四丁目".to_string(), - representative_point: None, - }), + Token::Town("貫井北町四丁目".to_string()), ]; tokens.sort_by(|a, b| a.partial_cmp(b).unwrap()); assert_eq!( @@ -96,10 +87,7 @@ mod tests { city_name: "小金井市".to_string(), representative_point: None, }), - Token::Town(Town { - town_name: "貫井北町四丁目".to_string(), - representative_point: None, - }), + Token::Town("貫井北町四丁目".to_string()), Token::Rest("2-1".to_string()), ] ); diff --git a/core/src/experimental/parse_with_chimeiruiju.rs b/core/src/experimental/parse_with_chimeiruiju.rs index df55a85e..5bb00282 100644 --- a/core/src/experimental/parse_with_chimeiruiju.rs +++ b/core/src/experimental/parse_with_chimeiruiju.rs @@ -100,7 +100,7 @@ impl Parser { #[cfg(test)] mod tests { - use crate::domain::common::token::{City, Prefecture, Token, Town}; + use crate::domain::common::token::{City, Prefecture, Token}; use crate::experimental::parser::{DataSource, Parser, ParserOptions}; #[tokio::test] @@ -196,10 +196,7 @@ mod tests { city_name: "横浜市磯子区".to_string(), representative_point: None, }), - Token::Town(Town { - town_name: "洋光台三丁目".to_string(), - representative_point: None, - }), + Token::Town("洋光台三丁目".to_string()), Token::Rest("10-3".to_string()) ] ) diff --git a/core/src/experimental/parse_with_geolonia.rs b/core/src/experimental/parse_with_geolonia.rs index a15b9a41..1d098225 100644 --- a/core/src/experimental/parse_with_geolonia.rs +++ b/core/src/experimental/parse_with_geolonia.rs @@ -86,7 +86,7 @@ impl Parser { #[cfg(test)] mod tests { - use crate::domain::common::token::{City, Prefecture, Token, Town}; + use crate::domain::common::token::{City, Prefecture, Token}; use crate::experimental::parser::{DataSource, Parser, ParserOptions}; #[tokio::test] @@ -182,10 +182,7 @@ mod tests { city_name: "横浜市磯子区".to_string(), representative_point: None, }), - Token::Town(Town { - town_name: "洋光台三丁目".to_string(), - representative_point: None, - }), + Token::Town("洋光台三丁目".to_string()), Token::Rest("10-3".to_string()) ] ) diff --git a/core/src/experimental/parser.rs b/core/src/experimental/parser.rs index 105192fe..13d778cd 100644 --- a/core/src/experimental/parser.rs +++ b/core/src/experimental/parser.rs @@ -168,13 +168,9 @@ impl From> for ParsedAddress { parsed_address.metadata.longitude = Some(lat_lng.longitude); } } - Token::Town(town) => { - parsed_address.town = town.town_name; + Token::Town(town_name) => { + parsed_address.town = town_name; parsed_address.metadata.depth = 3; - if let Some(lat_lng) = town.representative_point { - parsed_address.metadata.latitude = Some(lat_lng.latitude); - parsed_address.metadata.longitude = Some(lat_lng.longitude); - } } Token::Rest(rest) => { parsed_address.rest = rest; @@ -200,7 +196,7 @@ impl From<(Vec, Option)> for ParsedAddress { #[cfg(test)] mod tests { use crate::domain::common::latlng::LatLng; - use crate::domain::common::token::{City, Prefecture, Token, Town}; + use crate::domain::common::token::{City, Prefecture, Token}; use crate::experimental::parser::{Metadata, ParsedAddress}; #[test] @@ -307,16 +303,14 @@ mod tests { longitude: 35.708143, }), }), - Token::Town(Town { - town_name: "本駒込六丁目".to_string(), - representative_point: Some(LatLng { - latitude: 139.738043, - longitude: 35.72791, - }), - }), + Token::Town("本駒込六丁目".to_string()), Token::Rest("16-3".to_string()), ]; - let parsed_address = ParsedAddress::from(tokens); + let lat_lng = Some(LatLng { + latitude: 139.738043, + longitude: 35.72791, + }); + let parsed_address = ParsedAddress::from((tokens, lat_lng)); assert_eq!( parsed_address, ParsedAddress { diff --git a/core/src/parser.rs b/core/src/parser.rs index d9229091..29ebe61b 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -18,7 +18,7 @@ impl From> for Address { match token { Token::Prefecture(prefecture) => address.prefecture = prefecture.prefecture_name, Token::City(city) => address.city = city.city_name, - Token::Town(town) => address.town = town.town_name, + Token::Town(town_name) => address.town = town_name, Token::Rest(rest) => address.rest = rest, } } diff --git a/core/src/tokenizer/read_town.rs b/core/src/tokenizer/read_town.rs index 2421e39f..9c53bad8 100644 --- a/core/src/tokenizer/read_town.rs +++ b/core/src/tokenizer/read_town.rs @@ -1,4 +1,4 @@ -use crate::domain::common::token::{append_token, Token, Town}; +use crate::domain::common::token::{append_token, Token}; use crate::formatter::chome_with_arabic_numerals::format_chome_with_arabic_numerals; use crate::formatter::fullwidth_character::format_fullwidth_number; use crate::formatter::house_number::format_house_number; @@ -39,13 +39,7 @@ impl Tokenizer { Ok(( town_name.clone(), Tokenizer { - tokens: append_token( - &self.tokens, - Token::Town(Town { - town_name, - representative_point: None, - }), - ), + tokens: append_token(&self.tokens, Token::Town(town_name)), rest: if cfg!(feature = "format-house-number") && format_house_number(&rest).is_ok() { format_house_number(&rest).unwrap() From 8d4087dc538936ce2d24cc5b15569bacd4270fad Mon Sep 17 00:00:00 2001 From: ToriChan Date: Mon, 4 Nov 2024 12:46:26 +0900 Subject: [PATCH 02/12] =?UTF-8?q?Token=E3=81=AE=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF:=20`Token::City`=E3=81=AB=E6=A0=BC=E7=B4=8D?= =?UTF-8?q?=E3=81=99=E3=82=8B=E5=80=A4=E3=81=AE=E5=9E=8B=E3=82=92`City`?= =?UTF-8?q?=E3=81=8B=E3=82=89`String`=E3=81=AB=E5=A4=89=E6=9B=B4=20(#501)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update: #498: `Token::City`に格納する値の型を`City`から`String`に変更 * update: #498: 構造体`City`を削除 --- core/src/domain/common/token.rs | 20 +++--------- .../experimental/parse_with_chimeiruiju.rs | 12 ++----- core/src/experimental/parse_with_geolonia.rs | 12 ++----- core/src/experimental/parser.rs | 32 ++++++------------- core/src/parser.rs | 2 +- core/src/tokenizer/read_city.rs | 18 ++--------- .../read_city_with_county_name_completion.rs | 10 ++---- core/src/tokenizer/read_town.rs | 27 ++++------------ 8 files changed, 32 insertions(+), 101 deletions(-) diff --git a/core/src/domain/common/token.rs b/core/src/domain/common/token.rs index 45afc88a..1398c75d 100644 --- a/core/src/domain/common/token.rs +++ b/core/src/domain/common/token.rs @@ -5,7 +5,7 @@ use std::cmp::Ordering::{Equal, Greater, Less}; #[derive(Clone, Debug, PartialEq)] pub enum Token { Prefecture(Prefecture), - City(City), + City(String), Town(String), Rest(String), } @@ -47,28 +47,19 @@ pub(crate) struct Prefecture { pub(crate) representative_point: Option, } -#[derive(Debug, PartialEq, Clone)] -pub(crate) struct City { - pub(crate) city_name: String, - pub(crate) representative_point: Option, -} - pub(crate) fn append_token(tokens: &[Token], token: Token) -> Vec { [tokens.to_owned(), vec![token]].concat() } #[cfg(test)] mod tests { - use crate::domain::common::token::{City, Prefecture, Token}; + use crate::domain::common::token::{Prefecture, Token}; #[test] fn sort_token_vector() { let mut tokens = vec![ Token::Rest("2-1".to_string()), - Token::City(City { - city_name: "小金井市".to_string(), - representative_point: None, - }), + Token::City("小金井市".to_string()), Token::Prefecture(Prefecture { prefecture_name: "東京都".to_string(), representative_point: None, @@ -83,10 +74,7 @@ mod tests { prefecture_name: "東京都".to_string(), representative_point: None, }), - Token::City(City { - city_name: "小金井市".to_string(), - representative_point: None, - }), + Token::City("小金井市".to_string()), Token::Town("貫井北町四丁目".to_string()), Token::Rest("2-1".to_string()), ] diff --git a/core/src/experimental/parse_with_chimeiruiju.rs b/core/src/experimental/parse_with_chimeiruiju.rs index 5bb00282..691040fd 100644 --- a/core/src/experimental/parse_with_chimeiruiju.rs +++ b/core/src/experimental/parse_with_chimeiruiju.rs @@ -100,7 +100,7 @@ impl Parser { #[cfg(test)] mod tests { - use crate::domain::common::token::{City, Prefecture, Token}; + use crate::domain::common::token::{Prefecture, Token}; use crate::experimental::parser::{DataSource, Parser, ParserOptions}; #[tokio::test] @@ -164,10 +164,7 @@ mod tests { prefecture_name: "神奈川県".to_string(), representative_point: None, }), - Token::City(City { - city_name: "横浜市磯子区".to_string(), - representative_point: None, - }), + Token::City("横浜市磯子区".to_string()), Token::Rest("陽光台3-10-3".to_string()) ] ) @@ -192,10 +189,7 @@ mod tests { prefecture_name: "神奈川県".to_string(), representative_point: None, }), - Token::City(City { - city_name: "横浜市磯子区".to_string(), - representative_point: None, - }), + Token::City("横浜市磯子区".to_string()), Token::Town("洋光台三丁目".to_string()), Token::Rest("10-3".to_string()) ] diff --git a/core/src/experimental/parse_with_geolonia.rs b/core/src/experimental/parse_with_geolonia.rs index 1d098225..a08e3978 100644 --- a/core/src/experimental/parse_with_geolonia.rs +++ b/core/src/experimental/parse_with_geolonia.rs @@ -86,7 +86,7 @@ impl Parser { #[cfg(test)] mod tests { - use crate::domain::common::token::{City, Prefecture, Token}; + use crate::domain::common::token::{Prefecture, Token}; use crate::experimental::parser::{DataSource, Parser, ParserOptions}; #[tokio::test] @@ -150,10 +150,7 @@ mod tests { prefecture_name: "神奈川県".to_string(), representative_point: None, }), - Token::City(City { - city_name: "横浜市磯子区".to_string(), - representative_point: None, - }), + Token::City("横浜市磯子区".to_string()), Token::Rest("陽光台3-10-3".to_string()) ] ) @@ -178,10 +175,7 @@ mod tests { prefecture_name: "神奈川県".to_string(), representative_point: None, }), - Token::City(City { - city_name: "横浜市磯子区".to_string(), - representative_point: None, - }), + Token::City("横浜市磯子区".to_string()), Token::Town("洋光台三丁目".to_string()), Token::Rest("10-3".to_string()) ] diff --git a/core/src/experimental/parser.rs b/core/src/experimental/parser.rs index 13d778cd..54dccd60 100644 --- a/core/src/experimental/parser.rs +++ b/core/src/experimental/parser.rs @@ -160,13 +160,9 @@ impl From> for ParsedAddress { parsed_address.metadata.longitude = Some(lat_lng.longitude); } } - Token::City(city) => { - parsed_address.city = city.city_name; + Token::City(city_name) => { + parsed_address.city = city_name; parsed_address.metadata.depth = 2; - if let Some(lat_lng) = city.representative_point { - parsed_address.metadata.latitude = Some(lat_lng.latitude); - parsed_address.metadata.longitude = Some(lat_lng.longitude); - } } Token::Town(town_name) => { parsed_address.town = town_name; @@ -196,7 +192,7 @@ impl From<(Vec, Option)> for ParsedAddress { #[cfg(test)] mod tests { use crate::domain::common::latlng::LatLng; - use crate::domain::common::token::{City, Prefecture, Token}; + use crate::domain::common::token::{Prefecture, Token}; use crate::experimental::parser::{Metadata, ParsedAddress}; #[test] @@ -260,16 +256,14 @@ mod tests { longitude: 35.68532, }), }), - Token::City(City { - city_name: "台東区".to_string(), - representative_point: Some(LatLng { - latitude: 139.764379, - longitude: 35.711162, - }), - }), + Token::City("台東区".to_string()), Token::Rest("".to_string()), ]; - let parsed_address = ParsedAddress::from(tokens); + let lat_lng = Some(LatLng { + latitude: 139.764379, + longitude: 35.711162, + }); + let parsed_address = ParsedAddress::from((tokens, lat_lng)); assert_eq!( parsed_address, ParsedAddress { @@ -296,13 +290,7 @@ mod tests { longitude: 35.68532, }), }), - Token::City(City { - city_name: "文京区".to_string(), - representative_point: Some(LatLng { - latitude: 139.749542, - longitude: 35.708143, - }), - }), + Token::City("文京区".to_string()), Token::Town("本駒込六丁目".to_string()), Token::Rest("16-3".to_string()), ]; diff --git a/core/src/parser.rs b/core/src/parser.rs index 29ebe61b..8d12b072 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -17,7 +17,7 @@ impl From> for Address { for token in value.tokens { match token { Token::Prefecture(prefecture) => address.prefecture = prefecture.prefecture_name, - Token::City(city) => address.city = city.city_name, + Token::City(city_name) => address.city = city_name, Token::Town(town_name) => address.town = town_name, Token::Rest(rest) => address.rest = rest, } diff --git a/core/src/tokenizer/read_city.rs b/core/src/tokenizer/read_city.rs index ba98fbc2..ea1d7630 100644 --- a/core/src/tokenizer/read_city.rs +++ b/core/src/tokenizer/read_city.rs @@ -1,4 +1,4 @@ -use crate::domain::common::token::{append_token, City, Token}; +use crate::domain::common::token::{append_token, Token}; use crate::parser::adapter::orthographical_variant_adapter::{ OrthographicalVariantAdapter, OrthographicalVariants, Variant, }; @@ -17,13 +17,7 @@ impl Tokenizer { return Ok(( found.to_string(), Tokenizer { - tokens: append_token( - &self.tokens, - Token::City(City { - city_name: found.to_string(), - representative_point: None, - }), - ), + tokens: append_token(&self.tokens, Token::City(found.to_string())), rest: self .rest .chars() @@ -69,13 +63,7 @@ impl Tokenizer { return Ok(( city_name.clone(), Tokenizer { - tokens: append_token( - &self.tokens, - Token::City(City { - city_name, - representative_point: None, - }), - ), + tokens: append_token(&self.tokens, Token::City(city_name)), rest, _state: PhantomData::, }, diff --git a/core/src/tokenizer/read_city_with_county_name_completion.rs b/core/src/tokenizer/read_city_with_county_name_completion.rs index f00a06d5..c393fe3c 100644 --- a/core/src/tokenizer/read_city_with_county_name_completion.rs +++ b/core/src/tokenizer/read_city_with_county_name_completion.rs @@ -1,4 +1,4 @@ -use crate::domain::common::token::{append_token, City, Token}; +use crate::domain::common::token::{append_token, Token}; use crate::tokenizer::{CityNameFound, CityNameNotFound, End, Tokenizer}; use crate::util::sequence_matcher::SequenceMatcher; use std::marker::PhantomData; @@ -15,13 +15,7 @@ impl Tokenizer { return Ok(( highest_match.clone(), Tokenizer { - tokens: append_token( - &self.tokens, - Token::City(City { - city_name: highest_match.clone(), - representative_point: None, - }), - ), + tokens: append_token(&self.tokens, Token::City(highest_match.clone())), rest: complemented_address .chars() .skip(highest_match.chars().count()) diff --git a/core/src/tokenizer/read_town.rs b/core/src/tokenizer/read_town.rs index 9c53bad8..92981728 100644 --- a/core/src/tokenizer/read_town.rs +++ b/core/src/tokenizer/read_town.rs @@ -101,7 +101,7 @@ fn find_town(input: &str, candidates: &Vec) -> Option<(String, String)> #[cfg(test)] mod tests { - use crate::domain::common::token::{City, Prefecture, Token}; + use crate::domain::common::token::{Prefecture, Token}; use crate::tokenizer::{CityNameFound, Tokenizer}; use std::marker::PhantomData; @@ -113,10 +113,7 @@ mod tests { prefecture_name: "静岡県".to_string(), representative_point: None, }), - Token::City(City { - city_name: "静岡市清水区".to_string(), - representative_point: None, - }), + Token::City("静岡市清水区".to_string()), ], rest: "旭町6番8号".to_string(), _state: PhantomData::, @@ -143,10 +140,7 @@ mod tests { prefecture_name: "東京都".to_string(), representative_point: None, }), - Token::City(City { - city_name: "千代田区".to_string(), - representative_point: None, - }), + Token::City("千代田区".to_string()), ], rest: "一ッ橋二丁目1番".to_string(), // 「ッ」と「ツ」の表記ゆれ _state: PhantomData::, @@ -173,10 +167,7 @@ mod tests { prefecture_name: "京都府".to_string(), representative_point: None, }), - Token::City(City { - city_name: "京都市東山区".to_string(), - representative_point: None, - }), + Token::City("京都市東山区".to_string()), ], rest: "本町22丁目489番".to_string(), _state: PhantomData::, @@ -204,10 +195,7 @@ mod tests { prefecture_name: "東京都".to_string(), representative_point: None, }), - Token::City(City { - city_name: "西多摩郡日の出町".to_string(), - representative_point: None, - }), + Token::City("西多摩郡日の出町".to_string()), ], rest: "平井2780番地".to_string(), // 「大字」が省略されている _state: PhantomData::, @@ -228,10 +216,7 @@ mod tests { prefecture_name: "静岡県".to_string(), representative_point: None, }), - Token::City(City { - city_name: "静岡市清水区".to_string(), - representative_point: None, - }), + Token::City("静岡市清水区".to_string()), ], rest: "".to_string(), _state: PhantomData::, From ade7a13fe2a4ad05cd79a7cc5431a1832a97eb0d Mon Sep 17 00:00:00 2001 From: ToriChan Date: Mon, 4 Nov 2024 13:16:31 +0900 Subject: [PATCH 03/12] =?UTF-8?q?Token=E3=81=AE=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF:=20`Token::Prefecture`=E3=81=AB=E6=A0=BC?= =?UTF-8?q?=E7=B4=8D=E3=81=99=E3=82=8B=E5=80=A4=E3=81=AE=E5=9E=8B=E3=82=92?= =?UTF-8?q?`Prefecture`=E3=81=8B=E3=82=89`String`=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=20(#502)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update: #498: `Token::Prefecture`に格納する値の型を`Prefecture`からStringに変更 * update: #498: 構造体`Prefecture`を削除 --- core/src/domain/common/token.rs | 21 ++-------- .../experimental/parse_with_chimeiruiju.rs | 17 ++------ core/src/experimental/parse_with_geolonia.rs | 17 ++------ core/src/experimental/parser.rs | 40 +++++-------------- core/src/parser.rs | 2 +- core/src/tokenizer.rs | 4 +- core/src/tokenizer/read_city.rs | 17 ++------ .../read_city_with_county_name_completion.rs | 37 ++++------------- core/src/tokenizer/read_prefecture.rs | 7 +--- core/src/tokenizer/read_town.rs | 27 +++---------- 10 files changed, 46 insertions(+), 143 deletions(-) diff --git a/core/src/domain/common/token.rs b/core/src/domain/common/token.rs index 1398c75d..a7c63abb 100644 --- a/core/src/domain/common/token.rs +++ b/core/src/domain/common/token.rs @@ -1,10 +1,9 @@ -use crate::domain::common::latlng::LatLng; use std::cmp::Ordering; use std::cmp::Ordering::{Equal, Greater, Less}; #[derive(Clone, Debug, PartialEq)] pub enum Token { - Prefecture(Prefecture), + Prefecture(String), City(String), Town(String), Rest(String), @@ -41,39 +40,27 @@ impl PartialOrd for Token { } } -#[derive(Debug, PartialEq, Clone)] -pub(crate) struct Prefecture { - pub(crate) prefecture_name: String, - pub(crate) representative_point: Option, -} - pub(crate) fn append_token(tokens: &[Token], token: Token) -> Vec { [tokens.to_owned(), vec![token]].concat() } #[cfg(test)] mod tests { - use crate::domain::common::token::{Prefecture, Token}; + use crate::domain::common::token::Token; #[test] fn sort_token_vector() { let mut tokens = vec![ Token::Rest("2-1".to_string()), Token::City("小金井市".to_string()), - Token::Prefecture(Prefecture { - prefecture_name: "東京都".to_string(), - representative_point: None, - }), + Token::Prefecture("東京都".to_string()), Token::Town("貫井北町四丁目".to_string()), ]; tokens.sort_by(|a, b| a.partial_cmp(b).unwrap()); assert_eq!( tokens, vec![ - Token::Prefecture(Prefecture { - prefecture_name: "東京都".to_string(), - representative_point: None, - }), + Token::Prefecture("東京都".to_string()), Token::City("小金井市".to_string()), Token::Town("貫井北町四丁目".to_string()), Token::Rest("2-1".to_string()), diff --git a/core/src/experimental/parse_with_chimeiruiju.rs b/core/src/experimental/parse_with_chimeiruiju.rs index 691040fd..b04efede 100644 --- a/core/src/experimental/parse_with_chimeiruiju.rs +++ b/core/src/experimental/parse_with_chimeiruiju.rs @@ -100,7 +100,7 @@ impl Parser { #[cfg(test)] mod tests { - use crate::domain::common::token::{Prefecture, Token}; + use crate::domain::common::token::Token; use crate::experimental::parser::{DataSource, Parser, ParserOptions}; #[tokio::test] @@ -136,10 +136,7 @@ mod tests { assert_eq!( tokens, vec![ - Token::Prefecture(Prefecture { - prefecture_name: "神奈川県".to_string(), - representative_point: None, - }), + Token::Prefecture("神奈川県".to_string()), Token::Rest("横浜県磯子市洋光台3-10-3".to_string()) ] ) @@ -160,10 +157,7 @@ mod tests { assert_eq!( tokens, vec![ - Token::Prefecture(Prefecture { - prefecture_name: "神奈川県".to_string(), - representative_point: None, - }), + Token::Prefecture("神奈川県".to_string()), Token::City("横浜市磯子区".to_string()), Token::Rest("陽光台3-10-3".to_string()) ] @@ -185,10 +179,7 @@ mod tests { assert_eq!( tokens, vec![ - Token::Prefecture(Prefecture { - prefecture_name: "神奈川県".to_string(), - representative_point: None, - }), + Token::Prefecture("神奈川県".to_string()), Token::City("横浜市磯子区".to_string()), Token::Town("洋光台三丁目".to_string()), Token::Rest("10-3".to_string()) diff --git a/core/src/experimental/parse_with_geolonia.rs b/core/src/experimental/parse_with_geolonia.rs index a08e3978..043dd513 100644 --- a/core/src/experimental/parse_with_geolonia.rs +++ b/core/src/experimental/parse_with_geolonia.rs @@ -86,7 +86,7 @@ impl Parser { #[cfg(test)] mod tests { - use crate::domain::common::token::{Prefecture, Token}; + use crate::domain::common::token::Token; use crate::experimental::parser::{DataSource, Parser, ParserOptions}; #[tokio::test] @@ -122,10 +122,7 @@ mod tests { assert_eq!( result, vec![ - Token::Prefecture(Prefecture { - prefecture_name: "神奈川県".to_string(), - representative_point: None, - }), + Token::Prefecture("神奈川県".to_string()), Token::Rest("横浜県磯子市洋光台3-10-3".to_string()) ] ) @@ -146,10 +143,7 @@ mod tests { assert_eq!( result, vec![ - Token::Prefecture(Prefecture { - prefecture_name: "神奈川県".to_string(), - representative_point: None, - }), + Token::Prefecture("神奈川県".to_string()), Token::City("横浜市磯子区".to_string()), Token::Rest("陽光台3-10-3".to_string()) ] @@ -171,10 +165,7 @@ mod tests { assert_eq!( result, vec![ - Token::Prefecture(Prefecture { - prefecture_name: "神奈川県".to_string(), - representative_point: None, - }), + Token::Prefecture("神奈川県".to_string()), Token::City("横浜市磯子区".to_string()), Token::Town("洋光台三丁目".to_string()), Token::Rest("10-3".to_string()) diff --git a/core/src/experimental/parser.rs b/core/src/experimental/parser.rs index 54dccd60..3384746d 100644 --- a/core/src/experimental/parser.rs +++ b/core/src/experimental/parser.rs @@ -152,13 +152,9 @@ impl From> for ParsedAddress { for token in value { match token { - Token::Prefecture(prefecture) => { - parsed_address.prefecture = prefecture.prefecture_name; + Token::Prefecture(prefecture_name) => { + parsed_address.prefecture = prefecture_name; parsed_address.metadata.depth = 1; - if let Some(lat_lng) = prefecture.representative_point { - parsed_address.metadata.latitude = Some(lat_lng.latitude); - parsed_address.metadata.longitude = Some(lat_lng.longitude); - } } Token::City(city_name) => { parsed_address.city = city_name; @@ -192,7 +188,7 @@ impl From<(Vec, Option)> for ParsedAddress { #[cfg(test)] mod tests { use crate::domain::common::latlng::LatLng; - use crate::domain::common::token::{Prefecture, Token}; + use crate::domain::common::token::Token; use crate::experimental::parser::{Metadata, ParsedAddress}; #[test] @@ -220,16 +216,14 @@ mod tests { #[test] fn conversion_depthが1() { let tokens = vec![ - Token::Prefecture(Prefecture { - prefecture_name: "東京都".to_string(), - representative_point: Some(LatLng { - latitude: 139.748264, - longitude: 35.68532, - }), - }), + Token::Prefecture("東京都".to_string()), Token::Rest("".to_string()), ]; - let parsed_address = ParsedAddress::from(tokens); + let lat_lng = Some(LatLng { + latitude: 139.748264, + longitude: 35.68532, + }); + let parsed_address = ParsedAddress::from((tokens, lat_lng)); assert_eq!( parsed_address, ParsedAddress { @@ -249,13 +243,7 @@ mod tests { #[test] fn conversion_depthが2() { let tokens = vec![ - Token::Prefecture(Prefecture { - prefecture_name: "東京都".to_string(), - representative_point: Some(LatLng { - latitude: 139.748264, - longitude: 35.68532, - }), - }), + Token::Prefecture("東京都".to_string()), Token::City("台東区".to_string()), Token::Rest("".to_string()), ]; @@ -283,13 +271,7 @@ mod tests { #[test] fn conversion_depthが3() { let tokens = vec![ - Token::Prefecture(Prefecture { - prefecture_name: "東京都".to_string(), - representative_point: Some(LatLng { - latitude: 139.748264, - longitude: 35.68532, - }), - }), + Token::Prefecture("東京都".to_string()), Token::City("文京区".to_string()), Token::Town("本駒込六丁目".to_string()), Token::Rest("16-3".to_string()), diff --git a/core/src/parser.rs b/core/src/parser.rs index 8d12b072..4d719d6f 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -16,7 +16,7 @@ impl From> for Address { let mut address = Address::new("", "", "", ""); for token in value.tokens { match token { - Token::Prefecture(prefecture) => address.prefecture = prefecture.prefecture_name, + Token::Prefecture(prefecture_name) => address.prefecture = prefecture_name, Token::City(city_name) => address.city = city_name, Token::Town(town_name) => address.town = town_name, Token::Rest(rest) => address.rest = rest, diff --git a/core/src/tokenizer.rs b/core/src/tokenizer.rs index 725db633..764b04d4 100644 --- a/core/src/tokenizer.rs +++ b/core/src/tokenizer.rs @@ -29,8 +29,8 @@ pub struct Tokenizer { impl Tokenizer { fn get_prefecture_name(&self) -> Option<&str> { for token in &self.tokens { - if let Token::Prefecture(prefecture) = token { - return Some(&prefecture.prefecture_name); + if let Token::Prefecture(prefecture_name) = token { + return Some(prefecture_name); }; } None diff --git a/core/src/tokenizer/read_city.rs b/core/src/tokenizer/read_city.rs index ea1d7630..e0e58f53 100644 --- a/core/src/tokenizer/read_city.rs +++ b/core/src/tokenizer/read_city.rs @@ -81,17 +81,14 @@ impl Tokenizer { #[cfg(test)] mod tests { - use crate::domain::common::token::{Prefecture, Token}; + use crate::domain::common::token::Token; use crate::tokenizer::{PrefectureNameFound, Tokenizer}; use std::marker::PhantomData; #[test] fn read_city_成功() { let tokenizer = Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: "神奈川県".to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture("神奈川県".to_string())], rest: "横浜市保土ケ谷区川辺町2番地9".to_string(), _state: PhantomData::, }; @@ -110,10 +107,7 @@ mod tests { #[test] fn read_city_orthographical_variant_adapterで成功() { let tokenizer = Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: "神奈川県".to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture("神奈川県".to_string())], rest: "横浜市保土ヶ谷区川辺町2番地9".to_string(), // 「ヶ」と「ケ」の表記ゆれ _state: PhantomData::, }; @@ -132,10 +126,7 @@ mod tests { #[test] fn read_city_失敗() { let tokenizer = Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: "神奈川県".to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture("神奈川県".to_string())], rest: "京都市上京区川辺町2番地9".to_string(), _state: PhantomData::, }; diff --git a/core/src/tokenizer/read_city_with_county_name_completion.rs b/core/src/tokenizer/read_city_with_county_name_completion.rs index c393fe3c..c237cc5a 100644 --- a/core/src/tokenizer/read_city_with_county_name_completion.rs +++ b/core/src/tokenizer/read_city_with_county_name_completion.rs @@ -42,7 +42,7 @@ fn complement_county_name(vague_address: &str, with: &str) -> Result, }; @@ -95,10 +92,7 @@ mod tests { #[test] fn read_city_with_county_name_completion_吉田郡永平寺町() { let tokenizer = Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: "福井県".to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture("福井県".to_string())], rest: "永平寺町志比5-5".to_string(), _state: PhantomData::, }; @@ -114,10 +108,7 @@ mod tests { #[test] fn read_city_with_county_name_completion_今立郡池田町() { let tokenizer = Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: "福井県".to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture("福井県".to_string())], rest: "池田町稲荷28-7".to_string(), _state: PhantomData::, }; @@ -133,10 +124,7 @@ mod tests { #[test] fn read_city_with_county_name_completion_南条郡南越前町() { let tokenizer = Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: "福井県".to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture("福井県".to_string())], rest: "南越前町今庄74-7-1".to_string(), _state: PhantomData::, }; @@ -152,10 +140,7 @@ mod tests { #[test] fn read_city_with_county_name_completion_西村山郡河北町() { let tokenizer = Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: "山形県".to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture("山形県".to_string())], rest: "河北町大字吉田字馬場261".to_string(), _state: PhantomData::, }; @@ -172,10 +157,7 @@ mod tests { #[test] fn read_city_with_county_name_completion_杵島郡大町町() { let tokenizer = Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: "佐賀県".to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture("佐賀県".to_string())], rest: "大町町大字大町5017番地".to_string(), _state: PhantomData::, }; @@ -191,10 +173,7 @@ mod tests { #[test] fn read_city_with_county_name_completion_最上郡最上町() { let tokenizer = Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: "山形県".to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture("山形県".to_string())], rest: "最上町法田2672-2".to_string(), _state: PhantomData::, }; diff --git a/core/src/tokenizer/read_prefecture.rs b/core/src/tokenizer/read_prefecture.rs index 65fabfdf..d3d0bf22 100644 --- a/core/src/tokenizer/read_prefecture.rs +++ b/core/src/tokenizer/read_prefecture.rs @@ -1,4 +1,4 @@ -use crate::domain::common::token::{Prefecture, Token}; +use crate::domain::common::token::Token; use crate::tokenizer::{End, Init, PrefectureNameFound, Tokenizer}; use crate::util::extension::StrExt; use std::marker::PhantomData; @@ -25,10 +25,7 @@ impl Tokenizer { Ok(( prefecture.clone(), Tokenizer { - tokens: vec![Token::Prefecture(Prefecture { - prefecture_name: prefecture_name.to_string(), - representative_point: None, - })], + tokens: vec![Token::Prefecture(prefecture_name.to_string())], rest: self .rest .chars() diff --git a/core/src/tokenizer/read_town.rs b/core/src/tokenizer/read_town.rs index 92981728..b8abeef7 100644 --- a/core/src/tokenizer/read_town.rs +++ b/core/src/tokenizer/read_town.rs @@ -101,7 +101,7 @@ fn find_town(input: &str, candidates: &Vec) -> Option<(String, String)> #[cfg(test)] mod tests { - use crate::domain::common::token::{Prefecture, Token}; + use crate::domain::common::token::Token; use crate::tokenizer::{CityNameFound, Tokenizer}; use std::marker::PhantomData; @@ -109,10 +109,7 @@ mod tests { fn read_town_成功() { let tokenizer = Tokenizer { tokens: vec![ - Token::Prefecture(Prefecture { - prefecture_name: "静岡県".to_string(), - representative_point: None, - }), + Token::Prefecture("静岡県".to_string()), Token::City("静岡市清水区".to_string()), ], rest: "旭町6番8号".to_string(), @@ -136,10 +133,7 @@ mod tests { fn read_town_orthographical_variant_adapterで成功() { let tokenizer = Tokenizer { tokens: vec![ - Token::Prefecture(Prefecture { - prefecture_name: "東京都".to_string(), - representative_point: None, - }), + Token::Prefecture("東京都".to_string()), Token::City("千代田区".to_string()), ], rest: "一ッ橋二丁目1番".to_string(), // 「ッ」と「ツ」の表記ゆれ @@ -163,10 +157,7 @@ mod tests { fn read_town_invalid_town_name_format_filterで成功() { let tokenizer = Tokenizer { tokens: vec![ - Token::Prefecture(Prefecture { - prefecture_name: "京都府".to_string(), - representative_point: None, - }), + Token::Prefecture("京都府".to_string()), Token::City("京都市東山区".to_string()), ], rest: "本町22丁目489番".to_string(), @@ -191,10 +182,7 @@ mod tests { fn read_town_大字が省略されている場合_成功() { let tokenizer = Tokenizer { tokens: vec![ - Token::Prefecture(Prefecture { - prefecture_name: "東京都".to_string(), - representative_point: None, - }), + Token::Prefecture("東京都".to_string()), Token::City("西多摩郡日の出町".to_string()), ], rest: "平井2780番地".to_string(), // 「大字」が省略されている @@ -212,10 +200,7 @@ mod tests { fn read_town_失敗() { let tokenizer = Tokenizer { tokens: vec![ - Token::Prefecture(Prefecture { - prefecture_name: "静岡県".to_string(), - representative_point: None, - }), + Token::Prefecture("静岡県".to_string()), Token::City("静岡市清水区".to_string()), ], rest: "".to_string(), From 09bb9a01618eb1ecade8d19143caab0f6fb9f318 Mon Sep 17 00:00:00 2001 From: ToriChan Date: Mon, 4 Nov 2024 15:04:51 +0900 Subject: [PATCH 04/12] =?UTF-8?q?api=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=92=E9=9D=9E=E6=8E=A8=E5=A5=A8=E5=8C=96:=20`Geol?= =?UTF-8?q?oniaInteractor`=E3=82=92=E4=BD=9C=E6=88=90=20(#503)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update: #499: `interactor::geolonia`モジュールを作成 * add: #499: `GeoloniaInteractor`を作成 * add: #499: 同期版の関数を追加 --- core/src/interactor.rs | 1 + core/src/interactor/geolonia.rs | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 core/src/interactor/geolonia.rs diff --git a/core/src/interactor.rs b/core/src/interactor.rs index d7483914..d947d766 100644 --- a/core/src/interactor.rs +++ b/core/src/interactor.rs @@ -1,2 +1,3 @@ #[cfg(feature = "experimental")] pub mod chimei_ruiju; +pub mod geolonia; diff --git a/core/src/interactor/geolonia.rs b/core/src/interactor/geolonia.rs new file mode 100644 index 00000000..ef4bac7d --- /dev/null +++ b/core/src/interactor/geolonia.rs @@ -0,0 +1,56 @@ +use crate::api::city_master_api::CityMasterApi; +use crate::api::prefecture_master_api::PrefectureMasterApi; +use crate::domain::geolonia::entity::{City, Prefecture}; +use crate::domain::geolonia::error::Error; + +#[allow(dead_code)] +pub(crate) trait GeoloniaInteractor { + /// 都道府県マスタを取得(非同期) + async fn get_prefecture_master(&self, prefecture_name: &str) -> Result; + + /// 都道府県マスタを取得(同期) + #[cfg(feature = "blocking")] + fn get_blocking_prefecture_master(&self, prefecture_name: &str) -> Result; + + /// 市区町村マスタを取得(非同期) + async fn get_city_master(&self, prefecture_name: &str, city_name: &str) -> Result; + + /// 市区町村マスタを取得(同期) + #[cfg(feature = "blocking")] + fn get_blocking_city_master( + &self, + prefecture_name: &str, + city_name: &str, + ) -> Result; +} + +#[allow(dead_code)] +pub(crate) struct GeoloniaInteractorImpl; + +impl GeoloniaInteractor for GeoloniaInteractorImpl { + async fn get_prefecture_master(&self, prefecture_name: &str) -> Result { + let prefecture_master_api = PrefectureMasterApi::default(); + prefecture_master_api.get(prefecture_name).await + } + + #[cfg(feature = "blocking")] + fn get_blocking_prefecture_master(&self, prefecture_name: &str) -> Result { + let prefecture_master_api = PrefectureMasterApi::default(); + prefecture_master_api.get_blocking(prefecture_name) + } + + async fn get_city_master(&self, prefecture_name: &str, city_name: &str) -> Result { + let city_master_api = CityMasterApi::default(); + city_master_api.get(prefecture_name, city_name).await + } + + #[cfg(feature = "blocking")] + fn get_blocking_city_master( + &self, + prefecture_name: &str, + city_name: &str, + ) -> Result { + let city_master_api = CityMasterApi::default(); + city_master_api.get_blocking(prefecture_name, city_name) + } +} From 8fcf832416000f68b8674489b9b489a9c66510fb Mon Sep 17 00:00:00 2001 From: ToriChan Date: Mon, 4 Nov 2024 15:51:21 +0900 Subject: [PATCH 05/12] =?UTF-8?q?api=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=92=E9=9D=9E=E6=8E=A8=E5=A5=A8=E5=8C=96:=20`Pref?= =?UTF-8?q?ectureMasterRepository`=E3=81=8A=E3=82=88=E3=81=B3`CityMasterRe?= =?UTF-8?q?pository`=E3=81=AE=E8=BF=BD=E5=8A=A0=20(#504)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add: #499: `CityMasterRepository`を作成 * add: #499: `PrefectureMasterRepository`を作成 * update: #499: `GeoloniaInteractorImpl`の実装を`PrefectureMasterRepository`および`CityMasterRepository`ベースに書き換え --- core/src/interactor/geolonia.rs | 21 ++-- core/src/repository/geolonia.rs | 2 + core/src/repository/geolonia/city.rs | 102 ++++++++++++++++++ core/src/repository/geolonia/prefecture.rs | 120 +++++++++++++++++++++ 4 files changed, 234 insertions(+), 11 deletions(-) create mode 100644 core/src/repository/geolonia/city.rs create mode 100644 core/src/repository/geolonia/prefecture.rs diff --git a/core/src/interactor/geolonia.rs b/core/src/interactor/geolonia.rs index ef4bac7d..c840eb9f 100644 --- a/core/src/interactor/geolonia.rs +++ b/core/src/interactor/geolonia.rs @@ -1,7 +1,8 @@ -use crate::api::city_master_api::CityMasterApi; -use crate::api::prefecture_master_api::PrefectureMasterApi; use crate::domain::geolonia::entity::{City, Prefecture}; use crate::domain::geolonia::error::Error; +use crate::repository::geolonia::city::CityMasterRepository; +use crate::repository::geolonia::prefecture::PrefectureMasterRepository; +use crate::service::geolonia::GeoloniaApiService; #[allow(dead_code)] pub(crate) trait GeoloniaInteractor { @@ -25,23 +26,22 @@ pub(crate) trait GeoloniaInteractor { } #[allow(dead_code)] -pub(crate) struct GeoloniaInteractorImpl; +pub(crate) struct GeoloniaInteractorImpl { + api_service: GeoloniaApiService, +} impl GeoloniaInteractor for GeoloniaInteractorImpl { async fn get_prefecture_master(&self, prefecture_name: &str) -> Result { - let prefecture_master_api = PrefectureMasterApi::default(); - prefecture_master_api.get(prefecture_name).await + PrefectureMasterRepository::get(&self.api_service, prefecture_name).await } #[cfg(feature = "blocking")] fn get_blocking_prefecture_master(&self, prefecture_name: &str) -> Result { - let prefecture_master_api = PrefectureMasterApi::default(); - prefecture_master_api.get_blocking(prefecture_name) + PrefectureMasterRepository::get_blocking(&self.api_service, prefecture_name) } async fn get_city_master(&self, prefecture_name: &str, city_name: &str) -> Result { - let city_master_api = CityMasterApi::default(); - city_master_api.get(prefecture_name, city_name).await + CityMasterRepository::get(&self.api_service, prefecture_name, city_name).await } #[cfg(feature = "blocking")] @@ -50,7 +50,6 @@ impl GeoloniaInteractor for GeoloniaInteractorImpl { prefecture_name: &str, city_name: &str, ) -> Result { - let city_master_api = CityMasterApi::default(); - city_master_api.get_blocking(prefecture_name, city_name) + CityMasterRepository::get_blocking(&self.api_service, prefecture_name, city_name) } } diff --git a/core/src/repository/geolonia.rs b/core/src/repository/geolonia.rs index 0c2dceda..0e218edc 100644 --- a/core/src/repository/geolonia.rs +++ b/core/src/repository/geolonia.rs @@ -1,2 +1,4 @@ +pub(crate) mod city; pub mod city_master_api; +pub(crate) mod prefecture; pub mod prefecture_master_api; diff --git a/core/src/repository/geolonia/city.rs b/core/src/repository/geolonia/city.rs new file mode 100644 index 00000000..8364cd52 --- /dev/null +++ b/core/src/repository/geolonia/city.rs @@ -0,0 +1,102 @@ +use crate::domain::geolonia::entity::{City, Town}; +use crate::domain::geolonia::error::Error; +use crate::service::geolonia::GeoloniaApiService; + +pub struct CityMasterRepository {} + +impl CityMasterRepository { + pub async fn get( + api_service: &GeoloniaApiService, + prefecture_name: &str, + city_name: &str, + ) -> Result { + let server_url = "https://geolonia.github.io/japanese-addresses/api/ja"; + let endpoint = format!("{}/{}/{}.json", server_url, prefecture_name, city_name); + let towns = api_service.get::>(&endpoint).await?; + Ok(City { + name: city_name.to_string(), + towns, + }) + } + + #[cfg(feature = "blocking")] + pub fn get_blocking( + api_service: &GeoloniaApiService, + prefecture_name: &str, + city_name: &str, + ) -> Result { + let server_url = "https://geolonia.github.io/japanese-addresses/api/ja"; + let endpoint = format!("{}/{}/{}.json", server_url, prefecture_name, city_name); + let towns = api_service.get_blocking::>(&endpoint)?; + Ok(City { + name: city_name.to_string(), + towns, + }) + } +} + +#[cfg(all(test, not(feature = "blocking")))] +mod async_tests { + use crate::domain::geolonia::entity::Town; + use crate::repository::geolonia::city::CityMasterRepository; + use crate::service::geolonia::GeoloniaApiService; + + #[tokio::test] + async fn 非同期_石川県羽咋郡志賀町_成功() { + let api_service = GeoloniaApiService {}; + let result = CityMasterRepository::get(&api_service, "石川県", "羽咋郡志賀町").await; + let city = result.unwrap(); + assert_eq!(city.name, "羽咋郡志賀町"); + let town = Town { + name: "末吉".to_string(), + koaza: "千古".to_string(), + lat: Some(37.006235), + lng: Some(136.779155), + }; + assert!(city.towns.contains(&town)); + } + + #[tokio::test] + async fn 非同期_誤った市区町村名_失敗() { + let api_service = GeoloniaApiService {}; + let result = CityMasterRepository::get(&api_service, "石川県", "敦賀市").await; + assert!(result.is_err()); + assert_eq!( + result.err().unwrap().error_message, + "https://geolonia.github.io/japanese-addresses/api/ja/石川県/敦賀市.jsonを取得できませんでした" + ); + } +} + +#[cfg(all(test, feature = "blocking"))] +mod blocking_tests { + use crate::domain::geolonia::entity::Town; + use crate::repository::geolonia::city::CityMasterRepository; + use crate::service::geolonia::GeoloniaApiService; + + #[test] + fn 同期_石川県羽咋郡志賀町_成功() { + let api_service = GeoloniaApiService {}; + let result = CityMasterRepository::get_blocking(&api_service, "石川県", "羽咋郡志賀町"); + let city = result.unwrap(); + assert_eq!(city.name, "羽咋郡志賀町"); + let town = Town { + name: "末吉".to_string(), + koaza: "千古".to_string(), + lat: Some(37.006235), + lng: Some(136.779155), + }; + assert!(city.towns.contains(&town)); + } + + #[test] + fn 同期_誤った市区町村名_失敗() { + let api_service = GeoloniaApiService {}; + let result = CityMasterRepository::get_blocking(&api_service, "石川県", "敦賀市"); + assert!(result.is_err()); + assert_eq!( + result.err().unwrap().error_message, + "https://geolonia.github.io/japanese-addresses/api/ja/石川県/敦賀市.jsonを取得できませんでした", + ); + } +} diff --git a/core/src/repository/geolonia/prefecture.rs b/core/src/repository/geolonia/prefecture.rs new file mode 100644 index 00000000..9681c587 --- /dev/null +++ b/core/src/repository/geolonia/prefecture.rs @@ -0,0 +1,120 @@ +use crate::domain::geolonia::entity::Prefecture; +use crate::domain::geolonia::error::Error; +use crate::service::geolonia::GeoloniaApiService; + +pub struct PrefectureMasterRepository {} + +impl PrefectureMasterRepository { + pub async fn get( + api_service: &GeoloniaApiService, + prefecture_name: &str, + ) -> Result { + let server_url = "https://yuukitoriyama.github.io/geolonia-japanese-addresses-accompanist"; + let endpoint = format!("{}/{}/master.json", server_url, prefecture_name); + api_service.get::(&endpoint).await + } + + #[cfg(feature = "blocking")] + pub fn get_blocking( + api_service: &GeoloniaApiService, + prefecture_name: &str, + ) -> Result { + let server_url = "https://yuukitoriyama.github.io/geolonia-japanese-addresses-accompanist"; + let endpoint = format!("{}/{}/master.json", server_url, prefecture_name); + api_service.get_blocking::(&endpoint) + } +} + +#[cfg(all(test, not(feature = "blocking")))] +mod tests { + use crate::repository::geolonia::prefecture::PrefectureMasterRepository; + use crate::repository::geolonia::prefecture_master_api::PrefectureMasterApi; + use crate::service::geolonia::GeoloniaApiService; + + #[tokio::test] + async fn 非同期_富山県_成功() { + let api_service = GeoloniaApiService {}; + let result = PrefectureMasterRepository::get(&api_service, "富山県").await; + let prefecture = result.unwrap(); + assert_eq!(prefecture.name, "富山県"); + let cities = vec![ + "富山市", + "高岡市", + "魚津市", + "氷見市", + "滑川市", + "黒部市", + "砺波市", + "小矢部市", + "南砺市", + "射水市", + "中新川郡舟橋村", + "中新川郡上市町", + "中新川郡立山町", + "下新川郡入善町", + "下新川郡朝日町", + ]; + for city in cities { + assert!(prefecture.cities.contains(&city.to_string())); + } + } + + #[tokio::test] + async fn 非同期_誤った都道府県名_失敗() { + let prefecture_master_api: PrefectureMasterApi = Default::default(); + let result = prefecture_master_api.get("大阪都").await; + assert!(result.is_err()); + assert_eq!( + result.err().unwrap().error_message, + format!( + "{}/大阪都/master.jsonを取得できませんでした", + prefecture_master_api.server_url + ) + ); + } +} + +#[cfg(all(test, feature = "blocking"))] +mod blocking_tests { + use crate::repository::geolonia::prefecture::PrefectureMasterRepository; + use crate::service::geolonia::GeoloniaApiService; + + #[test] + fn 同期_富山県_成功() { + let api_service = GeoloniaApiService {}; + let result = PrefectureMasterRepository::get_blocking(&api_service, "富山県"); + let prefecture = result.unwrap(); + assert_eq!(prefecture.name, "富山県"); + let cities = vec![ + "富山市", + "高岡市", + "魚津市", + "氷見市", + "滑川市", + "黒部市", + "砺波市", + "小矢部市", + "南砺市", + "射水市", + "中新川郡舟橋村", + "中新川郡上市町", + "中新川郡立山町", + "下新川郡入善町", + "下新川郡朝日町", + ]; + for city in cities { + assert!(prefecture.cities.contains(&city.to_string())); + } + } + + #[test] + fn 同期_誤った都道府県名_失敗() { + let api_service = GeoloniaApiService {}; + let result = PrefectureMasterRepository::get_blocking(&api_service, "大阪都"); + assert!(result.is_err()); + assert_eq!( + result.err().unwrap().error_message, + "https://yuukitoriyama.github.io/geolonia-japanese-addresses-accompanist/大阪都/master.jsonを取得できませんでした", + ); + } +} From 75281419c805ea9794c6c31634fda8cc2dc3d2f1 Mon Sep 17 00:00:00 2001 From: ToriChan Date: Mon, 4 Nov 2024 16:09:02 +0900 Subject: [PATCH 06/12] =?UTF-8?q?api=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=92=E9=9D=9E=E6=8E=A8=E5=A5=A8=E5=8C=96:=20`expe?= =?UTF-8?q?rimental`=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC=E3=83=AB=E3=81=AE?= =?UTF-8?q?`Parser`=E3=81=AE=E5=AE=9F=E8=A3=85=E3=82=92`interactor::geolon?= =?UTF-8?q?ia::GeoloniaInteractor`=E3=83=99=E3=83=BC=E3=82=B9=E3=81=AB?= =?UTF-8?q?=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=81=88=20(#505)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update: #499: `GeoloniaInteractorImpl`に`Default`クレートを実装 * update: #499: `parse_with_geolonia()`の実装を`api::AsyncApi`ではなく`interactor::geolonia::GeoloniaInteractor`ベースに書き換え --- core/src/experimental/parse_with_geolonia.rs | 11 ++++------- core/src/interactor/geolonia.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/src/experimental/parse_with_geolonia.rs b/core/src/experimental/parse_with_geolonia.rs index a15b9a41..2b3064c5 100644 --- a/core/src/experimental/parse_with_geolonia.rs +++ b/core/src/experimental/parse_with_geolonia.rs @@ -1,12 +1,12 @@ -use crate::api::AsyncApi; use crate::domain::common::token::Token; use crate::experimental::parser::Parser; +use crate::interactor::geolonia::{GeoloniaInteractor, GeoloniaInteractorImpl}; use crate::tokenizer::Tokenizer; impl Parser { #[inline] pub(crate) async fn parse_with_geolonia(&self, address: &str) -> Vec { - let geolonia_api = AsyncApi::default(); + let interactor = GeoloniaInteractorImpl::default(); let tokenizer = Tokenizer::new(address); // 都道府県名の検出 @@ -21,10 +21,7 @@ impl Parser { }; // 市区町村名の検出 - let prefecture_master = match geolonia_api - .get_prefecture_master(prefecture.name_ja()) - .await - { + let prefecture_master = match interactor.get_prefecture_master(prefecture.name_ja()).await { Ok(result) => result, Err(error) => { if self.options.verbose { @@ -57,7 +54,7 @@ impl Parser { }; // 町名の検出 - let city_master = match geolonia_api + let city_master = match interactor .get_city_master(prefecture.name_ja(), &city_name) .await { diff --git a/core/src/interactor/geolonia.rs b/core/src/interactor/geolonia.rs index c840eb9f..fe6b0723 100644 --- a/core/src/interactor/geolonia.rs +++ b/core/src/interactor/geolonia.rs @@ -30,6 +30,14 @@ pub(crate) struct GeoloniaInteractorImpl { api_service: GeoloniaApiService, } +impl Default for GeoloniaInteractorImpl { + fn default() -> Self { + Self { + api_service: GeoloniaApiService {}, + } + } +} + impl GeoloniaInteractor for GeoloniaInteractorImpl { async fn get_prefecture_master(&self, prefecture_name: &str) -> Result { PrefectureMasterRepository::get(&self.api_service, prefecture_name).await From 0618a2104fc095a9a0fb0173eb4c5514f5e2f7ec Mon Sep 17 00:00:00 2001 From: ToriChan Date: Mon, 4 Nov 2024 16:57:43 +0900 Subject: [PATCH 07/12] =?UTF-8?q?api=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=92=E9=9D=9E=E6=8E=A8=E5=A5=A8=E5=8C=96:=20`pars?= =?UTF-8?q?er::Parser`=E3=81=AE=E5=AE=9F=E8=A3=85=E3=82=92`GeoloniaInterac?= =?UTF-8?q?tor`=E3=83=99=E3=83=BC=E3=82=B9=E3=81=AB=E6=9B=B8=E3=81=8D?= =?UTF-8?q?=E6=8F=9B=E3=81=88=20(#506)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update: #499: `parser`モジュールの`parse()`および`parse_blocking()`をDeprecatedに指定 * update: #499: `Parser#parse`と`Parser#parse_blocking`の実装を`interactor::geolonia::GeoloniaInteractor`ベースに書き換え * update: #499: `parse()`および`parse_blocking()`に対するテストコードを`Parser`に対するテストに書き換え --- core/src/parser.rs | 208 +++++++++++++++++++++++++++++++-------------- 1 file changed, 145 insertions(+), 63 deletions(-) diff --git a/core/src/parser.rs b/core/src/parser.rs index d9229091..0432d8af 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -6,6 +6,7 @@ use crate::api::BlockingApi; use crate::domain::common::token::Token; use crate::domain::geolonia::entity::Address; use crate::domain::geolonia::error::{Error, ParseErrorKind}; +use crate::interactor::geolonia::{GeoloniaInteractor, GeoloniaInteractorImpl}; use crate::tokenizer::{End, Tokenizer}; use serde::Serialize; @@ -39,25 +40,14 @@ impl From> for Address { /// } /// ``` pub struct Parser { - async_api: Arc, - #[cfg(feature = "blocking")] - blocking_api: Arc, + interactor: Arc, } impl Default for Parser { /// Constructs a new `Parser`. - #[cfg(feature = "blocking")] - fn default() -> Self { - Self { - async_api: Arc::new(Default::default()), - blocking_api: Arc::new(Default::default()), - } - } - /// Constructs a new `Parser`. - #[cfg(not(feature = "blocking"))] fn default() -> Self { Self { - async_api: Arc::new(Default::default()), + interactor: Arc::new(Default::default()), } } } @@ -65,19 +55,144 @@ impl Default for Parser { impl Parser { /// Parses the given `address` asynchronously. pub async fn parse(&self, address: &str) -> ParseResult { - parse(self.async_api.clone(), address).await + let interasctor = self.interactor.clone(); + let tokenizer = Tokenizer::new(address); + // 都道府県を特定 + let (prefecture, tokenizer) = match tokenizer.read_prefecture() { + Ok(found) => found, + Err(tokenizer) => { + return ParseResult { + address: Address::from(tokenizer), + error: Some(Error::new_parse_error(ParseErrorKind::Prefecture)), + } + } + }; + // その都道府県の市町村名リストを取得 + let prefecture_master = match interasctor + .get_prefecture_master(prefecture.name_ja()) + .await + { + Err(error) => { + return ParseResult { + address: Address::from(tokenizer.finish()), + error: Some(error), + }; + } + Ok(result) => result, + }; + // 市町村名を特定 + let (city_name, tokenizer) = match tokenizer.read_city(&prefecture_master.cities) { + Ok(found) => found, + Err(not_found) => { + // 市区町村が特定できない場合かつフィーチャフラグが有効な場合、郡名が抜けている可能性を検討 + match not_found.read_city_with_county_name_completion(&prefecture_master.cities) { + Ok(found) if cfg!(feature = "city-name-correction") => found, + _ => { + // それでも見つからない場合は終了 + return ParseResult { + address: Address::from(tokenizer.finish()), + error: Some(Error::new_parse_error(ParseErrorKind::City)), + }; + } + } + } + }; + // その市町村の町名リストを取得 + let city = match interasctor + .get_city_master(prefecture.name_ja(), &city_name) + .await + { + Err(error) => { + return ParseResult { + address: Address::from(tokenizer.finish()), + error: Some(error), + }; + } + Ok(result) => result, + }; + // 町名を特定 + let Ok((_, tokenizer)) = + tokenizer.read_town(city.towns.iter().map(|x| x.name.clone()).collect()) + else { + return ParseResult { + address: Address::from(tokenizer.finish()), + error: Some(Error::new_parse_error(ParseErrorKind::Town)), + }; + }; + + ParseResult { + address: Address::from(tokenizer.finish()), + error: None, + } } /// Parses the given `address` synchronously. #[cfg(feature = "blocking")] pub fn parse_blocking(&self, address: &str) -> ParseResult { - parse_blocking(self.blocking_api.clone(), address) + let interactor = self.interactor.clone(); + let tokenizer = Tokenizer::new(address); + let (prefecture, tokenizer) = match tokenizer.read_prefecture() { + Ok(found) => found, + Err(tokenizer) => { + return ParseResult { + address: Address::from(tokenizer), + error: Some(Error::new_parse_error(ParseErrorKind::Prefecture)), + } + } + }; + let prefecture_master = + match interactor.get_blocking_prefecture_master(prefecture.name_ja()) { + Err(error) => { + return ParseResult { + address: Address::from(tokenizer.finish()), + error: Some(error), + }; + } + Ok(result) => result, + }; + let (city_name, tokenizer) = match tokenizer.read_city(&prefecture_master.cities) { + Ok(found) => found, + Err(not_found) => { + match not_found.read_city_with_county_name_completion(&prefecture_master.cities) { + Ok(found) if cfg!(feature = "city-name-correction") => found, + _ => { + return ParseResult { + address: Address::from(tokenizer.finish()), + error: Some(Error::new_parse_error(ParseErrorKind::City)), + }; + } + } + } + }; + let city = match interactor.get_blocking_city_master(prefecture.name_ja(), &city_name) { + Err(error) => { + return ParseResult { + address: Address::from(tokenizer.finish()), + error: Some(error), + }; + } + Ok(result) => result, + }; + let Ok((_, tokenizer)) = + tokenizer.read_town(city.towns.iter().map(|x| x.name.clone()).collect()) + else { + return ParseResult { + address: Address::from(tokenizer.finish()), + error: Some(Error::new_parse_error(ParseErrorKind::Town)), + }; + }; + + ParseResult { + address: Address::from(tokenizer.finish()), + error: None, + } } } /// A function to parse the given address asynchronously. /// /// publicにしていますが、直接の使用は推奨されません。[Parser]の利用を検討してください。 +#[deprecated(since = "0.1.23", note = "This module will be deleted in v0.2")] pub async fn parse(api: Arc, input: &str) -> ParseResult { let tokenizer = Tokenizer::new(input); // 都道府県を特定 @@ -145,17 +260,14 @@ pub async fn parse(api: Arc, input: &str) -> ParseResult { #[cfg(all(test, not(feature = "blocking")))] mod tests { - use crate::api::AsyncApi; use crate::domain::geolonia::error::ParseErrorKind; - use crate::parser::parse; - use crate::repository::geolonia::city_master_api::CityMasterApi; - use crate::repository::geolonia::prefecture_master_api::PrefectureMasterApi; + use crate::parser::Parser; use wasm_bindgen_test::{wasm_bindgen_test, wasm_bindgen_test_configure}; #[tokio::test] async fn 都道府県名が誤っている場合() { - let api: AsyncApi = Default::default(); - let result = parse(api.into(), "青盛県青森市長島1丁目1−1").await; + let parser = Parser::default(); + let result = parser.parse("青盛県青森市長島1丁目1−1").await; assert_eq!(result.address.prefecture, ""); assert_eq!(result.address.city, ""); assert_eq!(result.address.town, ""); @@ -167,25 +279,10 @@ mod tests { ); } - #[tokio::test] - async fn 都道府県マスタが取得できない場合() { - let mut api: AsyncApi = Default::default(); - api.prefecture_master_api = PrefectureMasterApi { - server_url: "https://example.com/invalid_url/api/", - }; - - let result = parse(api.into(), "青森県青森市長島1丁目1−1").await; - assert_eq!(result.error.is_some(), true); - assert_eq!(result.address.prefecture, "青森県"); - assert_eq!(result.address.city, ""); - assert_eq!(result.address.town, ""); - assert_eq!(result.address.rest, "青森市長島1丁目1−1"); - } - #[tokio::test] async fn 市区町村名が誤っている場合() { - let api: AsyncApi = Default::default(); - let result = parse(api.into(), "青森県青盛市長島1丁目1−1").await; + let parser = Parser::default(); + let result = parser.parse("青森県青盛市長島1丁目1−1").await; assert_eq!(result.address.prefecture, "青森県"); assert_eq!(result.address.city, ""); assert_eq!(result.address.town, ""); @@ -197,25 +294,10 @@ mod tests { ); } - #[tokio::test] - async fn 市区町村マスタが取得できない場合() { - let mut api: AsyncApi = Default::default(); - api.city_master_api = CityMasterApi { - server_url: "https://example.com/invalid_url/api/", - }; - - let result = parse(api.into(), "青森県青森市長島1丁目1−1").await; - assert_eq!(result.error.is_some(), true); - assert_eq!(result.address.prefecture, "青森県"); - assert_eq!(result.address.city, "青森市"); - assert_eq!(result.address.town, ""); - assert_eq!(result.address.rest, "長島1丁目1−1"); - } - #[tokio::test] async fn 町名が誤っている場合() { - let api: AsyncApi = Default::default(); - let result = parse(api.into(), "青森県青森市永嶋1丁目1−1").await; + let parser = Parser::default(); + let result = parser.parse("青森県青森市永嶋1丁目1−1").await; assert_eq!(result.address.prefecture, "青森県"); assert_eq!(result.address.city, "青森市"); assert_eq!(result.address.town, ""); @@ -231,8 +313,8 @@ mod tests { #[wasm_bindgen_test] async fn parse_wasm_success() { - let api: AsyncApi = Default::default(); - let result = parse(api.into(), "兵庫県淡路市生穂新島8番地").await; + let parser = Parser::default(); + let result = parser.parse("兵庫県淡路市生穂新島8番地").await; assert_eq!(result.address.prefecture, "兵庫県".to_string()); assert_eq!(result.address.city, "淡路市".to_string()); assert_eq!(result.address.town, "生穂".to_string()); @@ -245,6 +327,7 @@ mod tests { /// /// publicにしていますが、直接の使用は推奨されません。[Parser]の利用を検討してください。 #[cfg(feature = "blocking")] +#[deprecated(since = "0.1.23", note = "This module will be deleted in v0.2")] pub fn parse_blocking(api: Arc, input: &str) -> ParseResult { let tokenizer = Tokenizer::new(input); let (prefecture, tokenizer) = match tokenizer.read_prefecture() { @@ -305,14 +388,13 @@ pub fn parse_blocking(api: Arc, input: &str) -> ParseResult { #[cfg(all(test, feature = "blocking"))] mod blocking_tests { - use crate::api::BlockingApi; use crate::domain::geolonia::error::ParseErrorKind; - use crate::parser::parse_blocking; + use crate::parser::Parser; #[test] fn parse_blocking_success_埼玉県秩父市熊木町8番15号() { - let client: BlockingApi = Default::default(); - let result = parse_blocking(client.into(), "埼玉県秩父市熊木町8番15号"); + let parser = Parser::default(); + let result = parser.parse_blocking("埼玉県秩父市熊木町8番15号"); assert_eq!(result.address.prefecture, "埼玉県"); assert_eq!(result.address.city, "秩父市"); assert_eq!(result.address.town, "熊木町"); @@ -322,8 +404,8 @@ mod blocking_tests { #[test] fn parse_blocking_fail_市町村名が間違っている場合() { - let client: BlockingApi = Default::default(); - let result = parse_blocking(client.into(), "埼玉県秩父柿熊木町8番15号"); + let parser = Parser::default(); + let result = parser.parse_blocking("埼玉県秩父柿熊木町8番15号"); assert_eq!(result.address.prefecture, "埼玉県"); assert_eq!(result.address.city, ""); assert_eq!(result.address.town, ""); From a9b79439de9022625ee1981720073bf92041095e Mon Sep 17 00:00:00 2001 From: ToriChan Date: Mon, 4 Nov 2024 17:21:07 +0900 Subject: [PATCH 08/12] =?UTF-8?q?api=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=92=E9=9D=9E=E6=8E=A8=E5=A5=A8=E5=8C=96:=20?= =?UTF-8?q?=E9=9D=9E=E6=8E=A8=E5=A5=A8=E5=8C=96=E3=81=99=E3=82=8B=E3=83=A2?= =?UTF-8?q?=E3=82=B8=E3=83=A5=E3=83=BC=E3=83=AB=E3=81=AB`#[deprecated]`?= =?UTF-8?q?=E3=82=92=E4=BB=98=E4=B8=8E=20(#507)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update: #499: `repository::geolonia::city_master_api`モジュールを非推奨化 * update: #499: `repository::geolonia::prefecture_master_api`モジュールを非推奨化 * update: #499: `api`モジュールを非推奨化 * update: #499: deprecatedなAPIを使用せざるを得ないモジュールに`#![allow(deprecated)]`を付与 --- core/src/api.rs | 1 + core/src/lib.rs | 1 + core/src/parser.rs | 1 + core/src/repository/geolonia.rs | 2 ++ 4 files changed, 5 insertions(+) diff --git a/core/src/api.rs b/core/src/api.rs index e364f4bd..0c9696c5 100644 --- a/core/src/api.rs +++ b/core/src/api.rs @@ -1,3 +1,4 @@ +#![allow(deprecated)] pub use crate::repository::geolonia::city_master_api; pub use crate::repository::geolonia::prefecture_master_api; diff --git a/core/src/lib.rs b/core/src/lib.rs index afc58fa6..8c1a35cf 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -13,6 +13,7 @@ compile_error! { "The `blocking` feature is not supported with wasm target." } +#[deprecated(since = "0.1.23", note = "This module will be deleted in v0.2")] pub mod api; pub(crate) mod domain; #[deprecated(since = "0.1.6", note = "This module will be deleted in v0.2")] diff --git a/core/src/parser.rs b/core/src/parser.rs index 0432d8af..631d861c 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -1,3 +1,4 @@ +#![allow(deprecated)] use std::sync::Arc; use crate::api::AsyncApi; diff --git a/core/src/repository/geolonia.rs b/core/src/repository/geolonia.rs index 0e218edc..5a4724a4 100644 --- a/core/src/repository/geolonia.rs +++ b/core/src/repository/geolonia.rs @@ -1,4 +1,6 @@ pub(crate) mod city; +#[deprecated(since = "0.1.23", note = "This module will be deleted in v0.2")] pub mod city_master_api; pub(crate) mod prefecture; +#[deprecated(since = "0.1.23", note = "This module will be deleted in v0.2")] pub mod prefecture_master_api; From 3169dec0844a8e9e12c70ef47d2c277ac214fbfc Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Mon, 4 Nov 2024 18:06:33 +0900 Subject: [PATCH 09/12] update-version: 0.1.22 -> 0.1.23 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8dde1c89..936e1c3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ resolver = "2" [workspace.package] -version = "0.1.22" +version = "0.1.23" edition = "2021" description = "A Rust Library to parse japanese addresses." repository = "https://github.com/YuukiToriyama/japanese-address-parser" From 364db0bd21b247953a207101f530a11122b91150 Mon Sep 17 00:00:00 2001 From: ToriChan Date: Mon, 4 Nov 2024 18:05:17 +0900 Subject: [PATCH 10/12] =?UTF-8?q?api=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=92=E9=9D=9E=E6=8E=A8=E5=A5=A8=E5=8C=96:=20`wasm?= =?UTF-8?q?`=E3=82=AF=E3=83=AC=E3=83=BC=E3=83=88=E3=81=AE`Parser`=E3=82=92?= =?UTF-8?q?`api::AsyncApi`=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=97=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=82=82=E3=81=AE=E3=81=AB=E5=B7=AE=E3=81=97=E6=9B=BF?= =?UTF-8?q?=E3=81=88=20(#508)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `api::AsyncApi`が非推奨になるため --- wasm/src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index fc83dbad..5054d856 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -1,9 +1,7 @@ #[cfg(feature = "nightly")] mod nightly; -use japanese_address_parser::api::AsyncApi; use japanese_address_parser::parser; -use std::sync::Arc; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; @@ -35,7 +33,7 @@ export class Parser { #[wasm_bindgen(skip_typescript)] pub struct Parser { - async_api: Arc, + parser: parser::Parser, } #[warn(clippy::new_without_default)] @@ -46,12 +44,12 @@ impl Parser { #[cfg(feature = "debug")] console_error_panic_hook::set_once(); Parser { - async_api: Arc::new(Default::default()), + parser: parser::Parser::default(), } } pub async fn parse(&self, address: &str) -> JsValue { - let result = parser::parse(self.async_api.clone(), address).await; + let result = self.parser.parse(address).await; serde_wasm_bindgen::to_value(&result).unwrap() } } From 656410ec92eaab0b12b0d08580be280f7b53eb1b Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Mon, 4 Nov 2024 20:34:36 +0900 Subject: [PATCH 11/12] =?UTF-8?q?fix:=20#499:=20=E4=B8=8D=E8=A6=81?= =?UTF-8?q?=E3=81=AA`#[allow(dead=5Fcode)]`=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/interactor/geolonia.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/interactor/geolonia.rs b/core/src/interactor/geolonia.rs index fe6b0723..2cbc54eb 100644 --- a/core/src/interactor/geolonia.rs +++ b/core/src/interactor/geolonia.rs @@ -4,7 +4,6 @@ use crate::repository::geolonia::city::CityMasterRepository; use crate::repository::geolonia::prefecture::PrefectureMasterRepository; use crate::service::geolonia::GeoloniaApiService; -#[allow(dead_code)] pub(crate) trait GeoloniaInteractor { /// 都道府県マスタを取得(非同期) async fn get_prefecture_master(&self, prefecture_name: &str) -> Result; @@ -25,7 +24,6 @@ pub(crate) trait GeoloniaInteractor { ) -> Result; } -#[allow(dead_code)] pub(crate) struct GeoloniaInteractorImpl { api_service: GeoloniaApiService, } From 66d5dba81ce26eb7f02f5d7997fc7395534bd50a Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Mon, 4 Nov 2024 20:43:06 +0900 Subject: [PATCH 12/12] =?UTF-8?q?fix:=20#499:=20typo=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/parser.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core/src/parser.rs b/core/src/parser.rs index 631d861c..92404754 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -56,7 +56,7 @@ impl Default for Parser { impl Parser { /// Parses the given `address` asynchronously. pub async fn parse(&self, address: &str) -> ParseResult { - let interasctor = self.interactor.clone(); + let interactor = self.interactor.clone(); let tokenizer = Tokenizer::new(address); // 都道府県を特定 let (prefecture, tokenizer) = match tokenizer.read_prefecture() { @@ -69,10 +69,7 @@ impl Parser { } }; // その都道府県の市町村名リストを取得 - let prefecture_master = match interasctor - .get_prefecture_master(prefecture.name_ja()) - .await - { + let prefecture_master = match interactor.get_prefecture_master(prefecture.name_ja()).await { Err(error) => { return ParseResult { address: Address::from(tokenizer.finish()), @@ -99,7 +96,7 @@ impl Parser { } }; // その市町村の町名リストを取得 - let city = match interasctor + let city = match interactor .get_city_master(prefecture.name_ja(), &city_name) .await {