Search in sources :

Example 1 with Option

use of edu.illinois.cs.cogcomp.core.datastructures.Option in project cogcomp-nlp by CogComp.

the class PredicateDetector method getLemma.

public Option<String> getLemma(TextAnnotation ta, int tokenId) {
    String pos = WordHelpers.getPOS(ta, tokenId);
    String token = ta.getToken(tokenId).toLowerCase();
    String lemma = WordHelpers.getLemma(ta, tokenId);
    boolean predicate = false;
    // any token that is a verb is a predicate
    if (POSUtils.isPOSVerb(pos) && !pos.equals("AUX")) {
        if (token.equals("'s") || token.equals("'re") || token.equals("'m"))
            lemma = "be";
        else if (token.equals("'d") || lemma.equals("wo") || lemma.equals("'ll"))
            lemma = "xmodal";
        predicate = !(lemma.equals("xmodal") || pos.equals("MD") || token.equals("'ve"));
        // ignore all instances of has + "to be" if they are followed by a
        // verb or if the token is "be" followed by a verb
        boolean doVerb = lemma.equals("do");
        boolean be = lemma.equals("be");
        boolean have = lemma.equals("have");
        if (tokenId < ta.size() - 1) {
            if (be) {
                SpanLabelView chunk = (SpanLabelView) ta.getView(ViewNames.SHALLOW_PARSE);
                for (Constituent c : chunk.getConstituentsCoveringToken(tokenId)) {
                    // token, then there is another verb here
                    if (c.getEndSpan() - 1 != tokenId) {
                        predicate = false;
                        break;
                    }
                }
            }
            // ignore "have + be"
            if (have && WordHelpers.getLemma(ta, tokenId + 1).equals("be")) {
                predicate = false;
            }
            // ignore "have/do + verb"
            if ((have || doVerb) && POSUtils.isPOSVerb(WordHelpers.getPOS(ta, tokenId + 1)))
                predicate = false;
            if (token.equals("according") && ta.getToken(tokenId + 1).toLowerCase().equals("to"))
                predicate = false;
        }
        if (tokenId < ta.size() - 2) {
            // ignore don't + V or haven't + V
            if (doVerb || have) {
                String nextToken = ta.getToken(tokenId + 1).toLowerCase();
                if ((nextToken.equals("n't") || nextToken.equals("not")) && POSUtils.isPOSVerb(WordHelpers.getPOS(ta, tokenId + 2)))
                    predicate = false;
            }
        }
    } else if (token.startsWith("re-")) {
        String trim = token.replace("re-", "");
        predicate = WordNetPlusLemmaViewGenerator.lemmaDict.contains(trim);
    }
    if (predicate) {
        return new Option<>(lemma);
    } else {
        return Option.empty();
    }
}
Also used : Option(edu.illinois.cs.cogcomp.core.datastructures.Option) SpanLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

Option (edu.illinois.cs.cogcomp.core.datastructures.Option)1 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)1 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)1