-
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 #25 from YuukiToriyama/feature/adapt-variety-of-sp…
…elling/master 地名の表記ゆれへの対応をmainにマージ
- Loading branch information
Showing
5 changed files
with
154 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use itertools::Itertools; | ||
use nom::bytes::complete::tag; | ||
use nom::error::VerboseError; | ||
use nom::Parser; | ||
|
||
pub fn adapt_variety_of_spelling( | ||
input: &str, | ||
region_name: &String, | ||
variety_of_spelling: Vec<&str>, | ||
) -> Option<(String, String)> { | ||
if variety_of_spelling.iter().all(|s| region_name.contains(s) == false) { | ||
return None; | ||
} | ||
for permutation in variety_of_spelling.iter().permutations(2) { | ||
if region_name.contains(permutation[0]) { | ||
let edited_region_name = region_name.replace(permutation[0], permutation[1]); | ||
if let Ok((rest, _)) = tag::<&str, &str, VerboseError<&str>>(&edited_region_name).parse(input) { | ||
return Some((rest.to_string(), region_name.to_string())); | ||
}; | ||
} | ||
} | ||
None | ||
} |
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