Example #1
0
def extract_and_get_intent(text):
    #     try:
    #         text = compound2unicode(text)
    #         if text.count(" ") == 0:
    #             text = text + "."
    #         for k,v in MAPPING_DICT.items():
    #             text = text.replace(k, v)

    print('\nINPUT: ' + text)
    extracted = extract(text)
    extracted_dict = dict()
    for extractEle in extracted:
        key = extractEle['key']
        value = extractEle['value']
        if key not in extracted_dict.keys():
            extracted_dict[key] = [value]
        else:
            if value not in extracted_dict[key]:
                extracted_dict[key].append(value)
    extracted_dict_keys = extracted_dict.keys()
    candidate_intent_dict = get_candidate_intent([text])

    for key in DEFINED_INTENTS:
        if key in extracted_dict_keys and key in candidate_intent_dict.keys():
            candidate_intent_dict.pop(key)

    print('\n     OUTPUT: INTENT:' + str(candidate_intent_dict))
    print('\n     OUTPUT: EXTRACT:' + str(extracted_dict))
    return extracted, extracted_dict, candidate_intent_dict
def main():
    infile = ''
    template = ''
    outfile = ''
    csvFile = False
    compFile = False

    #argument handleing
    try:
        optList, args = getopt.getopt(
            sys.argv[1:], 'hi:t:ovc',
            ["ifile=", "templatefile=", "ofile=", "csvfile=", "compoundfile="])
    except getopt.GetoptError:
        print(
            'Usage: BRENDAExtract.py --ifile <inputfile> --templatefile <templatefile> --ofile <outputfile>'
        )
        sys.exit(2)
    for opt, arg in optList:

        if opt == '-h':
            print(
                'Usage: BRENDAExtract.py --ifile <inputfile> --templatefile <templatefile> --ofile <outputfile>'
            )
            sys.exit()

        elif opt in ("-i", "--ifile"):
            infile = arg

        elif opt in ("-t", "--templatefile"):
            template = arg

        elif opt in ("-o", "--ofile"):
            outfile = arg

        elif opt in ("-v", "--csvfile"):
            csvFile = arg

        elif opt in ("-c", "--compoundfile"):
            compFile = arg

    q = extract()

    input_file = open(infile).read()
    input_json = json.loads(input_file)

    template_file = open(template).read()
    template_json = json.loads(template_file)

    q.templateExtract(input_json, outfile, csvFile, compFile, template_json)
Example #3
0
def summariser():

    reqData = request.get_json()
    print(reqData)
    res = extract(reqData["url"])

    data = res["content"]
    t = res["title"]
    title = t[0].text

    summary = text_rank(data)

    res = make_response(jsonify({
        "Summary": summary,
        "Title": str(title)
    }), 200)

    return res
def extract_data(train_filename, test_filename, extra_filename):
    #extract datasets
    train_folder = extract(train_filename)
    test_folder = extract(test_filename)
    extra_folder = extract(extra_filename)
    return train_folder, test_folder, extra_folder