[−][src]Struct gnverify::GNVerify
Keeps configuration parameters and organizes main functions for changing configuration and performing name-strings verification and formatting of verification output.
Fields
sources: Option<Vec<i64>>
list of IDs of Data Sources. Each Data Source is a checklist of scientific names / (e.g Encyclopedia of Life, GBIF, Catalogue of Life) and can be curated to a degree, automatically curated or not curated. If a name-string has a match to any of these sources, the matching result will always be returned in preferred_results section of the output.
preferred_only: bool
Normally output would
name_field: i64
Position of ScientificName field in the document. Default value is 1 (the first field is 1, not 0). If gnverify verifies names from a txt file, it assumes that the text has one name per line, and nothing else.
batch_size: usize
size of a bach of names sent as a unit for verification to gnindex.
format: Format
sets format of the final output. It can be CSV, JSON, or Pretty JSON.
Methods
impl GNVerify
[src]
pub fn new() -> Self
[src]
Creates a new instance of GNVerify and sets default values for all fields.
pub fn sources(&mut self, sources: Vec<i64>)
[src]
Sets sources field. Sources is a list of IDs for data sources. If a match found for these data-sources, such data will be always returned to the user even if such results are not the best-scored results.
Example
use gnverify::GNVerify; let mut gnv = GNVerify::new(); assert!(gnv.sources.is_none()); gnv.sources(vec![1,11,169]); assert_eq!(gnv.sources.unwrap()[1], 11_i64);
pub fn name_field(&mut self, name_field: i64)
[src]
Sets the index of name-string field. For example, if your TSV file contains "ID", "ScientificName", "Reference", use name_index 2.
Example
use gnverify::GNVerify; let mut gnv = GNVerify::new(); assert_eq!(gnv.name_field, 1); gnv.name_field(3); assert_eq!(gnv.name_field, 3);
pub fn preferred_only(&mut self)
[src]
Sets preferred_only field to true
Example
use gnverify::GNVerify; let mut gnv = GNVerify::new(); assert_eq!(gnv.preferred_only, false); gnv.preferred_only(); assert_eq!(gnv.preferred_only, true);
pub fn format(&mut self, format: Format)
[src]
Sets output format to one of: CSV, JSON, Pretty JSON.
Example
use gnverify::{GNVerify, Format}; let mut gnv = GNVerify::new(); assert_eq!(gnv.format.to_string(), "CSV"); gnv.format(Format::Pretty); assert_eq!(gnv.format.to_string(), "Pretty");
pub fn verify_stream(
&self,
in_r: Receiver<Vec<Input>>,
out_s: Sender<Vec<Output>>
)
[src]
&self,
in_r: Receiver<Vec<Input>>,
out_s: Sender<Vec<Output>>
)
Takes input channel with name-strings to verify and uses output channel to send back results of verification. The input channel is then cloned for several workers, so they all send data to gnindex server in parallel. There input send name-string in batches and their size is determined by batch_size field.
Example
use gnverify::{GNVerify, Input}; use crossbeam_channel::bounded; use std::thread; let mut gnv = GNVerify::new(); let (in_s, in_r) = bounded(0); let (out_s, out_r) = bounded(0); thread::spawn(move || gnv.clone().verify_stream(in_r, out_s)); let inputs: Vec<Input> = vec![Input{id: None, name: "Homo sapiens".to_owned()}]; in_s.send(inputs).unwrap(); let o = out_r.recv().unwrap(); assert_eq!(o.iter().next().unwrap().name, "Homo sapiens");
pub fn verify(&self, inputs: &Vec<Input>) -> Vec<Output>
[src]
Takes as input a vector name-strings and returns back a vector of corresponding verification outputs for the name-strings.
Example
use gnverify::{GNVerify, Input, MatchType}; let gnv = GNVerify::new(); let inputs: Vec<Input> = vec![Input{id: None, name: "Homo sapiens".to_owned()}]; let outputs = gnv.verify(&inputs); assert_eq!(outputs.len(), 1); if let Some(output) = outputs.iter().next() { assert_eq!(output.match_type.to_string(), "Exact".to_owned()); }
pub fn verify_and_format(&self, inputs: &Vec<Input>)
[src]
Convenience function that takes as an input a vector of name-strings and prints out results in desired output format.
Example
use gnverify::{GNVerify, Input, MatchType}; let gnv = GNVerify::new(); let inputs: Vec<Input> = vec![Input{id: None, name: "Homo sapiens".to_owned()}]; gnv.verify_and_format(&inputs);
pub fn format_outputs(&self, outputs: Vec<Output>, with_headers: bool)
[src]
Takes outputs of name-verification process and prints out the outputs in a desired format. It also takes with_headers parameter. If it is true, the printed output will have corresponding headers in CSV format.
Example
use gnverify::{GNVerify, Input, MatchType}; let gnv = GNVerify::new(); let inputs: Vec<Input> = vec![Input{id: None, name: "Homo sapiens".to_owned()}]; let outputs = gnv.verify(&inputs); assert_eq!(outputs.len(), 1); gnv.format_outputs(outputs, true);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for GNVerify
impl Send for GNVerify
impl Sync for GNVerify
impl Unpin for GNVerify
impl UnwindSafe for GNVerify
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,