core.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "core.h"
  2. bool LSR_is_init = false;
  3. /*
  4. * Initial namespace map.
  5. */
  6. static char *nsm_str[][2] = {
  7. {"ebucore", "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#"},
  8. {"rsrc", LSR_RSRC_PFX},
  9. {"lsup", "http://data.knowledgetx.com/onto/lsup#"},
  10. {"premis", "http://www.loc.gov/premis/rdf/v1#"},
  11. {NULL, NULL}
  12. };
  13. /*
  14. * Repo-managed predicates.
  15. */
  16. static char *mgd_pred_str[] = {
  17. "ebucore:hasMimeType",
  18. "lsup:created",
  19. "lsup:createdBy",
  20. "lsup:lastModified",
  21. "lsup:lastModifiedBy",
  22. "ore:proxyIn",
  23. "ore:proxyFor",
  24. "premis:hasSize",
  25. "premis:hasMessageDigest",
  26. NULL
  27. };
  28. /*
  29. * Repo-managed RDF types.
  30. */
  31. static char *mgd_type_str[] = {
  32. "lsup:AdminMetadata",
  33. "lsup:DataResource",
  34. "lsup:DescriptiveResource",
  35. "lsup:List",
  36. "lsup:ListItem",
  37. "lsup:Metadata",
  38. "lsup:Resource",
  39. "lsup:Set",
  40. "lsup:UserMetadata",
  41. "ore:Aggregation",
  42. "ore:Proxy",
  43. NULL
  44. };
  45. LSR_TermMap *LSR_managed_preds, *LSR_managed_types;
  46. /*
  47. * Callbacks.
  48. */
  49. /// Hash function for term map.
  50. static uint64_t tmap_hash_fn (const void *item, uint64_t seed0, uint64_t seed1)
  51. { return LSUP_term_hash ((LSUP_Term *) item); }
  52. /// Compare function for term map.
  53. static int tmap_cmp_fn (const void *a, const void *b, void *udata)
  54. {
  55. const LSUP_Term *ta = a, *tb = b;
  56. return strcmp(ta->data, tb->data);
  57. }
  58. /// Free element within the term map.
  59. static void tmap_free_fn (void *item)
  60. { LSUP_term_free ((LSUP_Term *) item); }
  61. LSUP_rc LSR_init (void)
  62. {
  63. if (LSR_is_init) return LSUP_NOACTION;
  64. LSUP_rc rc = LSUP_init();
  65. if (rc < 0) return rc;
  66. // Load additional LSUP_repo namespaces into store and memory.
  67. LSUP_NSMap *nsm = LSUP_default_nsm;
  68. for (int i = 0; nsm_str[i][0] != NULL; i++)
  69. LSUP_nsmap_add (nsm, nsm_str[i][0], nsm_str[i][1]);
  70. // Store the additional NS if this is the first time.
  71. //LSUP_nsmap_add (LSUP_default_mdb_store, nsm);
  72. // Cache managed predicates.
  73. LSR_managed_preds = hashmap_new (
  74. sizeof (LSUP_Term), 0, LSUP_HASH_SEED, 0,
  75. tmap_hash_fn, tmap_cmp_fn, tmap_free_fn, NULL);
  76. for (int i = 0; mgd_pred_str[i] != NULL; i++) {
  77. LSUP_Term *uri = LSUP_iriref_new (mgd_pred_str[i], LSUP_default_nsm);
  78. hashmap_set (LSR_managed_preds, uri);
  79. }
  80. // Cache managed types.
  81. LSR_managed_types = hashmap_new (
  82. sizeof (LSUP_Term), 0, LSUP_HASH_SEED, 0,
  83. tmap_hash_fn, tmap_cmp_fn, tmap_free_fn, NULL);
  84. for (int i = 0; mgd_type_str[i] != NULL; i++) {
  85. LSUP_Term *uri = LSUP_iriref_new (
  86. mgd_type_str[i], LSUP_default_nsm);
  87. hashmap_set (LSR_managed_types, uri);
  88. }
  89. LSR_is_init = true;
  90. atexit (LSR_done);
  91. return LSUP_OK;
  92. }
  93. void LSR_done (void)
  94. {
  95. if (!LSR_is_init) return;
  96. log_info ("Tearing down LSUP repo environment.");
  97. hashmap_free (LSR_managed_preds);
  98. hashmap_free (LSR_managed_types);
  99. LSUP_done();
  100. LSR_is_init = false;
  101. }
  102. LSUP_Term *LSR_id_to_urn (const uuid_t id, const char *frag);