blob: 48a5116389af09a68eb894e20f9cafa25d2ed813 (
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
|
#pragma once
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <msgpack.hpp>
#include <vector>
#include "sparse_vector.hh"
#include "util.hh"
using namespace std;
namespace G {
struct NT {
string symbol;
size_t index;
NT() {};
NT(string& s);
string repr() const;
string escaped() const;
friend ostream& operator<<(ostream& os, const NT& t);
};
struct T {
string word; // use word ids instead?
T(const string& s);
string repr() const;
string escaped() const;
friend ostream& operator<<(ostream& os, const NT& nt);
};
enum item_type {
NON_TERMINAL,
TERMINAL
};
struct Item {
item_type type;
NT* nt;
T* t;
Item(string& s);
string repr() const;
string escaped() const;
friend ostream& operator<<(ostream& os, const Item& i);
};
struct Rule {
NT* lhs;
vector<Item*> rhs;
vector<Item*> target;
size_t arity;
Sv::SparseVector<string, score_t>* f;
map<size_t, size_t> order;
string as_str_; // FIXME
Rule() {};
Rule(const string& s);
string repr() const;
string escaped() const;
friend ostream& operator<<(ostream& os, const Rule& r);
void prep_for_serialization_() { as_str_ = escaped(); }; // FIXME
MSGPACK_DEFINE(as_str_); // TODO
};
struct Grammar {
vector<Rule*> rules;
vector<Rule*> flat;
vector<Rule*> start_nt;
vector<Rule*> start_t;
Grammar() {};
Grammar(const string& fn);
void add_glue(); // TODO
void add_pass_through(const string& input); // TODO
friend ostream& operator<<(ostream& os, const Grammar& g);
};
} // namespace G
|