gt:                 if (isAddedWord(realWord)) {
context: /*
   *  LK Copy of GenericTermDocumentVectorSpaceCompounds
   *  Only but processDocument changed!
   */
  
  package cz.zcu.luk.sspace.common;
  
  import edu.ucla.sspace.basis.BasisMapping;
  import edu.ucla.sspace.basis.StringBasisMapping;
  import edu.ucla.sspace.common.SemanticSpace;
  import edu.ucla.sspace.matrix.Matrices;
  import edu.ucla.sspace.matrix.Matrix;
  import edu.ucla.sspace.matrix.MatrixBuilder;
  import edu.ucla.sspace.matrix.MatrixFile;
  import edu.ucla.sspace.matrix.SparseHashMatrix;
  import edu.ucla.sspace.util.*;
  import edu.ucla.sspace.vector.DoubleVector;
  import edu.ucla.sspace.vector.SparseHashDoubleVector;
  import edu.ucla.sspace.vector.Vector;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.IOError;
  import java.io.IOException;
  import java.util.Iterator;
  import java.util.LinkedHashSet;
  import java.util.Map;
  import java.util.Set;
  import java.util.concurrent.atomic.AtomicInteger;
  import java.util.logging.Logger;
  
  import cz.zcu.luk.sspace.matrix.*;
  import cz.zcu.luk.sspace.text.IteratorFactoryStopwords;
  
  
  /**
   * This base class centralizes much of the common text processing needed for
   * term-document based {@link edu.ucla.sspace.common.SemanticSpace}s.  It processes a document by
   * tokenizing all of the provided text and counting the term occurrences within
   * the document.  Each column in these spaces represent a document, and the
   * column values initially represent the number of occurrences for each word.
   * After all documents are processed, the word space can be modified with one of
   * the many {@link edu.ucla.sspace.matrix.Matrix} {@link edu.ucla.sspace.matrix.Transform} classes.  The transform, if
   * provided, will be used to rescore each term document occurrence count.
   * Typically, this reweighting is typically done to increase the score for
   * important and distinguishing terms while less salient terms, such as stop
   * words, are given a lower score.  After calling {@link
   * #processSpace(edu.ucla.sspace.matrix.Transform) processSpace}, sub classes should call assign thei
   * final data matrix to {@code wordSpace}.  This final matrix should maintain
   * the same row ordering, but the column ordering and dimensionality can be
   * modified in any way.
   *
   * <p>
   *
   * This class is thread-safe for concurrent calls of {@link
   * #processDocument(java.io.BufferedReader) processDocument}.  Once {@link
   * #processSpace(edu.ucla.sspace.matrix.Transform) processSpace} has been called, no further calls to
   * {@link #processDocument(java.io.BufferedReader) processDocument} should be made.
   * This implementation does not support access to the semantic vectors until
   * after {@link #processSpace(java.util.Properties) processSpace} has been called.
   *
   * @see edu.ucla.sspace.matrix.Transform
   * @see edu.ucla.sspace.matrix.SVD
   *
   * @author Keith Stevens
   */
  public abstract class GenericTermDocumentVectorSpaceExtended
          implements SemanticSpace, java.io.Serializable {
  
      // LK added..
      private Set<String> addedWords;
  
      private static final long serialVersionUID = 1L;
  
      protected static final Logger LOG =
          Logger.getLogger(GenericTermDocumentVectorSpaceExtended.class.getName());
  
      /**
       * A mapping from a word to the row index in the that word-document matrix
       * that contains occurrence counts for that word.
       */
      protected final BasisMapping<String, String> termToIndex;
  
      /**
       * The counter for recording the current number of documents observed.
       * Subclasses can use this for any reporting.
       */
      protected final AtomicInteger documentCounter;
  
      /**
       * The builder used to construct the term-document matrix as new documents
       * are processed.
       */
      private transient MatrixBuilder termDocumentMatrixBuilder;
  
      /**
       * If true, the first token in each document is considered to be a document
       * header.
       */
      private final boolean readHeaderToken;
  
      /**
       * The word space of the term document based word space model.  If the word
       * space is reduced, it is the left factor matrix of the SVD of the
       * word-document matrix.  This matrix is only available after the {@link
       * #processSpace(edu.ucla.sspace.matrix.Transform) processSpace}
       * method has been called.
       */
      protected Matrix wordSpace;
  
      /**
       * LK added..
       * A mapping from compound to index number.
       */
      protected BasisMapping<String, String> addedWordToIndex;
      /**
       * LK added..
       * The builder used to construct the compound-document matrix as new documents
       * are processed.
       */
      private transient MatrixBuilder addedWordsDocumentMatrixBuilder;
      /**
       * LK added..
       */
      protected Matrix addedWordsSpace;
  
      /**
       * Constructs the {@code GenericTermDocumentVectorSpace}.
       *
       * @throws java.io.IOException if this instance encounters any errors when creatng
       *         the backing array files required for processing
       */
      public GenericTermDocumentVectorSpaceExtended() throws IOException {
          this(false,new StringBasisMapping(),Matrices.getMatrixBuilderForSVD(), Matrices.getMatrixBuilderForSVD(), null);
      }
  
      /**
       * Constructs the {@code GenericTermDocumentVectorSpace} using the provided
       * objects for processing.
       *
       * @param readHeaderToken If true, the first token of each document will be
       *        read and passed to {@link #handleDocumentHeader(int, String)
       *        handleDocumentHeader}, which by default discards the header.
       * @param termToIndex The {@link edu.ucla.sspace.basis.BasisMapping} used to map strings to
       *        indices.
       * @param termDocumentMatrixBuilder The {@link edu.ucla.sspace.matrix.MatrixBuilder} used to write
       *        document vectors to disk which later get processed in {@link
       *        #processSpace(java.util.Properties) processSpace}.
       *
       * @throws java.io.IOException if this instance encounters any errors when creatng
       *         the backing array files required for processing
       */
      public GenericTermDocumentVectorSpaceExtended(
              boolean readHeaderToken,
              BasisMapping<String, String> termToIndex,
              MatrixBuilder termDocumentMatrixBuilder,
              MatrixBuilder addedWordsDocumentMatrixBuilder,
              Set<String> addedWords) throws IOException {
          this.readHeaderToken = readHeaderToken;
          this.termToIndex = termToIndex;
          this.addedWords = addedWords;
          documentCounter = new AtomicInteger(0);
  
          // LK added..
          this.addedWordToIndex = new StringBasisMapping();
          this.addedWordsDocumentMatrixBuilder = addedWordsDocumentMatrixBuilder;
  
          this.termDocumentMatrixBuilder = termDocumentMatrixBuilder;
  
          wordSpace = null;
      }
  
      private boolean isAddedWord(String possibleAddedWord) {
          if (addedWords.contains(possibleAddedWord)) return true;
          else return false;
      }
  
      /**
       * Tokenizes the document using the {@link edu.ucla.sspace.text.IteratorFactory} and updates the
       * term-document frequency counts.
       *
       * <p>
       *
       * This method is thread-safe and may be called in parallel with separate
       * documents to speed up overall processing time.
       *
       * @param document {@inheritDoc}
       */
      public void processDocument(BufferedReader document) throws IOException {
          // Create a mapping for each term that is seen in the document to the
          // number of times it has been seen.  This mapping would more elegantly
          // be a SparseArray<Integer> however, the length of the sparse array
          // isn't known ahead of time, which prevents it being used by the
          // MatrixBuilder.  Note that the SparseArray implementation would also
          // incur an additional performance hit since each word would have to be
          // converted to its index form for each occurrence, which results in a
          // double Map look-up.
          Counter<String> termCounts = new ObjectCounter<String>();
  
          // LK added
          Counter<String> addedWordsCounts = new ObjectCounter<String>();
  
          Iterator<String> documentTokens = IteratorFactoryStopwords.tokenize(document);
  
          // Increaes the count of documents observed so far.
          int docCount = documentCounter.getAndAdd(1);
  
          // If the first token is to be interpreted as a document header read it.
          if (readHeaderToken)
              handleDocumentHeader(docCount, documentTokens.next());
  
          // If the document is empty, skip it
          if (!documentTokens.hasNext())
              return;
  
          // For each word in the text document, keep a count of how many times it
          // has occurred
          while (documentTokens.hasNext()) {
              // LK changed
              //String word = documentTokens.next();
              String word;
              String possibleWord = documentTokens.next();
              boolean wordInSpace = false;
              if (possibleWord.endsWith(IteratorFactoryStopwords.STOPWORD_FLAG)) {
                  word = IteratorFactoryStopwords.EMPTY_TOKEN;
              }
              else {
                  word = possibleWord;
                  wordInSpace = true;
              }
  
              // LK added.. for addedWords..
              if (!wordInSpace && addedWords != null) {
                  String realWord = possibleWord.substring(0, possibleWord.length()-IteratorFactoryStopwords.STOPWORD_FLAG.length()); // store the stopword!
  