Volksdata 1.0b7
RDF library
Loading...
Searching...
No Matches
RDF graph module
Collaboration diagram for RDF graph module:

Macros

#define VOLK_graph_get(...)
 Non-transactional version of VOLK_graph_get_txn().
#define VOLK_graph_copy_contents(...)
#define VOLK_graph_copy(src, dest)
#define VOLK_graph_bool_op(...)
 Non-transactional version of VOLK_graph_bool_op_txn.
#define VOLK_graph_add_init(...)
 Non-transactional version of VOLK_graph_add_init_txn().
#define VOLK_graph_add(...)
 Non-transactional version of VOLK_graph_add_txn.
#define VOLK_graph_remove(...)
 Non-transactional version of VOLK_graph_remove_txn.
#define VOLK_graph_lookup(...)
 Non-transactional version of VOLK_graph_lookup_txn.
#define VOLK_graph_list(...)
 Non-transactional version of VOLK_graph_list_txn.

Functions

VOLK_Graph * VOLK_graph_new (VOLK_Store *store, const char *uri_str)
 Create new graph.
VOLK_Graph * VOLK_graph_new_ns (VOLK_Store *store, const char *ns_str)
 Create an empty graph using a namespace-prefixed string for its URI.
VOLK_Graph * VOLK_graph_get_txn (void *txn, VOLK_Store *store, const VOLK_Term *uri, size_t *ct)
 Create a temp graph from stored triples.
VOLK_rc VOLK_graph_copy_contents_txn (void *txn, const VOLK_Graph *src, VOLK_Graph *dest, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o)
 Copy triples from a source graph into a destination one.
VOLK_rc VOLK_graph_bool_op_txn (void *txn, const VOLK_bool_op op, const VOLK_Graph *gr1, const VOLK_Graph *gr2, VOLK_Graph *res)
void VOLK_graph_free (VOLK_Graph *gr)
 Free a graph.
bool VOLK_graph_equals (const VOLK_Graph *gr1, const VOLK_Graph *gr2)
 Compare two graphs.
const VOLK_TermVOLK_graph_uri (const VOLK_Graph *gr)
 Read-only graph URI.
VOLK_StoreVOLK_graph_store (const VOLK_Graph *gr)
 Underlying graph store handle.
VOLK_rc VOLK_graph_set_uri (VOLK_Graph *gr, const char *uri_str)
size_t VOLK_graph_size (const VOLK_Graph *gr)
 Number of triples in a graph.
bool VOLK_graph_contains (const VOLK_Graph *gr, const VOLK_Triple *spo)
 Whether a graph contains a triple.
VOLK_GraphIterator * VOLK_graph_add_init_txn (void *txn, VOLK_Graph *gr)
 Initialize an iterator to add triples.
VOLK_rc VOLK_graph_add_iter (VOLK_GraphIterator *it, const VOLK_Triple *spo)
 Add a single triple to the store.
VOLK_rc VOLK_graph_add_txn (void *txn, VOLK_Graph *gr, VOLK_Triple *const *trp, size_t *ct)
 Add triples to a graph.
VOLK_rc VOLK_graph_remove_txn (void *txn, VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o, size_t *ct)
 Delete triples by a matching pattern.
VOLK_GraphIterator * VOLK_graph_lookup_txn (void *txn, const VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o, size_t *ct)
 Look up triples by a matching pattern and yield an iterator.
VOLK_rc VOLK_graph_iter_next (VOLK_GraphIterator *it, VOLK_Triple **spo)
 Advance a cursor obtained by a lookup and return a matching triple.
const VOLK_Graph * VOLK_graph_iter_graph (VOLK_GraphIterator *it)
 Return the graph related to an iterator.
void VOLK_graph_iter_free (VOLK_GraphIterator *it)
 Free a graph iterator.
void VOLK_graph_print (const VOLK_Graph *gr)
 Print graph information and triples to stdout.
VOLK_LinkMapVOLK_graph_connections (const VOLK_Graph *gr, const VOLK_Term *t, const VOLK_LinkType type)
 Get term pairs connected to a term in a graph.
VOLK_TermSetVOLK_graph_term_set (const VOLK_Graph *gr, const VOLK_Term *t1, const VOLK_TriplePos t1_pos, const VOLK_Term *t2, const VOLK_TriplePos t2_pos)
 Get a list of terms related to a term pair in a graph.
VOLK_TermSetVOLK_graph_unique_terms (const VOLK_Graph *gr, VOLK_TriplePos pos)
 Get all unique subjcts, predicates, or objects in a graph.
VOLK_TermSetVOLK_graph_list_txn (void *txn, VOLK_Store *store)
 List all graph URIs in a store.
size_t VOLK_graph_add_link_map (VOLK_GraphIterator *it, VOLK_LinkMap *lm)
 Add triples for a term and related link map to a graph.
VOLK_TermVOLK_bnode_add_collection (VOLK_GraphIterator *it, VOLK_TermSet *ts)
 Add triples for an anonymous collection to a graph.

Detailed Description

Macro Definition Documentation

◆ VOLK_graph_get

#define VOLK_graph_get ( ...)
Value:
VOLK_graph_get_txn (NULL, __VA_ARGS__)
VOLK_Graph * VOLK_graph_get_txn(void *txn, VOLK_Store *store, const VOLK_Term *uri, size_t *ct)
Create a temp graph from stored triples.
Definition graph.c:63

Non-transactional version of VOLK_graph_get_txn().

Definition at line 90 of file graph.h.

◆ VOLK_graph_copy_contents

#define VOLK_graph_copy_contents ( ...)
Value:
VOLK_graph_copy_contents_txn (NULL, __VA_ARGS__)
VOLK_rc VOLK_graph_copy_contents_txn(void *txn, const VOLK_Graph *src, VOLK_Graph *dest, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o)
Copy triples from a source graph into a destination one.
Definition graph.c:480

Definition at line 134 of file graph.h.

◆ VOLK_graph_copy

#define VOLK_graph_copy ( src,
dest )
Value:
VOLK_graph_copy_contents_txn (NULL, src, dest, NULL, NULL, NULL)

Definition at line 150 of file graph.h.

◆ VOLK_graph_bool_op

#define VOLK_graph_bool_op ( ...)
Value:
VOLK_graph_bool_op_txn (NULL, __VA_ARGS__)
VOLK_rc VOLK_graph_bool_op_txn(void *txn, const VOLK_bool_op op, const VOLK_Graph *gr1, const VOLK_Graph *gr2, VOLK_Graph *res)
Definition graph.c:100

Non-transactional version of VOLK_graph_bool_op_txn.

Definition at line 184 of file graph.h.

◆ VOLK_graph_add_init

#define VOLK_graph_add_init ( ...)
Value:
VOLK_graph_add_init_txn (NULL, __VA_ARGS__)
VOLK_GraphIterator * VOLK_graph_add_init_txn(void *txn, VOLK_Graph *gr)
Initialize an iterator to add triples.
Definition graph.c:343

Non-transactional version of VOLK_graph_add_init_txn().

Definition at line 282 of file graph.h.

◆ VOLK_graph_add

#define VOLK_graph_add ( ...)
Value:
VOLK_graph_add_txn (NULL, __VA_ARGS__)
VOLK_rc VOLK_graph_add_txn(void *txn, VOLK_Graph *gr, VOLK_Triple *const *trp, size_t *ct)
Add triples to a graph.
Definition graph.c:422

Non-transactional version of VOLK_graph_add_txn.

Definition at line 313 of file graph.h.

◆ VOLK_graph_remove

#define VOLK_graph_remove ( ...)
Value:
VOLK_graph_remove_txn (NULL, __VA_ARGS__)
VOLK_rc VOLK_graph_remove_txn(void *txn, VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o, size_t *ct)
Delete triples by a matching pattern.
Definition graph.c:456

Non-transactional version of VOLK_graph_remove_txn.

Definition at line 334 of file graph.h.

◆ VOLK_graph_lookup

#define VOLK_graph_lookup ( ...)
Value:
VOLK_graph_lookup_txn (NULL, __VA_ARGS__)
VOLK_GraphIterator * VOLK_graph_lookup_txn(void *txn, const VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o, size_t *ct)
Look up triples by a matching pattern and yield an iterator.
Definition graph.c:508

Non-transactional version of VOLK_graph_lookup_txn.

Definition at line 364 of file graph.h.

◆ VOLK_graph_list

#define VOLK_graph_list ( ...)
Value:
VOLK_graph_list_txn (NULL, __VA_ARGS__)
VOLK_TermSet * VOLK_graph_list_txn(void *txn, VOLK_Store *store)
List all graph URIs in a store.
Definition graph.c:627

Non-transactional version of VOLK_graph_list_txn.

Definition at line 472 of file graph.h.

Function Documentation

◆ VOLK_graph_new()

VOLK_Graph * VOLK_graph_new ( VOLK_Store * store,
const char * uri_str )

Create new graph.

Parameters
[in]storeBack end store handle. It may be the result of VOLK_store_new(), or NULL; in the latter case, it defaults to a temporary HTable store that is freed together with the graph.
[in]uri_strURI string of the new graph. It MUST be a non-prefixed URI. For a namespace-prefixed URI, use VOLK_graph_new_ns(). If NULL, a UUID4 URN is generated.
Returns
New graph, or NULL on error. Must be freed with VOLK_graph_free().

Definition at line 44 of file graph.c.

◆ VOLK_graph_new_ns()

VOLK_Graph * VOLK_graph_new_ns ( VOLK_Store * store,
const char * ns_str )
inline

Create an empty graph using a namespace-prefixed string for its URI.

Parameters
[in]storeBack end store handle. It may be the result of VOLK_store_new(), or NULL; in the latter case, it defaults to a temporary HTable store that is freed together with the graph.
[in]ns_strURI string of the new graph. It MUST be a namespace- prefixed URI registered in the global namespace map. It cannot be NULL.
Returns
New graph, or NULL on error. Must be freed with VOLK_graph_free().

Definition at line 54 of file graph.h.

◆ VOLK_graph_get_txn()

VOLK_Graph * VOLK_graph_get_txn ( void * txn,
VOLK_Store * store,
const VOLK_Term * uri,
size_t * ct )

Create a temp graph from stored triples.

The new graph is stored in a hash map and is made up of all the triples found in the store with the given context URI. The new graph URI is the same as the given context.

Parameters
[in]txnTransaction handle. If not NULL, new child transaction will be opened under the one provided.
[in]storeBack end store handle.
[in]uriURI of the graph to retrieve.
[out]ctIf not NULL, it will be populated with the number of triples found. TODO deprecate. VOLK_graph_size() does the same.
Returns
New graph handle. It must be freed by the caller. If no matching context URI was found, NULL is returned.

Definition at line 63 of file graph.c.

◆ VOLK_graph_copy_contents_txn()

VOLK_rc VOLK_graph_copy_contents_txn ( void * txn,
const VOLK_Graph * src,
VOLK_Graph * dest,
const VOLK_Term * s,
const VOLK_Term * p,
const VOLK_Term * o )

Copy triples from a source graph into a destination one.

The destination graph is not initialized here, so the copy is cumulative.

A 3-term pattern may be provided to filter triples to be extracted from the source graph. If all terms are NULL, all triples are copied.

Parameters
[in]txnTransaction handle. It may be NULL, or an open transaction handle, in which case the copy is done within the specified transaction.
[in]srcSource graph.
[in]destDestination graph.
[in]s,p,oTerms to look up for filtering. Any and all terms can be NULL, which indicate unbound terms.
Returns
VOLK_OK on success; VOLK_NOACTION if no triples were copied; <0 if an error occurred.

Definition at line 480 of file graph.c.

◆ VOLK_graph_bool_op_txn()

VOLK_rc VOLK_graph_bool_op_txn ( void * txn,
const VOLK_bool_op op,
const VOLK_Graph * gr1,
const VOLK_Graph * gr2,
VOLK_Graph * res )

Perform a boolean operation between two graphs.

This method populates an initialized graph with the result of the operation between two other graphs. The resulting graph may be of any store type and may be the result of graphs of different store types.

Parameters
[in]txnR/W transaction handle for the destination store. It may be NULL, or an open transaction within which the operation is performed.
[in]opOperation to perform. One of VOLK_bool_op.
[in]gr1First operand.
[in]gr2Second operand.
[out]resResult graph. The handle should be initialized via VOLK_graph_new() or equivalent. Any preexisting contents are not removed. If an unrecoverable error occurs, this graph is freed, and any preexisting triples are lost. Therefore, reusing a result graph handle should only be done in tightly controlled loops or sequences.
Returns
VOLK_OK on success; <0 on error.

Definition at line 100 of file graph.c.

◆ VOLK_graph_free()

void VOLK_graph_free ( VOLK_Graph * gr)

Free a graph.

Definition at line 246 of file graph.c.

◆ VOLK_graph_equals()

bool VOLK_graph_equals ( const VOLK_Graph * gr1,
const VOLK_Graph * gr2 )

Compare two graphs.

Note that if any of the two graphs has an open transaction, the function is performed in the first graph's transaction.

Parameters
[in]gr1First operand.
[in]gr2Second operand.
Returns
True if the graphs are topologically equal, false otherwise.

Definition at line 330 of file graph.c.

◆ VOLK_graph_uri()

const VOLK_Term * VOLK_graph_uri ( const VOLK_Graph * gr)

Read-only graph URI.

Note that, while VOLK_graph_new() and VOLK_graph_set_uri() expect a string, this function returns the complete VOLK_Term structure.

To change the graph URI, use VOLK_graph_set_uri.

Definition at line 263 of file graph.c.

◆ VOLK_graph_store()

VOLK_Store * VOLK_graph_store ( const VOLK_Graph * gr)

Underlying graph store handle.

Definition at line 267 of file graph.c.

◆ VOLK_graph_set_uri()

VOLK_rc VOLK_graph_set_uri ( VOLK_Graph * gr,
const char * uri_str )

Set the URI of a graph.

Note that by changing the URI of a graph backed by a context-sensitive store (i.e. VOLK_STORE_MDB*) effectively changes the underlying context that the triples are bound to. Triples are looked up in, and added to, the context that the graph URI represents. A non-context graph retains the same triple set when a graph URI changes, and relative URI lookups are resolved in real-time against the current graph URI.

Parameters
[in]grGraph handle.
[in]uri_strNew URI string. If namespace-prefixed, it will be resolved according to the graph's namespace map.
Returns
VOLK_OK on success; <0 on error.

Definition at line 272 of file graph.c.

◆ VOLK_graph_size()

size_t VOLK_graph_size ( const VOLK_Graph * gr)

Number of triples in a graph.

Parameters
grGraph handle.
Returns
Number of triples, or a negative value on error.

Extern inline definitions.

Definition at line 311 of file graph.c.

◆ VOLK_graph_contains()

bool VOLK_graph_contains ( const VOLK_Graph * gr,
const VOLK_Triple * spo )

Whether a graph contains a triple.

Parameters
[in]grGraph to look up into.
[in]spoTriple to look up.
Returns
1 if the triple is found, 0 if not found.

Definition at line 654 of file graph.c.

◆ VOLK_graph_add_init_txn()

VOLK_GraphIterator * VOLK_graph_add_init_txn ( void * txn,
VOLK_Graph * gr )

Initialize an iterator to add triples.

Parameters
[in]txnTransaction handle. It may be NULL. If not NULL, its handle will be bound to the iterator handle for its whole life cycle.
[in]grGraph to add to. It is added to the iterator state.
Returns
Iterator handle. This should be passed to VOLK_graph_add_iter() and must be freed with VOLK_graph_iter_free().

Definition at line 343 of file graph.c.

◆ VOLK_graph_add_iter()

VOLK_rc VOLK_graph_add_iter ( VOLK_GraphIterator * it,
const VOLK_Triple * spo )

Add a single triple to the store.

Parameters
[in]itIterator obtained with VOLK_graph_add_init_txn().
[in]spoTriple to add. Caller retains ownership. NOTE: the triple subject and object, if IRIRefs, are stored as relative to the graph URI.

Definition at line 360 of file graph.c.

◆ VOLK_graph_add_txn()

VOLK_rc VOLK_graph_add_txn ( void * txn,
VOLK_Graph * gr,
VOLK_Triple *const * trp,
size_t * ct )

Add triples to a graph.

Parameters
[in]txnTransaction handle. It may be NULL.
[in]grGraph to add triples to.
[in]trpNULL-terminated array of triple handles to add.
[out]ctThis will be filled with the total number of triples inserted.

Definition at line 422 of file graph.c.

◆ VOLK_graph_remove_txn()

VOLK_rc VOLK_graph_remove_txn ( void * txn,
VOLK_Graph * gr,
const VOLK_Term * s,
const VOLK_Term * p,
const VOLK_Term * o,
size_t * ct )

Delete triples by a matching pattern.

Parameters
[in]txnTransaction handle. It may be NULL.
[in]grGraph to delete triples from.
[in]s,p,oMatching pattern. Any and all of s, p, o can be NULL.
[out]ctIf not NULL it is populated with the number of triples deleted.

Definition at line 456 of file graph.c.

◆ VOLK_graph_lookup_txn()

VOLK_GraphIterator * VOLK_graph_lookup_txn ( void * txn,
const VOLK_Graph * gr,
const VOLK_Term * s,
const VOLK_Term * p,
const VOLK_Term * o,
size_t * ct )

Look up triples by a matching pattern and yield an iterator.

Parameters
[in]txnTransaction handle. It may be NULL.
[in]grGraph to look up.
[in]sSubject to look for. It can be NULL, which indicates an unbound term.
[in]pPredicate to look for. It can be NULL, which indicates an unbound term.
[in]oObject to look for. It can be NULL, which indicates an unbound term.
[out]ctIf not NULL, this handle is populated with the number of entries found.
Returns
Pointer to a VOLK_GraphIterator to be generated. It must be freed with VOLK_graph_iter_free() after use.

Definition at line 508 of file graph.c.

◆ VOLK_graph_iter_next()

VOLK_rc VOLK_graph_iter_next ( VOLK_GraphIterator * it,
VOLK_Triple ** spo )

Advance a cursor obtained by a lookup and return a matching triple.

Parameters
[in]itIterator handle obtained through VOLK_graph_lookup_txn.
[out]spoTriple handle pointer to be populated with the next result. If not NULL, it will allocate a new triple and new terms, and should be freed with VOLK_triple_free().
Returns
VOLK_OK if a result was found; VOLK_END if the end of the match list was reached.

Definition at line 568 of file graph.c.

◆ VOLK_graph_iter_graph()

const VOLK_Graph * VOLK_graph_iter_graph ( VOLK_GraphIterator * it)

Return the graph related to an iterator.

Definition at line 588 of file graph.c.

◆ VOLK_graph_iter_free()

void VOLK_graph_iter_free ( VOLK_GraphIterator * it)

Free a graph iterator.

DO NOT USE with iterators obtained with VOLK_graph_add_init_txn(). Use VOLK_graph_iter_free() with those.

Parameters
[in]itIterator to finalize.

Definition at line 598 of file graph.c.

◆ VOLK_graph_print()

void VOLK_graph_print ( const VOLK_Graph * gr)

Print graph information and triples to stdout.

Parameters
[in]grGraph handle to display.

Definition at line 669 of file graph.c.

◆ VOLK_graph_connections()

VOLK_LinkMap * VOLK_graph_connections ( const VOLK_Graph * gr,
const VOLK_Term * t,
const VOLK_LinkType type )

Get term pairs connected to a term in a graph.

This returns a VOLK_LinkMap extracted from a graph for a given term. The map can generate triples using VOLK_link_map_triples().

Depending on the type requested (VOLK_CONN_*), the term can be leveraged as a subject, predicate, or object.

Parameters
[in]grGraph to extract the connection list from.
[in]tTerm to query for connections.
[in]typeType of connections to look up.
Returns
Link map for the requested term. It should be freed with VOLK_link_map_free().

Definition at line 697 of file graph.c.

◆ VOLK_graph_term_set()

VOLK_TermSet * VOLK_graph_term_set ( const VOLK_Graph * gr,
const VOLK_Term * t1,
const VOLK_TriplePos t1_pos,
const VOLK_Term * t2,
const VOLK_TriplePos t2_pos )

Get a list of terms related to a term pair in a graph.

Parameters
[in]grGraph to extract terms from.
[in]t1First term.
[in]t1_posPosition of the first term in the triples to look up.
[in]t2Second term.
[in]t2_posPosition of the second term in the triples to look up.
Returns
Term set of results.

Definition at line 757 of file graph.c.

◆ VOLK_graph_unique_terms()

VOLK_TermSet * VOLK_graph_unique_terms ( const VOLK_Graph * gr,
VOLK_TriplePos pos )

Get all unique subjcts, predicates, or objects in a graph.

Parameters
[in]grGraph handle.
[in]posPosition in the triples of the terms to look for.

Definition at line 791 of file graph.c.

◆ VOLK_graph_list_txn()

VOLK_TermSet * VOLK_graph_list_txn ( void * txn,
VOLK_Store * store )

List all graph URIs in a store.

Parameters
[in]txnTransaction handle to work in. It may be NULL.
[in]storeStore to look for graphs.
Returns
Term set of graph URIs, or NULL on error.

Definition at line 627 of file graph.c.

◆ VOLK_graph_add_link_map()

size_t VOLK_graph_add_link_map ( VOLK_GraphIterator * it,
VOLK_LinkMap * lm )

Add triples for a term and related link map to a graph.

The link map can be of inbound, outbound, or edge type; depending on that, triples are added with the given term as the subject, the predicate, or the object.

Parameters
[in]itGraph iterator obtained with VOLK_graph_add_init_txn().
[in]lmLink map.
Returns
Number of triples parsed on success, or <0 (VOLK_*_ERR) on error.

Definition at line 812 of file graph.c.

◆ VOLK_bnode_add_collection()

VOLK_Term * VOLK_bnode_add_collection ( VOLK_GraphIterator * it,
VOLK_TermSet * ts )

Add triples for an anonymous collection to a graph.

The rdf:first, rdf:rest, etc. terms are automatically added and the term for the first item in the list is returned.

Parameters
[in]itGraph iterator to use for insertion.
[in]tsSource term set.
Returns
Blank node representing the first list item.

Definition at line 831 of file graph.c.