Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.
*/
package org.apache.mahout.text;
import org.apache.commons.io.DirectoryWalker;
import org.apache.commons.io.comparator.CompositeFileComparator;
import org.apache.commons.io.comparator.DirectoryFileComparator;
import org.apache.commons.io.comparator.PathFileComparator;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
import org.apache.hadoop.util.ToolRunner;
import org.apache.mahout.common.AbstractJob;
import org.apache.mahout.common.HadoopUtil;
import org.apache.mahout.common.commandline.DefaultOptionCreator;
import org.apache.mahout.utils.email.MailOptions;
import org.apache.mahout.utils.email.MailProcessor;
import org.apache.mahout.utils.io.ChunkedWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
/**
* Converts a directory of gzipped mail archives into SequenceFiles of specified
* chunkSize. This class is similar to {@link SequenceFilesFromDirectory} except
* it uses block-compressed {@link org.apache.hadoop.io.SequenceFile}s and parses out the subject and
* body text of each mail message into a separate key/value pair.
*/
public final class SequenceFilesFromMailArchives extends AbstractJob {
private static final Logger log = LoggerFactory.getLogger(SequenceFilesFromMailArchives.class);
public static final String[] CHUNK_SIZE_OPTION = {"chunkSize", "chunk"};
public static final String[] KEY_PREFIX_OPTION = {"keyPrefix", "prefix"};
public static final String[] CHARSET_OPTION = {"charset", "c"};
public static final String[] SUBJECT_OPTION = {"subject", "s"};
public static final String[] TO_OPTION = {"to", "to"};
public static final String[] FROM_OPTION = {"from", "from"};
public static final String[] REFERENCES_OPTION = {"references", "refs"};
public static final String[] BODY_OPTION = {"body", "b"};
public static final String[] STRIP_QUOTED_OPTION = {"stripQuoted", "q"};
public static final String[] QUOTED_REGEX_OPTION = {"quotedRegex", "regex"};
public static final String[] SEPARATOR_OPTION = {"separator", "sep"};
public static final String[] BODY_SEPARATOR_OPTION = {"bodySeparator", "bodySep"};
public static final String BASE_INPUT_PATH = "baseinputpath";
private static final int MAX_JOB_SPLIT_LOCATIONS = 1000000;
public void createSequenceFiles(MailOptions options) throws IOException {
try (ChunkedWriter writer =
new ChunkedWriter(getConf(), options.getChunkSize(), new Path(options.getOutputDir()))){
MailProcessor processor = new MailProcessor(options, options.getPrefix(), writer);
if (options.getInput().isDirectory()) {
PrefixAdditionDirectoryWalker walker = new PrefixAdditionDirectoryWalker(processor, writer);
walker.walk(options.getInput());
log.info("Parsed {} messages from {}", walker.getMessageCount(), options.getInput().getAbsolutePath());
} else {
long start = System.currentTimeMillis();
long cnt = processor.parseMboxLineByLine(options.getInput());
long finish = System.currentTimeMillis();
log.info("Parsed {} messages from {} in time: {}", cnt, options.getInput().getAbsolutePath(), finish - start);
}
}
}
private static class PrefixAdditionDirectoryWalker extends DirectoryWalker