Example #1
0
def digit():
    start = fsg.Node()
    end = fsg.Node()
    nz = nzdigit()

    start.AddEdge(nz)
    nz.AddEdge(end)
    start.AddEdge(end, "ZERO")
    start.AddEdge(end, "OH")

    return fsg.Supernode(start, end)
Example #2
0
def expr():
    """ Clever trick alert: the contents of an expression can themselves contain
  expressions within parentheses, so we pass our start and end nodes to our
  internals before they are built."""
    start = fsg.Node()
    end = fsg.Node()
    super = fsg.Supernode(start, end)
    b = binary(super)
    start.AddEdge(b)
    b.AddEdge(end)

    return super
Example #3
0
def tens():
    start = fsg.Node()
    end = fsg.Node()
    start.AddEdge(end, "TWENTY")
    start.AddEdge(end, "THIRTY")
    start.AddEdge(end, "FORTY")
    start.AddEdge(end, "FIFTY")
    start.AddEdge(end, "SIXTY")
    start.AddEdge(end, "SEVENTY")
    start.AddEdge(end, "EIGHTY")
    start.AddEdge(end, "NINETY")
    return fsg.Supernode(start, end)
Example #4
0
def teens():
    start = fsg.Node()
    end = fsg.Node()
    start.AddEdge(end, "TEN")
    start.AddEdge(end, "ELEVEN")
    start.AddEdge(end, "TWELVE")
    start.AddEdge(end, "THIRTEEN")
    start.AddEdge(end, "FOURTEEN")
    start.AddEdge(end, "FIFTEEN")
    start.AddEdge(end, "SIXTEEN")
    start.AddEdge(end, "EIGHTEEN")
    start.AddEdge(end, "NINETEEN")
    return fsg.Supernode(start, end)
Example #5
0
def integer():
    start = fsg.Node()
    end = fsg.Node()
    number = twelve_d()

    start.AddEdge(end, "ZERO")
    start.AddEdge(number)
    start.AddEdge(number, "MINUS")
    start.AddEdge(number, "NEGATIVE")

    number.AddEdge(end)

    return fsg.Supernode(start, end)
Example #6
0
def nzdigit():
    start = fsg.Node()
    end = fsg.Node()
    start.AddEdge(end, "ONE")
    start.AddEdge(end, "TWO")
    start.AddEdge(end, "THREE")
    start.AddEdge(end, "FOUR")
    start.AddEdge(end, "FIVE")
    start.AddEdge(end, "SIX")
    start.AddEdge(end, "SEVEN")
    start.AddEdge(end, "EIGHT")
    start.AddEdge(end, "NINE")
    return fsg.Supernode(start, end)
Example #7
0
def three_d():
    start = fsg.Node()
    end = fsg.Node()
    nz = nzdigit()
    two_d_node = two_d()

    start.AddEdge(nz)
    start.AddEdge(two_d_node)
    nz.AddEdge(two_d_node, "HUNDRED")
    nz.AddEdge(end, "HUNDRED")
    two_d_node.AddEdge(end)

    return fsg.Supernode(start, end)
Example #8
0
def binary(expr):
    start = fsg.Node()
    end = fsg.Node()
    u = unary(expr)

    start.AddEdge(u)
    u.AddEdge(end)
    u.AddEdge(u, "PLUS")
    u.AddEdge(u, "MINUS")
    u.AddEdge(u, "TIMES")
    u.AddEdge(u, "DIVIDED BY")
    u.AddEdge(u, "TO THE POWER OF")

    return fsg.Supernode(start, end)
Example #9
0
def unary(expr):
    start = fsg.Node()
    end = fsg.Node()
    v = value(expr)

    start.AddEdge(v)
    start.AddEdge(v, "THE SQUAREROOT OF")

    v.AddEdge(end)
    v.AddEdge(end, "SQUARED")
    v.AddEdge(end, "CUBED")
    v.AddEdge(end, "FACTORIAL")

    return fsg.Supernode(start, end)
Example #10
0
def value(expr):
    # expr is the supernode of an entire expression that we can encapsulate in
    # parentheses here.
    start = fsg.Node()
    end = fsg.Node()
    n = number()

    start.AddEdge(n)
    n.AddEdge(end)

    start.AddEdge(expr, "OPEN_PAREN")
    expr.AddEdge(end, "CLOSE_PAREN")

    return fsg.Supernode(start, end)
Example #11
0
def twelve_d():
    start = fsg.Node()
    end = fsg.Node()
    extra = fsg.Node()
    three_d_node = three_d()
    other = nine_d()

    start.AddEdge(three_d_node)
    start.AddEdge(other)
    three_d_node.AddEdge(extra, "BILLION")
    extra.AddEdge(other)
    extra.AddEdge(end)
    other.AddEdge(end)

    return fsg.Supernode(start, end)
Example #12
0
def six_d():
    start = fsg.Node()
    end = fsg.Node()
    extra = fsg.Node()
    three_d_node = three_d()
    other = three_d()

    start.AddEdge(three_d_node)
    start.AddEdge(other)
    three_d_node.AddEdge(extra, "THOUSAND")
    extra.AddEdge(other)
    extra.AddEdge(end)
    other.AddEdge(end)

    return fsg.Supernode(start, end)
Example #13
0
def number():
    start = fsg.Node()
    end = fsg.Node()
    int_node = integer()
    digit_node = digit()

    start.AddEdge(int_node)
    int_node.AddEdge(digit_node, "POINT")
    int_node.AddEdge(end)

    oh_point = fsg.Node()
    start.AddEdge(oh_point, "OH")
    oh_point.AddEdge(digit_node, "POINT")

    digit_node.AddEdge(digit_node)
    digit_node.AddEdge(end)

    return fsg.Supernode(start, end)
Example #14
0
def two_d():
    start = fsg.Node()
    end = fsg.Node()
    tens_node = tens()
    teens_node = teens()
    nz = nzdigit()

    start.AddEdge(teens_node)
    start.AddEdge(tens_node)
    start.AddEdge(nz)

    tens_node.AddEdge(nz)
    tens_node.AddEdge(end)

    teens_node.AddEdge(end)

    nz.AddEdge(end)

    return fsg.Supernode(start, end)
Example #15
0
#!/usr/bin/python

import fsg_generator

start = fsg_generator.Node()
end = fsg_generator.Node()
middle = fsg_generator.Node()
start.AddEdge(middle, "ONE")
start.AddEdge(middle, "TWO")
start.AddEdge(middle, "THREE")
middle.AddEdge(end, "STOP")
middle.AddEdge(end, "END")

fsg_generator.PrintFSG()
Example #16
0
#!/usr/bin/python

import fsg_generator

start = fsg_generator.Node()
end = fsg_generator.Node()

# To be honest, we want unknown noises to be more likely than the important
# phrase. Consequently, I have edited the probabilities in the .fsg file from
# what this generates.
start.AddEdge(end, "OH COMPUTER BOX")
start.AddEdge(end, "UNK")

fsg_generator.PrintFSG()
Example #17
0
#!/usr/bin/python

import fsg_generator as fsg
"""
Future Commands:
Read me all headlines
read me science headlines
read me world headlines
read me US headlines
weather report
weather forecast
calculate
"""

start = fsg.Node()
end = fsg.Node()

headlines_start = fsg.Node()
headlines_end = fsg.Node()
start.AddEdge(headlines_start, "READ ME")
headlines_start.AddEdge(headlines_end, "ALL")
headlines_start.AddEdge(headlines_end, "SCIENCE")
headlines_start.AddEdge(headlines_end, "YOU ESS")
headlines_start.AddEdge(headlines_end, "WORLD")
headlines_end.AddEdge(end, "HEADLINES")
headlines_end.AddEdge(end, "NEWS")

start.AddEdge(end, "WEATHER REPORT")
start.AddEdge(end, "WEATHER FORECAST")

start.AddEdge(end, "NEVER MIND")
Example #18
0
    return fsg.Supernode(start, end)


def expr():
    """ Clever trick alert: the contents of an expression can themselves contain
  expressions within parentheses, so we pass our start and end nodes to our
  internals before they are built."""
    start = fsg.Node()
    end = fsg.Node()
    super = fsg.Supernode(start, end)
    b = binary(super)
    start.AddEdge(b)
    b.AddEdge(end)

    return super


# These are the true starting and ending nodes. The end node must be separate
# from expr's end node because expr's end can loop back into a CLOSE_PAREN,
# while the final end node cannot (due to the HMM deciding we're done).
start = fsg.Node()
end = fsg.Node()
e = expr()

start.AddEdge(e)
e.AddEdge(end)

#integer()

fsg.PrintFSG()
Example #19
0
#!/usr/bin/python

import fsg_generator as fsg

start = fsg.Node()
end = fsg.Node()

read = fsg.Node()
start.AddEdge(read, "READ ME")
read.AddEdge(end, "THAT ONE")
read.AddEdge(end, "PREVIOUS ONE")
read.AddEdge(end, "THE PREVIOUS ONE")
start.AddEdge(end, "STOP READING HEADLINES")
start.AddEdge(end, "STOP READING NEWS")

fsg.PrintFSG()