Skip to content

Commit

Permalink
Added a local version of varnam webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
jijeshmohan committed Oct 30, 2014
1 parent 499adac commit 0fcc1ac
Show file tree
Hide file tree
Showing 27 changed files with 7,410 additions and 0 deletions.
4 changes: 4 additions & 0 deletions varnam-local/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
libvarnam-golang
================

Golang bindings for libvarnam
55 changes: 55 additions & 0 deletions varnam-local/libvarnam/libvarnam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package libvarnam

// #cgo pkg-config: varnam
// #include <stdio.h>
// #include <varnam.h>
import "C"

type Varnam struct {
handle *C.varnam
}

type VarnamError struct {
errorCode int
message string
}

func (e *VarnamError) Error() string {
return e.message
}

func (v *Varnam) Transliterate(text string) []string {
var va *C.varray
C.varnam_transliterate(v.handle, C.CString(text), &va)
var i C.int
var array []string
for i = 0; i < C.varray_length(va); i++ {
word := (*C.vword)(C.varray_get(va, i))
array = append(array, C.GoString(word.text))
}
return array
}

func (v *Varnam) ReverseTransliterate(text string) string {
var output *C.char
C.varnam_reverse_transliterate(v.handle, C.CString(text), &output)
return C.GoString(output)
}

func (v *Varnam) Learn(text string) *VarnamError {
rc := C.varnam_learn(v.handle, C.CString(text))
if rc != 0 {
return &VarnamError{errorCode: (int)(rc), message: "Error in Learn"}
}
return nil
}

func Init(langCode string) (*Varnam, *VarnamError) {
var v *C.varnam
var msg *C.char
rc := C.varnam_init_from_lang(C.CString(langCode), &v, &msg)
if rc != 0 {
return nil, &VarnamError{errorCode: (int)(rc), message: C.GoString(msg)}
}
return &Varnam{handle: v}, nil
}
62 changes: 62 additions & 0 deletions varnam-local/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"encoding/json"
"flag"
"log"
"net/http"

"github.com/gorilla/mux"
"github.com/varnamproject/libvarnam-golang/libvarnam"
)

var (
v *libvarnam.Varnam
lang = flag.String("lang", "ml", "Language")
)

type response struct {
Errors []string `json:"errors"`
Word string `json:"input"`
Result []string `json:"result"`
}

func TranslitrateHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
text := vars["text"]
results := v.Transliterate(text)
res := &response{Errors: []string{}, Word: text, Result: results}
data, _ := json.Marshal(res)
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
w.Write(data)
w.Write([]byte("\n"))
}

func LearnHandler(w http.ResponseWriter, r *http.Request) {
rc := v.Learn(r.FormValue("text"))
if rc != nil {
log.Println("Error while learing word")
w.WriteHeader(500)
} else {
w.WriteHeader(200)
}
}

func main() {
flag.Parse()
var err *libvarnam.VarnamError
v, err = libvarnam.Init(*lang)

if err != nil {
log.Fatalln(err)
}

r := mux.NewRouter()
r.HandleFunc("/api/tl/{lang}/{text}", TranslitrateHandler)
r.HandleFunc("/api/learn", LearnHandler).Methods("POST")
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./public/")))
log.Println("http://localhost:8081")
log.Fatal(http.ListenAndServe(":8081", r))
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added varnam-local/public/images/bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added varnam-local/public/images/bkg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added varnam-local/public/images/close_button.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added varnam-local/public/images/main.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added varnam-local/public/images/stressed_linen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added varnam-local/public/img/glyphicons-halflings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
158 changes: 158 additions & 0 deletions varnam-local/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/stylesheets/bootstrap.css">
<link rel="stylesheet" href="/stylesheets/bootstrap-responsive.css">
<link rel="stylesheet" href="/stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/ambiance.css">
<link rel="stylesheet" href="stylesheets/codemirror.css">
<link rel="stylesheet" media="print" href="stylesheets/print.css">

<title>Varnam - Type in Indian languages</title>

<style type="text/css">
/*body{
background: url("./img/bg.png") repeat scroll 0 0 #EDEDED;
-webkit-font-smoothing: antialiased;
height: 100%
}*/
.CodeMirror-completions {
position: absolute;
z-index: 10;
overflow: hidden;
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
}
.CodeMirror-completions select {
background: #fafafa;
outline: none;
border: none;
padding: 0;
margin: 0;
font-family: monospace;
}
.CodeMirror{

background:#EDEDED;
border: #333 solid 1px;
}
iframe {
/* width: 100%;*/
display:block; width:100%;
height: 400px;
background-color: #fff;
/*padding: 5px;*/
overflow: auto;
/*margin-right:5px;*/
border: 1px solid black;
box-shadow: rgba(0, 0, 0, 0.75) 0 2px 5px;
border-radius: 3px;
}

.CodeMirror pre {
line-height: inherit;
color: #B3B3B3;
}
.CodeMirror-wrap pre {
word-break: normal;
}

.CodeMirror-gutter {
background: none repeat scroll 0 0 rgba(186, 196, 204, 0.12);
}

.navbar h1{
color:#000;
margin-top: 5px;
display: inline;
}
.toolbar{
position: relative;
padding-right: 10px;
}
.caption{
position: absolute;
bottom: 17px;
left:155px;
}

.navbar .navbar-inner {
background: none repeat scroll 0 0 #FFFFFF;
border-radius: 0 0 0 0;
box-shadow: none;
color: #000000;
padding-top: 10px;
text-shadow: none;
}

.networkerror {
z-index: 9;
position:fixed;
top:0px;
left:18%;
display: none;
margin:0 auto;
width:60%;
}

</style>
</head>

<body>
<div id="network-error" class="alert alert-error networkerror">
Your Internet connection might have interrupted
<button type="button" class="close" id="network-error-close">×</button>
</div>
<div class="container main-content">
<div class="navbar toolbar" >

<div class="btn-toolbar pull-right" style="display:none">
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#" id='selected_lang' data-lang='ml'>
Malayalam
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#" class='lang' data-lang='en'>English</a></li>
<li><a tabindex="-1" href="#" class='lang' data-lang='hi'>Hindi</a></li>
<li><a tabindex="-1" href="#" class='lang' data-lang='ml'>Malayalam</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn" title='Print' id='printBtn'>
<i class="icon-print"> </i>
</button>
</div>
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn" data-preview="editor" title='Editor' id='editorBtn'>
<i class="icon-edit"> </i>
</button>
<button type="button" class="btn" data-preview="preview" title='Preview' id='previewBtn'>
<i class="icon-eye-open"></i>
</button>
</div>
</div>
</div>
<div class="editor">
<div id='editor_div'>
<textarea id='code' name='code'></textarea>
</div>
<div id='preview_div'>
<iframe id='preview'>

</iframe>
</div>
<div style='display:none' id='reserve'></div>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="javascripts/jquery-1.8.2.min.js">\x3C/script>')</script>
<script src="javascripts/varnam.js"></script>
</body>
</html>

4 changes: 4 additions & 0 deletions varnam-local/public/javascripts/addon.js

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions varnam-local/public/javascripts/copycss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
(function($) {

$.fn.getStyles = function(only, except) {

// the map to return with requested styles and values as KVP
var product = {};

// the style object from the DOM element we need to iterate through
var style;

// recycle the name of the style attribute
var name;

// if it's a limited list, no need to run through the entire style object
if (only && only instanceof Array) {

for (var i = 0, l = only.length; i < l; i++) {
// since we have the name already, just return via built-in .css method
name = only[i];
product[name] = this.css(name);
}

} else {

// otherwise, we need to get everything
var dom = this.get(0);

// standards
if (window.getComputedStyle) {

// convenience methods to turn css case ('background-image') to camel ('backgroundImage')
var pattern = /\-([a-z])/g;
var uc = function(a, b) {
return b.toUpperCase();
};
var camelize = function(string) {
return string.replace(pattern, uc);
};

// make sure we're getting a good reference
if (style = window.getComputedStyle(dom, null)) {
var camel, value;
// opera doesn't give back style.length - use truthy since a 0 length may as well be skipped anyways
if (style.length) {
for (var i = 0, l = style.length; i < l; i++) {
name = style[i];
camel = camelize(name);
value = style.getPropertyValue(name);
product[camel] = value;
}
} else {
// opera
for (name in style) {
camel = camelize(name);
value = style.getPropertyValue(name) || style[name];
product[camel] = value;
}
}
}
}
// IE - first try currentStyle, then normal style object - don't bother with runtimeStyle
else if (style = dom.currentStyle) {
for (name in style) {
product[name] = style[name];
}
} else if (style = dom.style) {
for (name in style) {
if (typeof style[name] != 'function') {
product[name] = style[name];
}
}
}

}

// remove any styles specified...
// be careful on blacklist - sometimes vendor-specific values aren't obvious but will be visible... e.g., excepting 'color' will still let '-webkit-text-fill-color' through, which will in fact color the text
if (except && except instanceof Array) {
for (var i = 0, l = except.length; i < l; i++) {
name = except[i];
delete product[name];
}
}

// one way out so we can process blacklist in one spot
return product;

};

// sugar - source is the selector, dom element or jQuery instance to copy from - only and except are optional
$.fn.copyCSS = function(source, only, except) {
var styles = $(source).getStyles(only, except);
this.css(styles);
};

})(jQuery);
2 changes: 2 additions & 0 deletions varnam-local/public/javascripts/jquery-1.8.2.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 0fcc1ac

Please sign in to comment.