Ejemplo n.º 1
0
def append_relation(root, utype, global_id1, global_id2):
    """
    Append a new relation level annotation to the given root element.
    Note that this generates a new identifier behind the scenes.

    Parameters
    ----------
    root :
        node of the XML tree to which we want to add a "relation" child
    utype : string
        type of the relation we want to create (sequence, continuation,
        QAP...)
    global_id1 : string
        global id of the first element (EDU or CDU) of the relation
    global_id2 : string
        global id of the second element (EDU or CDU) of the relation
    """
    unit_id, date = mk_id(author=_AUTHOR)

    id1 = global_id1.split('_')
    id2 = global_id2.split('_')

    subdoc1 = id1[1]
    subdoc2 = id2[1]

    if subdoc1 == subdoc2:
        local_id1 = '_'.join([id1[-2], id1[-1]])
        local_id2 = '_'.join([id2[-2], id2[-1]])

        metadata = [('author', _AUTHOR), ('creation-date', str(date)),
                    ('lastModifier', 'n/a'), ('lastModificationDate', '0')]
        elm_relation = ET.SubElement(root, 'relation', {'id': unit_id})
        elm_metadata = ET.SubElement(elm_relation, 'metadata')
        for key, val in metadata:
            ET.SubElement(elm_metadata, key).text = val
        elm_charact = ET.SubElement(elm_relation, 'characterisation')
        ET.SubElement(elm_charact, 'type').text = utype

        elm_features = ET.SubElement(elm_charact, 'featureSet')
        comments = ET.SubElement(elm_features, 'feature', {'name': 'Comments'})
        comments.text = 'Please write in remarks...'
        argument_scope = ET.SubElement(elm_features, 'feature',
                                       {'name': 'Argument_scope'})
        argument_scope.text = 'Please choose...'

        positioning = ET.SubElement(elm_relation, 'positioning')
        edu1 = ET.SubElement(positioning, 'term', {'id': local_id1})
        edu2 = ET.SubElement(positioning, 'term', {'id': local_id2})

        return []

    else:
        err1 = "Implicit relation from subdoc %s to subdoc %s :" % (subdoc1,
                                                                    subdoc2)
        print(err1)
        err2 = "%s ------ %s -----> %s" % (global_id1, utype, global_id2)
        print(err2)
        return [err1, err2]
Ejemplo n.º 2
0
def append_relation(root, utype, global_id1, global_id2):
    """
    Append a new relation level annotation to the given root element.
    Note that this generates a new identifier behind the scenes.

    Parameters
    ----------
    root :
        node of the XML tree to which we want to add a "relation" child
    utype : string
        type of the relation we want to create (sequence, continuation, QAP...)
    global_id1 : string
        global id of the first element (EDU or CDU) of the relation
    global_id2 : string
        global id of the second element (EDU or CDU) of the relation
    """
    unit_id, date = mk_id()

    id1 = global_id1.split('_')
    id2 = global_id2.split('_')

    subdoc1 = id1[1]
    subdoc2 = id2[1]

    if subdoc1 == subdoc2:
        local_id1 = '_'.join([id1[-2], id1[-1]])
        local_id2 = '_'.join([id2[-2], id2[-1]])

        metadata = [('author', 'stac'),
                    ('creation-date', str(date)),
                    ('lastModifier', 'n/a'),
                    ('lastModificationDate', '0')]
        elm_relation = ET.SubElement(root, 'relation', {'id': unit_id})
        elm_metadata = ET.SubElement(elm_relation, 'metadata')
        for key, val in metadata:
            ET.SubElement(elm_metadata, key).text = val
        elm_charact = ET.SubElement(elm_relation, 'characterisation')
        ET.SubElement(elm_charact, 'type').text = utype

        elm_features = ET.SubElement(elm_charact, 'featureSet')
        comments = ET.SubElement(elm_features, 'feature', {'name': 'Comments'})
        comments.text = 'Please write in remarks...'
        argument_scope = ET.SubElement(elm_features, 'feature', {'name': 'Argument_scope'})
        argument_scope.text = 'Please choose...'

        positioning = ET.SubElement(elm_relation, 'positioning')
        edu1 = ET.SubElement(positioning, 'term', {'id': local_id1})
        edu2 = ET.SubElement(positioning, 'term', {'id': local_id2})

        return []

    else:
        err1 = "Implicit relation from subdoc %s to subdoc %s :" % (subdoc1, subdoc2)
        print(err1)
        err2 = "%s ------ %s -----> %s" % (global_id1, utype, global_id2)
        print(err2)
        return [err1, err2]
Ejemplo n.º 3
0
def append_schema(root, utype, edus):
    """
    Append a new schema level annotation to the given root element.
    Note that this generates a new identifier behind the scenes.

    Parameters
    ----------
    root :
        node of the XML tree to which we want to add a "schema" child
    utype : string
        type of the schema we want to create. Usually, a
        "Complex_discourse_unit".
    edus :
        list of the global ids of the EDUs that compose the CDU

    Returns
    -------
    cdu_id : string
        local id of the CDU created (used later to create a relation
        between this CDU and another element)
    """
    cdu_id, date = mk_id(author=_AUTHOR)

    metadata = [('author', _AUTHOR),
                ('creation-date', str(date)),
                ('lastModifier', 'n/a'),
                ('lastModificationDate', '0')]
    elm_schema = ET.SubElement(root, 'schema', {'id': cdu_id})
    elm_metadata = ET.SubElement(elm_schema, 'metadata')
    for key, val in metadata:
        ET.SubElement(elm_metadata, key).text = val
    elm_charact = ET.SubElement(elm_schema, 'characterisation')
    # utype = 'Complex_discourse_unit'
    ET.SubElement(elm_charact, 'type').text = utype
    elm_features = ET.SubElement(elm_charact, 'featureSet')

    positioning = ET.SubElement(elm_schema, 'positioning')
    for edu in edus:
        edusplit = edu.split('_')
        local_id = '_'.join([edusplit[-2], edusplit[-1]])
        ET.SubElement(positioning, 'embedded-unit', {'id': local_id})

    return cdu_id
Ejemplo n.º 4
0
def append_schema(root, utype, edus):
    """
    Append a new schema level annotation to the given root element.
    Note that this generates a new identifier behind the scenes.

    Parameters
    ----------
    root :
        node of the XML tree to which we want to add a "schema" child
    utype : string
        type of the schema we want to create. Usually, a
        "Complex_discourse_unit".
    edus :
        list of the global ids of the EDUs that compose the CDU

    Returns
    -------
    cdu_id : string
        local id of the CDU created (used later to create a relation
        between this CDU and another element)
    """
    cdu_id, date = mk_id(author=_AUTHOR)

    metadata = [('author', _AUTHOR), ('creation-date', str(date)),
                ('lastModifier', 'n/a'), ('lastModificationDate', '0')]
    elm_schema = ET.SubElement(root, 'schema', {'id': cdu_id})
    elm_metadata = ET.SubElement(elm_schema, 'metadata')
    for key, val in metadata:
        ET.SubElement(elm_metadata, key).text = val
    elm_charact = ET.SubElement(elm_schema, 'characterisation')
    # utype = 'Complex_discourse_unit'
    ET.SubElement(elm_charact, 'type').text = utype
    elm_features = ET.SubElement(elm_charact, 'featureSet')

    positioning = ET.SubElement(elm_schema, 'positioning')
    for edu in edus:
        edusplit = edu.split('_')
        local_id = '_'.join([edusplit[-2], edusplit[-1]])
        ET.SubElement(positioning, 'embedded-unit', {'id': local_id})

    return cdu_id