Skip to content

Commit

Permalink
version 0.0.2 ready :D
Browse files Browse the repository at this point in the history
  • Loading branch information
angelip2303 committed Jun 10, 2023
1 parent ae7f406 commit 8fc4f11
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
*/target/*

# These are backup files generated by rustfmt
**/*.rs.bk
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions wikidata-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wikidata-rs"
version = "0.0.1"
version = "0.0.2"
authors = [ "Ángel Iglesias Préstamo <[email protected]>" ]
description = "Utilities for working with Wikidata entities programmatically"
repository = "https://github.com/angelip2303/wd2duckdb"
Expand All @@ -15,6 +15,6 @@ duckdb = { version = "0.7.1", features = ["chrono"] }
chrono = "0.4.23"
lazy_static = "1.4.0"
wikidata = "0.3.0"
polars = { version = "0.29.0", features = ["lazy", "dtype-u8"]}
polars = { version = "0.30.0", features = ["lazy", "dtype-u8"]}
strum = "0.24.1"
strum_macros = "0.24"
13 changes: 12 additions & 1 deletion wikidata-rs/src/id.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::dtype::DataType;
use wikidata::{Fid, Lid, Pid, Qid, Sid};

/// The `Id` enum is defining different types of identifiers that can be used in the
Expand All @@ -11,6 +12,7 @@ pub enum Id {
Pid(Pid),
Qid(Qid),
Sid(Sid),
DataType(DataType),
}

/// This code defines a conversion function from a string slice (`&str`) to an `Id`
Expand Down Expand Up @@ -41,7 +43,15 @@ impl<'a> From<&'a str> for Id {
parts.next().unwrap()[1..].parse::<u16>().unwrap(),
))
}
_ => panic!("Invalid ID: {}", value),
Some("@") => match &value[1..] {
"Quantity" => Self::DataType(DataType::Quantity),
"Coordinate" => Self::DataType(DataType::Coordinate),
"String" => Self::DataType(DataType::String),
"DateTime" => Self::DataType(DataType::DateTime),
"Entity" => Self::DataType(DataType::Entity),
&_ => panic!("Unknown data type: {}", value),
},
_ => panic!("Not valid value: {}", value),
}
}
}
Expand All @@ -65,6 +75,7 @@ impl From<Id> for u32 {
Id::Sid(sid) => {
u32::from(Id::Lid(sid.0)) + (sid.1 as u32 * 3_000_000_000) + 500_000_000
}
Id::DataType(dt) => u8::from(&dt) as u32 + 4_000_000_000,
}
}
}

0 comments on commit 8fc4f11

Please sign in to comment.