Search in sources :

Example 26 with LineNumberReader

use of java.io.LineNumberReader in project jackrabbit-oak by apache.

the class QueryLogAnalyzer method analyze.

private static void analyze(String fileName) throws IOException {
    LineNumberReader r = new LineNumberReader(new FileReader(fileName));
    int totalLineCount = 0, traversedLineCount = 0;
    TreeMap<String, QueryStats> queries = new TreeMap<String, QueryStats>();
    while (true) {
        String line = r.readLine();
        if (line == null) {
            break;
        }
        totalLineCount++;
        String number = retrieve(line, "Traversed ", " nodes ");
        if (number == null) {
            continue;
        }
        traversedLineCount++;
        line = line.substring(line.indexOf("Traversed " + number + " nodes "));
        String index = retrieve(line, "nodes using index ", " with filter");
        String rawQuery = retrieve(line, "Filter(query=", null);
        if (rawQuery == null) {
            System.out.println("Unknown line: " + line);
        }
        String rawXpath = retrieve(rawQuery, "/* xpath: ", "*/, ");
        String query = filterParams(rawQuery);
        if (rawXpath != null) {
            rawQuery = rawXpath;
            query = filterParams(rawXpath);
        }
        String key = query;
        QueryStats q = queries.get(key);
        if (q == null) {
            q = new QueryStats();
            queries.put(key, q);
            q.query = query;
        }
        q.index = index;
        q.lineCount++;
        int nodes = Integer.parseInt(number);
        if (nodes > q.maxNodeCount) {
            q.longestQuery = rawQuery;
            q.maxNodeCount = nodes;
        }
        if (q.lastNodeCount == 0 || nodes < q.lastNodeCount) {
            // start
            q.runCount++;
            q.lastNodeCount = 0;
        } else {
        // continuation
        }
        q.nodeCount += nodes - q.lastNodeCount;
        q.lastNodeCount = nodes;
    }
    System.out.println("File: " + fileName);
    System.out.println("Lines: " + totalLineCount);
    System.out.println("Lines with 'Traversed': " + traversedLineCount);
    ArrayList<QueryStats> list = new ArrayList<QueryStats>();
    list.addAll(queries.values());
    Collections.sort(list);
    for (QueryStats q : list) {
        System.out.println();
        System.out.println("  Query: " + formatQuery(q.query));
        if (!q.query.equals(q.longestQuery)) {
            System.out.println("  Longest: " + formatQuery(q.longestQuery));
        }
        if (q.index != null) {
            System.out.println("  Index: " + q.index);
        }
        System.out.printf("  %,d nodes traversed; " + "ran %,d times, max %,d nodes, %,d lines\n", q.nodeCount, q.runCount, q.maxNodeCount, q.lineCount);
    }
    System.out.println();
    r.close();
}
Also used : ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) TreeMap(java.util.TreeMap) LineNumberReader(java.io.LineNumberReader)

Example 27 with LineNumberReader

use of java.io.LineNumberReader in project jackrabbit-oak by apache.

the class QueryShapeTool method processFile.

private static void processFile(File file) throws IOException {
    if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            processFile(f);
        }
        return;
    }
    System.out.println("File " + file);
    LineNumberReader r = new LineNumberReader(new BufferedReader(new FileReader(file)));
    try {
        process(r);
    } finally {
        r.close();
    }
    System.out.println();
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) LineNumberReader(java.io.LineNumberReader)

Example 28 with LineNumberReader

use of java.io.LineNumberReader in project geode by apache.

the class CompiledClassUtils method loadClassesAndMethods.

public static List<ClassAndMethodDetails> loadClassesAndMethods(File file) throws IOException {
    List<ClassAndMethodDetails> result = new LinkedList<ClassAndMethodDetails>();
    FileReader fr = new FileReader(file);
    LineNumberReader in = new LineNumberReader(fr);
    ClassAndMethodDetails cam;
    while ((cam = ClassAndMethodDetails.create(in)) != null) {
        result.add(cam);
    }
    fr.close();
    return result;
}
Also used : FileReader(java.io.FileReader) LinkedList(java.util.LinkedList) LineNumberReader(java.io.LineNumberReader)

Example 29 with LineNumberReader

use of java.io.LineNumberReader in project lucene-solr by apache.

the class Compile method main.

/**
   * Entry point to the Compile application.
   * <p>
   * This program takes any number of arguments: the first is the name of the
   * desired stemming algorithm to use (a list is available in the package
   * description) , all of the rest should be the path or paths to a file or
   * files containing a stemmer table to compile.
   * 
   * @param args the command line arguments
   */
@SuppressForbidden(reason = "System.out required: command line tool")
public static void main(java.lang.String[] args) throws Exception {
    if (args.length < 1) {
        return;
    }
    args[0].toUpperCase(Locale.ROOT);
    backward = args[0].charAt(0) == '-';
    int qq = (backward) ? 1 : 0;
    boolean storeorig = false;
    if (args[0].charAt(qq) == '0') {
        storeorig = true;
        qq++;
    }
    multi = args[0].charAt(qq) == 'M';
    if (multi) {
        qq++;
    }
    String charset = System.getProperty("egothor.stemmer.charset", "UTF-8");
    char[] optimizer = new char[args[0].length() - qq];
    for (int i = 0; i < optimizer.length; i++) {
        optimizer[i] = args[0].charAt(qq + i);
    }
    for (int i = 1; i < args.length; i++) {
        // System.out.println("[" + args[i] + "]");
        Diff diff = new Diff();
        allocTrie();
        System.out.println(args[i]);
        try (LineNumberReader in = new LineNumberReader(Files.newBufferedReader(Paths.get(args[i]), Charset.forName(charset)))) {
            for (String line = in.readLine(); line != null; line = in.readLine()) {
                try {
                    line = line.toLowerCase(Locale.ROOT);
                    StringTokenizer st = new StringTokenizer(line);
                    String stem = st.nextToken();
                    if (storeorig) {
                        trie.add(stem, "-a");
                    }
                    while (st.hasMoreTokens()) {
                        String token = st.nextToken();
                        if (token.equals(stem) == false) {
                            trie.add(token, diff.exec(token, stem));
                        }
                    }
                } catch (java.util.NoSuchElementException x) {
                // no base token (stem) on a line
                }
            }
        }
        Optimizer o = new Optimizer();
        Optimizer2 o2 = new Optimizer2();
        Lift l = new Lift(true);
        Lift e = new Lift(false);
        Gener g = new Gener();
        for (int j = 0; j < optimizer.length; j++) {
            String prefix;
            switch(optimizer[j]) {
                case 'G':
                    trie = trie.reduce(g);
                    prefix = "G: ";
                    break;
                case 'L':
                    trie = trie.reduce(l);
                    prefix = "L: ";
                    break;
                case 'E':
                    trie = trie.reduce(e);
                    prefix = "E: ";
                    break;
                case '2':
                    trie = trie.reduce(o2);
                    prefix = "2: ";
                    break;
                case '1':
                    trie = trie.reduce(o);
                    prefix = "1: ";
                    break;
                default:
                    continue;
            }
            trie.printInfo(System.out, prefix + " ");
        }
        try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(Files.newOutputStream(Paths.get(args[i] + ".out"))))) {
            os.writeUTF(args[0]);
            trie.store(os);
        }
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) LineNumberReader(java.io.LineNumberReader) StringTokenizer(java.util.StringTokenizer) BufferedOutputStream(java.io.BufferedOutputStream) SuppressForbidden(org.apache.lucene.util.SuppressForbidden)

Example 30 with LineNumberReader

use of java.io.LineNumberReader in project lucene-solr by apache.

the class DiffIt method main.

/**
   * Entry point to the DiffIt application.
   * <p>
   * This application takes one argument, the path to a file containing a
   * stemmer table. The program reads the file and generates the patch commands
   * for the stems.
   * 
   * @param args the path to a file containing a stemmer table
   */
@SuppressForbidden(reason = "System.out required: command line tool")
public static void main(java.lang.String[] args) throws Exception {
    int ins = get(0, args[0]);
    int del = get(1, args[0]);
    int rep = get(2, args[0]);
    int nop = get(3, args[0]);
    for (int i = 1; i < args.length; i++) {
        // System.out.println("[" + args[i] + "]");
        Diff diff = new Diff(ins, del, rep, nop);
        String charset = System.getProperty("egothor.stemmer.charset", "UTF-8");
        try (LineNumberReader in = new LineNumberReader(Files.newBufferedReader(Paths.get(args[i]), Charset.forName(charset)))) {
            for (String line = in.readLine(); line != null; line = in.readLine()) {
                try {
                    line = line.toLowerCase(Locale.ROOT);
                    StringTokenizer st = new StringTokenizer(line);
                    String stem = st.nextToken();
                    System.out.println(stem + " -a");
                    while (st.hasMoreTokens()) {
                        String token = st.nextToken();
                        if (token.equals(stem) == false) {
                            System.out.println(stem + " " + diff.exec(token, stem));
                        }
                    }
                } catch (java.util.NoSuchElementException x) {
                // no base token (stem) on a line
                }
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) LineNumberReader(java.io.LineNumberReader) SuppressForbidden(org.apache.lucene.util.SuppressForbidden)

Aggregations

LineNumberReader (java.io.LineNumberReader)401 IOException (java.io.IOException)203 InputStreamReader (java.io.InputStreamReader)167 FileReader (java.io.FileReader)102 File (java.io.File)79 InputStream (java.io.InputStream)64 StringReader (java.io.StringReader)64 ArrayList (java.util.ArrayList)54 FileInputStream (java.io.FileInputStream)33 BufferedReader (java.io.BufferedReader)27 PrintWriter (java.io.PrintWriter)25 HashMap (java.util.HashMap)22 FileNotFoundException (java.io.FileNotFoundException)20 BufferedWriter (java.io.BufferedWriter)16 FileWriter (java.io.FileWriter)16 Pattern (java.util.regex.Pattern)16 Test (org.junit.jupiter.api.Test)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 Reader (java.io.Reader)14