Skip to main content

shacl_ir/components/
language_in.rs

1use rudof_rdf::rdf_core::term::literal::Lang;
2use std::fmt::Display;
3
4/// The condition specified by sh:languageIn is that the allowed language tags
5/// for each value node are limited by a given list of language tags.
6///
7/// https://www.w3.org/TR/shacl/#LanguageInConstraintComponent
8#[derive(Debug, Clone)]
9pub struct LanguageIn {
10    langs: Vec<Lang>,
11}
12
13impl LanguageIn {
14    pub fn new(langs: Vec<Lang>) -> Self {
15        LanguageIn { langs }
16    }
17
18    pub fn langs(&self) -> &Vec<Lang> {
19        &self.langs
20    }
21}
22
23impl Display for LanguageIn {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        let langs = self
26            .langs()
27            .iter()
28            .map(|l| l.to_string())
29            .collect::<Vec<_>>()
30            .join(", ");
31        write!(f, "LanguageIn: [{langs}]")
32    }
33}