Skip to content

Commit

Permalink
srgs compiles, working on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crienzo committed Jan 13, 2014
1 parent 2842344 commit de481ec
Show file tree
Hide file tree
Showing 7 changed files with 393 additions and 369 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ lib_LTLIBRARIES = libcspeech-@[email protected]
## from each source file. Note that it is not necessary to list header files
## which are already listed elsewhere in a _HEADERS variable assignment.
libcspeech_@CSPEECH_API_VERSION@_la_SOURCES = cspeech.cc \
cspeech/logger.cc \
cspeech/nlsml.cc \
cspeech/srgs.cc
cspeech/srgs.cc \
cspeech/utils.cc

## Instruct libtool to include ABI version information in the generated shared
## library file (.so). The library ABI version is defined in configure.ac, so
Expand Down
14 changes: 8 additions & 6 deletions cspeech.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
#include "cspeech.h"
#include "cspeech/cspeech_private.h"

#include <string.h>

struct cspeech_srgs_parser {
struct srgs_parser *parser;
};

struct cspeech_srgs_grammar {
struct srgs_grammar *grammar;
}
};

int cspeech_init(void)
{
Expand Down Expand Up @@ -60,7 +62,7 @@ const char *cspeech_srgs_grammar_to_jsgf(struct cspeech_srgs_grammar *grammar)
if (!grammar) {
return NULL;
}
const str::string &jsgf = grammar->grammar->to_jsgf();
const std::string &jsgf = grammar->grammar->to_jsgf();
if (jsgf == "") {
return NULL;
}
Expand All @@ -69,25 +71,25 @@ const char *cspeech_srgs_grammar_to_jsgf(struct cspeech_srgs_grammar *grammar)

const char *cspeech_srgs_grammar_to_jsgf_file(struct cspeech_srgs_grammar *grammar, const char *basedir, const char *ext)
{
if (!grammar || !basedir || !ext) {
if (!grammar || cspeech_zstr(basedir) || cspeech_zstr(ext)) {
return NULL;
}
const str::string &jsgf_file = grammar->grammar->to_jsgf_file(basedir_str, ext_str);
const std::string &jsgf_file = grammar->grammar->to_jsgf_file(std::string(basedir), std::string(ext));
if (jsgf_file == "") {
return NULL;
}
return jsgf_file.c_str();
}

enum srgs_match_type cspeech_srgs_grammar_match(struct cspeech_srgs_grammar *grammar, const char *input, const char **interpretation)
enum cspeech_srgs_match_type cspeech_srgs_grammar_match(struct cspeech_srgs_grammar *grammar, const char *input, char **interpretation)
{
std::string input_str;
std::string interpretation_str;
*interpretation = NULL;
if (!cspeech_zstr(input)) {
input_str = input;
}
enum_srgs_match_type match = grammar->grammar->match(input_str, interpretation_str);
enum cspeech_srgs_match_type match = grammar->grammar->match(input_str, interpretation_str);
if (interpretation_str != "") {
*interpretation = strdup(interpretation_str.c_str());
}
Expand Down
7 changes: 4 additions & 3 deletions cspeech.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ typedef enum {
CSPEECH_LOG_ALERT = 1,
} cspeech_log_level_t;

typedef int (*cspeech_logging_callback)(void *context, cspeech_log_level_t log_level, const char *log_message, ...);
typedef int (*cspeech_logging_callback)(cspeech_log_level_t log_level, const char *id, const char *file, int line, const char *log_message);
void cspeech_set_logger(cspeech_logging_callback logger);

#if 0
/* NLSML */
Expand Down Expand Up @@ -67,11 +68,11 @@ enum cspeech_srgs_match_type {
};

struct cspeech_srgs_parser *cspeech_srgs_parser_new(const char *uuid);
struct cspeech_srgs_grammar *srgs_parse(struct cspeech_srgs_parser *parser, const char *document);
struct cspeech_srgs_grammar *cspeech_srgs_parse(struct cspeech_srgs_parser *parser, const char *document);
const char *cspeech_srgs_to_regex(struct cspeech_srgs_grammar *grammar);
const char *cspeech_srgs_to_jsgf(struct cspeech_srgs_grammar *grammar);
const char *cspeech_srgs_to_jsgf_file(struct cspeech_srgs_grammar *grammar, const char *basedir, const char *ext);
enum cspeech_srgs_match_type srgs_grammar_match(struct cspeech_srgs_grammar *grammar, const char *input, const char **interpretation);
enum cspeech_srgs_match_type cspeech_srgs_grammar_match(struct cspeech_srgs_grammar *grammar, const char *input, char **interpretation);
void cspeech_srgs_grammar_destroy(struct cspeech_srgs_grammar *grammar);
void cspeech_srgs_parser_destroy(struct cspeech_srgs_parser *parser);

Expand Down
15 changes: 12 additions & 3 deletions cspeech/cspeech_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
* cspeech_private.h
*
*/
#ifndef CSPEECH_PRIVATE_H
#define CSPEECH_PRIVATE_H
#ifndef CSPEECH_PRIVATE_H_
#define CSPEECH_PRIVATE_H_

#include <pcre.h>

#include <map>
#include <string>
Expand All @@ -23,11 +25,18 @@ struct srgs_node;
struct srgs_grammar;
struct srgs_parser;

int cspeech_zstr(const char *s);
bool cspeech_is_number(const std::string &str);

#define cspeech_log_printf(level, id, ...) _cspeech_log_printf(level, id, __FILE__, __LINE__, __VA_ARGS__)
void _cspeech_log_printf(cspeech_log_level_t log_level, const char *id, const char *file, int line, const char *format, ...);

/** function to handle tag attributes */
typedef int (* tag_attribs_fn)(srgs_grammar *, char **);
/** function to handle tag CDATA */
typedef int (* tag_cdata_fn)(srgs_grammar *, const std::string &);

int srgs_init(void);

/**
* Tag definition
Expand Down Expand Up @@ -137,7 +146,7 @@ struct srgs_grammar {
srgs_grammar(const std::string &uuid);
~srgs_grammar();
pcre *get_compiled_regex(void);
srgs_match_type match(const std::string &input, std::string &interpretation);
cspeech_srgs_match_type match(const std::string &input, std::string &interpretation);
const std::string &to_regex(void);
const std::string &to_jsgf(void);
const std::string &to_jsgf_file(const std::string &basedir, const std::string &ext);
Expand Down
Loading

0 comments on commit de481ec

Please sign in to comment.