summaryrefslogtreecommitdiff
path: root/python/cdec/grammar.pxd
blob: 3607a544512b392f35cc9dd335bdd900f57e8909 (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
from libcpp.vector cimport vector
from libcpp.string cimport string
from utils cimport *

cdef extern from "decoder/trule.h":
    cdef cppclass AlignmentPoint:
        AlignmentPoint(int s, int t)
        AlignmentPoint Inverted()
        short s_
        short t_

    cdef cppclass TRule:
        vector[WordID] f_
        vector[WordID] e_
        vector[AlignmentPoint] a_
        FastSparseVector[weight_t] scores_
        WordID lhs_
        int arity_
        bint ReadFromString(string& line, bint monolingual)
        bint IsUnary()
        bint IsGoal()
        void ComputeArity()

cdef extern from "decoder/grammar.h":
    cdef cppclass RuleBin:
        int GetNumRules()
        shared_ptr[TRule] GetIthRule(int i)
        int Arity()

    ctypedef RuleBin const_RuleBin "const RuleBin"

    cdef cppclass GrammarIter:
        const_RuleBin* GetRules()

    ctypedef GrammarIter const_GrammarIter "const GrammarIter"

    cdef cppclass Grammar:
        const_GrammarIter* GetRoot()
        string GetGrammarName()
        void SetGrammarName(string)

    cdef cppclass TextGrammar(Grammar):
        TextGrammar()
        void AddRule(shared_ptr[TRule]& rule) nogil