-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow including secondary output from libpostal
We add a new command-line flag allowing the user to combine regular geocoder output with columns from libpostal.
- Loading branch information
Showing
4 changed files
with
77 additions
and
3 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,65 @@ | ||
//! Paired geocoder. Run two geocoders, return both. | ||
//! | ||
//! ¿Por qué no los dos? | ||
use async_trait::async_trait; | ||
|
||
use crate::geocoders::{Geocoded, Geocoder}; | ||
use crate::{addresses::Address, Result}; | ||
|
||
/// A geocoder that runs two geocoders and returns both results. | ||
pub struct Paired { | ||
/// The first geocoder. | ||
fst: Box<dyn Geocoder>, | ||
/// The second geocoder. | ||
snd: Box<dyn Geocoder>, | ||
/// The column names output by this geocoder. Includes both sets | ||
/// of column names. | ||
column_names: Vec<String>, | ||
/// The configuration key for this geocoder. | ||
config_key: String, | ||
} | ||
|
||
impl Paired { | ||
/// Create a new pair of geocoders. | ||
pub fn new(fst: Box<dyn Geocoder>, snd: Box<dyn Geocoder>) -> Paired { | ||
let column_names = fst | ||
.column_names() | ||
.iter() | ||
.chain(snd.column_names()) | ||
.cloned() | ||
.collect(); | ||
let config_key = | ||
format!("{}+{}", fst.configuration_key(), snd.configuration_key()); | ||
Paired { | ||
fst, | ||
snd, | ||
column_names, | ||
config_key, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Geocoder for Paired { | ||
fn tag(&self) -> &str { | ||
"pair" | ||
} | ||
|
||
fn configuration_key(&self) -> &str { | ||
&self.config_key | ||
} | ||
|
||
fn column_names(&self) -> &[String] { | ||
&self.column_names | ||
} | ||
|
||
async fn geocode_addresses( | ||
&self, | ||
addresses: &[Address], | ||
) -> Result<Vec<Option<Geocoded>>> { | ||
let fst = self.fst.geocode_addresses(addresses).await?; | ||
let snd = self.snd.geocode_addresses(addresses).await?; | ||
Ok(fst.into_iter().chain(snd.into_iter()).collect()) | ||
} | ||
} |
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