Example usage for edu.stanford.nlp.util Sets intersection

List of usage examples for edu.stanford.nlp.util Sets intersection

Introduction

In this page you can find the example usage for edu.stanford.nlp.util Sets intersection.

Prototype

public static <E> Set<E> intersection(Set<E> s1, Set<E> s2) 

Source Link

Document

Returns the intersection of sets s1 and s2.

Usage

From source file:edu.cmu.lti.oaqa.baseqa.answer.yesno.scorers.SentimentYesNoScorer.java

License:Apache License

@Override
public Map<String, Double> score(JCas jcas) throws AnalysisEngineProcessException {
    List<JCas> views = ViewType.listViews(jcas, viewNamePrefix);
    List<Integer> negativeWordsCounts = new ArrayList<>();
    List<Integer> positiveWordsCounts = new ArrayList<>();
    Map<String, Double> features = new HashMap<>();
    for (JCas view : views) {
        Set<String> tokens = TypeUtil.getOrderedTokens(view).stream()
                .flatMap(token -> Stream.of(token.getLemmaForm(), token.getCoveredText().toLowerCase()))
                .collect(toSet());//w w  w. j  av a  2s  .c  om
        Set<String> containedPositiveWords = Sets.intersection(tokens, positiveWords);
        positiveWordsCounts.add(containedPositiveWords.isEmpty() ? 0 : 1);
        containedPositiveWords.forEach(word -> features.put("sentiment-word@" + word, 1.0));
        Set<String> containedNegativeWords = Sets.intersection(tokens, negativeWords);
        negativeWordsCounts.add(containedNegativeWords.isEmpty() ? 0 : 1);
        containedNegativeWords.forEach(word -> features.put("sentiment-word@" + word, 1.0));
    }
    features.putAll(YesNoScorer.aggregateFeatures(negativeWordsCounts, "negative-words"));
    features.putAll(YesNoScorer.aggregateFeatures(positiveWordsCounts, "positive-words"));
    return features;
}