Skip to content

Commit

Permalink
Merge pull request #532 from YuukiToriyama/feature/purge-deprecates/m…
Browse files Browse the repository at this point in the history
…aster

非推奨モジュール・関数の削除(v0.2)をrelease/v0.2.0-rc.1にマージ
  • Loading branch information
YuukiToriyama authored Nov 14, 2024
2 parents 85eb196 + 9c9d4a1 commit 39bc0be
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 592 deletions.
2 changes: 0 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ eliminate-whitespaces = []
experimental = []

[dependencies]
itertools = "0.13.0" # 互換性のために残してあるが、`core::parser::adapter`を削除する際に忘れずに削除する
log.workspace = true
rapidfuzz = "0.5.0"
regex = { version = "1.10.6", default-features = false, features = ["std", "unicode-perl"] }
Expand All @@ -34,7 +33,6 @@ thiserror = "1.0.63"
jisx0401 = "0.1.0-beta.3"

[dev-dependencies]
criterion = { version = "0.5.1", default-features = false, features = ["html_reports"] }
tokio.workspace = true
wasm-bindgen-test = { workspace = true }

Expand Down
47 changes: 0 additions & 47 deletions core/src/api.rs

This file was deleted.

4 changes: 2 additions & 2 deletions core/src/domain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "experimental")]
pub mod chimei_ruiju;
pub mod common;
pub(crate) mod chimei_ruiju;
pub(crate) mod common;
pub mod geolonia;
46 changes: 15 additions & 31 deletions core/src/domain/geolonia/entity.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
use serde::{Deserialize, Serialize};

#[derive(Deserialize, PartialEq, Debug)]
pub struct Prefecture {
pub(crate) struct Prefecture {
pub name: String,
pub cities: Vec<String>,
}

impl Prefecture {
// 主にテストコードで使用する
pub fn new(prefecture_name: &str, city_names: Vec<&str>) -> Self {
Prefecture {
name: prefecture_name.to_string(),
cities: city_names.iter().map(|s| s.to_string()).collect(),
}
}
}

#[derive(Debug)]
pub struct City {
pub(crate) struct City {
#[allow(dead_code)]
pub name: String,
pub towns: Vec<Town>,
}

#[derive(PartialEq, Deserialize, Debug)]
pub struct Town {
pub(crate) struct Town {
#[serde(alias = "town")]
pub name: String,
pub koaza: String,
Expand All @@ -32,18 +23,6 @@ pub struct Town {
pub lng: Option<f32>,
}

impl Town {
// 主にテストコードで使用する
pub fn new(town_name: &str, koaza_name: &str, lat: f32, lng: f32) -> Self {
Town {
name: town_name.to_string(),
koaza: koaza_name.to_string(),
lat: Some(lat),
lng: Some(lng),
}
}
}

#[derive(Serialize, PartialEq, Debug)]
pub struct Address {
pub prefecture: String,
Expand All @@ -53,7 +32,12 @@ pub struct Address {
}

impl Address {
pub fn new(prefecture_name: &str, city_name: &str, town_name: &str, rest_name: &str) -> Self {
pub(crate) fn new(
prefecture_name: &str,
city_name: &str,
town_name: &str,
rest_name: &str,
) -> Self {
Address {
prefecture: prefecture_name.to_string(),
city: city_name.to_string(),
Expand All @@ -63,10 +47,10 @@ impl Address {
}
}

#[doc(hidden)]
#[cfg(test)]
impl Prefecture {
/// only for testing
pub fn yamagata() -> Self {
pub(crate) fn yamagata() -> Self {
Prefecture {
name: "山形県".to_string(),
cities: vec![
Expand Down Expand Up @@ -110,7 +94,7 @@ impl Prefecture {
}

/// only for testing
pub fn fukushima() -> Self {
pub(crate) fn fukushima() -> Self {
Prefecture {
name: "福島県".to_string(),
cities: vec![
Expand Down Expand Up @@ -178,7 +162,7 @@ impl Prefecture {
}

/// only for testing
pub fn fukui() -> Self {
pub(crate) fn fukui() -> Self {
Prefecture {
name: "福井県".to_string(),
cities: vec![
Expand All @@ -204,7 +188,7 @@ impl Prefecture {
}

/// only for testing
pub fn saga() -> Self {
pub(crate) fn saga() -> Self {
Prefecture {
name: "佐賀県".to_string(),
cities: vec![
Expand Down
8 changes: 4 additions & 4 deletions core/src/domain/geolonia/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ pub struct Error {
}

impl Error {
pub fn new_parse_error(parse_error_kind: ParseErrorKind) -> Self {
pub(crate) fn new_parse_error(parse_error_kind: ParseErrorKind) -> Self {
Error {
error_type: "ParseError".to_string(),
error_message: parse_error_kind.to_string(),
}
}
pub fn new_api_error(api_error_kind: ApiErrorKind) -> Self {
pub(crate) fn new_api_error(api_error_kind: ApiErrorKind) -> Self {
let error_message = match api_error_kind {
ApiErrorKind::Fetch(url) => format!("{}を取得できませんでした", url),
ApiErrorKind::Deserialize(url) => format!("{}のデシリアライズに失敗しました", url),
Expand All @@ -27,7 +27,7 @@ impl Error {
}
}

pub enum ParseErrorKind {
pub(crate) enum ParseErrorKind {
Prefecture,
City,
Town,
Expand All @@ -44,7 +44,7 @@ impl Display for ParseErrorKind {
}
}

pub enum ApiErrorKind {
pub(crate) enum ApiErrorKind {
Fetch(String),
Deserialize(String),
}
5 changes: 0 additions & 5 deletions core/src/entity.rs

This file was deleted.

6 changes: 1 addition & 5 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ compile_error! {
}

mod adapter;
#[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")]
pub mod entity;
pub mod domain;
#[cfg(feature = "experimental")]
#[cfg_attr(docsrs, doc(cfg(feature = "experimental")))]
pub mod experimental;
Expand Down
139 changes: 0 additions & 139 deletions core/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#![allow(deprecated)]
use std::sync::Arc;

use crate::api::AsyncApi;
#[cfg(feature = "blocking")]
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;

#[deprecated(since = "0.1.24", note = "This module will be deleted in v0.2")]
pub mod adapter;

impl From<Tokenizer<End>> for Address {
fn from(value: Tokenizer<End>) -> Self {
let mut address = Address::new("", "", "", "");
Expand Down Expand Up @@ -188,75 +181,6 @@ impl Parser {
}
}

/// 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<AsyncApi>, input: &str) -> ParseResult {
let tokenizer = Tokenizer::new(input);
// 都道府県を特定
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 api.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 api.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,
}
}

#[cfg(all(test, not(feature = "blocking")))]
mod tests {
use crate::domain::geolonia::error::ParseErrorKind;
Expand Down Expand Up @@ -322,69 +246,6 @@ mod tests {
}
}

/// A function to parse the given address synchronously.
///
/// 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<BlockingApi>, input: &str) -> ParseResult {
let tokenizer = Tokenizer::new(input);
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 api.get_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 api.get_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,
}
}

#[cfg(all(test, feature = "blocking"))]
mod blocking_tests {
use crate::domain::geolonia::error::ParseErrorKind;
Expand Down
1 change: 0 additions & 1 deletion core/src/parser/adapter.rs

This file was deleted.

Loading

0 comments on commit 39bc0be

Please sign in to comment.