summaryrefslogtreecommitdiff
path: root/src/runtime/c/pgf/pgf.h
blob: 9a88cebffcb7132eae1ce444d5b3ae0ec3af9710 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* 
 * Copyright 2010 University of Gothenburg.
 *   
 * This file is part of libpgf.
 * 
 * Libpgf is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * Libpgf is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with libpgf. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file
 *
 * The public libpgf API.
 */

#ifndef PGF_H_
#define PGF_H_

#include <gu/exn.h>
#include <gu/mem.h>
#include <gu/map.h>
#include <gu/enum.h>
#include <gu/string.h>


typedef GuString PgfCId;
extern GU_DECLARE_TYPE(PgfCId, typedef);


extern GU_DECLARE_TYPE(PgfExn, abstract);

/// @name PGF Grammar objects
/// @{

typedef struct PgfPGF PgfPGF;

typedef struct PgfConcr PgfConcr;


/**< A representation of a PGF grammar. 
 */

#include <pgf/expr.h>
#include <pgf/lexer.h>
#include <pgf/graphviz.h>

/// An enumeration of #PgfExpr elements.
typedef GuEnum PgfExprEnum;

PgfPGF*
pgf_read(const char* fpath,
         GuPool* pool, GuExn* err);

/**< Read a grammar from a PGF file.
 *
 * @param from  PGF input stream.
 * The stream must be positioned in the beginning of a binary
 * PGF representation. After a succesful invocation, the stream is
 * still open and positioned at the end of the representation.
 *
 * @param[out] err_out  Raised error.
 * If non-\c NULL, \c *err_out should be \c NULL. Then, upon
 * failure, \c *err_out is set to point to a newly allocated
 * error object, which the caller must free with #g_exn_free
 * or #g_exn_propagate.
 *
 * @return A new PGF object, or \c NULL upon failure. The returned
 * object must later be freed with #pgf_free.
 *
 */


void
pgf_load_meta_child_probs(PgfPGF*, const char* fpath, 
                          GuPool* pool, GuExn* err);

GuString
pgf_abstract_name(PgfPGF*);

void
pgf_iter_languages(PgfPGF*, GuMapItor*, GuExn* err);

PgfConcr*
pgf_get_language(PgfPGF*, PgfCId lang);

GuString
pgf_concrete_name(PgfConcr*);

GuString
pgf_language_code(PgfConcr* concr);

void
pgf_iter_categories(PgfPGF* pgf, GuMapItor* fn, GuExn* err);

PgfCId
pgf_start_cat(PgfPGF* pgf, GuPool* pool);

void
pgf_iter_functions(PgfPGF* pgf, GuMapItor* fn, GuExn* err);

void
pgf_iter_functions_by_cat(PgfPGF* pgf, PgfCId catname,
                          GuMapItor* fn, GuExn* err);

PgfType*
pgf_function_type(PgfPGF* pgf, PgfCId funname);

GuString
pgf_print_name(PgfConcr*, PgfCId id);

void
pgf_linearize(PgfConcr* concr, PgfExpr expr, GuOut* out, GuExn* err);

PgfExprEnum*
pgf_parse(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, 
          GuPool* pool, GuPool* out_pool);

typedef struct PgfMorphoCallback PgfMorphoCallback;
struct PgfMorphoCallback {
	void (*callback)(PgfMorphoCallback* self,
	                 PgfCId lemma, GuString analysis, prob_t prob,
	                 GuExn* err);
};

void
pgf_lookup_morpho(PgfConcr *concr, PgfLexer *lexer,
                  PgfMorphoCallback* callback, GuExn* err);

typedef GuMapKeyValue PgfFullFormEntry;

GuEnum*
pgf_fullform_lexicon(PgfConcr *concr, GuPool* pool);

GuString
pgf_fullform_get_string(PgfFullFormEntry* entry);

void
pgf_fullform_get_analyses(PgfFullFormEntry* entry,
                          PgfMorphoCallback* callback, GuExn* err);

PgfExprEnum*
pgf_parse_with_heuristics(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, 
                          double heuristics, 
                          GuPool* pool, GuPool* out_pool);

GuEnum*
pgf_complete(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, 
             GuString prefix, GuPool* pool);

bool
pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat, 
             double *precision, double *recall, double *exact);
                    
PgfExprEnum*
pgf_generate_all(PgfPGF* pgf, PgfCId cat, GuPool* pool);

/// @}

void
pgf_print(PgfPGF* pgf, GuOut* out, GuExn* err); 

#endif // PGF_H_