graph.pxd 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from libc.stdint cimport uint32_t, uint64_t
  2. from cymem.cymem cimport Pool
  3. from lakesuperior.cy_include.collections cimport (
  4. HashSet, HashSetConf,
  5. #_hash_ft, _key_compare_ft, _mem_alloc_ft, _mem_calloc_ft, _mem_free_ft,
  6. )
  7. from lakesuperior.model.base cimport Buffer
  8. from lakesuperior.model.graph.triple cimport BufferTriple
  9. from lakesuperior.model.structures.keyset cimport Keyset
  10. from lakesuperior.store.ldp_rs.lmdb_triplestore cimport LmdbTriplestore
  11. from lakesuperior.store.ldp_rs.lmdb_triplestore cimport TripleKey
  12. # Lookup function that returns whether a triple contains a match pattern.
  13. ctypedef bint (*lookup_fn_t)(
  14. const BufferTriple *trp, const Buffer *t1, const Buffer *t2)
  15. ctypedef Buffer SPOBuffer[3]
  16. ctypedef Buffer *BufferPtr
  17. cdef:
  18. int term_cmp_fn(const void* key1, const void* key2)
  19. int triple_cmp_fn(const void* key1, const void* key2)
  20. size_t trp_hash_fn(const void* key, int l, uint32_t seed)
  21. size_t hash_ptr_passthrough(const void* key, int l, uint32_t seed)
  22. cdef class SimpleGraph:
  23. cdef:
  24. HashSet *_terms # Set of unique serialized terms.
  25. HashSet *_triples # Set of unique triples.
  26. readonly LmdbTriplestore store
  27. # Temp data pool. It gets managed with the object lifecycle via cymem.
  28. Pool _pool
  29. void _data_from_lookup(self, tuple trp_ptn, ctx=*) except *
  30. void _data_from_keyset(self, Keyset data) except *
  31. inline void _add_from_spok(self, const TripleKey spok) except *
  32. inline void _add_triple(
  33. self, Buffer *ss, Buffer *sp, Buffer *so
  34. ) except *
  35. int _add_or_get_term(self, Buffer **data) except -1
  36. set _data_as_set(self)
  37. cpdef void set(self, tuple trp) except *
  38. cpdef void remove_triples(self, pattern) except *
  39. cpdef object as_rdflib(self)
  40. cpdef set terms(self, str type)
  41. cdef class Imr(SimpleGraph):
  42. cdef:
  43. readonly str uri
  44. cpdef as_rdflib(self)