예제 #1
0
def index():
    fproc = FileProcessor()
    db = Database()

    button = None
    mode = "Class"

    # MIGHT NOT NEED

    sessionid = str(uuid.uuid1())
    if request.get_cookie(COOKIE_NAME) is None:
        response.set_cookie(COOKIE_NAME, sessionid)

    if fproc.is_relation(db):
        button = RelationButton()
        mode = "Relation"
    else:
        button = ClassButton()

    class_button = ClassButton()
    info = {
        'filename': fproc.get_filename(db),
        'content': fproc.token_to_span_colour(db, class_button),
        'result': fproc.output_annotated_str(db),
        'buttons': button.get_html_format(db),
        'mode': mode
    }

    return template('views/index', info)
예제 #2
0
def default_annotation():
    fproc = FileProcessor()
    db = Database()
    relation_button = RelationButton()

    return fproc.output_annotated_str(
        db) + '\n' + relation_button.output_relation_plain(db)
예제 #3
0
def switch_to_relation():
    db = Database()
    relation_button = RelationButton()
    fproc = FileProcessor()

    buttons = relation_button.get_html_format(db)
    fproc.set_relation_mode(db, "true")
    return {'buttons': buttons}
예제 #4
0
def save_file():
    db = Database()
    fproc = FileProcessor()
    relation_button = RelationButton()

    data = request.json
    save_path = './annotated_results'
    complete_name = os.path.join(save_path, data['filename'])

    text_file = open(complete_name, "w")
    text_file.write(
        fproc.output_annotated_str(db) + '\n' +
        relation_button.output_relation_plain(db))
    text_file.close()
예제 #5
0
def add_relation_button():
    data = request.json
    db = Database()
    relation_button = RelationButton()

    rels = relation_button.get_relation_buttons(db)
    if rels:
        if data['className'] not in rels:
            relation_button.add_button(db, data['className'])
            return {'buttons': relation_button.get_html_format(db)}
    else:
        relation_button.add_button(db, data['className'])
        return {'buttons': relation_button.get_html_format(db)}
예제 #6
0
def delete_button():
    db = Database()
    fproc = FileProcessor()
    class_button = ClassButton()
    data = request.json
    class_name = data['name']

    if fproc.is_relation(db):
        relation_button = RelationButton()
        relation_button.delete_button(db, class_name)
        return {
            'content': fproc.token_to_span_colour(db, class_button),
            'buttons': relation_button.get_html_format(db)
        }
    else:
        class_button.delete_button(db, class_name)
        fproc.delete_annotation(db, class_name)
        return {
            'content': fproc.token_to_span_colour(db, class_button),
            'buttons': class_button.get_html_format(db)
        }
예제 #7
0
def update_relation():
    data = request.json
    db = Database()
    relation_button = RelationButton()
    relation_button.add_relation(db, data['domain'], data['range'],
                                 data['relation'])

    return {
        'output': relation_button.output_relation_plain(db),
        'relations': relation_button.get_relations(db)
    }
예제 #8
0
def do_upload():
    db = Database()
    fproc = FileProcessor()
    class_button = ClassButton()
    fproc.reset(db)

    upload = request.files.get('upload')
    name, ext = os.path.splitext(upload.filename)
    filename = name + ext

    data = request.files.upload
    file_raw = data.file.read()
    file_content = file_raw.decode("utf-8")

    if ext not in ('.docx', '.pdf', '.doc', '.txt'):
        filename = "File uploaded was not valid"

    # CHECKS WHETHER THE FILE IS ANNOTATED DATA OR TEXT FILE
    is_annot_file = False
    for i in range(len(file_raw)):
        if file_raw[i] == 9:
            is_annot_file = file_raw[i + 1] == 68 or 77
            break

    content = ""
    results = ""

    if is_annot_file:

        # SPLIT TO CLASS DATA AND RELATION DATA
        file_content_split = file_content.split("\n\n")

        classes = fproc.parse_annotated_text(db, file_content_split[0])

        for cls in classes:
            if cls != 'O':
                class_button.add_button(db, cls, [255, 0, 0], [255, 255, 255])

        relation_button = RelationButton()
        relations = []
        if len(file_content_split) > 1:
            relations = fproc.parse_annotated_text_relations(
                db, file_content_split[1], relation_button)

        output_content = fproc.token_to_span_colour(db, class_button)
        content = output_content

    else:
        content = fproc.str_to_span(file_content)
        results = fproc.str_to_default_annotation(db, file_content)

    fproc.store_content(db, name, content)

    info = {
        'filename': filename,
        'content': content,
        'result': "",
        'buttons': class_button.get_html_format(db)
    }

    redirect('/')
예제 #9
0
def get_relations():
    db = Database()
    relation_button = RelationButton()

    return {'relations': relation_button.get_relations(db)}