*)Daily Quotas/apps :
application: nama_app version: 1 runtime: python27 api_version: 1 threadsafe: yes handlers: - url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico - url: .* script: main.app libraries: - name: webapp2 version: "2.5.1"
import webapp2 class MainHandler(webapp2.RequestHandler): def get(self): self.response.write('Hello world!') app = webapp2.WSGIApplication([ ('/', MainHandler) ], debug=True)
from bottle import route, run, template @route('/hello/:name') def index(name='World'): return template('Hello {{name}}!', name=name) run(host='localhost', port=8080)
application: kebalikan version: 1 runtime: python27 api_version: 1 threadsafe: yes handlers: - url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico - url: .* script: main.app
from bottle import * import parse @route('/') @view('index') def index(): return {'q':'', 'a':'', 'd':''} @post('/tanya') @view('index') def jawab(): masukan = request.forms.get('q', '') stat, tanggapan,debug = parse.respon(masukan) return {'q': masukan,'status':stat, 'a':tanggapan, 'd':debug} app = default_app()
<!DOCTYPE html> <html> <head> <title>test app</title> </head> <body> <form method="POST" id="newcat" action="/tanya"> <input type="text" name="q" id="q" value="{{q}}"/> <input type="submit" name="ask" value="tanya"/> </form> <div id="result" style="width:500px;background-color:#ccc;float:left;padding:8px;">{{a}}<br/> {{d}} </div> </body> </html>
KALIMAT -> PERTANYAAN | PERNYATAAN | PERINTAH | LARANGAN | SAPAAN ... PERNYATAAN -> SUBJEK PREDIKAT | KATA_TUNJUK KATA_BENDA KATA_BENDA ... KATA_BENDA -> KATA_BENDA KATA_HUBUNG KATA_BENDA | KATA_BENDA KATA_BENDA | KATA_BENDA KATA_SIFAT | KATA_PERAN KATA_BENDA ... KATA_GANTI_ORANG -> 'saya' | 'kamu' | 'dia' | 'ia' | 'beliau' | 'aku' | 'kalian' | 'kami' | 'kita' | 'ibu' | 'bapak' | 'anak' | 'anda' ...
import nltk import nltk.data import pickle import random from tokenization import tokenisasi_kalimat from nltk.parse.earleychart import EarleyChartParser gr = nltk.data.load('file:id.cfg') parser = EarleyChartParser(gr)
def respon(inputkal): sent = inputkal.strip() if len(sent)==0: return False,'',[] sent = tokenisasi_kalimat(sent) try: trees = parser.nbest_parse(sent) for n in trees[0]: if isinstance(n, nltk.tree.Tree): if n.node == 'SAPAAN': if n[0].node == 'SAPAAN_SINGKAT': return False, n[0][0]+' juga',n else: return False,nn[1][0],n elif n.node == 'PERNYATAAN': if random.randint(0,10)>4: return False, 'Oke',n else: return False, 'Oya?',n elif n.node == 'PERTANYAAN': return False, 'Saya tidak tahu',n return False,repr(e) except: if sent[0] == 'quit': return True, 'OK',sent return False,'saya tidak mengerti',sent
The question of whether a computer can think is no more interesting than the question of whether a submarine can swim.
further discussion