org.ansj.app.extracting.domain.Token Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ansj_seg Show documentation
Show all versions of ansj_seg Show documentation
best java chinese word seg !
The newest version!
package org.ansj.app.extracting.domain;
import org.ansj.app.extracting.exception.RuleFormatException;
import java.util.*;
/**
* Created by Ansj on 29/08/2017.
*/
public class Token {
public static final String ALL = ":*" ;
private int index;
private Set terms = new HashSet();
private List regexs;//正则限定
private int[] range;//范围限定
private Token prev ;
private Token next ;
public Token(int index, String termsStr) {
this.index = index;
String[] split = termsStr.substring(1, termsStr.length() - 1).split("\\|");
for (String str : split) {
terms.add(str);
}
}
public void addAttr(String str) throws RuleFormatException {
char head = str.charAt(0);
str = str.substring(1, str.length() - 1);
if (head == '[') {
if (regexs == null) {
regexs = new ArrayList();
}
regexs.add(str);
} else if (head == '{') {
String[] split = str.split(",");
if (range == null) {
range = new int[2];
}
if (split.length >= 2) {
range[0] = Integer.parseInt(split[0].trim());
range[1] = Integer.parseInt(split[1].trim());
} else {
range[0] = Integer.parseInt(split[0].trim());
range[1] = Integer.parseInt(split[0].trim());
}
} else {
throw new RuleFormatException("err format attr by " + str);
}
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public Set getTerms() {
return terms;
}
public void setTerms(Set terms) {
this.terms = terms;
}
public List getRegexs() {
if(regexs==null){
return Collections.emptyList() ;
}
return regexs;
}
public void setRegexs(List regexs) {
this.regexs = regexs;
}
public int[] getRange() {
return range;
}
public void setRange(int[] range) {
this.range = range;
}
public Token getPrev() {
return prev;
}
public Token getNext() {
return next;
}
public void setNext(Token next) {
this.next = next;
next.prev = this;
}
@Override
public String toString() {
return "index="+index+",terms="+terms+",regexs="+regexs+",range="+ Arrays.toString(range);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy