Skip to content

Commit

Permalink
Add is_literal predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
ckindermann committed Aug 22, 2024
1 parent 83c6cc9 commit b9e4d06
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ofn_2_ldtab/annotation_translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ pub fn get_annotations(v : &Value) -> Vec<Value> {
}
}

pub fn is_literal(value: &Value) -> bool {
// Ensure the Value is a string
if let Some(s) = value.as_str() {
// Regex for a simple quoted string
let simple_string_re = Regex::new("^\"(.+)\"$").unwrap();
// Regex for a string with a language tag (e.g., "hello"@en)
let lang_tag_re = Regex::new("^\"(.+)\"@(.*)$").unwrap();
// Regex for a string with a datatype IRI or CURIE (e.g., "42"^^<http://example.com> or "42"^^prefix:suffix)
let iri_or_curie_re = Regex::new("^\"(.+)\"\\^\\^(.*)$").unwrap();

// Check if the string matches any of the forms
return simple_string_re.is_match(s) || lang_tag_re.is_match(s) || iri_or_curie_re.is_match(s);
}
false
}

pub fn translate_literal(s: &str) -> Value {

let language_tag = Regex::new("^\"(.+)\"@(.*)$").unwrap();
Expand Down

0 comments on commit b9e4d06

Please sign in to comment.