def index(): text = request.args.get('text', "coi pilno mi'e camxes") try: ast = camxes.parse(text) grammatical = camxes.isgrammatical(text) except: return redirect(url_for('index')) if 'json' in request.args: return jsonify(html=render_template('box.html', dict(text=text, ast=ast)), grammatical=grammatical) return render_response('index.html', dict(ast=ast, text=text, grammatical=grammatical))
def getEnglishTranslation(sentence): """parse a lojban sentence return the english translation""" # get a list of all the names names = [str(e) for e in re.findall(r"\.[^\s]*\.", sentence)] # replace all occurences with "ko" sentence = re.sub(r"\.[^\s]*\.", "ko", sentence) # make a parse tree rootNode = camxes.parse(sentence) if tree: print rootNode return translateSentence(rootNode, names=names)
def getEnglishTranslation( sentence ): """parse a lojban sentence return the english translation""" # get a list of all the names names = [ str(e) for e in re.findall( r"\.[^\s]*\.", sentence ) ] # replace all occurences with "ko" sentence = re.sub( r"\.[^\s]*\.", "ko", sentence) # make a parse tree rootNode = camxes.parse( sentence ) if tree: print rootNode return translateSentence( rootNode, names=names )
def parse_tree(): yield camxes.parse("coi rodo mi cipra loka na cfila la camxes")
def parse_trees_from_outer_space(): yield camxes.parse("coi rodo!"), camxes.parse("coi rodo!", spaces=True)
import sys from camxes import parse, isgrammatical print parse(sys.argv[1]) print if not isgrammatical(sys.argv[1]): print 'not', print 'grammatical:', sys.argv[1]