10 #include "patternsp.h"
11 #include "patternprob.h"
14 struct pattern_pdict
*
15 pattern_pdict_init(char *filename
, struct pattern_config
*pc
)
18 filename
= "patterns.prob";
19 FILE *f
= fopen(filename
, "r");
22 fprintf(stderr
, "No pattern probtable, will not use learned patterns.\n");
26 struct pattern_pdict
*dict
= calloc2(1, sizeof(*dict
));
28 dict
->table
= calloc2(pc
->spat_dict
->nspatials
+ 1, sizeof(*dict
->table
));
31 while (fgets(sbuf
, sizeof(sbuf
), f
)) {
32 struct pattern_prob
*pb
= calloc2(1, sizeof(*pb
));
36 if (buf
[0] == '#') continue;
37 while (isspace(*buf
)) buf
++;
38 while (!isspace(*buf
)) buf
++; // we recompute the probability
39 while (isspace(*buf
)) buf
++;
40 c
= strtol(buf
, &buf
, 10);
41 while (isspace(*buf
)) buf
++;
42 o
= strtol(buf
, &buf
, 10);
43 pb
->prob
= (floating_t
) c
/ o
;
44 while (isspace(*buf
)) buf
++;
45 str2pattern(buf
, &pb
->p
);
47 uint32_t spi
= pattern2spatial(dict
, &pb
->p
);
48 if (!dict
->table
[spi
]) {
49 dict
->table
[spi
] = pb
;
51 struct pattern_prob
*ppb
= dict
->table
[spi
];
52 while (ppb
->next
) ppb
= ppb
->next
;