Example usage for edu.stanford.nlp.util Pair makePair

List of usage examples for edu.stanford.nlp.util Pair makePair

Introduction

In this page you can find the example usage for edu.stanford.nlp.util Pair makePair.

Prototype

public static <X, Y> Pair<X, Y> makePair(X x, Y y) 

Source Link

Document

Returns a Pair constructed from X and Y.

Usage

From source file:com.asimihsan.handytrowel.nlp.StopwordAnnotator.java

License:Open Source License

@Override
public void annotate(Annotation annotation) {
    if (stopwords != null && stopwords.size() > 0 && annotation.containsKey(TokensAnnotation.class)) {
        List<CoreLabel> tokens = annotation.get(TokensAnnotation.class);
        for (CoreLabel token : tokens) {
            boolean isWordStopword = stopwords.contains(token.word().toLowerCase());
            boolean isLemmaStopword = checkLemma ? stopwords.contains(token.lemma().toLowerCase()) : false;
            Pair<Boolean, Boolean> pair = Pair.makePair(isWordStopword, isLemmaStopword);
            token.set(StopwordAnnotator.class, pair);
        }//w w  w . jav a 2s .co  m
    }
}

From source file:de.l3s.content.timex.extracting.utils.DateUtil.java

License:Apache License

public static Pair<String, String> extractDateFromURL_(String url) {
    Pair<String, String> extractedDate = null;
    if (url.contains("_"))
        url = url.replace("_", "/");
    Pattern p = Pattern.compile(p1);
    Matcher date = p.matcher(url);
    if (date.find()) {
        String[] token = date.group().substring(1).split("/");

        String month = token[0];/*from   w w  w  .  java2 s .  c om*/
        if (month.contains("January") || month.contains("Jan")) {
            month = "01";
        } else if (month.contains("February") || month.contains("Feb")) {
            month = "02";
        } else if (month.contains("March") || month.contains("Mar")) {
            month = "03";
        } else if (month.contains("April") || month.contains("Apr")) {
            month = "04";
        } else if (month.contains("May")) {
            month = "05";
        } else if (month.contains("June") || month.contains("Jun")) {
            month = "06";
        } else if (month.contains("July") || month.contains("Jul")) {
            month = "07";
        } else if (month.contains("August") || month.contains("Aug")) {
            month = "08";
        } else if (month.contains("September") || month.contains("Sep")) {
            month = "09";
        } else if (month.contains("October") || month.contains("Oct")) {
            month = "10";
        } else if (month.contains("November") || month.contains("Nov")) {
            month = "11";
        } else if (month.contains("December") || month.contains("Dec")) {
            month = "12";
        }

        extractedDate = Pair.makePair(
                LocalDate.parse((token[1] + month + "15").toString(), dateFormat).toString(), "strong");
    } else {

        p = Pattern.compile(p2);
        date = p.matcher(url);
        if (date.find()) {
            String[] token = date.group().substring(1).split("/");

            String month = token[0];
            if (month.contains("January") || month.contains("Jan")) {
                month = "01";
            } else if (month.contains("February") || month.contains("Feb")) {
                month = "02";
            } else if (month.contains("March") || month.contains("Mar")) {
                month = "03";
            } else if (month.contains("April") || month.contains("Apr")) {
                month = "04";
            } else if (month.contains("May")) {
                month = "05";
            } else if (month.contains("June") || month.contains("Jun")) {
                month = "06";
            } else if (month.contains("July") || month.contains("Jul")) {
                month = "07";
            } else if (month.contains("August") || month.contains("Aug")) {
                month = "08";
            } else if (month.contains("September") || month.contains("Sep")) {
                month = "09";
            } else if (month.contains("October") || month.contains("Oct")) {
                month = "10";
            } else if (month.contains("November") || month.contains("Nov")) {
                month = "11";
            } else if (month.contains("December") || month.contains("Dec")) {
                month = "12";
            }

            extractedDate = Pair.makePair(
                    LocalDate.parse((token[1] + month + "15").toString(), dateFormat).toString(),
                    "mildly strong");
        } else {

            p = Pattern.compile(p3);
            date = p.matcher(url);
            if (date.find()) {
                String[] token = date.group().substring(1).split("/");
                try {
                    extractedDate = Pair.makePair(
                            LocalDate.parse((token[1] + token[0] + "15").toString(), dateFormat).toString(),
                            "mildy strong");
                } catch (IllegalFieldValueException e) {
                    return null;
                }
            } else {

                p = Pattern.compile(p4);
                date = p.matcher(url);
                if (date.find()) {
                    String[] token = date.group().substring(1).split("/");
                    try {
                        extractedDate = Pair.makePair(LocalDate
                                .parse((token[1] + "0" + token[0] + "15").toString(), dateFormat).toString(),
                                "mildly strong");
                    } catch (IllegalFieldValueException e) {
                        return null;
                    }
                } else {
                    p = Pattern.compile(p7);
                    date = p.matcher(url);
                    if (date.find()) {
                        String[] token = date.group().substring(1).split("/");
                        try {
                            extractedDate = Pair.makePair(
                                    LocalDate.parse(token[0] + token[1] + token[2], dateFormat).toString(),
                                    "very strong");
                        } catch (IllegalFieldValueException e) {
                            return null;
                        }
                    } else {

                        p = Pattern.compile(p6);
                        date = p.matcher(url);
                        if (date.find()) {
                            String[] token = date.group().substring(1).split("/");
                            try {
                                extractedDate = Pair.makePair(LocalDate
                                        .parse((token[0] + token[1] + "15").toString(), dateFormat).toString(),
                                        "mildly strong");
                            } catch (IllegalFieldValueException e) {
                                return null;
                            }
                        } else {
                            p = Pattern.compile(p5);
                            date = p.matcher(url);
                            if (date.find()) {
                                String[] token = date.group().substring(1).split("/");
                                try {
                                    extractedDate = Pair.makePair(
                                            LocalDate.parse((token[0] + token[1] + "15").toString(), dateFormat)
                                                    .toString(),
                                            "mildly strong");
                                } catch (IllegalFieldValueException e) {
                                    return null;
                                }
                            } else {
                                p = Pattern.compile(p8);
                                date = p.matcher(url);
                                if (date.find()) {
                                    String[] token = date.group().substring(1).split("_");
                                    try {
                                        extractedDate = Pair.makePair(LocalDate
                                                .parse(token[0] + token[1] + token[2], dateFormat).toString(),
                                                "very strong");
                                    } catch (IllegalFieldValueException e) {
                                        return null;
                                    }
                                } else {
                                    p = Pattern.compile(p9);
                                    date = p.matcher(url);
                                    if (date.find()) {
                                        String[] token = date.group().substring(1).split("_");
                                        try {
                                            extractedDate = Pair.makePair(LocalDate
                                                    .parse(token[0] + token[1] + "15", dateFormat).toString(),
                                                    "mildly strong");
                                        } catch (IllegalFieldValueException e) {
                                            return null;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return extractedDate;
}

From source file:knu.univ.lingvo.coref.Document.java

License:Open Source License

public void mergeIncompatibles(CorefCluster to, CorefCluster from) {
    List<Pair<Pair<Integer, Integer>, Pair<Integer, Integer>>> replacements = new ArrayList<Pair<Pair<Integer, Integer>, Pair<Integer, Integer>>>();
    for (Pair<Integer, Integer> p : incompatibleClusters) {
        Integer other = null;/*  w ww .j  a  v a 2s.  c om*/
        if (p.first == from.clusterID) {
            other = p.second;
        } else if (p.second == from.clusterID) {
            other = p.first;
        }
        if (other != null && other != to.clusterID) {
            int cid1 = Math.min(other, to.clusterID);
            int cid2 = Math.max(other, to.clusterID);
            replacements.add(Pair.makePair(p, Pair.makePair(cid1, cid2)));
        }
    }
    for (Pair<Pair<Integer, Integer>, Pair<Integer, Integer>> r : replacements) {
        incompatibleClusters.remove(r.first.first(), r.first.second());
        incompatibleClusters.add(r.second.first(), r.second.second());
    }
}