forked from rudof-project/rudof
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5159ed5
commit 43b4347
Showing
12 changed files
with
230 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
use oxrdf::{Literal as OxLiteral, Term as OxTerm}; | ||
use srdf::lang::Lang; | ||
use std::collections::HashMap; | ||
use std::str::FromStr; | ||
|
||
#[derive(Debug, Default, Clone)] | ||
pub struct MessageMap { | ||
// mmap: HashMap<Option<Lang>, String> | ||
messages: HashMap<Option<Lang>, String>, | ||
} | ||
|
||
impl MessageMap { | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
pub fn with_message(mut self, lang: Option<Lang>, message: String) -> Self { | ||
self.messages.insert(lang, message); | ||
self | ||
} | ||
|
||
pub fn messages(&self) -> &HashMap<Option<Lang>, String> { | ||
&self.messages | ||
} | ||
|
||
pub fn to_term_iter(&self) -> impl Iterator<Item = OxTerm> + '_ { | ||
self.messages.iter().map(|(lang, message)| { | ||
let literal = if let Some(lang) = lang { | ||
OxLiteral::new_language_tagged_literal(message, lang.value()).unwrap() | ||
} else { | ||
OxLiteral::new_simple_literal(message) | ||
}; | ||
|
||
OxTerm::Literal(literal) | ||
}) | ||
} | ||
} | ||
|
||
impl FromStr for MessageMap { | ||
type Err = (); | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Ok(Self { | ||
messages: HashMap::from([(None, s.to_string())]), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,3 @@ pub mod shacl_vocab; | |
pub use ast::*; | ||
pub use converter::*; | ||
pub use shacl_vocab::*; | ||
|
||
#[cfg(test)] | ||
mod tests {} |
Oops, something went wrong.