本文整理汇总了Java中edu.umass.cs.mallet.base.types.Instance.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.getName方法的具体用法?Java Instance.getName怎么用?Java Instance.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umass.cs.mallet.base.types.Instance
的用法示例。
在下文中一共展示了Instance.getName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pipe
import edu.umass.cs.mallet.base.types.Instance; //导入方法依赖的package包/类
/**
* Convert the data in the given <tt>Instance</tt> from a <tt>CharSequence</tt>
* of sparse feature-value pairs to a <tt>FeatureVector</tt>
*
* @throws IllegalStateException If <CODE>Instance.getTarget()</CODE> is
* not a Labeling
*/
public Instance pipe(Instance carrier)
throws IllegalStateException
{
CharSequence c = (CharSequence) carrier.getData();
String[] pairs = c.toString().trim().split("\\s+");
String[] keys = new String[pairs.length];
double[] values = new double[pairs.length];
for (int i = 0; i < pairs.length; i++) {
int delimIndex = pairs[i].lastIndexOf(":");
if (delimIndex <= 0 || delimIndex == (pairs[i].length()-1))
throw new IllegalStateException("token is not a valid feature name-feature value pair: "
+ pairs[i] + "\nfaulting instance name:" + carrier.getName());
keys[i] = pairs[i].substring(0, delimIndex);
values[i] = Double.parseDouble(pairs[i].substring(delimIndex+1));
dataDict.lookupIndex(keys[i], true); // add the feature name
}
// Sort indices beforehand to prevent the bubble sort used in
// constructor of SparseVector from taking too much time
int[] keyIndices = FeatureVector.getObjectIndices(keys, dataDict, true);
java.util.Arrays.sort(keyIndices);
FeatureVector fv = new FeatureVector(dataDict, keyIndices, values);
// Check if we've set the target alphabet member
if (targetDict == null) {
if (carrier.getTarget() instanceof Labeling)
targetDict = ((Labeling)carrier.getTarget()).getLabelAlphabet();
else
throw new IllegalStateException ("Instance target is not a " +
"Labeling; it is a " +
carrier.getTarget().getClass().getName());
}
carrier.setData( fv );
return carrier;
}
示例2: iteratePipe
import edu.umass.cs.mallet.base.types.Instance; //导入方法依赖的package包/类
public static PipeOutputAccumulator iteratePipe (Pipe iteratedPipe,
PipeOutputAccumulator accumulator,
Instance carrier)
{
PipeInputIterator iter = (PipeInputIterator) carrier.getData();
iter.setParentInstance (carrier);
while (iter.hasNext()) {
// Make sure that instance.pipe field gets set when piping instance.
Instance subInstance = iter.nextInstance();
Instance pipedInstance = new Instance (subInstance.getData (), subInstance.getTarget (),
subInstance.getName (), subInstance.getSource (), iteratedPipe);
accumulator.pipeOutputAccumulate (pipedInstance, iteratedPipe);
}
return accumulator;
}
示例3: convert
import edu.umass.cs.mallet.base.types.Instance; //导入方法依赖的package包/类
/**
*
* @param inst input instance, with FeatureVectorSequence as data.
* @param alphabetsPipe a Noop pipe containing the data and target alphabets for
* the resulting InstanceList and AugmentableFeatureVectors
* @return list of instances, each with one AugmentableFeatureVector as data
*/
public static InstanceList convert(Instance inst, Noop alphabetsPipe)
{
InstanceList ret = new InstanceList(alphabetsPipe);
Object obj = inst.getData();
assert(obj instanceof FeatureVectorSequence);
FeatureVectorSequence fvs = (FeatureVectorSequence) obj;
LabelSequence ls = (LabelSequence) inst.getTarget();
assert(fvs.size() == ls.size());
Object instName = (inst.getName() == null ? "NONAME" : inst.getName());
for (int j = 0; j < fvs.size(); j++) {
FeatureVector fv = fvs.getFeatureVector(j);
int[] indices = fv.getIndices();
FeatureVector data = new AugmentableFeatureVector (alphabetsPipe.getDataAlphabet(),
indices, fv.getValues(), indices.length);
Labeling target = ls.getLabelAtPosition(j);
String name = instName.toString() + "[email protected]_POS_" + (j + 1);
Object source = inst.getSource();
Instance toAdd = new Instance(data, target, name, source, alphabetsPipe);
ret.add(toAdd);
}
return ret;
}
示例4: classify
import edu.umass.cs.mallet.base.types.Instance; //导入方法依赖的package包/类
/**
*
* @param instance the instance to classify
* @param useOutOfFold whether to check the instance name and use the out-of-fold classifier
* if the instance name matches one in the training data
* @return the token classifier's output
*/
public Classification classify(Instance instance, boolean useOutOfFold)
{
Object instName = instance.getName();
if (! useOutOfFold || ! m_table.containsKey(instName))
return m_tokenClassifier.classify(instance);
Classifier classifier = (Classifier) m_table.get(instName);
return classifier.classify(instance);
}
示例5: nextInstance
import edu.umass.cs.mallet.base.types.Instance; //导入方法依赖的package包/类
public Instance nextInstance ()
{
final Instance instance = iter.nextInstance ();
Instance ret = new Instance (instance.getData(), instance.getTarget(), instance.getName(), instance.getSource());
ret.setPropertyList (instance.getPropertyList ());
return ret;
}
示例6: output
import edu.umass.cs.mallet.base.types.Instance; //导入方法依赖的package包/类
public TagList output (Transducer crf, InstanceList eval, java.util.Vector spans) throws IOException
{
//String toReturn="";
//for (int i = 0; i < eval.size(); i++) {
Instance instance = eval.getInstance(eval.size()-1);
Sequence input = (Sequence) instance.getData();
Sequence predOutput = crf.viterbiPath(input).output();
String[] tokens = (String[])instance.getName();
Tag currentTag = null;
TagList tagList = new TagList();
for(int j = 0; j < tokens.length; j++) {
boolean foundTag = false;
for(int s = 0; s < segmentStartTags.length; s++) {
if(((String)predOutput.get(j)).equals(segmentStartTags[s])) {
foundTag = true;
currentTag = new Tag(segmentStartTags[s].substring(2,segmentStartTags[s].length()));
currentTag.addSegment(tokens[j], j);
if(spans!=null) {
currentTag.updateOffset(((int[])spans.get(j))[0],((int[])spans.get(j))[1]);
}
//toReturn+="<"+segmentStartTags[s].substring(2,segmentStartTags[s].length())+">" + tokens[j];
for(int j1 = j+1; j1 < tokens.length && ((String)predOutput.get(j1)).equals(segmentContinueTags[s]); j1++) {
currentTag.addSegment(tokens[j1], j1);
if(spans!=null) {
currentTag.updateOffset(((int[])spans.get(j1))[0],((int[])spans.get(j1))[1]);
}
//toReturn+=" " + tokens[j1];
j=j1;
}
tagList.addTag(currentTag);
currentTag = null;
//toReturn+="</"+segmentStartTags[s].substring(2,segmentStartTags[s].length())+">";
break;
}
}
//if(!foundTag)
// toReturn+=tokens[j];
//if(j < tokens.length-1)
// toReturn+=" ";
}
//toReturn+="\n";
//}
return tagList;//toReturn;
}
示例7: output
import edu.umass.cs.mallet.base.types.Instance; //导入方法依赖的package包/类
public TagList output (Transducer crf, InstanceList eval, java.util.Vector spans) throws IOException
{
//String toReturn="";
//for (int i = 0; i < eval.size(); i++) {
Instance instance = eval.getInstance(eval.size()-1);
Sequence input = (Sequence) instance.getData();
Sequence predOutput = crf.viterbiPath(input).output();
String[] tokens = (String[])instance.getName();
Tag currentTag = null;
TagList tagList = new TagList();
for(int j = 0; j < tokens.length; j++) {
boolean foundTag = false;
for(int s = 0; s < segmentStartTags.length; s++) {
if(((String)predOutput.get(j)).equals(segmentStartTags[s])) {
foundTag = true;
currentTag = new Tag(segmentStartTags[s].substring(2,segmentStartTags[s].length()));
currentTag.addSegment(tokens[j], j);
if(spans!=null) {
currentTag.updateOffset(((int[])spans.get(j))[0],((int[])spans.get(j))[1]);
}
//toReturn+="<"+segmentStartTags[s].substring(2,segmentStartTags[s].length())+">" + tokens[j];
for(int j1 = j+1; j1 < tokens.length && ((String)predOutput.get(j1)).equals(segmentContinueTags[s]); j1++) {
currentTag.addSegment(tokens[j1], j1);
if(spans!=null) {
currentTag.updateOffset(((int[])spans.get(j1))[0],((int[])spans.get(j1))[1]);
}
//toReturn+=" " + tokens[j1];
j=j1;
}
tagList.addTag(currentTag);
currentTag = null;
//toReturn+="</"+segmentStartTags[s].substring(2,segmentStartTags[s].length())+">";
break;
}
}
//if(!foundTag)
// toReturn+=tokens[j];
//if(j < tokens.length-1)
// toReturn+=" ";
}
//toReturn+="\n";
//}
return tagList;//toReturn;
}