Skip to content

Relation creation between two entities #289

@bschembri-UoM

Description

@bschembri-UoM

Do you have any guidelines how to create a relation between two entities.
The entities all ready exist in the cas I am creating some relations between existing named entities based on some logic.
Have tried the bellow but I am not able to make it work;

`
Relation = typesystem.get_type('webanno.custom.Relation')
NamedEntity = typesystem.get_type('de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity')

for i in range(1, maxSent + 1):
    # Let's find RESTCHAIN (subject) sells (object) PROD (predicate) in each sentence
    df_subj = entities.df_entities.query("SentRef == @i & NamedEntity == 'RESTCHAIN'")
    if (df_subj.shape[0]) > 0:
        df_pred = entities.df_entities.query("SentRef == @i & NamedEntity == 'PROD'")
        if df_pred.shape[0] > 0:
            for index_subj, row_subj in df_subj.iterrows():
                for index_pred, row_pred in df_pred.iterrows():
                    namedentity = NamedEntity().get(str(row_pred['id']))
                    relation = Relation(begin=str(row_pred['Begin']), end=str(row_pred['End']), Dependent=namedentity,
                                        Governor=str(row_subj['id']), Feature="sells")
                    cas.add(relation)

                    print(f"{row_subj['EntityText']} at {row_subj['Begin']}, {row_subj['End']} "
                          f"sells "
                          f"{row_pred['EntityText']} at {row_pred['Begin']}, {row_pred['End']}")

cas.to_xmi(config.xmi_path)

`

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions