Package java.util

Examples of java.util.Scanner


      File file = res.getFile();
      if (file.getName().endsWith("stdout")) {
        // there has to be some content in stdout file
        assertThat("there has to be content in stdout file", file.length(), greaterThan(0l));
        if (file.getName().equals("Container.stdout")) {
          Scanner scanner = new Scanner(file);
          String content = scanner.useDelimiter("\\A").next();
          scanner.close();
          // check that we have a simple timestamp
          assertThat("content doesn't look like timestamp", content.length(), greaterThan(10));
          assertThat("content doesn't look like timestamp", content.length(), lessThan(40));
        }
      } else if (file.getName().endsWith("stderr")) {
        String content = "";
        if (file.length() > 0) {
          Scanner scanner = new Scanner(file);
          content = scanner.useDelimiter("\\A").next();
          scanner.close();
        }
        if (content.contains("Unable to load realm info from SCDynamicStore")) {
          // due to OS X giving 'Unable to load realm info from SCDynamicStore' errors we allow 100 bytes here
          assertThat("stderr file is not empty: " + content, file.length(), lessThan(100l));
        } else {
View Full Code Here


    initDefaultTable();
    configureExport(new ExportConf.Builder("xml").header(true).build());
    processExport(new XmlExport());
   
    // The header must exist
    Scanner scanner = new Scanner(new String(baos.toByteArray()));
    String firstLine = scanner.nextLine();
   
    assertThat(firstLine).contains("<?xml version=\"1.0\"?>");
    assertThat(firstLine).contains("<persons>");
    assertThat(firstLine).contains("</persons>");
    assertThat(firstLine).contains("<person id=\"1\" firstName=\"Selma\" lastName=\"Maldonado\" city=\"\" mail=\"venenatis@Duisvolutpat.com\"></person><person id=\"2\" firstName=\"Vanna\" lastName=\"Salas\" city=\"Denny\" mail=\"bibendum.fermentum.metus@ante.ca\"></person>");
View Full Code Here

    initDefaultTable();
    configureExport(new ExportConf.Builder("csv").header(true).build());
    processExport(new CsvExport());
   
    // The header must exist
    String firstLine = new Scanner(new String(baos.toByteArray())).nextLine();
    assertThat(firstLine).contains("Id;FirstName;LastName;City;Mail");
   
    // There must be as many line as entries in Mock.persons (+1 for the header row)
    assertThat(new String(baos.toByteArray()).split("\n")).hasSize(Mock.persons.size() + 1);
  }
View Full Code Here

    initDefaultTable();
    configureExport(new ExportConf.Builder("csv").header(false).build());
    processExport(new CsvExport());
   
    // The header must exist
    String firstLine = new Scanner(new String(baos.toByteArray())).nextLine();
    assertThat(firstLine).doesNotContain("Id;FirstName;LastName;City;Mail");
   
    // There must be as many line as entries in Mock.persons (+1 for the header row)
    assertThat(new String(baos.toByteArray()).split("\n")).hasSize(Mock.persons.size());
  }
View Full Code Here

   
    initTable();
    configureExport(new ExportConf.Builder("csv").header(false).build());
    processExport(new CsvExport());
   
    String firstLine = new Scanner(new String(baos.toByteArray())).nextLine();
    assertThat(StringUtils.countOccurrencesOf(firstLine, ";")).isEqualTo(4);
  }
View Full Code Here

     * @param analogy_file a {@code String} containing the absolute path to the analogy file.
     */
    public void loadAnalogiesFromFile(String analogy_file) {

            try {
                Scanner sc = new Scanner(new File(analogy_file));
                while (sc.hasNext()) {
                    String analogy = sc.next();
                    if (!isAnalogyFormat(analogy)) {
                        System.err.println("\"" + analogy + "\" not in proper format.");
                        continue;
                    }
                    String analogy_pair[] = analogy.split(":");
                    String A = analogy_pair[0];
                    String B = analogy_pair[1];

                    //1. Find alternates for A and B
                    Synset[] A_prime = findAlternatives(A);
                    Synset[] B_prime = findAlternatives(B);
                   
                    //2. Filter phrases
                    ArrayList<String> tmp = new ArrayList<String>(filterPhrases(INDEX_DIR,A,B,A_prime,B_prime));
                    filtered_phrases.addAll(tmp);
                    original_to_alternates.put(A+":"+B, tmp);
                }
                sc.close();
            } catch (Exception e) {
                System.err.println("Could not read file.");
            }
    }
View Full Code Here

        for (int i = 0; i < files.length; i++) {
            File f = files[i];
            if (f.isDirectory()) {
                pattern_set.addAll(searchDirectoryForPattern(f, A, B));
            } else if (f.getName().endsWith(".txt")) {
                Scanner sc = new Scanner(f);
                while (sc.hasNext()) {
                    if (A.equals(sc.next())) {
                        String pattern = "";
                        int count = 0;
                        while (count <= MAX_INTER && sc.hasNext()) {
                            String curr = sc.next();
                            if (count >= MIN_INTER && B.equals(curr)) {
                                //add the String onto a Set of Strings containing the patterns
                                //System.err.println("adding pattern: " + pattern);
                                pattern_set.add(pattern);
                                break;
View Full Code Here

        for (int i = 0; i < files.length; i++) {
            File f = files[i];
            if (f.isDirectory()) {
                total += countWildcardPhraseFrequencies(f, pattern);
            } else if (f.getName().endsWith(".txt")) {
                Scanner sc = new Scanner(f);
                while (sc.hasNext()) {
                    String line = sc.nextLine();
                    if (line.matches(pattern)) {
                        total++;
                    }
                }
            }
View Full Code Here

     *
     * @see #computeCosineSimilarity(String,Matrix)
     **/
    public void evaluateAnalogies(Matrix projection, String inputFileName, String outputFileName) {
            try {
                Scanner sc = new Scanner(new File(inputFileName));
                PrintStream out = new PrintStream(new FileOutputStream(outputFileName));
                while (sc.hasNext()) {
                    String analogy = sc.next();
                    if (!isAnalogyFormat(analogy,true)) {
                        System.err.println("\"" + analogy + "\" not in proper format.");
                        continue;
                    }
                    double cosineVal = computeCosineSimilarity(analogy, projection); //does the actual cosine value calculations and comparisons
                    out.println(analogy + " = " + cosineVal);
                }
                sc.close();
                out.close();
            } catch (Exception e) {
                System.err.println("Could not read file.");
            }
    }
View Full Code Here

     *
     * @see #computeCosineSimilarity(String,Matrix)
     **/
    public void evaluateAnalogies(Matrix projection) {
            try {
                Scanner sc = new Scanner(System.in);
                while (sc.hasNext()) {
                    String analogy = sc.next();
                    if (!isAnalogyFormat(analogy,true)) {
                        System.err.println("\"" + analogy + "\" not in proper format.");
                        continue;
                    }
                    double cosineVal = computeCosineSimilarity(analogy, projection); //does the actual cosine value calculations and comparisons
                    System.out.println(analogy + " = " + cosineVal);
                }
                sc.close();
            } catch (Exception e) {
                System.err.println("Could not read file.");
            }
    }
View Full Code Here

TOP

Related Classes of java.util.Scanner

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.