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
16 changed files
with
637 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ license = "GPL-3.0-or-later" | |
authors = [ | ||
"Jose Emilio Labra Gayo <[email protected]>", | ||
"Ángel Iglesias Préstamo <[email protected]>", | ||
"Marc-Antoine Arnaud <[email protected]>", | ||
] | ||
repository = "https://github.com/weso/shapes-rs" | ||
homepage = "https://www.weso.es/shapes-rs/" | ||
|
@@ -50,6 +51,7 @@ license = "MIT OR Apache-2.0" | |
authors = [ | ||
"Jose Emilio Labra Gayo <[email protected]>", | ||
"Ángel Iglesias Préstamo <[email protected]>", | ||
"Marc-Antoine Arnaud <[email protected]>", | ||
] | ||
description = "RDF data shapes implementation in Rust" | ||
repository = "https://github.com/weso/shapes-rs" | ||
|
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.