def testtalk(): s.listen(port) ports.log(port, "listening for client on %s"%(port)) with safeout("LOCKS/locked%s"%(port)) as out: out("") conn, addr = s.accept() with safeout("LOCKS/locked%s"%(port)) as out: out("locked") ports.log(port, '%s contacted by %s'%(port, addr)) rcvd = conn.recv(1024) ports.log(port, "TEST %s"%(rcvd)) sw = stringwriter() regexchunker.checksentences(sentences[start:end], mxltagger, outfile=sw, stages=stages) conn.sendal("RESENDING %s"%(rcvd)) conn.close() print "done"
def talkto(s, port, mxltagger, sentences): s.listen(port) ports.log(port, "listening for client on %s"%(port)) with safeout("LOCKS/locked%s"%(port)) as out: out("") conn, addr = s.accept() with safeout("LOCKS/locked%s"%(port)) as out: out("locked") ports.log(port, '%s contacted by %s'%(port, addr)) args = splitTSV(conn.recv(1024)) try: stages = map(int, args['stages'].split("&")) except: stages = [1,2,3,4,5] if 'showWNEntries' in args: try: start = int(args['start']) except: start = 0 try: end = int(args['end']) except: end = 20 ports.log(port, "analysing sentences from %s to %s"%(start, end)) sw = stringwriter() regexchunker.checksentences(sentences[start:end], mxltagger, outfile=sw, stages=stages) conn.sendall(sw.txt) elif 'parseOneSentence' in args: sentence = args['parseThisSentence'] ports.log(port, "tagging with HTML output %s"%(sentence)) sw = stringwriter() with safeout(sw) as out: regexchunker.checksentence(sentence, out, mxltagger, stages=stages) conn.sendall(sw.txt) elif 'justTag' in args: sentence = args['parseThisSentence'] ports.log(port, "just tagging %s"%(sentence)) sw = stringwriter() with safeout(sw) as out: out("%s.\n"%(regexchunker.justTag(sentence, mxltagger))) conn.sendall(sw.txt) conn.close() print "done"