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 4.3 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  1. --- #step Index authority entities
  2. DROP MATERIALIZED VIEW IF EXISTS locid.auth_entity CASCADE;
  3. CREATE MATERIALIZED VIEW locid.auth_entity AS
  4. SELECT ant.subject_id AS auth_id, sn.node_uuid AS auth_uuid, sn.node_iri AS auth_iri
  5. FROM locid.auth_node_triples ant
  6. JOIN locid.nodes sn ON (ant.subject_id = sn.node_id)
  7. JOIN locid.nodes pn ON (ant.pred_id = pn.node_id)
  8. LEFT OUTER JOIN locid.nodes obn ON (ant.object_uuid = obn.node_uuid)
  9. WHERE pn.node_iri = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
  10. AND ant.object_uuid = node_uuid('http://www.loc.gov/mads/rdf/v1#Authority');
  11. CREATE INDEX auth_entity_idx ON locid.auth_entity (auth_id);
  12. CREATE INDEX auth_entity_uuidx ON locid.auth_entity (auth_uuid);
  13. CREATE INDEX auth_entity_iri_idx ON locid.auth_entity (auth_iri);
  14. ANALYZE locid.auth_entity;
  15. --- #step Extract contributions from works
  16. --- #allow duplicate_object
  17. -- This view will map internal contribution node UUIDs to object UUIDs
  18. -- referencing the 'agent' (contributor).
  19. CREATE MATERIALIZED VIEW locid.work_contribution AS
  20. SELECT DISTINCT wt.subject_uuid, wt.object_uuid
  21. FROM locid.work_triples wt
  22. -- we need to check the role
  23. JOIN locid.work_triples rt USING (subject_uuid)
  24. -- and the type - we want primary contributions
  25. JOIN locid.work_node_type tt USING (subject_uuid)
  26. WHERE wt.pred_uuid = node_uuid('http://id.loc.gov/ontologies/bibframe/agent')
  27. AND rt.pred_uuid = node_uuid('http://id.loc.gov/ontologies/bibframe/role')
  28. AND rt.object_uuid = node_uuid('http://id.loc.gov/vocabulary/relators/ctb')
  29. AND tt.object_uuid = node_uuid('http://id.loc.gov/ontologies/bflc/PrimaryContribution');
  30. CREATE INDEX wc_subj_idx ON locid.work_contribution (subject_uuid);
  31. CREATE INDEX wc_obj_idx ON locid.work_contribution (object_uuid);
  32. ANALYZE locid.work_triples;
  33. --- #step Create auth labels
  34. CREATE TABLE IF NOT EXISTS locid.auth_node_label (
  35. subject_uuid UUID NOT NULL,
  36. label VARCHAR NOT NULL
  37. );
  38. INSERT INTO locid.auth_node_label
  39. SELECT DISTINCT subject_uuid, lit_value
  40. FROM locid.auth_literals
  41. JOIN locid.node_aliases pa ON (pred_uuid = pa.node_uuid)
  42. WHERE node_alias IN ('label', 'auth-label');
  43. CREATE INDEX IF NOT EXISTS auth_node_label_subj_idx
  44. ON locid.auth_node_label (subject_uuid);
  45. CREATE INDEX IF NOT EXISTS auth_node_label_lbl_idx
  46. ON locid.auth_node_label (label);
  47. ANALYZE locid.auth_node_label;
  48. --- #step Count node occurrences in subject & object positions
  49. DROP MATERIALIZED VIEW IF EXISTS locid.auth_node_count_subject CASCADE;
  50. CREATE MATERIALIZED VIEW locid.auth_node_count_subject AS
  51. SELECT node_id, node_uuid, COUNT(object_uuid) AS n_sub_triples
  52. FROM locid.nodes
  53. JOIN locid.auth_triples ON (subject_uuid = node_uuid)
  54. GROUP BY node_id;
  55. CREATE INDEX auth_node_count_subject_node_idx ON locid.auth_node_count_subject (node_id);
  56. CREATE INDEX auth_node_count_subject_node_uuidx ON locid.auth_node_count_subject (node_uuid);
  57. ANALYZE locid.auth_node_count_subject;
  58. DROP MATERIALIZED VIEW IF EXISTS locid.auth_node_count_object CASCADE;
  59. CREATE MATERIALIZED VIEW locid.auth_node_count_object AS
  60. SELECT node_id, node_uuid, COUNT(subject_uuid) AS n_obj_triples
  61. FROM locid.nodes
  62. JOIN locid.auth_triples ON (object_uuid = node_uuid)
  63. GROUP BY node_id;
  64. CREATE INDEX auth_node_count_object_node_idx ON locid.auth_node_count_object (node_id);
  65. CREATE INDEX auth_node_count_object_node_uuidx ON locid.auth_node_count_object (node_uuid);
  66. ANALYZE locid.auth_node_count_object;
  67. --- #step Summarize gender data
  68. CREATE MATERIALIZED VIEW locid.mads_gender_summary AS
  69. SELECT COUNT(t.subject_uuid) AS n_subjects, o.node_id, o.node_uuid, o.node_iri, l.label
  70. FROM locid.auth_triples t
  71. JOIN locid.node_aliases pa ON (pred_uuid = pa.node_uuid)
  72. JOIN locid.nodes o ON (object_uuid = o.node_uuid)
  73. LEFT JOIN locid.auth_node_label l ON (object_uuid = l.subject_uuid)
  74. WHERE pa.node_alias = 'gender'
  75. GROUP BY o.node_id, o.node_iri, l.label;
  76. CREATE MATERIALIZED VIEW locid.skos_gender AS
  77. SELECT nt.object_uuid AS node_id, l.label
  78. FROM
  79. -- author triple
  80. locid.auth_triple nt
  81. -- author object to exclude
  82. LEFT JOIN locid.nodes ton ON (nt.object_uuid = ton.node_id)
  83. --- node type triples
  84. JOIN locid.auth_triple tt ON (nt.object_uuid = tt.subject_uuid)
  85. --- node labels
  86. JOIN locid.auth_node_label l ON (l.subject_uuid = nt.object_uuid)
  87. WHERE
  88. nt.pred_uuid = locid.common_node('gender')
  89. AND ton.node_id IS NULL
  90. AND tt.pred_uuid = locid.common_node('type')
  91. AND tt.object_uuid = locid.common_node('concept');
Tip!

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

Comments

Loading...