json_ld_expansion_next/options.rs
1use json_ld_core_next::ProcessingMode;
2
3pub use json_ld_context_processing_next::algorithm::Action;
4
5/// Expansion options.
6#[derive(Clone, Copy, Default)]
7pub struct Options {
8 /// Sets the processing mode.
9 pub processing_mode: ProcessingMode,
10
11 /// Term expansion policy.
12 ///
13 /// Default is `Policy::Standard`.
14 pub policy: Policy,
15
16 /// If set to true, input document entries are processed lexicographically.
17 /// If false, order is not considered in processing.
18 pub ordered: bool,
19}
20
21impl Options {
22 pub fn unordered(self) -> Self {
23 Self {
24 ordered: false,
25 ..self
26 }
27 }
28}
29
30impl From<Options> for json_ld_context_processing_next::Options {
31 fn from(options: Options) -> json_ld_context_processing_next::Options {
32 json_ld_context_processing_next::Options {
33 processing_mode: options.processing_mode,
34 ..Default::default()
35 }
36 }
37}
38
39/// Key expansion policy.
40///
41/// The default behavior of the expansion algorithm
42/// is to drop keys that are not defined in the context unless:
43/// - there is a vocabulary mapping (`@vocab`) defined in the context; or
44/// - the term contains a `:` character.
45///
46/// In other words, a key that cannot be expanded into an
47/// IRI or a blank node identifier is dropped unless it contains a `:` character.
48///
49/// Sometimes, it is preferable to keep undefined keys in the
50/// expanded document, or to forbid them completely by raising an error.
51/// You can define your preferred policy using one of this type variant
52/// with the [`Options::policy`] field.
53#[derive(Debug, Clone, Copy, PartialEq, Eq)]
54pub struct Policy {
55 /// How to expand invalid terms.
56 pub invalid: Action,
57
58 /// How to expand valid terms that need a vocabulary mapping
59 /// (`@vocab` keyword).
60 pub vocab: Action,
61
62 /// How to expand valid terms when there is no vocabulary mapping.
63 pub allow_undefined: bool,
64}
65
66impl Default for Policy {
67 fn default() -> Self {
68 Self {
69 invalid: Action::Keep,
70 vocab: Action::Keep,
71 allow_undefined: true,
72 }
73 }
74}