Skip to content

Commit

Permalink
add constructor for Record
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Dec 15, 2023
1 parent e772c35 commit 4c596c7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
<a href="https://github.com/biopragmatics/curies.rs/blob/main/LICENSE">
<img alt="MIT license" src="https://img.shields.io/badge/License-MIT-brightgreen.svg" />
</a>
<!-- a href="https://codecov.io/gh/biopragmatics/curies.rs/branch/main">
<a href="https://codecov.io/gh/biopragmatics/curies.rs/branch/main">
<img src="https://codecov.io/gh/biopragmatics/curies.rs/branch/main/graph/badge.svg" alt="Codecov status" />
</a -->
</a>
</p>

Idiomatic conversion between URIs and compact URIs (CURIEs) in Rust.

## 📥 Install dependencies

[Rust](https://www.rust-lang.org/tools/install) is required for development.
[Rust](https://www.rust-lang.org/tools/install), python 3.8+ and npm are required for development.

```bash
rustup update
Expand Down
1 change: 0 additions & 1 deletion js/src/curies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ impl RecordJs {
) -> Result<RecordJs, JsValue> {
let prefix_synonyms_set: HashSet<String> = prefix_synonyms.into_iter().collect();
let uri_prefix_synonyms_set: HashSet<String> = uri_prefix_synonyms.into_iter().collect();

Ok(Self {
prefix,
uri_prefix,
Expand Down
40 changes: 15 additions & 25 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ pub struct Record {
// TODO: pattern: Option<String>,
}

impl Record {
fn new(prefix: &str, uri_prefix: &str) -> Self {
Record {
prefix: prefix.to_string(),
uri_prefix: uri_prefix.to_string(),
prefix_synonyms: HashSet::from([]),
uri_prefix_synonyms: HashSet::from([]),
}
}
}

/// A `Converter` is composed of 2 HashMaps (one for prefixes, one for URIs),
/// and a trie search to find the longest URI
/// # Examples
Expand Down Expand Up @@ -55,6 +66,7 @@ pub struct Converter {
trie_builder: TrieBuilder<u8>,
trie: Trie<u8>,
// TODO: pattern_map: HashMap<String, String>
// delimiter: char
}

impl Converter {
Expand Down Expand Up @@ -100,12 +112,7 @@ impl Converter {
pub fn from_prefix_map(prefix_map: HashMap<String, String>) -> Result<Self, CuriesError> {
let mut converter = Converter::default();
for (prefix, uri_prefix) in prefix_map {
converter.add_record(Record {
prefix,
uri_prefix,
prefix_synonyms: HashSet::from([]),
uri_prefix_synonyms: HashSet::from([]),
})?;
converter.add_record(Record::new(&prefix, &uri_prefix))?;
}
Ok(converter)
}
Expand Down Expand Up @@ -135,21 +142,11 @@ impl Converter {
}
match value {
Value::String(uri) => {
converter.add_record(Record {
prefix: key.clone(),
uri_prefix: uri.clone(),
prefix_synonyms: HashSet::from([]),
uri_prefix_synonyms: HashSet::from([]),
})?;
converter.add_record(Record::new(key, uri))?;
}
Value::Object(map) if map.get("@prefix") == Some(&Value::Bool(true)) => {
if let Some(Value::String(uri)) = map.get("@id") {
converter.add_record(Record {
prefix: key.clone(),
uri_prefix: uri.clone(),
prefix_synonyms: HashSet::from([]),
uri_prefix_synonyms: HashSet::from([]),
})?;
converter.add_record(Record::new(key, uri))?;
}
}
_ => continue,
Expand Down Expand Up @@ -315,10 +312,3 @@ impl DataSource for &Path {
// prefix: String,
// identifier: String,
// }

// pub struct Record {
// curie_prefix: String,
// uri_prefix: String,
// curie_prefix_synonyms: Vec<String>,
// uri_prefix_synonyms: Vec<String>,
// }

0 comments on commit 4c596c7

Please sign in to comment.