graph.pxd 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from libc.stdint cimport uint32_t, uint64_t
  2. from cymem.cymem cimport Pool
  3. from lakesuperior.cy_include cimport collections as cc
  4. from lakesuperior.model.base cimport Buffer
  5. from lakesuperior.model.graph.triple cimport BufferTriple
  6. from lakesuperior.model.structures.keyset cimport Keyset
  7. from lakesuperior.store.ldp_rs.lmdb_triplestore cimport LmdbTriplestore
  8. from lakesuperior.store.ldp_rs.lmdb_triplestore cimport TripleKey
  9. # Lookup function that returns whether a triple contains a match pattern.
  10. ctypedef bint (*lookup_fn_t)(
  11. const BufferTriple *trp, const Buffer *t1, const Buffer *t2)
  12. ctypedef Buffer SPOBuffer[3]
  13. ctypedef Buffer *BufferPtr
  14. cdef:
  15. int term_cmp_fn(const void* key1, const void* key2)
  16. int trp_cmp_fn(const void* key1, const void* key2)
  17. bint graph_eq_fn(SimpleGraph g1, SimpleGraph g2)
  18. size_t trp_hash_fn(const void* key, int l, uint32_t seed)
  19. size_t hash_ptr_passthrough(const void* key, int l, uint32_t seed)
  20. cdef class SimpleGraph:
  21. cdef:
  22. cc.HashSet *_terms # Set of unique serialized terms.
  23. cc.HashSet *_triples # Set of unique triples.
  24. readonly LmdbTriplestore store
  25. # Temp data pool. It gets managed with the object lifecycle via cymem.
  26. Pool _pool
  27. cc.key_compare_ft term_cmp_fn
  28. cc.key_compare_ft trp_cmp_fn
  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(self, BufferTriple *trp) except *
  33. int _remove_triple(self, BufferTriple* trp_buf) except -1
  34. bint _trp_contains(self, BufferTriple* btrp)
  35. _get_terms(self)
  36. set _to_pyset(self)
  37. # Basic graph operations.
  38. void ip_union(self, SimpleGraph other) except *
  39. void ip_intersection(self, SimpleGraph other) except *
  40. void ip_xor(self, SimpleGraph other) except *
  41. cpdef SimpleGraph xor(self, SimpleGraph other)
  42. cpdef SimpleGraph intersection(self, SimpleGraph other)
  43. cpdef SimpleGraph union(self, SimpleGraph other)
  44. cpdef void set(self, tuple trp) except *
  45. cpdef void remove_triples(self, pattern) except *
  46. cpdef object as_rdflib(self)
  47. #cpdef set terms(self, str type)
  48. cdef class Imr(SimpleGraph):
  49. cdef:
  50. readonly str uri
  51. cpdef as_rdflib(self)