-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryProductions.H
48 lines (44 loc) · 1.51 KB
/
BinaryProductions.H
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
/****************************************************************
BinaryProductions.H
Copyright (C)2013 William H. Majoros ([email protected]).
This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
License (GPL) version 3, as described at www.opensource.org.
****************************************************************/
#ifndef INCL_BinaryProductions_H
#define INCL_BinaryProductions_H
#include <iostream>
#include "BOOM/Alphabet.H"
#include "BOOM/Array1D.H"
#include "BOOM/Vector.H"
#include "BinaryProduction.H"
#include "SCFG.H"
using namespace std;
using namespace BOOM;
struct NonterminalProb {
int nonterminal;
float P;
NonterminalProb() {}
NonterminalProb(int nt,float p) : nonterminal(nt), P(p) {}
};
class BinaryProductions {
Alphabet terminals;
int numNonterminals;
int startSymbol;
Vector<BinaryProduction> productions; // A->BC
Array1D< Vector<NonterminalProb> > terminalProbs;// indexed by terminal ID
void initNonTermMap(HashMap<GrammarSymbol,int> &nonterminalMap,SCFG &);
void processGrammar(SCFG &G,HashMap<GrammarSymbol,int> &nonterminalMap);
public:
BinaryProductions();
BinaryProductions(SCFG &,Alphabet &);
void init(SCFG &,Alphabet &);
int numProductions() const;
int getNumNonterminals() const;
int getStartSymbol() const;
BinaryProduction &production(int i);
Vector<NonterminalProb> &terminal(int terminalID);
Vector<BinaryProduction>::const_iterator begin() const;
Vector<BinaryProduction>::const_iterator end() const;
Alphabet &getTerminals();
};
#endif