qualia_solid_bridge/
vocab.rs1use qualia_core_db::q_hash;
15
16pub const NS_LDP: &str = "http://www.w3.org/ns/ldp#";
18pub const NS_ACL: &str = "http://www.w3.org/ns/auth/acl#";
19pub const NS_SOLID: &str = "http://www.w3.org/ns/solid/terms#";
20pub const NS_SOLID_OIDC: &str = "http://www.w3.org/ns/solid/oidc#";
21pub const NS_PIM_SPACE: &str = "http://www.w3.org/ns/pim/space#";
22pub const NS_FOAF: &str = "http://xmlns.com/foaf/0.1/";
23pub const NS_CERT: &str = "http://www.w3.org/ns/auth/cert#";
24
25pub const LDP_RESOURCE: &str = "http://www.w3.org/ns/ldp#Resource";
27pub const LDP_RDF_SOURCE: &str = "http://www.w3.org/ns/ldp#RDFSource";
28pub const LDP_BASIC_CONTAINER: &str = "http://www.w3.org/ns/ldp#BasicContainer";
29pub const LDP_CONTAINER: &str = "http://www.w3.org/ns/ldp#Container";
30pub const LDP_CONTAINS: &str = "http://www.w3.org/ns/ldp#contains";
31pub const LDP_INBOX: &str = "http://www.w3.org/ns/ldp#inbox";
32
33pub const SOLID_OIDC_ISSUER: &str = "http://www.w3.org/ns/solid/terms#oidcIssuer";
35pub const SOLID_STORAGE: &str = "http://www.w3.org/ns/solid/terms#storage"; pub const SOLID_OIDC_ISSUER_SERVICE: &str =
37 "http://www.w3.org/ns/solid/terms#oidcIssuerRegistrationToken";
38
39pub const PIM_STORAGE: &str = "http://www.w3.org/ns/pim/space#storage";
41pub const PIM_PREFERENCES_FILE: &str = "http://www.w3.org/ns/pim/space#preferencesFile";
42
43pub const FOAF_PERSON: &str = "http://xmlns.com/foaf/0.1/Person";
45pub const FOAF_AGENT: &str = "http://xmlns.com/foaf/0.1/Agent";
46pub const FOAF_NAME: &str = "http://xmlns.com/foaf/0.1/name";
47
48pub const ACL_AUTHORIZATION: &str = "http://www.w3.org/ns/auth/acl#Authorization";
50pub const ACL_ACCESS_TO: &str = "http://www.w3.org/ns/auth/acl#accessTo";
51pub const ACL_MODE: &str = "http://www.w3.org/ns/auth/acl#mode";
52pub const ACL_AGENT: &str = "http://www.w3.org/ns/auth/acl#agent";
53pub const ACL_AGENT_CLASS: &str = "http://www.w3.org/ns/auth/acl#agentClass";
54pub const ACL_READ: &str = "http://www.w3.org/ns/auth/acl#Read";
55pub const ACL_WRITE: &str = "http://www.w3.org/ns/auth/acl#Write";
56pub const ACL_CONTROL: &str = "http://www.w3.org/ns/auth/acl#Control";
57pub const ACL_APPEND: &str = "http://www.w3.org/ns/auth/acl#Append";
58
59pub mod hash {
61 use super::*;
62 use std::sync::OnceLock;
63
64 fn h(iri: &str) -> u64 {
65 q_hash(iri)
66 }
67
68 static LDP_CONTAINS: OnceLock<u64> = OnceLock::new();
69 static SOLID_OIDC_ISSUER: OnceLock<u64> = OnceLock::new();
70 static PIM_STORAGE: OnceLock<u64> = OnceLock::new();
71
72 pub fn ldp_contains() -> u64 {
74 *LDP_CONTAINS.get_or_init(|| h(super::LDP_CONTAINS))
75 }
76 pub fn solid_oidc_issuer() -> u64 {
78 *SOLID_OIDC_ISSUER.get_or_init(|| h(super::SOLID_OIDC_ISSUER))
79 }
80 pub fn pim_storage() -> u64 {
82 *PIM_STORAGE.get_or_init(|| h(super::PIM_STORAGE))
83 }
84}
85
86pub const POD_ONTOLOGY_FILES: &[(&str, &str)] = &[
88 ("ldp.ttl", "Linked Data Platform"),
89 ("auth-acl.ttl", "Web Access Control"),
90 ("solid-terms.ttl", "Solid Terms"),
91 ("solid-oidc.ttl", "Solid-OIDC"),
92 ("pim-space.ttl", "PIM Workspace / Storage"),
93 ("foaf.ttl", "FOAF"),
94];
95
96pub fn resolve_ontology_source(file_name: &str) -> Option<std::path::PathBuf> {
98 if let Ok(extra) = std::env::var("QUALIA_BUNDLED_ONTOLOGIES_DIR") {
99 let root = std::path::PathBuf::from(extra);
100 let p = root.join(file_name);
101 if p.is_file() {
102 return Some(p);
103 }
104 let p2 = root.join("w3c-archives").join(file_name);
105 if p2.is_file() {
106 return Some(p2);
107 }
108 }
109 if let Ok(exe) = std::env::current_exe() {
110 if let Some(dir) = exe.parent() {
111 for rel in [
112 format!("bundled/ontologies/w3c-archives/{file_name}"),
113 format!("ontologies/w3c-archives/{file_name}"),
114 format!("w3c-archives/{file_name}"),
115 file_name.to_string(),
116 ] {
117 let mut p = dir.to_path_buf();
118 for seg in rel.split('/') {
119 p.push(seg);
120 }
121 if p.is_file() {
122 return Some(p);
123 }
124 }
125 }
126 }
127 let repo = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
129 .join("../../bundled/ontologies/w3c-archives")
130 .join(file_name);
131 if repo.is_file() {
132 return Some(repo);
133 }
134 None
135}
136
137#[cfg(test)]
138mod tests {
139 use super::*;
140
141 #[test]
142 fn solid_core_sources_resolve_in_dev_tree() {
143 for (file, _) in POD_ONTOLOGY_FILES {
144 let p = resolve_ontology_source(file);
145 assert!(
146 p.is_some(),
147 "missing bundled ontology {file} — copy from ontologies-2023/w3c-ns"
148 );
149 }
150 }
151
152 #[test]
153 fn hashes_are_stable_and_nonzero() {
154 assert_ne!(hash::ldp_contains(), 0);
155 assert_ne!(hash::solid_oidc_issuer(), 0);
156 assert_eq!(hash::ldp_contains(), q_hash(LDP_CONTAINS));
157 }
158}