rust_macios/natural_language/
nl_model_configuration.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4    foundation::{NSIndexSet, UInt},
5    object,
6    objective_c_runtime::{
7        macros::interface_impl,
8        traits::{FromId, PNSObject},
9    },
10    utils::to_optional,
11};
12
13use super::NLLanguage;
14
15/// The different types of a natural language model.
16#[derive(Debug)]
17#[repr(i64)]
18pub enum NLModelType {
19    /// A classifier model type that tags text at the phrase, sentence, paragraph, or higher level.
20    Classifier,
21    /// A sequence model type that tags text at the token level.
22    Sequence,
23}
24
25object! {
26    /// The configuration parameters of a natural language model.
27    unsafe pub struct NLModelConfiguration;
28}
29
30#[interface_impl(NSObject)]
31impl NLModelConfiguration {
32    /* Accessing the configuration
33     */
34
35    /// The language the model supports.
36    #[property]
37    pub fn language(&self) -> Option<NLLanguage> {
38        unsafe { to_optional(msg_send![self.m_self(), language]) }
39    }
40
41    /// The version of the Natural Language framework that trained the model.
42    #[property]
43    pub fn revision(&self) -> UInt {
44        unsafe { msg_send![self.m_self(), revision] }
45    }
46
47    /// Returns the versions of the Natural Language framework the OS supports.
48    #[method]
49    pub fn supported_revisions_for_type(r#type: NLModelType) -> NSIndexSet {
50        unsafe {
51            NSIndexSet::from_id(msg_send![
52                Self::m_class(),
53                supportedRevisionsForType: r#type
54            ])
55        }
56    }
57
58    /// Returns the current Natural Language framework version in the OS.
59    #[method]
60    pub fn current_revision_for_type(r#type: NLModelType) -> UInt {
61        unsafe { msg_send![Self::m_class(), currentRevisionForType: r#type] }
62    }
63
64    /// The natural language model type of the model.
65    #[property]
66    pub fn ml_type(&self) -> NLModelType {
67        unsafe { msg_send![self.m_self(), type] }
68    }
69}