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


Java StringSpan.setFeatureValue方法代码示例

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


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

示例1: pipe

import cc.mallet.extract.StringSpan; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
  String input;
  if (carrier.getData () instanceof CharSequence) {
    input = String.valueOf(carrier.getData ());
  } else {
    throw new ClassCastException("Needed a String; got "+carrier.getData());
  }
  
  String[] lines = input.split ("\n");

  StringSpan[] spans = new StringSpan[lines.length];
  Labels[] lbls = new Labels[lines.length];
  StringBuffer buf = new StringBuffer ();

  Alphabet dict = getDataAlphabet ();

  for (int i = 0; i < lines.length; i++) {
    String line = lines[i];
    String[] toks = line.split ("\\s+");

    int j = 0;
    ArrayList thisLabels = new ArrayList ();
    if (!labelsAtEnd) {
      while (!isLabelSeparator (toks, j)) {
        thisLabels.add (labelForTok (toks[j], j));
        j++;
      }
      if ((j < toks.length) && toks[j].equals ("----")) j++;
      lbls[i] = new Labels ((Label[]) thisLabels.toArray (new Label[thisLabels.size ()]));
    }

    int maxFeatureIdx = (labelsAtEnd) ? toks.length - numLabels : toks.length;

    String text = "*???*";
    if (featuresIncludeToken) {
      if (j < maxFeatureIdx) {
        text = toks [j++];
      }
    }

    int start = buf.length ();
    buf.append (text);
    int end = buf.length ();
    buf.append (" ");

    StringSpan span = new StringSpan (buf, start, end);

    while (j < maxFeatureIdx) {
      span.setFeatureValue (toks[j].intern (), 1.0);
      j++;
    }

    if (includeTokenText) {
      span.setFeatureValue ((textFeaturePrefix+text).intern(), 1.0);
    }

    if (labelsAtEnd) {
      int firstLblIdx = j;
      while (j < toks.length) {
        thisLabels.add (labelForTok (toks[j], j - firstLblIdx));
        j++;
      }
      lbls[i] = new Labels ((Label[]) thisLabels.toArray (new Label[thisLabels.size ()]));
    }

    spans[i] = span;

  }

  StringTokenization tokenization = new StringTokenization (buf);
  tokenization.addAll (spans);
  carrier.setData (tokenization);

  carrier.setTarget (new LabelsAssignment (new LabelsSequence (lbls)));
  return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:78,代码来源:GenericAcrfData2TokenSequence.java


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