Search in sources :

Example 1 with AceRelationMentionArgument

use of edu.stanford.nlp.ie.machinereading.domains.ace.reader.AceRelationMentionArgument in project CoreNLP by stanfordnlp.

the class AceReader method convertAceRelationMention.

private RelationMention convertAceRelationMention(AceRelationMention aceRelationMention, String docId, CoreMap sentence, Map<String, EntityMention> entityMap) {
    List<AceRelationMentionArgument> args = Arrays.asList(aceRelationMention.getArgs());
    List<ExtractionObject> convertedArgs = new ArrayList<>();
    List<String> argNames = new ArrayList<>();
    // the arguments are already stored in semantic order. Make sure we preserve the same ordering!
    int left = Integer.MAX_VALUE;
    int right = Integer.MIN_VALUE;
    for (AceRelationMentionArgument arg : args) {
        ExtractionObject o = entityMap.get(arg.getContent().getId());
        if (o == null) {
            logger.severe("READER ERROR: Failed to find relation argument with id " + arg.getContent().getId());
            logger.severe("This happens because a few relation mentions illegally span multiple sentences. Will ignore this mention.");
            return null;
        }
        convertedArgs.add(o);
        argNames.add(arg.getRole());
        if (o.getExtentTokenStart() < left)
            left = o.getExtentTokenStart();
        if (o.getExtentTokenEnd() > right)
            right = o.getExtentTokenEnd();
    }
    if (argNames.size() != 2 || !argNames.get(0).equalsIgnoreCase("arg-1") || !argNames.get(1).equalsIgnoreCase("arg-2")) {
        logger.severe("READER ERROR: Invalid succession of arguments in relation mention: " + argNames);
        logger.severe("ACE relations must have two arguments. Will ignore this mention.");
        return null;
    }
    RelationMention relation = new RelationMention(aceRelationMention.getId(), sentence, new Span(left, right), aceRelationMention.getParent().getType(), aceRelationMention.getParent().getSubtype(), convertedArgs, null);
    return relation;
}
Also used : AceRelationMentionArgument(edu.stanford.nlp.ie.machinereading.domains.ace.reader.AceRelationMentionArgument) AceRelationMention(edu.stanford.nlp.ie.machinereading.domains.ace.reader.AceRelationMention) RelationMention(edu.stanford.nlp.ie.machinereading.structure.RelationMention) ExtractionObject(edu.stanford.nlp.ie.machinereading.structure.ExtractionObject) ArrayList(java.util.ArrayList) Span(edu.stanford.nlp.ie.machinereading.structure.Span)

Aggregations

AceRelationMention (edu.stanford.nlp.ie.machinereading.domains.ace.reader.AceRelationMention)1 AceRelationMentionArgument (edu.stanford.nlp.ie.machinereading.domains.ace.reader.AceRelationMentionArgument)1 ExtractionObject (edu.stanford.nlp.ie.machinereading.structure.ExtractionObject)1 RelationMention (edu.stanford.nlp.ie.machinereading.structure.RelationMention)1 Span (edu.stanford.nlp.ie.machinereading.structure.Span)1 ArrayList (java.util.ArrayList)1