Example #1
0
  private void makeClumpGoldStandard() throws EvalError {
    switch (testFileType) {
      case WSJ:
        clumpGoldStandard = CorpusUtil.wsjClumpGoldStandard(alpha, corpusFiles);
        break;

      case NEGRA:
        clumpGoldStandard = CorpusUtil.negraClumpGoldStandard(alpha, corpusFiles);
        break;

      case CTB:
        clumpGoldStandard = CorpusUtil.ctbClumpGoldStandard(alpha, corpusFiles);
        break;

      case SPL:
        evalTypes.clear();
        evalTypes.add(OutputType.NONE);
        evals.clear();
        evals.add(NullEval.instance());
        break;

      default:
        throw new EvalError("Unexpected file type for clumping gold standard: " + corpusFiles);
    }

    if (filterLength > 0)
      clumpGoldStandard = clumpGoldStandard.filterBySentenceLength(filterLength);
  }
Example #2
0
 // look up and apply coarts for w to each sign in result
 @SuppressWarnings("unchecked")
 private void applyCoarts(Word w, SignHash result) throws LexException {
   List<Sign> inputSigns = new ArrayList<Sign>(result.asSignSet());
   result.clear();
   List<Sign> outputSigns = new ArrayList<Sign>(inputSigns.size());
   // for each surface attr, lookup coarts and apply to input signs, storing results in output
   // signs
   for (Iterator<Pair<String, String>> it = w.getSurfaceAttrValPairs(); it.hasNext(); ) {
     Pair<String, String> p = it.next();
     String attr = (String) p.a;
     if (!_indexedCoartAttrs.contains(attr)) continue;
     String val = (String) p.b;
     Word coartWord = Word.createWord(attr, val);
     SignHash coartResult = getSignsFromWord(coartWord, null, null, null);
     for (Iterator<Sign> it2 = coartResult.iterator(); it2.hasNext(); ) {
       Sign coartSign = it2.next();
       // apply to each input
       for (int j = 0; j < inputSigns.size(); j++) {
         Sign sign = inputSigns.get(j);
         grammar.rules.applyCoart(sign, coartSign, outputSigns);
       }
     }
     // switch output to input for next iteration
     inputSigns.clear();
     inputSigns.addAll(outputSigns);
     outputSigns.clear();
   }
   // add results back
   result.addAll(inputSigns);
 }
Example #3
0
 // look up and apply coarts for given rels to each sign in result
 private void applyCoarts(List<String> coartRels, Collection<Sign> result) {
   List<Sign> inputSigns = new ArrayList<Sign>(result);
   result.clear();
   List<Sign> outputSigns = new ArrayList<Sign>(inputSigns.size());
   // for each rel, lookup coarts and apply to input signs, storing results in output signs
   for (Iterator<String> it = coartRels.iterator(); it.hasNext(); ) {
     String rel = it.next();
     Collection<String> preds = (Collection<String>) _coartRelsToPreds.get(rel);
     if (preds == null) continue; // not expected
     Collection<Sign> coartResult = getSignsFromRelAndPreds(rel, preds);
     if (coartResult == null) continue;
     for (Iterator<Sign> it2 = coartResult.iterator(); it2.hasNext(); ) {
       Sign coartSign = it2.next();
       // apply to each input
       for (int j = 0; j < inputSigns.size(); j++) {
         Sign sign = inputSigns.get(j);
         grammar.rules.applyCoart(sign, coartSign, outputSigns);
       }
     }
     // switch output to input for next iteration
     inputSigns.clear();
     inputSigns.addAll(outputSigns);
     outputSigns.clear();
   }
   // add results back
   result.addAll(inputSigns);
 }
Example #4
0
 public void close() {
   for (ClassDataCollector cd : delegates)
     try {
       if (cd instanceof Closeable) ((Closeable) cd).close();
     } catch (Exception e) {
       reporter.error("Fail to call close on %s", cd);
     }
   delegates.clear();
   shortlist.clear();
 }
 public void clearRecycled() {
   for (ShelvedChangeList list : myRecycledShelvedChangeLists) {
     deleteListImpl(list);
   }
   myRecycledShelvedChangeLists.clear();
   notifyStateChanged();
 }
    public void write(final BufferedWriter w) {
      RW.writeln(w, "Module:" + myName);

      RW.writeln(w, "SourceProperties:");
      mySource.write(w);

      RW.writeln(w, "TestProperties:");
      myTest.write(w);

      RW.writeln(w, "Excludes:");
      RW.writeln(w, myExcludes, RW.fromString);

      RW.writeln(w, "Libraries:");
      RW.writeln(w, myLibraries);

      RW.writeln(w, "Dependencies:");

      final List<ClasspathItemWrapper> weakened = new ArrayList<ClasspathItemWrapper>();

      for (ClasspathItemWrapper cpiw : dependsOn(false)) {
        weakened.add(weaken(cpiw));
      }

      RW.writeln(w, weakened);

      weakened.clear();

      for (ClasspathItemWrapper cpiw : dependsOn(true)) {
        weakened.add(weaken(cpiw));
      }

      RW.writeln(w, weakened);
    }
 void removeInitListeners() {
   BundleContext context = createBundleContext(false);
   for (FrameworkListener initListener : initListeners) {
     context.removeFrameworkListener(initListener);
   }
   initListeners.clear();
 }
Example #8
0
  protected void reset() {
    paused = false;
    Sprite.spriteContext = this;
    sprites.clear();

    try {
      level = currentLevel.clone();
    } catch (CloneNotSupportedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    level.resetSpriteTemplate();

    layer = new LevelRenderer(level, graphicsConfiguration, 320, 240);

    double oldX = 0;

    if (mario != null) oldX = mario.x;

    mario = new Mario(this);
    sprites.add(mario);
    startTime = 1;

    timeLeft = 200 * 15;
    Art.startMusic(1);
    tick = 0;
    //        recorder = new DataRecorder(this,level,keys,gametype);
    if (recorder != null) {
      recorder.detailedLog = "";
    }
    gameStarted = false;
  }
Example #9
0
 /**
  * Method use OpenCsv Library for
  *
  * @param fileInputCsv the File CSV to parse.
  * @param separator the char separator.
  * @return the List of Bean parsed from the CSV file.
  */
 public static List<String[]> parseCSVFileAsList(File fileInputCsv, char separator) {
   try {
     List<String[]> records;
     // read all lines at once
     try ( // create CSVReader object
     CSVReader reader = new CSVReader(new FileReader(fileInputCsv), separator)) {
       // read all lines at once
       records = reader.readAll();
       Iterator<String[]> iterator = records.iterator();
       records.clear();
       // skip header row
       iterator.next();
       while (iterator.hasNext()) {
         String[] record = iterator.next();
         records.add(record);
       }
     }
     return records;
   } catch (IOException e) {
     logger.error(
         "Can't parse the CSV file:" + fileInputCsv.getAbsolutePath() + " -> " + e.getMessage(),
         e);
     return new ArrayList<>();
   }
 }
 public void clear() {
   map.clear();
   list.clear();
   map.put(null, (char) 0);
   list.add(null);
   addPosition = 1;
 }
Example #11
0
 public void sortGrammarFiles() throws IOException {
   // System.out.println("Grammar names "+getGrammarFileNames());
   Graph g = new Graph();
   List<String> missingFiles = new ArrayList<String>();
   for (String gfile : grammarFileNames) {
     try {
       GrammarSpelunker grammar = new GrammarSpelunker(inputDirectory, gfile);
       grammar.parse();
       String vocabName = grammar.getTokenVocab();
       String grammarName = grammar.getGrammarName();
       // Make all grammars depend on any tokenVocab options
       if (vocabName != null) g.addEdge(gfile, vocabName + CodeGenerator.VOCAB_FILE_EXTENSION);
       // Make all generated tokens files depend on their grammars
       g.addEdge(grammarName + CodeGenerator.VOCAB_FILE_EXTENSION, gfile);
     } catch (FileNotFoundException fnfe) {
       ErrorManager.error(ErrorManager.MSG_CANNOT_OPEN_FILE, gfile);
       missingFiles.add(gfile);
     }
   }
   List<Object> sorted = g.sort();
   // System.out.println("sorted="+sorted);
   grammarFileNames.clear(); // wipe so we can give new ordered list
   for (int i = 0; i < sorted.size(); i++) {
     String f = (String) sorted.get(i);
     if (missingFiles.contains(f)) continue;
     if (!(f.endsWith(".g") || f.endsWith(".g3"))) continue;
     grammarFileNames.add(f);
   }
   // System.out.println("new grammars="+grammarFileNames);
 }
Example #12
0
 public void cleanup() {
   if (!this.flags.contains(Flags.USECACHE)) {
     tempDirs.forEach(
         dir -> {
           deleteDir(dir);
         });
     tempDirs.clear();
   }
 }
Example #13
0
  /**
   * Set the MS2 queries of the MGF file. If this object was generated from an existing MGF file the
   * connection to this MGF file is lost.
   *
   * @param ms2Queries
   */
  public void setMs2Queries(List<Ms2Query> ms2Queries) {
    // remove the source file link
    sourceFile = null;
    index.clear();

    // save the queries in the HashMap
    for (int index = 0; index < ms2Queries.size(); index++)
      this.ms2Queries.put(index, ms2Queries.get(index));
  }
Example #14
0
 public void flatten() throws IOException {
   if (!dirty) {
     return;
   }
   loadRawData();
   for (PageDiff diff : diffList) {
     System.arraycopy(diff.getData(), 0, rawData, diff.getOffset(), diff.getData().length);
   }
   diffList.clear();
 }
Example #15
0
 @Override
 public void classEnd() throws Exception {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.classEnd();
     } catch (Exception e) {
       reporter.error("Fail to call classEnd on %s", cd);
     }
   shortlist.clear();
 }
 public void clear() {
   if (frequentItems != null) {
     frequentItems.clear();
   }
   frequentItems = null;
   if (sequences != null) {
     sequences.clear();
   }
   sequences = null;
   itemFactory = null;
 }
Example #17
0
 protected static synchronized void kill() {
   if (sessionList != null) {
     for (HTTPSession session : sessionList) {
       session.close();
     }
     sessionList.clear();
     // Rebuild the connection manager
     connmgr.shutdown();
     connmgr = new PoolingHttpClientConnectionManager(sslregistry);
     setGlobalThreadCount(DFALTTHREADCOUNT);
   }
 }
 private BundleInfo[] orderingInitialConfig(List setToInitialConfig) {
   List notToBeStarted = new LinkedList();
   List toBeStarted = new LinkedList();
   for (Iterator ite2 = setToInitialConfig.iterator(); ite2.hasNext(); ) {
     BundleInfo bInfo = (BundleInfo) ite2.next();
     if (bInfo.isMarkedAsStarted()) toBeStarted.add(bInfo);
     else notToBeStarted.add(bInfo);
   }
   setToInitialConfig.clear();
   setToInitialConfig.addAll(notToBeStarted);
   setToInitialConfig.addAll(toBeStarted);
   return Utils.getBundleInfosFromList(setToInitialConfig);
 }
Example #19
0
  /*
   * (non-Javadoc)
   * @see com.salesforce.dataloader.dao.csv.Writer#close()
   */
  public void close() {

    if (fileOut != null) {
      try {
        fileOut.close();
      } catch (IOException e) {
        logger.error(Messages.getString("CSVWriter.errorClosing"), e); // $NON-NLS-1$
      }
      if (!columnNames.isEmpty()) {
        columnNames.clear();
      }
    }
  }
  /**
   * Construct a logging event from currentMap and additionalLines (additionalLines contains
   * multiple message lines and any exception lines)
   *
   * <p>CurrentMap and additionalLines are cleared in the process
   *
   * @return event
   */
  private LoggingEvent buildEvent() {
    if (currentMap.size() == 0) {
      if (additionalLines.size() > 0) {
        for (Iterator iter = additionalLines.iterator(); iter.hasNext(); ) {
          getLogger().info("found non-matching line: " + iter.next());
        }
      }
      additionalLines.clear();
      return null;
    }
    // the current map contains fields - build an event
    int exceptionLine = getExceptionLine();
    String[] exception = buildException(exceptionLine);

    // messages are listed before exceptions in additionallines
    if (additionalLines.size() > 0 && exception.length > 0) {
      currentMap.put(MESSAGE, buildMessage((String) currentMap.get(MESSAGE), exceptionLine));
    }
    LoggingEvent event = convertToEvent(currentMap, exception);
    currentMap.clear();
    additionalLines.clear();
    return event;
  }
  /** Permanently removes all locally stored message history, remove recent contacts. */
  public void eraseLocallyStoredHistory() throws IOException {
    List<ComparableEvtObj> toRemove = null;
    synchronized (recentMessages) {
      toRemove = new ArrayList<ComparableEvtObj>(recentMessages);

      recentMessages.clear();
    }

    if (recentQuery != null) {
      for (ComparableEvtObj msc : toRemove) {
        recentQuery.fireContactRemoved(msc);
      }
    }
  }
Example #22
0
 /**
  * Removes redirection symbols from the parameter list params. Stores redirection information in
  * currentRedirection_.
  *
  * @return params without redirection symbols
  */
 public List<String> handleRedirection(List<String> params) {
   // Clear the data for redirection for each new case.
   currentRedirection_.clear();
   // If the correct syntax is found, then the if statement is executed.
   if (params.size() >= 2
       && params.get(params.size() - 2).equals(">") | params.get(params.size() - 2).equals(">>")) {
     // The redirection data is sent to a different private ArrayList.
     currentRedirection_.add(params.get(params.size() - 2));
     currentRedirection_.add(params.get(params.size() - 1));
     params.remove(params.size() - 1);
     params.remove(params.size() - 1);
   }
   return params;
 }
 /**
  * Submit differencers for running. All tree *must* have been received before this is called.
  */
 public void submitDifferencers() {
   // We need to difference all trees one against another
   for (int i = 0; i < trees.size() - 1; ++i) {
     TreeResponse r1 = trees.get(i);
     for (int j = i + 1; j < trees.size(); ++j) {
       TreeResponse r2 = trees.get(j);
       Differencer differencer = new Differencer(cfname, r1, r2);
       logger.debug("Queueing comparison {}", differencer);
       differencers.add(differencer);
     }
   }
   differencers.start();
   trees.clear(); // allows gc to do its thing
 }
Example #24
0
  public void setUp() throws IOException {
    file = new File(TEST_FILE_NAME);

    names.clear();
    names.add("John");
    names.add("Anton");
    names.add("Dirk");
    names.add("Heinz");

    PrintWriter out = new PrintWriter(file);
    for (String name : names) {
      out.println(name);
    }
    out.close();
  }
  // each sentence on one line
  public void readData(String dataFile) {
    if (data != null) {
      data.clear();
    } else {
      data = new ArrayList();
    }

    // open data file
    BufferedReader fin = null;

    try {
      fin = new BufferedReader(new FileReader(dataFile));

      System.out.println("Reading input data ...");

      String line = null;
      // start to read sentences => sequences
      while ((line = fin.readLine()) != null) {
        line = PennTokenizer.tokenize(line);

        StringTokenizer strTok = new StringTokenizer(line, " \t\r\n");

        if (strTok.countTokens() == 0) {
          // skip this blank line
          continue;
        }

        // create new data sequence
        List seq = new ArrayList();

        while (strTok.hasMoreTokens()) {
          Observation obsr = new Observation();
          obsr.originalData = strTok.nextToken();
          seq.add(obsr);
        }

        data.add(seq);
      }

      System.out.println(
          "Reading input data (" + Integer.toString(data.size()) + " sequences) completed!");

    } catch (IOException e) {
      System.out.println("Couldn't open data file" + dataFile);
      return;
    }
  }
Example #26
0
 private List<ParseResult> findBestParses(List<ParseResult> all, Exp e) {
   List<ParseResult> best = new LinkedList<ParseResult>();
   double bestScore = -Double.MAX_VALUE;
   for (ParseResult p : all) {
     if (p.getExp().inferType() != null) {
       if ((e == null || p.getExp().equals(e))) {
         if (p.getScore() == bestScore) best.add(p);
         if (p.getScore() > bestScore) {
           bestScore = p.getScore();
           best.clear();
           best.add(p);
         }
       }
     }
   }
   return best;
 }
  /** sublists contains elements at indexes offset from their base */
  public void testSubList() {
    List a = populatedArray(10);
    assertTrue(a.subList(1, 1).isEmpty());
    for (int j = 0; j < 9; ++j) {
      for (int i = j; i < 10; ++i) {
        List b = a.subList(j, i);
        for (int k = j; k < i; ++k) {
          assertEquals(new Integer(k), b.get(k - j));
        }
      }
    }

    List s = a.subList(2, 5);
    assertEquals(3, s.size());
    s.set(2, m1);
    assertEquals(a.get(4), m1);
    s.clear();
    assertEquals(7, a.size());
  }
Example #28
0
  /**
   * parse: break the input String into fields
   *
   * @return java.util.Iterator containing each field from the original as a String, in order.
   */
  public List parse(String line) {
    StringBuffer sb = new StringBuffer();
    list.clear(); // recycle to initial state
    int i = 0;

    if (line.length() == 0) {
      list.add(line);
      return list;
    }

    do {
      sb.setLength(0);
      if (i < line.length() && line.charAt(i) == '"') i = advQuoted(line, sb, ++i); // skip quote
      else i = advPlain(line, sb, i);
      list.add(sb.toString());
      i++;
    } while (i < line.length());

    return list;
  }
Example #29
0
  /**
   * Update packs to installed. A pack to be installed is: 1. A visible pack that has its checkbox
   * checked 2. A hidden pack that condition
   *
   * @return
   */
  public List<Pack> updatePacksToInstall() {
    packsToInstall.clear();
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      if (isChecked(i) && !installedPacks.containsKey(pack.getName())) {
        packsToInstall.add(pack);
      } else if (installedPacks.containsKey(pack.getName())) {
        checkValues[i] = REQUIRED_PARTIAL_SELECTED;
      }
    }

    for (Pack hiddenPack : this.hiddenPacks) {
      if (this.rules.canInstallPack(hiddenPack.getName(), variables)) {
        packsToInstall.add(hiddenPack);
      }
    }

    installData.setSelectedPacks(packsToInstall);
    return packsToInstall;
  }
Example #30
0
    public void run() {
      long end_time, wait_time;
      List<Request> requests = new LinkedList<Request>();
      while (Thread.currentThread().equals(thread) && !suspended) {
        try {
          boolean keepGoing = false;
          end_time = System.currentTimeMillis() + max_bundling_time;
          do {
            Request firstRequest =
                (Request)
                    queue.remove(INTERVAL); // throws a TimeoutException if it runs into timeout
            requests.add(firstRequest);
            if (!view_bundling) break;
            if (queue.size() > 0) {
              Request nextReq = (Request) queue.peek();
              keepGoing = view_bundling && firstRequest.canBeProcessedTogether(nextReq);
            } else {
              wait_time = end_time - System.currentTimeMillis();
              if (wait_time > 0)
                queue.waitUntilClosed(
                    wait_time); // misnomer: waits until element has been added or q closed
              keepGoing =
                  queue.size() > 0 && firstRequest.canBeProcessedTogether((Request) queue.peek());
            }
          } while (keepGoing && System.currentTimeMillis() < end_time);

          try {
            process(requests);
          } finally {
            requests.clear();
          }
        } catch (QueueClosedException e) {
          break;
        } catch (TimeoutException e) {
          break;
        } catch (Throwable catchall) {
          Util.sleep(50);
        }
      }
    }