Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/v0.1.0-beta.6をmainブランチにマージ #157

Merged
merged 14 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
bbb4bcf
rename: 「大字」の省略に対応: `parser_tests` -> `tests`
YuukiToriyama Jan 20, 2024
9b19a9a
fix: 「大字」の省略に対応: 複数行のcfgアトリビューションを一行にまとめた
YuukiToriyama Jan 20, 2024
b9d8527
update: 「大字」の省略に対応: `平井`,`大字平井`のテストケースを追加
YuukiToriyama Jan 20, 2024
dbc5507
update: 「大字」の省略に対応: 結合テストに`大字表記省略への対応テスト`を追加
YuukiToriyama Jan 20, 2024
f128f76
update: 「大字」の省略に対応: 住居表示一部実施済みだが大字も残っている地域の場合のケースを結合テストに追加
YuukiToriyama Jan 21, 2024
a3e6b1a
update: 「大字」の省略に対応: 大字が省略されている場合は補ってから処理をするように変更
YuukiToriyama Jan 20, 2024
de1c16c
Merge pull request #148 from YuukiToriyama/main
YuukiToriyama Jan 21, 2024
5c0b58b
update: 「大字」の省略に対応: `InvalidTownNameFormatFilter`において43以上の数字が来た場合はNon…
YuukiToriyama Feb 2, 2024
237edb9
Merge pull request #153 from YuukiToriyama/feature/ellipsis-of-ooaza/…
YuukiToriyama Feb 2, 2024
0ae02e2
Merge pull request #154 from YuukiToriyama/feature/ellipsis-of-ooaza/fix
YuukiToriyama Feb 2, 2024
c065dfe
PR作成時やmainブランチへのpush時に走るCIで`cargo fmt`を実行しないよう設定
YuukiToriyama Feb 2, 2024
0bfb3f4
package.versionを変更
YuukiToriyama Feb 2, 2024
8b6e999
Merge pull request #155 from YuukiToriyama/feature/remove-rustfmt-on-ci
YuukiToriyama Feb 2, 2024
008a74f
Merge pull request #156 from YuukiToriyama/feature/ellipsis-of-ooaza/…
YuukiToriyama Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up rustfmt
run: rustup component add rustfmt
- name: Code formatting
run: |
cargo fmt
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add --update
git commit -m "cargo fmt"
git push
continue-on-error: true
- name: Code style check
run: cargo fmt --check
- name: Set up clippy
run: rustup component add clippy
- name: Code review with clippy
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "japanese-address-parser"
version = "0.1.0-beta.5"
version = "0.1.0-beta.6"
edition = "2021"
description = "A Rust Library to parse japanses addresses."
authors = ["Yuuki Toriyama <github@toriyama.dev>"]
Expand Down
45 changes: 27 additions & 18 deletions src/parser/filter/invalid_town_name_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ fn extract_town_name_with_regex(input: &str) -> Option<String> {
} else {
return None;
};
let block_number = if let Some(matched) = captures.name("block_number") {
matched.as_str().parse::<i8>().ok()?.to_japanese_form()?
} else {
let block_number = captures.name("block_number")?.as_str().parse::<i8>().ok()?;
// 帯広市西十九条四十二丁目の42が最大なので、43以上の値の場合はNoneを返すようにする
if block_number > 42 {
return None;
};
}
let rest = if let Some(matched) = captures.name("rest") {
matched.as_str()
} else {
""
};
Some(format!("{}{}丁目{}", town_name, block_number, rest))
Some(format!(
"{}{}丁目{}",
town_name,
block_number.to_japanese_form()?,
rest
))
}

#[cfg(target_arch = "wasm32")]
Expand All @@ -47,17 +52,21 @@ fn extract_town_name_with_js_sys_regexp(input: &str) -> Option<String> {
);
let captures = expression.exec(input)?;
let town_name = captures.get(1).as_string()?;
let block_number = captures
.get(2)
.as_string()?
.parse::<i8>()
.ok()?
.to_japanese_form()?;
let block_number = captures.get(2).as_string()?.parse::<i8>().ok()?;
// 帯広市西十九条四十二丁目の42が最大なので、43以上の値の場合はNoneを返すようにする
if block_number > 42 {
return None;
}
let rest = captures
.get(3)
.as_string()
.unwrap_or_else(|| "".to_string());
Some(format!("{}{}丁目{}", town_name, block_number, rest))
Some(format!(
"{}{}丁目{}",
town_name,
block_number.to_japanese_form()?,
rest
))
}

#[cfg(all(test, not(target_arch = "wasm32")))]
Expand Down Expand Up @@ -103,10 +112,10 @@ mod tests {

#[test]
fn extract_town_name_with_regex_block_number_boundary_value() {
let result = extract_town_name_with_regex("有楽町127");
let result = extract_town_name_with_regex("西十九条南42");
assert!(result.is_some());
assert_eq!(result.unwrap(), "有楽町百二十七丁目");
let result = extract_town_name_with_regex("有楽町128");
assert_eq!(result.unwrap(), "西十九条南四十二丁目");
let result = extract_town_name_with_regex("西十九条南43");
assert!(result.is_none());
}
}
Expand Down Expand Up @@ -157,10 +166,10 @@ mod wasm_tests {

#[wasm_bindgen_test]
fn extract_town_name_with_js_sys_block_number_boundary_value() {
let result = extract_town_name_with_js_sys_regexp("有楽町127");
let result = extract_town_name_with_js_sys_regexp("西十九条南42");
assert!(result.is_some());
assert_eq!(result.unwrap(), "有楽町百二十七丁目");
let result = extract_town_name_with_js_sys_regexp("有楽町128");
assert_eq!(result.unwrap(), "西十九条南四十二丁目");
let result = extract_town_name_with_js_sys_regexp("西十九条南43");
assert!(result.is_none());
}

Expand Down
24 changes: 21 additions & 3 deletions src/parser/read_town.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub fn read_town(input: &str, city: &City) -> Option<(String, String)> {
if let Some(result) = find_town(&input, city) {
return Some(result);
}
// ここまでで町名の検出に成功しない場合は、「大字」の省略の可能性を検討する
if let Some(result) = find_town(&format!("大字{}", input), city) {
return Some(result);
}
None
}

Expand Down Expand Up @@ -49,9 +53,8 @@ fn find_town(input: &String, city: &City) -> Option<(String, String)> {
None
}

#[cfg(test)]
#[cfg(not(target_arch = "wasm32"))]
mod parser_tests {
#[cfg(all(test, not(target_arch = "wasm32")))]
mod tests {
use crate::api::{BlockingApi, BlockingApiImpl};
use crate::entity::{City, Town};
use crate::parser::read_town::read_town;
Expand Down Expand Up @@ -162,4 +165,19 @@ mod parser_tests {
assert_eq!(town, town_name);
}
}

#[test]
fn read_town_大字の省略_東京都西多摩郡日の出町大字平井() {
let blocking_api = BlockingApiImpl::new();
let city = blocking_api
.get_city_master("東京都", "西多摩郡日の出町")
.unwrap();

let (rest, town) = read_town("大字平井2780番地", &city).unwrap();
assert_eq!(town, "大字平井");
assert_eq!(rest, "2780番地");
let (rest, town) = read_town("平井2780番地", &city).unwrap();
assert_eq!(town, "大字平井");
assert_eq!(rest, "2780番地");
}
}
5 changes: 5 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ async fn 住居表示実施済みの住所において正式でない表記へ
)
.await
}

#[tokio::test]
async fn 大字表記省略への対応テスト() {
run_data_driven_tests("./tests/test_data/大字表記省略への対応.csv").await
}
12 changes: 12 additions & 0 deletions tests/test_data/大字表記省略への対応.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
address,prefecture,city,town,rest
東京都西多摩郡日の出町大字平井2780番地,東京都,西多摩郡日の出町,大字平井,2780番地
東京都西多摩郡日の出町平井2780番地,東京都,西多摩郡日の出町,大字平井,2780番地
埼玉県南埼玉郡宮代町大字東粂原110,埼玉県,南埼玉郡宮代町,大字東粂原,110
埼玉県南埼玉郡宮代町東粂原110,埼玉県,南埼玉郡宮代町,大字東粂原,110
愛知県名古屋市守山区大字上志段味馬洗淵,愛知県,名古屋市守山区,大字上志段味,馬洗淵
愛知県名古屋市守山区上志段味馬洗淵,愛知県,名古屋市守山区,大字上志段味,馬洗淵
# 住居表示一部実施済みだが大字も残っている地域の場合
福岡県福岡市南区大字桧原853-9,福岡県,福岡市南区,大字桧原,853-9
福岡県福岡市南区桧原6-44-20,福岡県,福岡市南区,桧原六丁目,44-20
福岡県遠賀郡遠賀町浅木463,福岡県,遠賀郡遠賀町,大字浅木,463
福岡県遠賀郡遠賀町浅木1-16,福岡県,遠賀郡遠賀町,浅木一丁目,16
Loading