当前位置: 首页>>代码示例>>Java>>正文


Java TokenSequence.add方法代码示例

本文整理汇总了Java中cc.mallet.types.TokenSequence.add方法的典型用法代码示例。如果您正苦于以下问题:Java TokenSequence.add方法的具体用法?Java TokenSequence.add怎么用?Java TokenSequence.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cc.mallet.types.TokenSequence的用法示例。


在下文中一共展示了TokenSequence.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
	TokenSequence ts = (TokenSequence) carrier.getData();
	// xxx This doesn't seem so efficient.  Perhaps have TokenSequence
	// use a LinkedList, and remove Tokens from it? -?
	// But a LinkedList implementation of TokenSequence would be quite inefficient -AKM
	TokenSequence ret = new TokenSequence ();
	Token prevToken = null;
	for (int i = 0; i < ts.size(); i++) {
		Token t = ts.get(i);
		if (! stoplist.contains (caseSensitive ? t.getText() : t.getText().toLowerCase())) {
			// xxx Should we instead make and add a copy of the Token?
			ret.add (t);
			prevToken = t;
		} else if (markDeletions && prevToken != null)
			prevToken.setProperty (FeatureSequenceWithBigrams.deletionMark, t.getText());
	}
	carrier.setData(ret);
	return carrier;
}
 
开发者ID:shalomeir,项目名称:tctm,代码行数:21,代码来源:TokenSequenceRemoveStopwords.java

示例2: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
@Override
public Instance pipe(Instance carrier) {

    TokenSequence ts = (TokenSequence) carrier.getData();
    TokenSequence targetTokenSeq = new TokenSequence(ts.size());

    for (int i = 0; i < ts.size(); i++) {

        Token t = ts.get(i);
        // System.out.println(t.getText());
        String lineWithoutFirst = t.getText().replaceFirst("[^\\t]*\t", "");
        // System.out.println(lineWithoutFirst);
        // targetTokenSeq.add(lineSplit[0]);

        targetTokenSeq.add(t.getText().split("\t")[0]);
        t.setText(lineWithoutFirst);

    }
    carrier.setTarget(targetTokenSeq);
    carrier.setData(ts);

    return carrier;
}
 
开发者ID:exciteproject,项目名称:refext,代码行数:24,代码来源:LineToTargetTextPipe.java

示例3: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe(Instance carrier) {
	TokenSequence ts = (TokenSequence) carrier.getData();
	TokenSequence newTs = new TokenSequence();
	FeatureSequence labelSeq = new FeatureSequence(getTargetAlphabet());
	boolean lastWasSpace = true;
	StringBuffer sb = new StringBuffer();
	for (int i = 0; i < ts.size(); i++) {
		Token t = ts.get(i);
		if (t.getText().equals(" "))
			lastWasSpace = true;
		else {
			sb.append(t.getText());
			newTs.add(t);
			labelSeq.add(lastWasSpace ? "start" : "notstart");
			lastWasSpace = false;
		}
	}
	if (isTargetProcessing())
		carrier.setTarget(labelSeq);
	carrier.setData(newTs);
	carrier.setSource(sb.toString());
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:24,代码来源:TestCRF.java

示例4: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
	String newTerm = null;
	TokenSequence tmpTS = new TokenSequence();
	TokenSequence ts = (TokenSequence) carrier.getData();

	for (int i = 0; i < ts.size(); i++) {
		Token t = ts.get(i);
		for(int j = 0; j < gramSizes.length; j++) {
			int len = gramSizes[j];
			if (len <= 0 || len > (i+1)) continue;
			if (len == 1) { tmpTS.add(t); continue; }
			newTerm = new String(t.getText());
			for(int k = 1; k < len; k++)
				newTerm = ts.get(i-k).getText() + "_" + newTerm;
			tmpTS.add(newTerm);
		}
	}

	carrier.setData(tmpTS);

	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:24,代码来源:TokenSequenceNGrams.java

示例5: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public TokenSequence pipe (BufferedReader br)
	throws java.io.IOException
{
	final int BUFSIZE = 2048;
	char[] buf = new char[BUFSIZE];
	int count;
	StringBuffer sb = new StringBuffer (BUFSIZE);
	do {
		count = br.read (buf, 0, BUFSIZE);
		sb.append (buf);
	} while (count == BUFSIZE);
	lexer.setCharSequence ((CharSequence)sb);
	TokenSequence ts = new TokenSequence ();
	while (lexer.hasNext())
		ts.add (new Token ((String) lexer.next()));
	return ts;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:18,代码来源:SourceLocation2TokenSequence.java

示例6: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
	TokenSequence ts = (TokenSequence) carrier.getData();
	// xxx This doesn't seem so efficient.  Perhaps have TokenSequence
	// use a LinkedList, and remove Tokens from it? -?
	// But a LinkedList implementation of TokenSequence would be quite inefficient -AKM
	TokenSequence ret = new TokenSequence ();
	Token prevToken = null;
	for (int i = 0; i < ts.size(); i++) {
		Token t = ts.get(i);
		String s = t.getText();
		if (CharSequenceLexer.LEX_ALPHA.matcher(s).matches()) {
			ret.add (t);
			prevToken = t;
		}	else if (markDeletions && prevToken != null)
			prevToken.setProperty (FeatureSequenceWithBigrams.deletionMark, t.getText());
	}
	carrier.setData(ret);
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:21,代码来源:TokenSequenceRemoveNonAlpha.java

示例7: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
	TokenSequence ts = (TokenSequence) carrier.getData();
	TokenSequence targetTokenSeq = new TokenSequence (ts.size());
	for (int i = 0; i < ts.size(); i++) {
		Token t = ts.get(i);
		Matcher matcher = regex.matcher (t.getText());
		if (matcher.matches()) {
			targetTokenSeq.add (matcher.group(targetGroup));
			t.setText (matcher.group (dataGroup));
		} else {
			logger.warning ("Skipping token: No match of "+regex.pattern()
											+" at token #"+i+" with text "+t.getText());
		}
	}
	carrier.setTarget(targetTokenSeq);
	carrier.setData(ts);
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:20,代码来源:TokenSequenceMatchDataAndTarget.java

示例8: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
	long millis = System.currentTimeMillis();
	TokenSequence ts = (TokenSequence) carrier.getData();
	// xxx This doesn't seem so efficient.  Perhaps have TokenSequence
	// use a LinkedList, and remove Tokens from it? -?
	// But a LinkedList implementation of TokenSequence would be quite inefficient -AKM
	TokenSequence ret = new TokenSequence ();
	Token prevToken = null;
	for (int i = 0; i < ts.size(); i++) {
		Token t = ts.get(i);
		if (! stoplist.contains (caseSensitive ? t.getText() : t.getText().toLowerCase())) {
			// xxx Should we instead make and add a copy of the Token?
			ret.add (t);
			prevToken = t;
		} else if (markDeletions && prevToken != null)
			prevToken.setProperty (FeatureSequenceWithBigrams.deletionMark, t.getText());
	}
	carrier.setData(ret);
	//System.out.println(this.getClass().getCanonicalName() + "===" + (System.currentTimeMillis()-millis));
	return carrier;
}
 
开发者ID:sameeraxiomine,项目名称:largelda,代码行数:23,代码来源:BigTokenSequenceRemoveStopwords.java

示例9: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier) {
	
	TokenSequence originalSequence = (TokenSequence) carrier.getData();
	TokenSequence newSequence = new TokenSequence();
	
	for (int i = 0; i < originalSequence.size(); i++) {
		Token t = originalSequence.get(i);
		
		boolean passed = true;
		String text = t.getText();
		for (Pattern pattern : stopPatterns) {
			Matcher matcher = pattern.matcher(text);
			if (matcher.matches()) {
				passed = false;
				break;
			}
		}
		
		if (passed) {
			newSequence.add (t);
		}
	}
	
	carrier.setData(newSequence);
	return carrier;
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:27,代码来源:TokenSequenceRemoveStopPatterns.java

示例10: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe(Instance carrier) {
    CharSequence string = (CharSequence) carrier.getData();
    TokenSequence ts = new StringTokenization(string);

    List<Term> terms = HanLP.segment(string.toString());

    for (Term term : terms) {
        if (term.word.length() < 2) {
            continue;
        }

        if (denydPosSet.contains(term.nature.name())) {
            continue;
        }

        ts.add(new Token(term.word));
    }

    carrier.setData(ts);
    return carrier;
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:22,代码来源:ChineseSequence2TokenSequence.java

示例11: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public TokenSequence pipe (BufferedReader br)
	throws IOException
{
	final int BUFSIZE = 2048;
	char[] buf = new char[BUFSIZE];
	int count;
	StringBuffer sb = new StringBuffer (BUFSIZE);
	do {
		count = br.read (buf, 0, BUFSIZE);
		sb.append (buf);
	} while (count == BUFSIZE);
	lexer.setCharSequence ((CharSequence)sb);
	TokenSequence ts = new TokenSequence ();
	while (lexer.hasNext())
		ts.add (new Token ((String) lexer.next()));
	return ts;
}
 
开发者ID:shalomeir,项目名称:tctm,代码行数:18,代码来源:SourceLocation2TokenSequence.java

示例12: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
	if (carrier.getData() instanceof CharSequence)
		carrier.setData(new TokenSequence (ngramify ((CharSequence)carrier.getData())));
	else if (carrier.getData() instanceof TokenSequence) {
		TokenSequence ts = (TokenSequence) carrier.getData();
		TokenSequence ret = new TokenSequence ();
		for (int i = 0; i < ts.size(); i++)
			ret.add (ngramify (ts.get(i).getText()).toString());
		carrier.setData(ret);
	} else
		throw new IllegalArgumentException ("Unhandled type "+carrier.getData().getClass());
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:15,代码来源:CharSequence2CharNGrams.java

示例13: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
	CharSequence string = (CharSequence) carrier.getData();
	lexer.setCharSequence (string);
	TokenSequence ts = new StringTokenization (string);
	while (lexer.hasNext()) {
		lexer.next();
		ts.add (new StringSpan (string, lexer.getStartOffset (), lexer.getEndOffset ()));
	}
	carrier.setData(ts);
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:13,代码来源:CharSequence2TokenSequence.java

示例14: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
	long millis=System.currentTimeMillis();
	CharSequence string = (CharSequence) carrier.getData();
	lexer.setCharSequence (string);
	TokenSequence ts = new StringTokenization (string);
	while (lexer.hasNext()) {
		lexer.next();
		ts.add (new StringSpan (string, lexer.getStartOffset (), lexer.getEndOffset ()));
	}
	
	carrier.setData(ts);
	//System.out.println(this.getClass().getCanonicalName() + "----" +(System.currentTimeMillis()-millis));
	return carrier;
}
 
开发者ID:sameeraxiomine,项目名称:largelda,代码行数:16,代码来源:BigCharSequence2TokenSequence.java

示例15: pipe

import cc.mallet.types.TokenSequence; //导入方法依赖的package包/类
@Override
public Instance pipe(Instance carrier) {
	String line = (String) carrier.getData();
	LabelAlphabet labels = (LabelAlphabet) getTargetAlphabet();
	TokenSequence ts = new TokenSequence();
	String[] tokens = line.split(" ");
	LabelSequence target = new LabelSequence(labels, tokens.length - 1);
	assert (tokens.length > 1);
	String prevTag = null;
	for (int i = 1; i < tokens.length; i++) {
		Matcher matcher = tokenPattern.matcher(tokens[i]);
		matcher.matches();
		String word = matcher.group(1);
		String tag = matcher.group(2);
		Token tok = new Token(word);
		tok.setFeatureValue(word, 1.0);
		ts.add(tok);
		String tmp = tag;
		if (targets.contains(tag)) {
			if (tag.equals(prevTag)) {
				tag = "I-GENE";
			} else {
				tag = "B-GENE";
			}
		} else {
			tag = "O";
		}
		target.add(tag);
		prevTag = tmp;
	}
	carrier.setData(ts);
	carrier.setTarget(target);
	return carrier;
}
 
开发者ID:siqil,项目名称:udaner,代码行数:35,代码来源:GenetagLine2TokenSequence.java


注:本文中的cc.mallet.types.TokenSequence.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。