summaryrefslogtreecommitdiff
path: root/src/runtime/c/pgf/reader.c
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2012-12-12 11:25:58 +0000
committerkr.angelov <kr.angelov@gmail.com>2012-12-12 11:25:58 +0000
commitaa13090b66d7ee1ffc68ad242c6419a83cf364d9 (patch)
treed36bacbc5f4e0990aae925da31ddeaf2a465a003 /src/runtime/c/pgf/reader.c
parent5e091d2e3dc428daa1d4b0d8df6e7b613adc22a9 (diff)
started an official API to the C runtime
Diffstat (limited to 'src/runtime/c/pgf/reader.c')
-rw-r--r--src/runtime/c/pgf/reader.c69
1 files changed, 3 insertions, 66 deletions
diff --git a/src/runtime/c/pgf/reader.c b/src/runtime/c/pgf/reader.c
index 63b06cd6d..92a67ecd7 100644
--- a/src/runtime/c/pgf/reader.c
+++ b/src/runtime/c/pgf/reader.c
@@ -20,6 +20,7 @@
#include "data.h"
#include "expr.h"
#include "literals.h"
+#include "reader.h"
#include <gu/defs.h>
#include <gu/map.h>
#include <gu/seq.h>
@@ -40,8 +41,6 @@
// PgfReader
//
-typedef struct PgfReader PgfReader;
-
struct PgfReader {
GuIn* in;
GuExn* err;
@@ -132,7 +131,7 @@ struct PgfReadNewFn {
size_t* size_out);
};
-static void*
+void*
pgf_read_new(PgfReader* rdr, GuType* type, GuPool* pool, size_t* size_out)
{
size_t size = 0;
@@ -884,7 +883,7 @@ pgf_read_new_table = GU_TYPETABLE(
PGF_READ_NEW(PgfConcr)
);
-static PgfReader*
+PgfReader*
pgf_new_reader(GuIn* in, GuPool* opool, GuPool* tmp_pool, GuExn* err)
{
PgfReader* rdr = gu_new(PgfReader, tmp_pool);
@@ -900,65 +899,3 @@ pgf_new_reader(GuIn* in, GuPool* opool, GuPool* tmp_pool, GuExn* err)
rdr->read_new_map = gu_new_type_map(&pgf_read_new_table, tmp_pool);
return rdr;
}
-
-
-PgfPGF*
-pgf_read(GuIn* in, GuPool* pool, GuExn* err)
-{
- GuPool* tmp_pool = gu_new_pool();
- PgfReader* rdr = pgf_new_reader(in, pool, tmp_pool, err);
- PgfPGF* pgf = pgf_read_new(rdr, gu_type(PgfPGF), pool, NULL);
- gu_pool_free(tmp_pool);
- gu_return_on_exn(err, NULL);
- return pgf;
-}
-
-bool
-pgf_load_meta_child_probs(PgfPGF* pgf, const char* fpath, GuPool* pool)
-{
- FILE *fp = fopen(fpath, "r");
- if (!fp)
- return false;
-
- GuPool* tmp_pool = gu_new_pool();
-
- for (;;) {
- char cat1_s[21];
- char cat2_s[21];
- prob_t prob;
-
- if (fscanf(fp, "%20s\t%20s\t%f", cat1_s, cat2_s, &prob) < 3)
- break;
-
- prob = - log(prob);
-
- GuString cat1 = gu_str_string(cat1_s, tmp_pool);
- PgfCat* abscat1 =
- gu_map_get(pgf->abstract.cats, &cat1, PgfCat*);
- if (abscat1 == NULL)
- return false;
-
- if (strcmp(cat2_s, "*") == 0) {
- abscat1->meta_prob = prob;
- } else if (strcmp(cat2_s, "_") == 0) {
- abscat1->meta_token_prob = prob;
- } else {
- GuString cat2 = gu_str_string(cat2_s, tmp_pool);
- PgfCat* abscat2 = gu_map_get(pgf->abstract.cats, &cat2, PgfCat*);
- if (abscat2 == NULL)
- return false;
-
- if (abscat1->meta_child_probs == NULL) {
- abscat1->meta_child_probs =
- gu_map_type_new(PgfMetaChildMap, pool);
- }
-
- gu_map_put(abscat1->meta_child_probs, abscat2, prob_t, prob);
- }
- }
-
- gu_pool_free(tmp_pool);
-
- fclose(fp);
- return true;
-}