Index: lucene/facet/src/java/org/apache/lucene/facet/taxonomy/PrintStats.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/taxonomy/PrintStats.java (revision 0) +++ lucene/facet/src/java/org/apache/lucene/facet/taxonomy/PrintStats.java (working copy) @@ -0,0 +1,72 @@ +package org.apache.lucene.facet.taxonomy; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.File; +import java.io.IOException; + +import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; +import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FSDirectory; + +/** Prints how many ords are under each dimension. */ + +public class PrintStats { + public static void main(String[] args) throws IOException { + if (args.length != 1) { + System.out.println("\nUsage: PrintStats /path/to/taxononmy/index\n"); + System.exit(1); + } + Directory dir = FSDirectory.open(new File(args[0])); + TaxonomyReader r = new DirectoryTaxonomyReader(dir); + ParallelTaxonomyArrays arrays = r.getParallelTaxonomyArrays(); + //int[] parents = arrays.parents(); + int[] children = arrays.children(); + int[] siblings = arrays.siblings(); + System.out.println(r.getSize() + " categories."); + + int numDims = 0; + int childOrd = children[TaxonomyReader.ROOT_ORDINAL]; + while(childOrd != -1) { + CategoryPath cp = r.getPath(childOrd); + int childOrd2 = children[childOrd]; + int numImmediateChildren = 0; + while(childOrd2 != -1) { + numImmediateChildren++; + childOrd2 = siblings[childOrd2]; + } + System.out.println("Dimension " + numDims + ": " + cp + "; " + numImmediateChildren + " immediate children; " + (1+countAllChildren(childOrd, children, siblings)) + " categories"); + numDims++; + childOrd = siblings[childOrd]; + } + + r.close(); + dir.close(); + } + + private static int countAllChildren(int ord, int[] children, int[] siblings) { + int childOrd = children[ord]; + int count = 0; + while(childOrd != -1) { + count += 1+countAllChildren(childOrd, children, siblings); + childOrd = siblings[childOrd]; + } + return count; + } +} Property changes on: lucene/facet/src/java/org/apache/lucene/facet/taxonomy/PrintStats.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property