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.
Showing
14 changed files
with
526 additions
and
74 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
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())]), | ||
}) | ||
} | ||
} |
Oops, something went wrong.