better match wikibase data model
This commit is contained in:
parent
10fad9247e
commit
d1d175628f
3 changed files with 20 additions and 8 deletions
|
@ -1,12 +1,14 @@
|
||||||
use crate::ids::{consts, Fid, Lid, Pid, Qid, Sid};
|
use crate::ids::{consts, Fid, Lid, Pid, Qid, Sid};
|
||||||
|
use crate::text::{Text, Lang};
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
use chrono::{DateTime, TimeZone, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A Wikibase entity.
|
/// A Wikibase entity: this could be an entity, property, or lexeme.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Entity {
|
pub struct Entity {
|
||||||
pub claims: Vec<(Pid, ClaimValue)>,
|
pub claims: Vec<(Pid, ClaimValue)>,
|
||||||
pub entity_type: EntityType,
|
pub entity_type: EntityType,
|
||||||
|
pub description: Text,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
|
@ -30,10 +32,8 @@ pub enum ClaimValueData {
|
||||||
Item(Qid),
|
Item(Qid),
|
||||||
Property(Pid),
|
Property(Pid),
|
||||||
Stringg(String),
|
Stringg(String),
|
||||||
MonolingualText {
|
MonolingualText(Text),
|
||||||
text: String,
|
MultilingualText(Vec<Text>),
|
||||||
lang: String,
|
|
||||||
},
|
|
||||||
ExternalID(String),
|
ExternalID(String),
|
||||||
Quantity {
|
Quantity {
|
||||||
amount: f64, // technically it could exceed the bound, but meh
|
amount: f64, // technically it could exceed the bound, but meh
|
||||||
|
@ -359,10 +359,10 @@ impl ClaimValueData {
|
||||||
precision: parse_wb_number(&take_prop("precision", &mut value))
|
precision: parse_wb_number(&take_prop("precision", &mut value))
|
||||||
.expect("Invalid precision {}") as u8,
|
.expect("Invalid precision {}") as u8,
|
||||||
}),
|
}),
|
||||||
"monolingualtext" => Ok(ClaimValueData::MonolingualText {
|
"monolingualtext" => Ok(ClaimValueData::MonolingualText(Text {
|
||||||
text: get_json_string(take_prop("text", &mut value))?,
|
text: get_json_string(take_prop("text", &mut value))?,
|
||||||
lang: get_json_string(take_prop("language", &mut value))?,
|
lang: Lang(get_json_string(take_prop("language", &mut value))?),
|
||||||
}),
|
})),
|
||||||
_ => Err(EntityError::UnknownDatatype),
|
_ => Err(EntityError::UnknownDatatype),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,3 +3,4 @@
|
||||||
|
|
||||||
pub mod entity;
|
pub mod entity;
|
||||||
pub mod ids;
|
pub mod ids;
|
||||||
|
pub mod text;
|
||||||
|
|
11
src/text.rs
Normal file
11
src/text.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// A language used in the Wikibase data model.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||||
|
pub struct Lang(pub String);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||||
|
pub struct Text {
|
||||||
|
pub text: String,
|
||||||
|
pub lang: Lang,
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue