|
Post by surogaseye on Mar 6, 2009 15:03:00 GMT -5
I'm currently creating a Sona hyperlink dictionary. The idea behind it is simply to provide hyperlinks within each entry that allow users to examine the composite radicals within each word. For example: kiny araji
|
|
|
Post by Arpee on Mar 8, 2009 14:22:27 GMT -5
This is excellent. I believe someone should make a translator though. It should be something like this: inamidst.com/services/tokipanaIt was written in Python. We can probably use to for making the Sona one: #!/usr/bin/env python """ Toki Pona to English Translation CGI Author: Sean B. Palmer, inamidst.com """
import cgitb; cgitb.enable() import sys, os, re, urllib import cgi, random, textwrap
r_wordOrTag = re.compile(r'((?:[A-Za-z]+)|(?:<(?!\!)[^>]+>))') r_head = re.compile(r'(?ims)<head[^>]*>') form = cgi.FieldStorage() form.__call__ = lambda s: form[s].value
nimi = {} if os.path.isfile('./nimi.txt'): nimifn = './nimi.txt' else: nimifn = '../misc/nimi.txt' f = open(nimifn) for line in f: line = line.rstrip('\r\n') word, translations = line.split(': ', 1) translations = translations.split(', ') nimi[word] = translations f.close()
def translateWord(word): w = word.lower() if nimi.has_key(w): return random.choice(nimi[w]) return {'li': 'is', 'la': "it's said", 'e': 'such'}.get(w) or word
def translate(s): def translateMatch(m): wordOrTag = m.group(1) if wordOrTag.startswith('<'): return wordOrTag return translateWord(wordOrTag) return r_wordOrTag.sub(translateMatch, s)
def translateURI(uri): u = urllib.urlopen(uri) translation = translate(u.read()) u.close() return translation
def homepage(): print textwrap.dedent((""" Content-Type: text/html; charset=utf-8
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>TokiPana - Toki Pona to English Translation Service</title> <link rel="stylesheet" type="text/css" href="/trove/svc.css" /> </head> <body> <h1>Toki Pona to English Translation</h1>
<form action="./tokipana" method="GET"> <div>URI: <input type="text" name="uri" size="35" /> <input type="submit" value="Translate" /></div> </form>
<form action="./tokipana" method="GET"> <div><textarea name="text" cols="75" rows="7"></textarea></div> <div>Text: <input type="submit" value="Translate" /></div> </form>
<ul> <li>Example One: <a href="./tokipana?uri=http%3A%2F%2F""" + """miscoranda.com%2Fcomments%2F127" >Jan Wasolitawa's comment on "On Toki Pona"</a></li> <li>Example Two: <a href="./tokipana?uri=http%3A%2F%2F""" + """www.livejournal.com%2Fcommunity%2Ftokipona%2F6724.html" >Stairway to Heaven (lyrics), from Toki Pona</a></li> </ul>
<p>More information: <a title="about">about this service</a>, <a href="/inside/services/tokipana">Python source</a>.</p>
<address> <a href="http://inamidst.com/sbp/">Sean B. Palmer</a> </address> </body> </html> """).lstrip('\n')) sys.exit()
def serve(): if form.has_key('uri'): uri = form('uri') else: uri = False if form.has_key('text'): text = form('text') else: text = False
if uri: assert ':' in uri u = urllib.urlopen(uri) info = u.info() text = u.read() u.close() mediatype = info.get('Content-Type') or 'text/html; charset=utf-8'
if mediatype.startswith('text/html'): base = '\n<base href="%s" />\n' % uri m = r_head.search(text) if m: endpos = m.end() text = text[:endpos] + base + text[endpos:] else: text = base + text elif text: mediatype = 'text/plain; charset=utf-8' else: homepage()
print "Content-Type: %s" % mediatype print result = translate(text) if text: def wrap(line): return '\n'.join(textwrap.wrap(line, width=79)) result = '\n'.join(wrap(line) for line in result.splitlines()) print result
def main(): fn = sys.argv[1] print translateURI(fn)
if __name__=="__main__": if os.environ.has_key('SCRIPT_NAME'): serve() else: main()
|
|
|
Post by surogaseye on Sept 11, 2010 19:12:48 GMT -5
Still working on the Hyperlink dictionaries. In the meantime I've made this site where Sona Rads can be picked at random: sonarads.blogspot.com/
|
|
|
Post by Holoddan on Jul 6, 2011 9:03:38 GMT -5
o cu seba: sonalanguageweb.x10.mx/default.htmlThis is excellent. I believe someone should make a translator though. It should be something like this: inamidst.com/services/tokipanaIt was written in Python. We can probably use to for making the Sona one: #!/usr/bin/env python """ Toki Pona to English Translation CGI Author: Sean B. Palmer, inamidst.com """
import cgitb; cgitb.enable() import sys, os, re, urllib import cgi, random, textwrap
r_wordOrTag = re.compile(r'((?:[A-Za-z]+)|(?:<(?!\!)[^>]+>))') r_head = re.compile(r'(?ims)<head[^>]*>') form = cgi.FieldStorage() form.__call__ = lambda s: form[s].value
nimi = {} if os.path.isfile('./nimi.txt'): nimifn = './nimi.txt' else: nimifn = '../misc/nimi.txt' f = open(nimifn) for line in f: line = line.rstrip('\r\n') word, translations = line.split(': ', 1) translations = translations.split(', ') nimi[word] = translations f.close()
def translateWord(word): w = word.lower() if nimi.has_key(w): return random.choice(nimi[w]) return {'li': 'is', 'la': "it's said", 'e': 'such'}.get(w) or word
def translate(s): def translateMatch(m): wordOrTag = m.group(1) if wordOrTag.startswith('<'): return wordOrTag return translateWord(wordOrTag) return r_wordOrTag.sub(translateMatch, s)
def translateURI(uri): u = urllib.urlopen(uri) translation = translate(u.read()) u.close() return translation
def homepage(): print textwrap.dedent((""" Content-Type: text/html; charset=utf-8
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>TokiPana - Toki Pona to English Translation Service</title> <link rel="stylesheet" type="text/css" href="/trove/svc.css" /> </head> <body> <h1>Toki Pona to English Translation</h1>
<form action="./tokipana" method="GET"> <div>URI: <input type="text" name="uri" size="35" /> <input type="submit" value="Translate" /></div> </form>
<form action="./tokipana" method="GET"> <div><textarea name="text" cols="75" rows="7"></textarea></div> <div>Text: <input type="submit" value="Translate" /></div> </form>
<ul> <li>Example One: <a href="./tokipana?uri=http%3A%2F%2F""" + """miscoranda.com%2Fcomments%2F127" >Jan Wasolitawa's comment on "On Toki Pona"</a></li> <li>Example Two: <a href="./tokipana?uri=http%3A%2F%2F""" + """www.livejournal.com%2Fcommunity%2Ftokipona%2F6724.html" >Stairway to Heaven (lyrics), from Toki Pona</a></li> </ul>
<p>More information: <a title="about">about this service</a>, <a href="/inside/services/tokipana">Python source</a>.</p>
<address> <a href="http://inamidst.com/sbp/">Sean B. Palmer</a> </address> </body> </html> """).lstrip('\n')) sys.exit()
def serve(): if form.has_key('uri'): uri = form('uri') else: uri = False if form.has_key('text'): text = form('text') else: text = False
if uri: assert ':' in uri u = urllib.urlopen(uri) info = u.info() text = u.read() u.close() mediatype = info.get('Content-Type') or 'text/html; charset=utf-8'
if mediatype.startswith('text/html'): base = '\n<base href="%s" />\n' % uri m = r_head.search(text) if m: endpos = m.end() text = text[:endpos] + base + text[endpos:] else: text = base + text elif text: mediatype = 'text/plain; charset=utf-8' else: homepage()
print "Content-Type: %s" % mediatype print result = translate(text) if text: def wrap(line): return '\n'.join(textwrap.wrap(line, width=79)) result = '\n'.join(wrap(line) for line in result.splitlines()) print result
def main(): fn = sys.argv[1] print translateURI(fn)
if __name__=="__main__": if os.environ.has_key('SCRIPT_NAME'): serve() else: main()
|
|