Package edu.stanford.nlp.ling

Examples of edu.stanford.nlp.ling.Word$WordFactoryHolder


        ArrayList<Word> Words = StringToWordsTokenizer.tokenize(text);
        ParsingOptions opts = new ParsingOptions();
        opts.setPosTag(true);
        opts.setParseRelations(true);
        ParsedData resultData = sParser.parse(Words, opts);
        Word featureWord = new Word(feature);
        int featIndex = Words.indexOf(featureWord);
        Sentiment sentimentResult = Sentiment.Neutral;
        if (!feature.equals("") && featIndex != -1) {
            WordPos theFeature = resultData.getWordByIndex(featIndex);
            return classifyTextByFeatures(resultData, Words, theFeature);
View Full Code Here


    private double computeWordWeight(WordPos currentWord, ArrayList<Word> allWords) {
        String wordString = allWords.get(currentWord.getWordIndex()).word();
        int sign = wordString.contains("N##") ? -1 : 1;
        if (sign == -1) {
            allWords.set(currentWord.getWordIndex(), new Word(wordString.replace("N##", "")));
        }
        Double wordWeight = aggregator.getWordScore(currentWord, allWords);
        if (wordWeight != null && wordWeight == 0 & sign == -1) {
            return -0.5;
        }
View Full Code Here

        return sign * wordWeight;
    }

    private void tagNegation(ArrayList<Word> allWords) {
        boolean negationFound = false;
        Word currentWord;
        List<Word> tempPattern;
        boolean exceptionFound;
        for (int i = 0; i < allWords.size(); i++) {
            currentWord = allWords.get(i);
            if (clauseEnds.contains(currentWord.toString())) {
                // Reset as a there is a new clause
                negationFound = false;
                continue;
            }
            if (negationWords.contains(currentWord.toString())) {
                // check if this is one of the exceptions
                exceptionFound = false;
                for (ArrayList<Word> exceptionPattern : negationExceptions) {
                    tempPattern = allWords.subList(i, i + (exceptionPattern.size()));
                    if (tempPattern.containsAll(exceptionPattern)) {
                        exceptionFound = true;
                    }
                }
                if (!exceptionFound) {
                    negationFound = !negationFound;
                }
            } else {
                if (negationFound) {
                    currentWord.setWord("N##" + currentWord.word());
                }
            }
        }
    }
View Full Code Here

        String[] tokens;
        for (String exception : exs) {
            tokens = exception.split(" ");
            currentEx = new ArrayList<Word>();
            for (String token : tokens) {
                currentEx.add(new Word(token));
            }
            negationExceptions.add(currentEx);
        }
        ArrayList<String> inverters = FilesReader.getAllLines(PropertiesGetter.getProperty("InvertersFile"));
        parsedInverters = new ArrayList<ArrayList<Word>>();
        ArrayList<Word> currentInverter;
        String[] lineTokens;
        for (String inverter : inverters) {
            currentInverter = new ArrayList<Word>();
            lineTokens = inverter.split(" ");
            for (String token : lineTokens) {
                currentInverter.add(new Word(token));
            }
            parsedInverters.add(currentInverter);
        }

    }
View Full Code Here

    } else {
      // Showing tokenization and parsing in code a couple of different ways.
      String[] sent = { "This", "is", "an", "easy", "sentence", "." };
      List<HasWord> sentence = new ArrayList<HasWord>();
      for (String word : sent) {
        sentence.add(new Word(word));
      }

      String sent2 = ("This is a slightly longer and more complex " +
                      "sentence requiring tokenization.");
      // Use the default tokenizer for this TreebankLanguagePack
View Full Code Here

    List<CoreLabel> words = new ArrayList<CoreLabel>();
    String[] testWords = {"I", "think", "I", "'ll",
                          "go", "to", "Boston", "."};

    for (String word : testWords) {
      CoreLabel label = new CoreLabel(new Word(word));
      label.setWord(label.value());
      words.add(label);
    }

    tagger.tagCoreLabels(words);
View Full Code Here

    // GrammaticalStructure.

    List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
    List<TypedDependency> dependencies = new ArrayList<>();

    IndexedWord root = new IndexedWord(new Word("ROOT"));
    root.set(CoreAnnotations.IndexAnnotation.class, 0);

    for (int i = 1; i <= result.n; i++) {
      int head = result.getHead(i);
      String label = result.getLabel(i);
View Full Code Here

          if (parse) {
            tree.pennPrint(pw);
          } else {
            Iterator sentIter = s.iterator();
            for (; ;) {
              Word word = (Word) sentIter.next();
              pw.print(word.word());
              if (sentIter.hasNext()) {
                pw.print(" ");
              } else {
                break;
              }
View Full Code Here

          }
        } else if (word instanceof HasTag) {
          TaggedWord tw = new TaggedWord(word.word(), ((HasTag) word).tag());
          sentenceB.add(tw);
        } else {
          sentenceB.add(new Word(word.word()));
        }
      }
      for (HasWord word : sentenceB) {
        word.setWord(op.wordFunction.apply(word.word()));
      }
View Full Code Here

    if (op.testOptions.verbose) {
      System.err.println("Adding missing final punctuation to sentence.");
    }
    String[] sfpWords = tlp.sentenceFinalPunctuationWords();
    if (sfpWords.length > 0) {
      sentence.add(new Word(sfpWords[0]));
    }
    return true;
  }
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.ling.Word$WordFactoryHolder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.