Search in sources :

Example 1 with Gender

use of edu.stanford.nlp.dcoref.Dictionaries.Gender in project CoreNLP by stanfordnlp.

the class Rules method entityAttributesAgree.

public static boolean entityAttributesAgree(CorefCluster mentionCluster, CorefCluster potentialAntecedent, boolean ignoreGender) {
    boolean hasExtraAnt = false;
    boolean hasExtraThis = false;
    // number
    if (!mentionCluster.numbers.contains(Number.UNKNOWN)) {
        for (Number n : potentialAntecedent.numbers) {
            if (n != Number.UNKNOWN && !mentionCluster.numbers.contains(n)) {
                hasExtraAnt = true;
                break;
            }
        }
    }
    if (!potentialAntecedent.numbers.contains(Number.UNKNOWN)) {
        for (Number n : mentionCluster.numbers) {
            if (n != Number.UNKNOWN && !potentialAntecedent.numbers.contains(n)) {
                hasExtraThis = true;
                break;
            }
        }
    }
    if (hasExtraAnt && hasExtraThis)
        return false;
    // gender
    hasExtraAnt = false;
    hasExtraThis = false;
    if (!ignoreGender) {
        if (!mentionCluster.genders.contains(Gender.UNKNOWN)) {
            for (Gender g : potentialAntecedent.genders) {
                if (g != Gender.UNKNOWN && !mentionCluster.genders.contains(g)) {
                    hasExtraAnt = true;
                    break;
                }
            }
        }
        if (!potentialAntecedent.genders.contains(Gender.UNKNOWN)) {
            for (Gender g : mentionCluster.genders) {
                if (g != Gender.UNKNOWN && !potentialAntecedent.genders.contains(g)) {
                    hasExtraThis = true;
                    break;
                }
            }
        }
    }
    if (hasExtraAnt && hasExtraThis)
        return false;
    // animacy
    hasExtraAnt = false;
    hasExtraThis = false;
    if (!mentionCluster.animacies.contains(Animacy.UNKNOWN)) {
        for (Animacy a : potentialAntecedent.animacies) {
            if (a != Animacy.UNKNOWN && !mentionCluster.animacies.contains(a)) {
                hasExtraAnt = true;
                break;
            }
        }
    }
    if (!potentialAntecedent.animacies.contains(Animacy.UNKNOWN)) {
        for (Animacy a : mentionCluster.animacies) {
            if (a != Animacy.UNKNOWN && !potentialAntecedent.animacies.contains(a)) {
                hasExtraThis = true;
                break;
            }
        }
    }
    if (hasExtraAnt && hasExtraThis)
        return false;
    // NE type
    hasExtraAnt = false;
    hasExtraThis = false;
    if (!mentionCluster.nerStrings.contains("O") && !mentionCluster.nerStrings.contains("MISC")) {
        for (String ne : potentialAntecedent.nerStrings) {
            if (!ne.equals("O") && !ne.equals("MISC") && !mentionCluster.nerStrings.contains(ne)) {
                hasExtraAnt = true;
                break;
            }
        }
    }
    if (!potentialAntecedent.nerStrings.contains("O") && !potentialAntecedent.nerStrings.contains("MISC")) {
        for (String ne : mentionCluster.nerStrings) {
            if (!ne.equals("O") && !ne.equals("MISC") && !potentialAntecedent.nerStrings.contains(ne)) {
                hasExtraThis = true;
                break;
            }
        }
    }
    return !(hasExtraAnt && hasExtraThis);
}
Also used : Animacy(edu.stanford.nlp.dcoref.Dictionaries.Animacy) Number(edu.stanford.nlp.dcoref.Dictionaries.Number) Gender(edu.stanford.nlp.dcoref.Dictionaries.Gender)

Example 2 with Gender

use of edu.stanford.nlp.dcoref.Dictionaries.Gender in project CoreNLP by stanfordnlp.

the class ConvertGenderFile method main.

public static void main(String[] args) throws IOException {
    String input = null;
    String output = null;
    for (int argIndex = 0; argIndex < args.length; ) {
        if (args[argIndex].equalsIgnoreCase("-input")) {
            input = args[argIndex + 1];
            argIndex += 2;
        } else if (args[argIndex].equalsIgnoreCase("-output")) {
            output = args[argIndex + 1];
            argIndex += 2;
        } else {
            throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
        }
    }
    if (input == null) {
        throw new IllegalArgumentException("Must specify input with -input");
    }
    if (output == null) {
        throw new IllegalArgumentException("Must specify output with -output");
    }
    Map<List<String>, Gender> genderNumber = Generics.newHashMap();
    BufferedReader reader = IOUtils.readerFromString(input);
    for (String line; (line = reader.readLine()) != null; ) {
        String[] split = line.split("\t");
        String[] countStr = split[1].split(" ");
        int male = Integer.parseInt(countStr[0]);
        int female = Integer.parseInt(countStr[1]);
        int neutral = Integer.parseInt(countStr[2]);
        Gender gender = Gender.UNKNOWN;
        if (male * 0.5 > female + neutral && male > 2) {
            gender = Gender.MALE;
        } else if (female * 0.5 > male + neutral && female > 2) {
            gender = Gender.FEMALE;
        } else if (neutral * 0.5 > male + female && neutral > 2) {
            gender = Gender.NEUTRAL;
        }
        if (gender == Gender.UNKNOWN) {
            continue;
        }
        String[] words = split[0].split(" ");
        List<String> tokens = Arrays.asList(words);
        genderNumber.put(tokens, gender);
    }
    IOUtils.writeObjectToFile(genderNumber, output);
}
Also used : BufferedReader(java.io.BufferedReader) List(java.util.List) Gender(edu.stanford.nlp.dcoref.Dictionaries.Gender)

Aggregations

Gender (edu.stanford.nlp.dcoref.Dictionaries.Gender)2 Animacy (edu.stanford.nlp.dcoref.Dictionaries.Animacy)1 Number (edu.stanford.nlp.dcoref.Dictionaries.Number)1 BufferedReader (java.io.BufferedReader)1 List (java.util.List)1