Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

loc-id-auth-index.sql 2.5 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  1. --- #step Create auth labels
  2. CREATE TABLE IF NOT EXISTS locid.auth_node_label (
  3. subject_id UUID NOT NULL,
  4. label VARCHAR NOT NULL
  5. );
  6. INSERT INTO locid.auth_node_label
  7. SELECT DISTINCT subject_id, lit_value
  8. FROM locid.auth_literals
  9. JOIN locid.node_aliases pa ON (pred_id = pa.node_uuid)
  10. WHERE node_alias IN ('label', 'auth-label');
  11. CREATE INDEX IF NOT EXISTS auth_node_label_subj_idx
  12. ON locid.auth_node_label (subject_id);
  13. CREATE INDEX IF NOT EXISTS auth_node_label_lbl_idx
  14. ON locid.auth_node_label (label);
  15. ANALYZE locid.auth_node_label;
  16. --- #step Count node occurrences in subject & object positions
  17. DROP MATERIALIZED VIEW IF EXISTS locid.auth_node_count_subject CASCADE;
  18. CREATE MATERIALIZED VIEW locid.auth_node_count_subject AS
  19. SELECT node_id, node_uuid, COUNT(object_id) AS n_sub_triples
  20. FROM locid.nodes
  21. JOIN locid.auth_triples ON (subject_id = node_uuid)
  22. GROUP BY node_id;
  23. CREATE INDEX auth_node_count_subject_node_idx ON locid.auth_node_count_subject (node_id);
  24. CREATE INDEX auth_node_count_subject_node_uuidx ON locid.auth_node_count_subject (node_uuid);
  25. ANALYZE locid.auth_node_count_subject;
  26. DROP MATERIALIZED VIEW IF EXISTS locid.auth_node_count_object CASCADE;
  27. CREATE MATERIALIZED VIEW locid.auth_node_count_object AS
  28. SELECT node_id, node_uuid, COUNT(subject_id) AS n_obj_triples
  29. FROM locid.nodes
  30. JOIN locid.auth_triples ON (object_id = node_uuid)
  31. GROUP BY node_id;
  32. CREATE INDEX auth_node_count_object_node_idx ON locid.auth_node_count_object (node_id);
  33. CREATE INDEX auth_node_count_object_node_uuidx ON locid.auth_node_count_object (node_uuid);
  34. ANALYZE locid.auth_node_count_object;
  35. --- #step Summarize gender data
  36. CREATE MATERIALIZED VIEW locid.mads_gender_summary AS
  37. SELECT COUNT(t.subject_id) AS n_subjects, o.node_id, o.node_uuid, o.node_iri, l.label
  38. FROM locid.auth_triples t
  39. JOIN locid.node_aliases pa ON (pred_id = pa.node_uuid)
  40. JOIN locid.nodes o ON (object_id = o.node_uuid)
  41. LEFT JOIN locid.auth_node_label l ON (object_id = l.subject_id)
  42. WHERE pa.node_alias = 'gender'
  43. GROUP BY o.node_id, o.node_iri, l.label;
  44. CREATE MATERIALIZED VIEW locid.skos_gender AS
  45. SELECT nt.object_id AS node_id, l.label
  46. FROM
  47. -- author triple
  48. locid.auth_triple nt
  49. -- author object to exclude
  50. LEFT JOIN locid.nodes ton ON (nt.object_id = ton.node_id)
  51. --- node type triples
  52. JOIN locid.auth_triple tt ON (nt.object_id = tt.subject_id)
  53. --- node labels
  54. JOIN locid.auth_node_label l ON (l.subject_id = nt.object_id)
  55. WHERE
  56. nt.pred_id = locid.common_node('gender')
  57. AND ton.node_id IS NULL
  58. AND tt.pred_id = locid.common_node('type')
  59. AND tt.object_id = locid.common_node('concept');
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...