I propose some fixes regarding jsgf2fsg and its corresponding lib in sphinxbase:
without the following change, when specifiying a start-rule, also rule-name being prefixes of the start-rule are choosen as start-rule to write the fsg
diff -r -u -N sphinxbase.orig/src/sphinx_jsgf2fsg/main.c sphinxbase/src/sphinx_jsgf2fsg/main.c
--- sphinxbase.orig/src/sphinx_jsgf2fsg/main.c 2008-07-06 22:28:21.000000000 +0200
+++ sphinxbase/src/sphinx_jsgf2fsg/main.c 2008-09-25 00:35:51.000000000 +0200
@@ -53,7 +53,8 @@
char const *rule_name = jsgf_rule_name(rule);
if ((name == NULL && jsgf_rule_public(rule))
The following patch fixes some problems in dealing with grammars which use the jsgf import mechanism.
1.when searching for the file to be imported in the JSGF_PATH potentially fclose is carried out on a null-pointer
2.specifiying a grammar-rule to be imported, where the file is in a subdirectoy (like: import <subdir.grammarfile.rule>), leads to
because when looking for a public rule matching the rulename to be imported: <subdir.grammarfile.rule> is compared to <grammarfile.rule>
3.when expanding the right-hand-side of a rule the atoms are qualified with the grammar-name of the root grammar instead qualifying with the current grammar-name (probably a imported one)
diff -r -u -N sphinxbase.orig/src/libsphinxbase/lm/jsgf.c sphinxbase/src/libsphinxbase/lm/jsgf.c
--- sphinxbase.orig/src/libsphinxbase/lm/jsgf.c 2008-07-06 22:28:21.000000000 +0200
+++ sphinxbase/src/libsphinxbase/lm/jsgf.c 2008-09-25 00:51:48.000000000 +0200
@@ -97,7 +97,7 @@
grammar->imports = hash_table_new(16, 0);
if ((jsgf_path = getenv("JSGF_PATH")) != NULL) {
char word, c;
-
+
/ FIXME: This should be a function in libsphinxbase. /
/ FIXME: Also nextword() is totally useless... /
word = jsgf_path = ckd_salloc(jsgf_path);
@@ -211,6 +211,20 @@
grammar->links = glist_add_ptr(grammar->links, link);
}
+static char
+extract_grammar_name(char _rule_name){
+ char dot_pos;
+ char grammar_name = ckd_salloc(_rule_name+1);
+ if ( (dot_pos = strrchr(grammar_name + 1, '.') )== NULL){
+ ckd_free(grammar_name);
+ return NULL;
+ }
+ dot_pos='\0';
+ return grammar_name;
+
+}
+
+
static char
jsgf_fullname(jsgf_t jsgf, const char name)
{
@@ -227,6 +241,49 @@
}
+static char
+jsgf_fullname_from_rule(jsgf_rule_t rule, const char name)
+{
+ char fullname;
+
+ / Check if it is already qualified /
+ if (strchr(name + 1, '.'))
+ return ckd_salloc(name);
+
+ / Skip leading < in name /
+ char grammar_name = extract_grammar_name(rule->name);
+ fullname = ckd_malloc(strlen(grammar_name) + strlen(name) + 4);
+ sprintf(fullname, "<%s.%s", grammar_name, name + 1);
+ return fullname;
+}
+
+/ Extract as rulename everything after the secondlast dot, if existent.
+ * Because everything before the secondlast dot is the path-specification. /
+static char
+importname2rulename(char importname){
+ char rulename = ckd_salloc(importname);
+ char last_dotpos;
+ char secondlast_dotpos;
+
+ if( (last_dotpos=strrchr(rulename+1, '.')) != NULL){
+ last_dotpos='\0';
+ if( (secondlast_dotpos=strrchr(rulename+1, '.')) != NULL){
+ last_dotpos='.';
+ secondlast_dotpos='<';
+ return secondlast_dotpos;
+ }
+ else {
+ last_dotpos='.';
+ return rulename;
+ }
+
+ }
+ else{
+ return rulename;
+ }
+}
+
+
static int expand_rule(jsgf_t grammar, jsgf_rule_t rule);
static int
expand_rhs(jsgf_t grammar, jsgf_rule_t rule, jsgf_rhs_t *rhs)
@@ -260,7 +317,7 @@
return -1;
}
fullname = jsgf_fullname_from_rule(rule, atom->name);
if (hash_table_lookup(grammar->rules, fullname, &val) == -1) {
E_ERROR("Undefined rule in RHS: %s\n", fullname);
ckd_free(fullname);
@@ -521,9 +578,10 @@
fullpath = string_join(gnode_ptr(gn), "/", path, NULL); tmp = fopen(fullpath, "r");
char * rule_name=importname2rulename(name);
if (import_all) { /* Match package name (symbol table is shared) */
Cheers,
Masrur Doostdar
BTW: The last Bug-entry was also posted by me - forgot to login...
Thank you! I'll test these patches as soon as possible