Permalink
Browse files

- Another code and comment cleanup iteration

  • Loading branch information...
reckart committed Feb 4, 2012
1 parent 55074a3 commit 8d922e2659858cd82c38e555924d0f608592801e
View
864 .pmd

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -48,7 +48,7 @@ public AggregatedCountsCreator(final File aBaseDir, final String aNGramSize)
scanner.setFilter(new IndexFilter());
while (scanner.hasNext()) {
- for (File file : scanner.next()) {
+ for (final File file : scanner.next()) {
read(file);
}
}
@@ -30,8 +30,6 @@
* Represents an index showing which ngrams (indexed by the first two characters) are to be found in which files on the disk.
*
* @author Claudio Giuliano
- * @version %I%, %G%
- * @since 1.0
*/
public class FileMap
{
@@ -116,7 +114,7 @@ public static int main(final String args[])
public String toString()
{
final StringBuilder buffer = new StringBuilder();
- for (String key : map.keySet()) {
+ for (final String key : map.keySet()) {
buffer.append(key);
buffer.append(" - ");
buffer.append(StringUtils.join(map.get(key), ","));
@@ -27,8 +27,6 @@
* Implements the actual (binary) search for an ngram in a Web1T-format file.
*
* @author Claudio Giuliano
- * @version %I%, %G%
- * @since 1.0
*/
public class FileSearch
{
@@ -59,14 +57,14 @@ public long getFreq(final String aSymbol) throws IOException
//logger.info("loop: " + loop);
m = s + ((e - s) / 2);
//logger.debug(s + ", [" + m + "], " + e);
- NGram n = read(m);
+ final NGram n = read(m);
if (n == null)
{
//logger.info("loop: " + loop);
return 0;
}
- int c = aSymbol.compareTo(n.symbol);
+ final int c = aSymbol.compareTo(n.symbol);
if (c == 0)
{
@@ -103,14 +101,14 @@ public NGram read(final long m) throws IOException
e = raf.length();
}
- int len = (int) (e - s);
- int nm = (int) (m - s);
+ final int len = (int) (e - s);
+ final int nm = (int) (m - s);
//logger.debug("nm = " + nm);
//logger.debug("len = " + len);
raf.seek(s);
- byte[] array = new byte[len];
+ final byte[] array = new byte[len];
raf.read(array);
@@ -123,7 +121,7 @@ public NGram read(final long m) throws IOException
}
//remember line start position
- int ns = i + 1;
+ final int ns = i + 1;
i = nm + 1;
@@ -134,18 +132,18 @@ public NGram read(final long m) throws IOException
}
//remember line end position
- int ne = i;
+ final int ne = i;
//copy the bytes for the current line to a new byte[]
- byte[] curLine = new byte[ne-ns];
+ final byte[] curLine = new byte[ne-ns];
int index = 0;
for (int j=ns;j<ne;j++)
{
curLine[index++]=array[j];
}
//convert the curLine-byte[] to UTF-8 String
- String lineAsString = new String(curLine, "UTF-8");
+ final String lineAsString = new String(curLine, "UTF-8");
if (lineAsString.length() == 0) {
return null;
@@ -44,8 +44,6 @@
* </pre>
*
* @author Claudio Giuliano
- * @version %I%, %G%
- * @since 2.0
*/
final class FolderScanner
{
@@ -57,7 +57,7 @@ public void inc(final T aSample)
public void incAll(final Iterable<T> aIterable)
{
- for (T sample : aIterable) {
+ for (final T sample : aIterable) {
addSample(sample, 1);
}
}
@@ -109,7 +109,7 @@ public void addSample(final T aSample, final long aNumber)
public String toString()
{
final StringBuilder buffer = new StringBuilder();
- for (Object o : freqDist.keySet()) {
+ for (final Object o : freqDist.keySet()) {
buffer.append(String.valueOf(o));
buffer.append(" - ");
buffer.append(freqDist.get(o));
@@ -87,10 +87,10 @@ private void write(final File outputFile)
try {
writer = new PrintWriter(new FileWriter(outputFile));
- for (String ch : map.keySet()) {
+ for (final String ch : map.keySet()) {
final List<File> fileList = map.get(ch);
writer.print(ch);
- for (File file : fileList) {
+ for (final File file : fileList) {
// store only the path relative to the index file
final String relative = baseDir.toURI().relativize(file.toURI()).getPath();
writer.print("\t" + relative);
@@ -24,8 +24,6 @@
* Automatically filters out some file types that are present in the Google Web1T release, but not needed to retrieve the frequencies.
*
* @author Claudio Giuliano
- * @version %I%, %G%
- * @since 1.0
*/
class IndexFilter
implements FileFilter
@@ -72,7 +72,7 @@ public JWeb1TSearcher(final File indexPath, final int minN, final int maxN)
}
final int size = maxN - minN + 1;
- String[] indexFiles = new String[size];
+ final String[] indexFiles = new String[size];
for (int i = 0; i < size; i++) {
final int ngramLevel = minN + i;
indexFiles[i] = new File(indexPath, "index-" + ngramLevel + "gms").getAbsolutePath();
@@ -68,11 +68,6 @@ public JWeb1TSearcherInMemory(final String ngramLocation, final int maxNgramSize
final File[] files = scanner.next();
for (int i = 0; i < files.length; i++) {
fillMap(files[i], level);
-
- // TODO remove when not needed anymore (added for cluster-test)
- if (i % 1000 == 0) {
- System.out.println(i + "#" + System.currentTimeMillis());
- }
}
}
}
@@ -21,8 +21,6 @@
* Represents an ngram as a combination of the ngram string and its frequency.
*
* @author Claudio Giuliano
- * @version %I%, %G%
- * @since 1.0
*/
public class NGram
{
@@ -31,7 +29,7 @@
public NGram(final String aLine) throws NumberFormatException
{
- String[] t = aLine.split("\t");
+ final String[] t = aLine.split("\t");
symbol = t[0];
frequency = Long.parseLong(t[1]);
}
@@ -21,7 +21,6 @@
/**
* Interface for any classes providing frequency counts.
- *
*/
public interface Searcher
{

0 comments on commit 8d922e2

Please sign in to comment.