text, fix_parenthesis=True ) scores, sim_mat = lexrank.lexrank(sentences) sents = [] for i in sorted(scores.keys()): el = (sentences[i], scores[i]) sents.append(el) elif algo == 'mcp': sents = mcp_summ.summarize(text, char_limit) except Exception, e: return json.dumps({'error': str(e)}, ensure_ascii=False, indent=2) else: res = json.dumps( tools.tree_encode(sents), ensure_ascii=False, indent=2 ) return res if __name__ == '__main__': options, args = getopt.getopt(sys.argv[1:], 'h:p:') options = dict(options) host, port = options['-h'], int(options['-p']) cherrypy.config.update({ 'server.socket_host': host, 'server.socket_port': port }) conf = {
elif mode == 'score': # [(文,重要度), ... ] sentences = tools.sent_splitter_ja(text, fix_parenthesis=True) scores, sim_mat = lexrank.lexrank(sentences) sents = [] for i in sorted(scores.keys()): el = (sentences[i], scores[i]) sents.append(el) elif algo == 'mcp': sents = mcp_summ.summarize(text, char_limit) except Exception, e: return json.dumps({'error': str(e)}, ensure_ascii=False, indent=2) else: res = json.dumps(tools.tree_encode(sents), ensure_ascii=False, indent=2) return res if __name__ == '__main__': options, args = getopt.getopt(sys.argv[1:], 'h:p:') options = dict(options) host, port = options['-h'], int(options['-p']) cherrypy.config.update({ 'server.socket_host': host, 'server.socket_port': port })
summarizer_params[param] = value if algo in ("lexrank", "clexrank"): summarizer = self.get_summarizer("lexrank") if algo == "clexrank": summarizer_params["continuous"] = True elif algo == "mcp": summarizer = self.get_summarizer("mcp") summary, debug_info = summarizer(text, **summarizer_params) except Exception, e: return json.dumps({"error": str(e)}, ensure_ascii=False, indent=2) else: res = json.dumps( tools.tree_encode({"summary": summary, "debug_info": debug_info}), ensure_ascii=False, indent=2 ) return res if __name__ == "__main__": options, args = getopt.getopt(sys.argv[1:], "h:p:") options = dict(options) host, port = options["-h"], int(options["-p"]) cherrypy.config.update({"server.socket_host": host, "server.socket_port": port}) conf = { "/": {"tools.staticdir.root": os.path.dirname(os.path.abspath(__file__))}, "/summarize": {
if algo in ('lexrank', 'clexrank'): summarizer = self.get_summarizer('lexrank') if algo == 'clexrank': summarizer_params['continuous'] = True elif algo == 'mcp': summarizer = self.get_summarizer('mcp') summary, debug_info = summarizer(text, **summarizer_params) except Exception, e: return json.dumps({'error': str(e)}, ensure_ascii=False, indent=2) else: res = json.dumps( tools.tree_encode({ 'summary': summary, 'debug_info': debug_info }), ensure_ascii=False, indent=2 ) return res if __name__ == '__main__': options, args = getopt.getopt(sys.argv[1:], 'h:p:') options = dict(options) host, port = options['-h'], int(options['-p']) cherrypy.config.update({ 'server.socket_host': host, 'server.socket_port': port