/*
* Copyright 2016
* Ubiquitous Knowledge Processing (UKP) Lab
* Technische Universität Darmstadt
*
* Licensed 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 de.tudarmstadt.ukp.dkpro.core.mallet.lda;
import de.tudarmstadt.ukp.dkpro.core.io.text.TextReader;
import de.tudarmstadt.ukp.dkpro.core.tokit.BreakIteratorSegmenter;
import org.apache.uima.UIMAException;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.collection.CollectionReaderDescription;
import org.apache.uima.fit.pipeline.SimplePipeline;
import java.io.File;
import java.io.IOException;
import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngineDescription;
import static org.apache.uima.fit.factory.CollectionReaderFactory.createReaderDescription;
public class MalletLdaUtil
{
public static final String CAS_DIR = "src/test/resources/txt";
public static final String CAS_FILE_PATTERN = "[+]*.txt";
private static final int N_TOPICS = 10;
private static final int N_ITERATIONS = 50;
public static final String LANGUAGE = "en";
/**
* Estimate a model for testing.
*
* @param modelFile the target {@link File}
* @throws UIMAException if a UIMA error occurs
* @throws IOException if an I/O error occurs
*/
public static void trainModel(File modelFile)
throws UIMAException, IOException
{
CollectionReaderDescription reader = createReaderDescription(TextReader.class,
TextReader.PARAM_SOURCE_LOCATION, CAS_DIR,
TextReader.PARAM_PATTERNS, CAS_FILE_PATTERN,
TextReader.PARAM_LANGUAGE, LANGUAGE);
AnalysisEngineDescription segmenter = createEngineDescription(BreakIteratorSegmenter.class);
AnalysisEngineDescription estimator = createEngineDescription(
MalletLdaTopicModelTrainer.class,
MalletLdaTopicModelTrainer.PARAM_TARGET_LOCATION, modelFile,
MalletLdaTopicModelTrainer.PARAM_N_ITERATIONS, N_ITERATIONS,
MalletLdaTopicModelTrainer.PARAM_N_TOPICS, N_TOPICS);
SimplePipeline.runPipeline(reader, segmenter, estimator);
}
}