nlp_annotations/
lib.rs

1//! NLP-annotations
2//!
3//! A collection of common NLP annotation schemes.
4
5pub use languages::Language;
6
7// a macro to generate enums whose variants are easily mapped to/from &str and are ordered
8// by their string representation
9macro_rules! strmapped_enum {
10    ( $(#[$attr:meta])* pub enum $name:ident { $($variant:ident = $value:expr,)+ } ) => {
11        $(#[$attr])*
12        #[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
13        pub enum $name {
14            $( $variant, )+
15        }
16
17        impl AsRef<str> for $name {
18            fn as_ref(&self) -> &'static str {
19                match *self {
20                    $( $name::$variant => $value, )+
21                }
22            }
23        }
24
25        impl ::std::str::FromStr for $name {
26            type Err = String;
27
28            fn from_str(value: &str) -> Result<$name, String> {
29                match value {
30                    $( $value => Ok($name::$variant), )+
31                    _ => return Err(value.to_string()),
32                }
33            }
34        }
35
36        impl ::std::cmp::PartialOrd for $name {
37            fn partial_cmp(&self, other: &$name) -> Option<::std::cmp::Ordering> {
38                ::std::cmp::PartialOrd::partial_cmp(self.as_ref(), other.as_ref())
39            }
40        }
41
42        impl ::std::cmp::Ord for $name {
43            fn cmp(&self, other: &$name) -> ::std::cmp::Ordering {
44                ::std::cmp::Ord::cmp(self.as_ref(), other.as_ref())
45            }
46        }
47    }
48}
49
50pub mod languages;
51pub mod deps;
52pub mod morpho;
53pub mod ner;
54pub mod pos;