|
@@ -61,6 +61,8 @@ typedef enum {
|
|
*/
|
|
*/
|
|
typedef struct iri_info_t LSUP_IRIInfo;
|
|
typedef struct iri_info_t LSUP_IRIInfo;
|
|
|
|
|
|
|
|
+typedef struct link_map_iter LSUP_LinkMapIterator;
|
|
|
|
+
|
|
/// RDF term.
|
|
/// RDF term.
|
|
typedef struct term_t {
|
|
typedef struct term_t {
|
|
char * data; // URI, literal value, or BNode label.
|
|
char * data; // URI, literal value, or BNode label.
|
|
@@ -85,65 +87,54 @@ typedef struct term_t {
|
|
((term)->type == LSUP_TERM_LITERAL || (term)->type == LSUP_TERM_LT_LITERAL)
|
|
((term)->type == LSUP_TERM_LITERAL || (term)->type == LSUP_TERM_LT_LITERAL)
|
|
|
|
|
|
|
|
|
|
|
|
+/** @brief RDF triple.
|
|
|
|
+ *
|
|
|
|
+ * This represents a complete RDF statement. Triple terms can be accessed
|
|
|
|
+ * directly via the `s`, `p`, `o` members or sequentially via
|
|
|
|
+ * #LSUP_triple_pos().
|
|
|
|
+ */
|
|
typedef struct triple_t {
|
|
typedef struct triple_t {
|
|
- LSUP_Term *s;
|
|
|
|
- LSUP_Term *p;
|
|
|
|
- LSUP_Term *o;
|
|
|
|
|
|
+ LSUP_Term *s; ///< Subject.
|
|
|
|
+ LSUP_Term *p; ///< Predicate.
|
|
|
|
+ LSUP_Term *o; ///< Object.
|
|
} LSUP_Triple;
|
|
} LSUP_Triple;
|
|
|
|
|
|
|
|
|
|
-/** @brief Key-term pair.
|
|
|
|
- */
|
|
|
|
-typedef struct term_cache_entry_t {
|
|
|
|
- LSUP_Key key; // Key (hash) of the term.
|
|
|
|
- LSUP_Term * term; // Term handle.
|
|
|
|
-} LSUP_KeyedTerm;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/// Connection type.
|
|
|
|
|
|
+/// Link type.
|
|
typedef enum {
|
|
typedef enum {
|
|
- LSUP_CONN_INBOUND, ///< Inbound connection (sp).
|
|
|
|
- LSUP_CONN_OUTBOUND, ///< Outbound connection (po).
|
|
|
|
- LSUP_CONN_EDGE, ///< Edge connection (so).
|
|
|
|
-} LSUP_ConnectionType;
|
|
|
|
|
|
+ LSUP_LINK_INBOUND, ///< Inbound link (sp).
|
|
|
|
+ LSUP_LINK_OUTBOUND, ///< Outbound link (po).
|
|
|
|
+ LSUP_LINK_EDGE, ///< Edge link (so).
|
|
|
|
+} LSUP_LinkType;
|
|
|
|
|
|
|
|
|
|
-/** @brief Connection list.
|
|
|
|
- *
|
|
|
|
- * A list of predicates and related lists of terms, that can be used to list
|
|
|
|
- * inbound or outbound connections to a node.
|
|
|
|
|
|
+/** @brief The immediate neighborhood of terms connected to a term.
|
|
*
|
|
*
|
|
- * Each term in the NUL-terminated `p` list represent a term which is
|
|
|
|
- * paired with a list of terms in the `tl` list. The index of each term in this
|
|
|
|
- * list corresponds to the same index of a term list in `tl`.
|
|
|
|
- *
|
|
|
|
- * If the type of the connection list is `LSUP_CONN_INBOUND`, the term list
|
|
|
|
- * represent subjects and a term that is associated with the connection list is
|
|
|
|
- * the related object; if `LSUP_CONN_OUTBOUND`, the term list represents
|
|
|
|
- * objects, and a term that is associated with the connection list represents
|
|
|
|
- * the subject. If `LSUP_CONN_EDGE`, the members of the connection list
|
|
|
|
- * represent subjects and objects, and the associated term is the predicate.
|
|
|
|
|
|
+ * This is a hash map whose each term is related to a set of one or more other
|
|
|
|
+ * terms. The hash map is inside an opaque handle and is manipulated via the
|
|
|
|
+ * `LSUP_link_map_*` functions.
|
|
*
|
|
*
|
|
|
|
+ * If the type of the link map is `LSUP_LINK_INBOUND`, the map keys
|
|
|
|
+ * represent predicates and the sets related to them are the objects, and the
|
|
|
|
+ * term associated to the link map is the object; if
|
|
|
|
+ * `LSUP_LINK_OUTBOUND`, the keys represent predicates, the related sets
|
|
|
|
+ * objects, and the associated term is the subject. If `LSUP_LINK_EDGE`, the
|
|
|
|
+ * keys represent subjects and the related sets objects, and the associated
|
|
|
|
+ * term is the predicate.
|
|
*/
|
|
*/
|
|
-typedef struct {
|
|
|
|
- LSUP_ConnectionType type; ///< Inbound or outbound connection.
|
|
|
|
- LSUP_Term ** t; ///< NUL-terminated array of term handles.
|
|
|
|
- LSUP_Term *** tl; /**<
|
|
|
|
- * NUL-terminated array of
|
|
|
|
- * NUL-terminated arrays of term handles.
|
|
|
|
- */
|
|
|
|
-} LSUP_ConnectionList;
|
|
|
|
|
|
+typedef struct link_map LSUP_LinkMap;
|
|
|
|
|
|
|
|
|
|
-/*
|
|
|
|
- * Extern variables.
|
|
|
|
|
|
+/** @brief a set of unique terms.
|
|
|
|
+ *
|
|
|
|
+ * This is used to bulk-add terms to a link map.
|
|
*/
|
|
*/
|
|
|
|
+typedef struct hashmap LSUP_TermSet;
|
|
|
|
|
|
-/** @brief Global term cache.
|
|
|
|
- *
|
|
|
|
- * Stores frequently used terms, e.g. data type URIs.
|
|
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * External variables.
|
|
*/
|
|
*/
|
|
-extern struct hashmap *LSUP_term_cache;
|
|
|
|
|
|
|
|
/** @brief Compiled hash of default literal data type.
|
|
/** @brief Compiled hash of default literal data type.
|
|
*/
|
|
*/
|
|
@@ -160,6 +151,12 @@ extern regex_t *LSUP_uri_ptn;
|
|
*/
|
|
*/
|
|
extern LSUP_Term *LSUP_default_datatype;
|
|
extern LSUP_Term *LSUP_default_datatype;
|
|
|
|
|
|
|
|
+/** @brief Global term cache.
|
|
|
|
+ *
|
|
|
|
+ * Stores frequently used terms, e.g. data type URIs.
|
|
|
|
+ */
|
|
|
|
+extern LSUP_TermSet *LSUP_term_cache;
|
|
|
|
+
|
|
|
|
|
|
/*
|
|
/*
|
|
* API functions.
|
|
* API functions.
|
|
@@ -492,83 +489,154 @@ LSUP_triple_hash (const LSUP_Triple *trp)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-/** @brief Add an identifier to the term cache.
|
|
|
|
|
|
+/** @brief Create a new term set.
|
|
*
|
|
*
|
|
- * @param[in] key Hash of the inserted term.
|
|
|
|
|
|
+ * @return New empty term set.
|
|
|
|
+ */
|
|
|
|
+LSUP_TermSet *
|
|
|
|
+LSUP_term_set_new (void);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Free a term set.
|
|
*
|
|
*
|
|
- * @param[in] term Term to insert. A copy of the term is stored in the cache,
|
|
|
|
- * which is freed on application teardown.
|
|
|
|
|
|
+ * @param[in] ts Term set handle.
|
|
|
|
+ */
|
|
|
|
+void
|
|
|
|
+LSUP_term_set_free (LSUP_TermSet *ts);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Add term to a term set.
|
|
|
|
+ *
|
|
|
|
+ * If the same term is already in the set, it is not replaced, and the existing
|
|
|
|
+ * term's handle is made available in the `existing` variable. In this case,
|
|
|
|
+ * the caller may want to free the passed term which has not been added.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] tl Term set to be added to.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] term Term to be added to the list. The term set will take
|
|
|
|
+ * ownership of the term and free it when it's freed with
|
|
|
|
+ * #LSUP_term_set_free()—only if the return code is LSUP_OK.
|
|
|
|
+ *
|
|
|
|
+ * @param[out] existing If not NULL, and if the term being added is a
|
|
|
|
+ * duplicate, this variable will be populated with the existing term handle.
|
|
|
|
+ *
|
|
|
|
+ * @return LSUP_OK on success; LSUP_NOACTION if the term is duplicate;
|
|
|
|
+ * LSUP_MEM_ERR on memory error. Note: if not LSUP_OK, the caller is in charge
|
|
|
|
+ * of freeing the `term` handle.
|
|
*/
|
|
*/
|
|
LSUP_rc
|
|
LSUP_rc
|
|
-LSUP_tcache_add (const LSUP_Key key, const LSUP_Term *term);
|
|
|
|
|
|
+LSUP_term_set_add (LSUP_TermSet *ts, LSUP_Term *term, LSUP_Term **existing);
|
|
|
|
+
|
|
|
|
|
|
-/** @brief Get an identifier from the cache.
|
|
|
|
|
|
+/** @brief Get a term from a term set.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] ts Term set handle.
|
|
*
|
|
*
|
|
* @param[in] key Key for the queried term.
|
|
* @param[in] key Key for the queried term.
|
|
*
|
|
*
|
|
- * @return The retrieved term if found, or NULL. The string must not be
|
|
|
|
|
|
+ * @return The retrieved term if found, or NULL. The term must not be
|
|
* modified or freed.
|
|
* modified or freed.
|
|
*/
|
|
*/
|
|
const LSUP_Term *
|
|
const LSUP_Term *
|
|
-LSUP_tcache_get (LSUP_Key key);
|
|
|
|
|
|
+LSUP_term_set_get (LSUP_TermSet *ts, LSUP_Key key);
|
|
|
|
|
|
|
|
|
|
-/** @brief Add term to a term list.
|
|
|
|
|
|
+/** @brief Iterate trough a term set.
|
|
*
|
|
*
|
|
- * @param[in] tl Array of term handles to be added to. The handle must be NUL-
|
|
|
|
- * terminated. On success, this handle will be reallocated and the new address
|
|
|
|
- * returned, so the passed handle should no longer be used. On failure, it
|
|
|
|
- * remains unchanged and may be reused.
|
|
|
|
|
|
+ * @param[in] ts Term set handle.
|
|
*
|
|
*
|
|
- * @param[in] t Term to be added to the list. The object list will take
|
|
|
|
- * ownership of the term.
|
|
|
|
|
|
+ * @param[in,out] i Iterator to be initially set to 0.
|
|
*
|
|
*
|
|
- * @return Reallocated list on success; NULL on failure.
|
|
|
|
|
|
+ * @param[out] term Pointer to be populated with the next term on success. It
|
|
|
|
+ * may be NULL.
|
|
|
|
+ *
|
|
|
|
+ * @return LSUP_OK if the next term was retrieved; LSUP_END if the end of the
|
|
|
|
+ * set has been reached.
|
|
*/
|
|
*/
|
|
-LSUP_Term **
|
|
|
|
-LSUP_term_list_add (LSUP_Term **tl, LSUP_Term *t);
|
|
|
|
|
|
+LSUP_rc
|
|
|
|
+LSUP_term_set_next (LSUP_TermSet *ts, size_t *i, LSUP_Term **term);
|
|
|
|
|
|
|
|
|
|
-/** @brief New connection list.
|
|
|
|
|
|
+/** @brief New link map.
|
|
*
|
|
*
|
|
* The initial state of the returned list is: `{t: [NULL], tl: [NULL]}`
|
|
* The initial state of the returned list is: `{t: [NULL], tl: [NULL]}`
|
|
*
|
|
*
|
|
- * Predicates and term lists can be added with #LSUP_conn_list_add, and terms
|
|
|
|
|
|
+ * Predicates and term lists can be added with #LSUP_link_map_add, and terms
|
|
* can be added to a term list with #LSUP_term_list_add.
|
|
* can be added to a term list with #LSUP_term_list_add.
|
|
*
|
|
*
|
|
* @return a new empty predicate-object list.
|
|
* @return a new empty predicate-object list.
|
|
*/
|
|
*/
|
|
-LSUP_ConnectionList *
|
|
|
|
-LSUP_conn_list_new (LSUP_ConnectionType type);
|
|
|
|
|
|
+LSUP_LinkMap *
|
|
|
|
+LSUP_link_map_new (LSUP_LinkType type);
|
|
|
|
|
|
|
|
|
|
-/** @brief Free a predicate-object list.
|
|
|
|
|
|
+/** @brief Free a link map.
|
|
*
|
|
*
|
|
* All arrays and term handles are recursively freed.
|
|
* All arrays and term handles are recursively freed.
|
|
*
|
|
*
|
|
- * @param[in] pol Predicate-object list handle obtained with
|
|
|
|
- * #LSUP_conn_list_new().
|
|
|
|
|
|
+ * @param[in] pol link map handle obtained with #LSUP_link_map_new().
|
|
*/
|
|
*/
|
|
void
|
|
void
|
|
-LSUP_conn_list_free (LSUP_ConnectionList *pol);
|
|
|
|
|
|
+LSUP_link_map_free (LSUP_LinkMap *pol);
|
|
|
|
+
|
|
|
|
|
|
|
|
+/// Return the link map type.
|
|
|
|
+LSUP_LinkType
|
|
|
|
+LSUP_link_map_type (const LSUP_LinkMap *map);
|
|
|
|
|
|
-/** @brief Add a term - term list pair to a connection list.
|
|
|
|
|
|
+
|
|
|
|
+/** @brief Add a term - term set pair to a link map.
|
|
|
|
+ *
|
|
|
|
+ * If there is already a term set for the given term, items from the added term
|
|
|
|
+ * are added to the existing term set (if not duplicated). Otherwise, the term
|
|
|
|
+ * set handle is linked to the new term.
|
|
|
|
+ *
|
|
|
|
+ * In any case, the caller should not directly use the term and term set after
|
|
|
|
+ * passing them to this function.
|
|
*
|
|
*
|
|
- * @param[in] cl Connection list handle obtained with
|
|
|
|
- * #LSUP_conn_list_new().
|
|
|
|
|
|
+ * @param[in] cm Link map handle obtained with #LSUP_link_map_new().
|
|
*
|
|
*
|
|
* @param[in] t Term to be associated with the given object list. The
|
|
* @param[in] t Term to be associated with the given object list. The
|
|
- * connection list structure takes ownership of the term.
|
|
|
|
|
|
+ * link map structure takes ownership of the term.
|
|
*
|
|
*
|
|
- * @param[in] o NULL-terminated array of object term handles to be associated
|
|
|
|
- * with the given predicate. The connection list structire takes ownership of
|
|
|
|
- * the whole term array.
|
|
|
|
|
|
+ * @param[in] ts term set to be associated with the given term. The link
|
|
|
|
+ * list structire takes ownership of the term set and the terms in it.
|
|
*
|
|
*
|
|
* @return LSUP_OK on success; LSUP_MEM_ERR on allocation error.
|
|
* @return LSUP_OK on success; LSUP_MEM_ERR on allocation error.
|
|
*/
|
|
*/
|
|
LSUP_rc
|
|
LSUP_rc
|
|
-LSUP_conn_list_add (
|
|
|
|
- LSUP_ConnectionList *cl, LSUP_Term *t, LSUP_Term **tl);
|
|
|
|
|
|
+LSUP_link_map_add (
|
|
|
|
+ LSUP_LinkMap *cmap, LSUP_Term *term, LSUP_TermSet *tset);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Create a new iterator to loop through a link map.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] lmap Map handle to iterate.
|
|
|
|
+ */
|
|
|
|
+LSUP_LinkMapIterator *
|
|
|
|
+LSUP_link_map_iter_new (const LSUP_LinkMap *lmap);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**@brief Iterate over a link map and generate triples.
|
|
|
|
+ *
|
|
|
|
+ * Calling this function repeatedly builds triples for all the linked terms and
|
|
|
|
+ * term sets in the map, based on a given related term.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] it Link map iterator handle, obtained with
|
|
|
|
+ * #LSUP_link_map_iter_new().
|
|
|
|
+ *
|
|
|
|
+ * @param[in] term Term to relate to the link map.
|
|
|
|
+ *
|
|
|
|
+ * @param[in|out] spo Result triple. The triple handle must be pre-allocated
|
|
|
|
+ * (it may be TRP_DUMMY) and calls to this function will be set its memebers
|
|
|
|
+ * to term handles owned by the link map. If rc != LSUP_OK, the contents are
|
|
|
|
+ * undefined.
|
|
|
|
+ *
|
|
|
|
+ * @return LSUP_OK if a new triple was yielded; LSUP_END if the end of the loop
|
|
|
|
+ * has been reached; <0 on error.
|
|
|
|
+ */
|
|
|
|
+LSUP_rc
|
|
|
|
+LSUP_link_map_triples (
|
|
|
|
+ LSUP_LinkMapIterator *it, LSUP_Term *term, LSUP_Triple *spo);
|
|
|
|
|
|
#endif
|
|
#endif
|