GithubHelp home page GithubHelp logo

antecedent / ostia-visualizer Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 316 KB

Records the construction of a finite-state transducer as done by OSTIA (Onward Subsequential Transducer Inference Algorithm), then plays it back using vis.js.

Home Page: https://antecedent.github.io/ostia-visualizer/

License: GNU General Public License v3.0

HTML 6.78% Python 93.22%

ostia-visualizer's Introduction

ostia-visualizer

Records the construction of a finite-state transducer as done by OSTIA (Onward Subsequential Transducer Inference Algorithm), then plays it back using vis.js.

Recording

To make use of ostia-visualizer, you will need to run OSTIA on your dataset of choice and obtain a log.

(Alternatively, a sample log is available for demonstration purposes: if this is of interest to you, please proceed to Playback.)

  • Install SigmaPie.
  • Override its FST class with the one provided in the patch that is found in this repository.
  • Proceed to invoke OSTIA as usual, which will provide a FST object as a return value. Let fst be this object.
  • fst.notifications is now a line-by-line list representation of the log. Therefore, you will most likely want to do this:
with open('ostia-log.py', 'w') as ostia_log:
    ostia_log.write('\n'.join(fst.notifications))

The log is also a Python script that reenacts the FST construction, hence the .py extension.

Playback

  • Navigate to this copy of ostia-visualizer or use your own.
  • "Upload" the ostia-log.py file or any other one that contains the log.
    • No uploading actually takes place, only client-side computations are involved.
  • Interpret the animation that ensues.

Tracking state colors

OSTIA colors the transducer's states red and blue. If one desires to reflect that in the visualization, it is also necessary to redefine the ostia function as follows:

def ostia(S, Sigma, Gamma):
    """This function implements OSTIA (Onward Subsequential Transduction
    Inference Algorithm).

    Arguments:
        S (list): a list of pairs (o, t), where `o` is the original
            string, and `t` is its translation;
        Sigma (list): the input alphabet;
        Gamma (list): the output alphabet.
    Returns:
        FST: a transducer defining the mapping.
    """
    # create a template of the onward PTT
    T = build_ptt(S, Sigma, Gamma)
    T = onward_ptt(T, "", "")[0]

    # color the nodes
    red = [""]
    blue = [tr[3] for tr in T.E if tr[0] == "" and len(tr[1]) == 1]

    T.color_state("", "red")

    for blue_state in blue:
        T.color_state(blue_state, "blue")

    # choose a blue state
    while len(blue) != 0:
        blue_state = blue[0]

        # if exists state that we can merge with, do it
        exists = False
        for red_state in red:

            # if you already merged that blue state with something, stop
            if exists == True:
                break

            # try to merge these two states
            if ostia_merge(T, red_state, blue_state):
                T = ostia_merge(T, red_state, blue_state)
                exists = True

        # if it is not possible, color that blue state red
        if not exists:
            red.append(blue_state)
            T.color_state(blue_state, "red")

        # if possible, remove the folded state from the list of states
        else:
            T.Q.remove(blue_state)
            del T.stout[blue_state]

        # add in blue list other states accessible from the red ones that are not red
        blue = []
        for tr in T.E:
            if tr[0] in red and tr[3] not in red:
                blue.append(tr[3])
                T.color_state(tr[3], "blue")

    # clean the transducer from non-reachable states
    T = ostia_clean(T)
    T.E = [tuple(i) for i in T.E]

    return T

ostia-visualizer's People

Contributors

antecedent avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.