YAZ
5.34.0
|
Implements CQL transform (CQL to RPN conversion). More...
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <yaz/rpn2cql.h>
#include <yaz/xmalloc.h>
#include <yaz/diagsrw.h>
#include <yaz/tokenizer.h>
#include <yaz/wrbuf.h>
#include <yaz/z-core.h>
#include <yaz/matchstr.h>
#include <yaz/oid_db.h>
#include <yaz/log.h>
#include <yaz/proxunit.h>
Go to the source code of this file.
Data Structures | |
struct | cql_prop_entry |
struct | cql_transform_t_ |
Functions | |
cql_transform_t | cql_transform_create (void) |
creates a CQL transform handle More... | |
static int | cql_transform_parse_tok_line (cql_transform_t ct, const char *pattern, yaz_tok_parse_t tp) |
int | cql_transform_define_pattern (cql_transform_t ct, const char *pattern, const char *value) |
defines CQL transform pattern More... | |
cql_transform_t | cql_transform_open_FILE (FILE *f) |
creates a CQL transform handle from am opened file handle More... | |
void | cql_transform_close (cql_transform_t ct) |
destroys a CQL transform handle More... | |
cql_transform_t | cql_transform_open_fname (const char *fname) |
creates a CQL transform handle from a file More... | |
static int | compare_attr (Z_AttributeElement *a, Z_AttributeElement *b) |
const char * | cql_lookup_reverse (cql_transform_t ct, const char *category, Z_AttributeList *attributes) |
find a pattern that has a subset of attributes More... | |
static const char * | cql_lookup_property (cql_transform_t ct, const char *pat1, const char *pat2, const char *pat3) |
int | cql_pr_attr_uri (cql_transform_t ct, WRBUF addinfo, const char *category, const char *uri, const char *val, const char *default_val, void(*pr)(const char *buf, void *client_data), void *client_data, int errcode) |
int | cql_pr_attr (cql_transform_t ct, WRBUF addinfo, const char *category, const char *val, const char *default_val, void(*pr)(const char *buf, void *client_data), void *client_data, int errcode) |
static void | cql_pr_int (int val, void(*pr)(const char *buf, void *client_data), void *client_data) |
static int | cql_pr_prox (cql_transform_t ct, struct cql_node *mods, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data) |
static int | has_modifier (struct cql_node *cn, const char *name) |
static int | emit_term (cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, const char *term, int length, void(*pr)(const char *buf, void *client_data), void *client_data) |
static int | emit_terms (cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data, const char *op) |
static int | emit_wordlist (cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data, const char *op) |
static int | emit_node (cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data) |
int | cql_transform_r (cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data) |
tranforms PQF given a CQL tree (re-entrant) More... | |
int | cql_transform (cql_transform_t ct, struct cql_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data) |
tranforms PQF given a CQL tree (NOT re-entrant) More... | |
int | cql_transform_FILE (cql_transform_t ct, struct cql_node *cn, FILE *f) |
transforms PQF given a CQL tree from FILE (not re-entrant) More... | |
int | cql_transform_buf (cql_transform_t ct, struct cql_node *cn, char *out, int max) |
transforms PQF given a CQL tree from buffer (not re-entrant) More... | |
int | cql_transform_error (cql_transform_t ct, const char **addinfo) |
returns additional information for last transform More... | |
void | cql_transform_set_error (cql_transform_t ct, int error, const char *addinfo) |
sets error and addinfo for transform More... | |
Implements CQL transform (CQL to RPN conversion).
Evaluation order of rules:
always relation structure position truncation index relationModifier
Definition in file cqltransform.c.
|
static |
Definition at line 301 of file cqltransform.c.
References odr_createmem(), odr_destroy(), ODR_ENCODE, odr_getbuf(), yaz_memcmp(), and z_AttributeElement().
Referenced by cql_lookup_reverse().
|
static |
Definition at line 363 of file cqltransform.c.
References cql_strcmp(), cql_transform_t_::entry, cql_prop_entry::next, cql_prop_entry::pattern, and cql_prop_entry::value.
Referenced by cql_pr_attr_uri(), and emit_term().
const char* cql_lookup_reverse | ( | cql_transform_t | ct, |
const char * | category, | ||
Z_AttributeList * | attributes | ||
) |
find a pattern that has a subset of attributes
ct | CQL transform handle |
category | pattern category |
attributes | RPN attributes |
Definition at line 322 of file cqltransform.c.
References cql_prop_entry::attr_list, Z_AttributeList::attributes, Z_AttributeElement::attributeSet, compare_attr(), cql_transform_t_::entry, cql_prop_entry::next, Z_AttributeList::num_attributes, oid_oidcmp(), cql_prop_entry::pattern, and yaz_oid_attset_bib_1.
Referenced by rpn2cql_attr(), and solr_lookup_reverse().
int cql_pr_attr | ( | cql_transform_t | ct, |
WRBUF | addinfo, | ||
const char * | category, | ||
const char * | val, | ||
const char * | default_val, | ||
void(*)(const char *buf, void *client_data) | pr, | ||
void * | client_data, | ||
int | errcode | ||
) |
Definition at line 475 of file cqltransform.c.
References cql_pr_attr_uri().
Referenced by emit_node(), and emit_term().
int cql_pr_attr_uri | ( | cql_transform_t | ct, |
WRBUF | addinfo, | ||
const char * | category, | ||
const char * | uri, | ||
const char * | val, | ||
const char * | default_val, | ||
void(*)(const char *buf, void *client_data) | pr, | ||
void * | client_data, | ||
int | errcode | ||
) |
Definition at line 389 of file cqltransform.c.
References cql_lookup_property(), cql_transform_t_::entry, cql_prop_entry::next, cql_prop_entry::pattern, cql_prop_entry::value, and wrbuf_puts().
Referenced by cql_pr_attr(), emit_node(), and emit_term().
|
static |
Definition at line 486 of file cqltransform.c.
Referenced by cql_pr_prox().
|
static |
Definition at line 497 of file cqltransform.c.
References cql_pr_int(), name, cql_node::st, cql_node::u, wrbuf_puts(), YAZ_SRW_UNSUPP_BOOLEAN_MODIFIER, YAZ_SRW_UNSUPP_PROX_RELATION, YAZ_SRW_UNSUPP_PROX_UNIT, and z_str_to_ProxUnit().
Referenced by emit_node().
int cql_transform | ( | cql_transform_t | ct, |
struct cql_node * | cn, | ||
void(*)(const char *buf, void *client_data) | pr, | ||
void * | client_data | ||
) |
tranforms PQF given a CQL tree (NOT re-entrant)
ct | CQL transform handle |
cn | CQL node tree |
pr | print function |
client_data | data to be passed to pr |
0 | success |
!= | 0 error |
The result is written to a user-defined stream.
Definition at line 987 of file cqltransform.c.
References cql_transform_r(), cql_transform_set_error(), wrbuf_alloc(), wrbuf_cstr(), and wrbuf_destroy().
Referenced by cql2pqf(), cql_transform_buf(), and cql_transform_FILE().
int cql_transform_buf | ( | cql_transform_t | ct, |
struct cql_node * | cn, | ||
char * | out, | ||
int | max | ||
) |
transforms PQF given a CQL tree from buffer (not re-entrant)
ct | CQL transform handle |
cn | CQL tree |
out | buffer for output |
max | maximum bytes for output (size of buffer) |
0 | success |
!=0 | failure (error code) |
Definition at line 1003 of file cqltransform.c.
References cql_buf_write_info::buf, cql_buf_write_handler(), cql_transform(), cql_transform_set_error(), cql_buf_write_info::max, cql_buf_write_info::off, and YAZ_SRW_TOO_MANY_CHARS_IN_QUERY.
void cql_transform_close | ( | cql_transform_t | ct | ) |
destroys a CQL transform handle
ct | CQL transform handle |
Definition at line 256 of file cqltransform.c.
References cql_transform_t_::addinfo, cql_transform_t_::entry, cql_prop_entry::next, cql_transform_t_::nmem, nmem_destroy(), cql_prop_entry::pattern, cql_transform_t_::tok_cfg, cql_prop_entry::value, wrbuf_destroy(), xfree, and yaz_tok_cfg_destroy().
Referenced by cql2pqf(), cql_transform_open_FILE(), and solr_transform_close().
cql_transform_t cql_transform_create | ( | void | ) |
creates a CQL transform handle
Definition at line 53 of file cqltransform.c.
References cql_transform_t_::addinfo, cql_transform_t_::entry, cql_transform_t_::error, cql_transform_t_::nmem, nmem_create(), cql_transform_t_::tok_cfg, wrbuf_alloc(), xmalloc, and yaz_tok_cfg_create().
Referenced by cql_transform_open_FILE(), and solr_transform_create().
int cql_transform_define_pattern | ( | cql_transform_t | ct, |
const char * | pattern, | ||
const char * | value | ||
) |
defines CQL transform pattern
ct | CQL transform handle |
pattern | pattern string |
value | pattern value |
Definition at line 204 of file cqltransform.c.
References cql_transform_parse_tok_line(), cql_prop_entry::pattern, cql_transform_t_::tok_cfg, cql_prop_entry::value, yaz_tok_cfg_single_tokens(), yaz_tok_parse_buf(), and yaz_tok_parse_destroy().
Referenced by solr_transform_define_pattern().
int cql_transform_error | ( | cql_transform_t | ct, |
const char ** | addinfo | ||
) |
returns additional information for last transform
ct | CQL transform handle |
addinfo | additional info (result) |
Definition at line 1027 of file cqltransform.c.
References cql_transform_t_::addinfo, cql_transform_t_::error, wrbuf_cstr(), and wrbuf_len.
Referenced by cql2pqf(), and solr_transform_error().
int cql_transform_FILE | ( | cql_transform_t | ct, |
struct cql_node * | cn, | ||
FILE * | f | ||
) |
transforms PQF given a CQL tree from FILE (not re-entrant)
ct | CQL transform handle |
cn | CQL tree |
f | FILE where output is written |
0 | success |
!=0 | failure (error code) |
The result is written to a file specified by FILE handle (which must be opened for writing.
Definition at line 998 of file cqltransform.c.
References cql_fputs(), and cql_transform().
cql_transform_t cql_transform_open_FILE | ( | FILE * | f | ) |
creates a CQL transform handle from am opened file handle
f | file where transformation spec is read |
The transformation spec is read from a FILE handle which is assumed opened for reading.
Definition at line 215 of file cqltransform.c.
References cql_transform_close(), cql_transform_create(), cql_transform_parse_tok_line(), cql_prop_entry::pattern, cql_transform_t_::tok_cfg, xfree, xstrdup, yaz_tok_cfg_single_tokens(), YAZ_TOK_EOF, yaz_tok_move(), yaz_tok_parse_buf(), yaz_tok_parse_destroy(), yaz_tok_parse_string(), and YAZ_TOK_STRING.
Referenced by cql_transform_open_fname(), and solr_transform_open_FILE().
cql_transform_t cql_transform_open_fname | ( | const char * | fname | ) |
creates a CQL transform handle from a file
fname | name of where transformation spec is read |
Definition at line 276 of file cqltransform.c.
References cql_transform_open_FILE().
Referenced by cql2pqf(), solr_transform_open_fname(), and xml_config_read().
|
static |
Definition at line 64 of file cqltransform.c.
References Z_AttributeElement::attributeSet, Z_AttributeElement::attributeType, CLASS_ATTSET, Z_AttributeElement::complex, cql_transform_t_::entry, Z_ComplexAttribute::list, cql_prop_entry::next, cql_transform_t_::nmem, nmem_intdup(), nmem_malloc(), nmem_strdup(), Z_ComplexAttribute::num_list, Z_ComplexAttribute::num_semanticAction, Z_AttributeElement::numeric, odr_createmem(), odr_destroy(), ODR_INT_PRINTF, ODR_PRINT, odr_setprint_noclose(), cql_prop_entry::pattern, Z_ComplexAttribute::semanticAction, Z_StringOrNumeric::string, Z_StringOrNumeric::u, Z_AttributeElement::value, Z_AttributeElement::which, Z_StringOrNumeric::which, wrbuf_alloc(), wrbuf_cstr(), wrbuf_destroy(), wrbuf_puts(), xmalloc, xstrdup, yaz_isdigit, yaz_log(), yaz_log_file(), yaz_oid_std(), yaz_string_to_oid_nmem(), YAZ_TOK_EOF, yaz_tok_move(), yaz_tok_parse_string(), YAZ_TOK_STRING, YLOG_WARN, z_AttributeList(), Z_AttributeValue_complex, Z_AttributeValue_numeric, and Z_StringOrNumeric_string.
Referenced by cql_transform_define_pattern(), and cql_transform_open_FILE().
int cql_transform_r | ( | cql_transform_t | ct, |
struct cql_node * | cn, | ||
WRBUF | addinfo, | ||
void(*)(const char *buf, void *client_data) | pr, | ||
void * | client_data | ||
) |
tranforms PQF given a CQL tree (re-entrant)
ct | CQL transform handle |
cn | CQL node tree |
addinfo | additional information (if error) |
pr | print function |
client_data | data to be passed to pr |
0 | success |
!= | 0 error code |
The result is written to a user-defined stream.
Definition at line 966 of file cqltransform.c.
References cql_apply_prefix(), cql_strcmp(), cql_strncmp(), emit_node(), cql_transform_t_::entry, cql_prop_entry::next, nmem_create(), nmem_destroy(), cql_prop_entry::pattern, and cql_prop_entry::value.
Referenced by cql_transform().
void cql_transform_set_error | ( | cql_transform_t | ct, |
int | error, | ||
const char * | addinfo | ||
) |
sets error and addinfo for transform
ct | CQL transform handle |
error | error code |
addinfo | additional info |
Definition at line 1033 of file cqltransform.c.
References cql_transform_t_::addinfo, cql_transform_t_::error, wrbuf_puts(), and wrbuf_rewind().
Referenced by cql_transform(), cql_transform_buf(), cql_transform_rpn2cql_stream(), and solr_transform_set_error().
|
static |
Definition at line 848 of file cqltransform.c.
References cql_node::boolean, CQL_NODE_BOOL, CQL_NODE_SORT, CQL_NODE_ST, cql_pr_attr(), cql_pr_attr_uri(), cql_pr_prox(), cql_strcmp(), cql_uri(), emit_terms(), emit_wordlist(), cql_node::sort, cql_node::st, cql_node::u, cql_node::which, wrbuf_puts(), YAZ_SRW_UNSUPP_BOOLEAN_MODIFIER, YAZ_SRW_UNSUPP_COMBI_OF_RELATION_AND_TERM, YAZ_SRW_UNSUPP_CONTEXT_SET, YAZ_SRW_UNSUPP_INDEX, and YAZ_SRW_UNSUPP_RELATION.
Referenced by cql_transform_r().
|
static |
Definition at line 579 of file cqltransform.c.
References cql_lookup_property(), CQL_NODE_ST, cql_pr_attr(), cql_pr_attr_uri(), has_modifier(), cql_node::st, cql_node::term, cql_node::u, cql_node::which, yaz_isdigit, YAZ_SRW_ANCHORING_CHAR_IN_UNSUPP_POSITION, YAZ_SRW_MASKING_CHAR_UNSUPP, YAZ_SRW_UNSUPP_INDEX, and YAZ_SRW_UNSUPP_RELATION_MODIFIER.
Referenced by emit_terms(), and emit_wordlist().
|
static |
Definition at line 782 of file cqltransform.c.
References emit_term(), cql_node::st, and cql_node::u.
Referenced by emit_node().
|
static |
Definition at line 812 of file cqltransform.c.
References emit_term(), cql_node::st, and cql_node::u.
Referenced by emit_node().
|
static |
Definition at line 569 of file cqltransform.c.
References name, cql_node::st, and cql_node::u.
Referenced by emit_term().