All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ansj.splitWord.analysis.BaseAnalysis Maven / Gradle / Ivy

There is a newer version: 5.1.6
Show newest version
package org.ansj.splitWord.analysis;

import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.splitWord.Analysis;
import org.ansj.util.AnsjReader;
import org.ansj.util.Graph;

/**
 * 基本的分词.只做了.ngram模型.和数字发现.其他一律不管
 * 
 * @author ansj
 * 
 */
public class BaseAnalysis extends Analysis {

	@Override
	protected List getResult(final Graph graph) {
		Merger merger = new Merger() {
			@Override
			public List merger() {
				graph.walkPath();
				return getResult();
			}

			private List getResult() {
				List result = new ArrayList();
				int length = graph.terms.length - 1;
				for (int i = 0; i < length; i++) {
					if (graph.terms[i] != null) {
						result.add(graph.terms[i]);
					}
				}

				setRealName(graph, result);
				return result;
			}
		};
		return merger.merger();
	}

	public BaseAnalysis() {
	};

	public BaseAnalysis(Reader reader) {
		super.resetContent(new AnsjReader(reader));
	}

	public static Result parse(String str) {
		return new BaseAnalysis().parseStr(str);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy