Skip to main content

entrenar/research/archive/
identifiers.rs

1//! Related identifiers and relation types.
2
3use serde::{Deserialize, Serialize};
4
5/// Related identifier for linking resources
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct RelatedIdentifier {
8    /// The identifier value (DOI, URL, etc.)
9    pub identifier: String,
10    /// Relation type
11    pub relation: RelationType,
12    /// Identifier scheme (DOI, URL, etc.)
13    pub scheme: IdentifierScheme,
14}
15
16impl RelatedIdentifier {
17    /// Create a "is identical to" relation
18    pub fn is_identical_to(identifier: impl Into<String>) -> Self {
19        let id = identifier.into();
20        let scheme = if id.starts_with("10.") {
21            IdentifierScheme::Doi
22        } else if id.starts_with("http") {
23            IdentifierScheme::Url
24        } else {
25            IdentifierScheme::Other
26        };
27
28        Self { identifier: id, relation: RelationType::IsIdenticalTo, scheme }
29    }
30
31    /// Create a "is supplement to" relation
32    pub fn is_supplement_to(identifier: impl Into<String>) -> Self {
33        let id = identifier.into();
34        let scheme =
35            if id.starts_with("10.") { IdentifierScheme::Doi } else { IdentifierScheme::Url };
36
37        Self { identifier: id, relation: RelationType::IsSupplementTo, scheme }
38    }
39
40    /// Create a "cites" relation
41    pub fn cites(identifier: impl Into<String>) -> Self {
42        Self {
43            identifier: identifier.into(),
44            relation: RelationType::Cites,
45            scheme: IdentifierScheme::Doi,
46        }
47    }
48}
49
50/// Relation types (based on DataCite)
51#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
52pub enum RelationType {
53    IsCitedBy,
54    Cites,
55    IsSupplementTo,
56    IsSupplementedBy,
57    IsContinuedBy,
58    Continues,
59    IsDescribedBy,
60    Describes,
61    HasMetadata,
62    IsMetadataFor,
63    HasVersion,
64    IsVersionOf,
65    IsNewVersionOf,
66    IsPreviousVersionOf,
67    IsPartOf,
68    HasPart,
69    IsReferencedBy,
70    References,
71    IsDocumentedBy,
72    Documents,
73    IsCompiledBy,
74    Compiles,
75    IsVariantFormOf,
76    IsOriginalFormOf,
77    IsIdenticalTo,
78    IsReviewedBy,
79    Reviews,
80    IsDerivedFrom,
81    IsSourceOf,
82    IsRequiredBy,
83    Requires,
84    IsObsoletedBy,
85    Obsoletes,
86}
87
88/// Identifier scheme
89#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
90pub enum IdentifierScheme {
91    Doi,
92    Url,
93    Orcid,
94    Ror,
95    Arxiv,
96    Pmid,
97    Other,
98}