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-triple-index.sql 2.6 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
  1. --- #step Index node IRIs
  2. CREATE INDEX IF NOT EXISTS node_iri_idx ON locid.nodes (node_iri);
  3. --- #step Vacuum and analyze node table
  4. --- #notx
  5. VACUUM ANALYZE locid.nodes;
  6. --- #step Index authority subjects and objects
  7. CREATE INDEX IF NOT EXISTS auth_subject_idx ON locid.auth_triples (subject_id);
  8. CREATE INDEX IF NOT EXISTS auth_object_idx ON locid.auth_triples (object_id);
  9. --- #step Analyze auth triples
  10. --- #notx
  11. VACUUM ANALYZE locid.auth_triples;
  12. --- #step Analyze auth literals
  13. --- #notx
  14. VACUUM ANALYZE locid.auth_literals;
  15. --- #step Index authority literal subjects
  16. CREATE INDEX IF NOT EXISTS auth_lit_subject_idx ON locid.auth_literals (subject_id);
  17. --- #step Index work subjects and objects
  18. CREATE INDEX IF NOT EXISTS work_subject_idx ON locid.work_triples (subject_id);
  19. CREATE INDEX IF NOT EXISTS work_object_idx ON locid.work_triples (object_id);
  20. ANALYZE locid.work_triples;
  21. --- #step Index work literal subjects
  22. CREATE INDEX IF NOT EXISTS work_lit_subject_idx ON locid.work_literals (subject_id);
  23. ANALYZE locid.work_literals;
  24. --- #step Analyze work triples
  25. --- #notx
  26. VACUUM ANALYZE locid.work_triples;
  27. --- #step Analyze work literals
  28. --- #notx
  29. VACUUM ANALYZE locid.work_literals;
  30. --- #step Index well-known nodes
  31. CREATE TABLE IF NOT EXISTS locid.node_aliases (
  32. node_alias VARCHAR UNIQUE NOT NULL,
  33. node_id INTEGER UNIQUE NOT NULL,
  34. node_uuid UUID UNIQUE NOT NULL,
  35. node_iri VARCHAR UNIQUE NOT NULL
  36. );
  37. CREATE OR REPLACE PROCEDURE locid.alias_node (alias VARCHAR, iri VARCHAR)
  38. LANGUAGE plpgsql
  39. AS $ln$
  40. BEGIN
  41. INSERT INTO locid.node_aliases (node_alias, node_id, node_uuid, node_iri)
  42. SELECT alias, node_id, node_uuid, node_iri
  43. FROM locid.nodes
  44. WHERE node_iri = iri
  45. ON CONFLICT DO NOTHING;
  46. END;
  47. $ln$;
  48. CREATE OR REPLACE FUNCTION locid.common_node(alias VARCHAR) RETURNS UUID
  49. LANGUAGE SQL STABLE PARALLEL SAFE COST 10
  50. AS $$
  51. SELECT node_uuid FROM locid.node_aliases WHERE node_alias = alias;
  52. $$;
  53. CALL locid.alias_node('label', 'http://www.w3.org/2000/01/rdf-schema#label');
  54. CALL locid.alias_node('auth-label', 'http://www.loc.gov/mads/rdf/v1#authoritativeLabel');
  55. CALL locid.alias_node('gender', 'http://www.loc.gov/mads/rdf/v1#gender');
  56. CALL locid.alias_node('concept', 'http://www.w3.org/2004/02/skos/core#Concept');
  57. CALL locid.alias_node('type', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type');
  58. CALL locid.alias_node('isbn', 'http://id.loc.gov/ontologies/bibframe/Isbn');
  59. CALL locid.alias_node('value', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
  60. CALL locid.alias_node('bf-id-by', 'http://id.loc.gov/ontologies/bibframe/identifiedBy');
  61. ANALYSE locid.node_aliases;
Tip!

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

Comments

Loading...