def _consume_message(ch, method, properties, body):
    try:
        sentence = Sentence()
        sentence.from_json(body)
        _persist_sentence(sentence)
        mq_handler.ack(method)
    except Exception as e:
        logging.error("Could not consume message: " + body + ".\nException:" + str(e))
def _consume_message(ch, method, properties, body):
    try:
        original_sentence = Sentence()
        original_sentence.from_json(body)
        _translate_to_all_languages(original_sentence)
        mq_handler.ack(method)
    except Exception as e:
        logging.error(
            "Could not consume message: " + body + ".\nException:" + str(e))
def segment_aspects(input_fname,out_fname):
    print "begin loading sentences, ......"
    with open(input_fname,"rt") as inf:
        dd = json.load(inf)
        sentences = [ Sentence.from_json(d) for d in dd]
    print "{} sentences loaded".format(len(sentences))

    ######### for test and debug
    # sentences = random.sample(sentences,2000)
    ######### end test and debug

    seed_aspect_keywords = {
        "Overall":set(["recommend","recommendation","love","return","best","regret","rating"]),
        "Value": set(["value", "price", "quality", "worth"]),
        "Room": set([ "suite", "view", "bed","spacious","noisy","small"]),
        "Location": set(["location", "traffic", "minute", "parking","restaurant","shop","locate","subway","bus","airport","downtown"]),
        "Cleanliness": set(["clean", "dirty", "maintain", "smell"]),
        "Service": set(["staff","check", "help","service","helpful","friendly"]),
        "Business service": set(["business", "center", "computer", "internet","wifi","free"])
    }
    segmenter = AspectSegmentation(sentences,seed_aspect_keywords)
    segmenter.run()

    # save resuls
    print "begin dumping the results, ......"
    save_segmentation_results(segmenter,out_fname)
    print "!!! DONE !!!"