| 1 |
/*************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* Language Technologies Institute */ |
| 4 |
/* Carnegie Mellon University */ |
| 5 |
/* Copyright (c) 1999 */ |
| 6 |
/* All Rights Reserved. */ |
| 7 |
/* */ |
| 8 |
/* Permission is hereby granted, free of charge, to use and distribute */ |
| 9 |
/* this software and its documentation without restriction, including */ |
| 10 |
/* without limitation the rights to use, copy, modify, merge, publish, */ |
| 11 |
/* distribute, sublicense, and/or sell copies of this work, and to */ |
| 12 |
/* permit persons to whom this work is furnished to do so, subject to */ |
| 13 |
/* the following conditions: */ |
| 14 |
/* 1. The code must retain the above copyright notice, this list of */ |
| 15 |
/* conditions and the following disclaimer. */ |
| 16 |
/* 2. Any modifications must be clearly marked as such. */ |
| 17 |
/* 3. Original authors' names are not deleted. */ |
| 18 |
/* 4. The authors' names are not used to endorse or promote products */ |
| 19 |
/* derived from this software without specific prior written */ |
| 20 |
/* permission. */ |
| 21 |
/* */ |
| 22 |
/* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */ |
| 23 |
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ |
| 24 |
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */ |
| 25 |
/* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */ |
| 26 |
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ |
| 27 |
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ |
| 28 |
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ |
| 29 |
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ |
| 30 |
/* THIS SOFTWARE. */ |
| 31 |
/* */ |
| 32 |
/*************************************************************************/ |
| 33 |
/* Author: Alan W Black ([email protected]) */ |
| 34 |
/* Date: April 2000 */ |
| 35 |
/*************************************************************************/ |
| 36 |
/* */ |
| 37 |
/* Read some data, build an utt, look up words and extract some feats */ |
| 38 |
/* Actually doing osmething here */ |
| 39 |
/* */ |
| 40 |
/* */ |
| 41 |
/*************************************************************************/ |
| 42 |
#include <stdio.h> |
| 43 |
#include "cst_hrg.h" |
| 44 |
#include "cst_tokenstream.h" |
| 45 |
#include "cst_lexicon.h" |
| 46 |
|
| 47 |
extern cst_lexicon cmu_lex; |
| 48 |
void cmu_lex_init(); |
| 49 |
|
| 50 |
static int bbb_relation_load(cst_relation *r,const char *filename); |
| 51 |
static int WordSylSeg(cst_utterance *u); |
| 52 |
|
| 53 |
int main(int argc, char **argv) |
| 54 |
{ |
| 55 |
cst_utterance *u; |
| 56 |
cst_relation *r; |
| 57 |
cst_item *item=0; |
| 58 |
int i; |
| 59 |
|
| 60 |
cmu_lex_init(); |
| 61 |
|
| 62 |
u = new_utterance(); |
| 63 |
r = utt_relation_create(u,"Word"); |
| 64 |
|
| 65 |
bbb_relation_load(r,"ttt.txt"); |
| 66 |
|
| 67 |
WordSylSeg(u); |
| 68 |
|
| 69 |
for (i=0,item=item_next(relation_head(utt_relation(u,"Segment"))); |
| 70 |
item; item=item_next(item),i++) |
| 71 |
{ |
| 72 |
printf("Segment %s %s %s %s\n", |
| 73 |
ffeature_string(item,"name"), |
| 74 |
ffeature_string(item,"n.name"), |
| 75 |
ffeature_string(item,"p.name"), |
| 76 |
ffeature_string(item,"R:SylStructure.parent.name") |
| 77 |
/* ffeature_string(item,"R:SylStructure.parent.R:Word.n.name"), */ |
| 78 |
/* item_feat_float(item,"duration")); */ |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
delete_utterance(u); |
| 83 |
|
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
static int WordSylSeg(cst_utterance *u) |
| 88 |
{ |
| 89 |
cst_item *word; |
| 90 |
cst_relation *sylstructure,*seg; |
| 91 |
cst_val *phones; |
| 92 |
const cst_val *p; |
| 93 |
cst_item *ssword,*segitem; |
| 94 |
|
| 95 |
sylstructure = utt_relation_create(u,"SylStructure"); |
| 96 |
seg = utt_relation_create(u,"Segment"); |
| 97 |
|
| 98 |
for (word=relation_head(utt_relation(u,"Word")); |
| 99 |
word; word=item_next(word)) |
| 100 |
{ |
| 101 |
printf("word: %s\n",item_feat_string(word,"name")); |
| 102 |
ssword = relation_append(sylstructure,word); |
| 103 |
phones = lex_lookup((cst_lexicon *)&cmu_lex,item_feat_string(word,"name"),NULL,NULL); |
| 104 |
for (p=phones; p; p=val_cdr(p)) |
| 105 |
{ |
| 106 |
segitem = relation_append(seg,NULL); |
| 107 |
item_set(segitem,"name",val_car(p)); |
| 108 |
printf("seg: %s\n",item_feat_string(segitem,"name")); |
| 109 |
item_add_daughter(ssword,segitem); |
| 110 |
} |
| 111 |
delete_val_list(phones); |
| 112 |
} |
| 113 |
|
| 114 |
return TRUE; |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
static int bbb_relation_load(cst_relation *r,const char *filename) |
| 119 |
{ |
| 120 |
const char *token; |
| 121 |
cst_item *item; |
| 122 |
cst_tokenstream *fd; |
| 123 |
|
| 124 |
fd = ts_open(filename, |
| 125 |
cst_ts_default_whitespacesymbols, |
| 126 |
cst_ts_default_singlecharsymbols, |
| 127 |
cst_ts_default_prepunctuationsymbols, |
| 128 |
cst_ts_default_postpunctuationsymbols); |
| 129 |
if (fd == 0) |
| 130 |
return 0; |
| 131 |
|
| 132 |
while (!ts_eof(fd)) |
| 133 |
{ |
| 134 |
token = ts_get(fd); |
| 135 |
if (cst_streq(token,"")) |
| 136 |
continue; |
| 137 |
item = relation_append(r,NULL); |
| 138 |
item_set_string(item,"name",token); |
| 139 |
item_set_string(item,"whitespace",fd->whitespace); |
| 140 |
item_set_string(item,"prepunctuation",fd->prepunctuation); |
| 141 |
item_set_string(item,"punc",fd->postpunctuation); |
| 142 |
item_set_int(item,"file_pos",fd->file_pos); |
| 143 |
item_set_int(item,"line_number",fd->line_number); |
| 144 |
} |
| 145 |
|
| 146 |
ts_close(fd); |
| 147 |
|
| 148 |
return 1; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|