Java源码示例:cc.mallet.pipe.Noop
示例1
/**
* Constructor for creating a new CorpusRepresentation from a FeatureInfo.
*
* @param fi FeatureInfo instance
* @param targetType type of target
*/
public CorpusRepresentationMalletTarget(FeatureInfo fi, TargetType targetType) {
featureInfo = fi;
scalingMethod = fi.getGlobalScalingMethod();
this.targetType = targetType;
LabelAlphabet targetAlphabet = (targetType == TargetType.NOMINAL) ? new LabelAlphabet() : null;
Pipe innerPipe = new Noop(new LFAlphabet(), targetAlphabet);
List<Pipe> pipes = new ArrayList<>();
pipes.add(innerPipe);
pipe = new LFPipe(pipes);
pipe.setFeatureInfo(fi);
instances = new LFInstanceList(pipe);
}
示例2
public CorpusRepresentationMalletLDA(FeatureInfo fi) {
featureInfo = fi; // always null
// since we always pass a null feature info, the scaling method is hard-wired to be NONE
scalingMethod = ScalingMethod.NONE;
// TODO: we really do not need any of this, figure out if we can simplify,
// but keeping this should not really do any harm!
Pipe innerPipe = new Noop(new LFAlphabet(), null);
List<Pipe> pipes = new ArrayList<>();
pipes.add(innerPipe);
pipe = new LFPipe(pipes);
pipe.setFeatureInfo(fi);
instances = new LFInstanceList(pipe);
targetType = TargetType.NONE;
}
示例3
public CorpusRepresentationMalletSeq(FeatureInfo fi) {
featureInfo = fi;
scalingMethod = fi.getGlobalScalingMethod();
Pipe innerPipe = new Noop(new LFAlphabet(), new LabelAlphabet());
List<Pipe> pipes = new ArrayList<>();
pipes.add(innerPipe);
pipe = new LFPipe(pipes);
pipe.setFeatureInfo(fi);
instances = new LFInstanceList(pipe);
targetType = TargetType.NOMINAL;
}
示例4
@Test
public void testPipeSerialization1() throws ResourceInstantiationException, IOException, ClassNotFoundException {
String spec = "<ROOT>"+
"<ATTRIBUTE><TYPE>theType</TYPE><FEATURE>feature1</FEATURE><DATATYPE>nominal</DATATYPE><CODEAS>number</CODEAS></ATTRIBUTE>"+
"</ROOT>";
FeatureInfo fi = new FeatureSpecification(spec).getFeatureInfo();
// Create a pipe with a data and target alphabet
Pipe tmppipe = new Noop(new LFAlphabet(),new LabelAlphabet());
List<Pipe> pipes = new ArrayList<>();
pipes.add(tmppipe);
LFPipe pipe = new LFPipe(pipes);
pipe.setFeatureInfo(fi);
// add an entry to the data alphabet
pipe.getDataAlphabet().lookupIndex("feature1");
// extract an instance - this should create/update the alphabet for the number representation of the feature
Document doc = newDocument();
Annotation instAnn = addAnn(doc,"",0,0,"theType",gate.Utils.featureMap("feature1","val1"));
Instance inst = newInstance();
FeatureSpecAttribute attr = fi.getAttributes().get(0);
// make sure the attribute is a SimpleAttribute as expected
assertEquals(FeatureSpecSimpleAttribute.class, attr.getClass());
FeatureSpecSimpleAttribute sa = (FeatureSpecSimpleAttribute)attr;
FeatureExtractionMalletSparse.extractFeature(inst, sa, doc.getAnnotations(), instAnn);
// verify that we do have an alphabet in the attribute info
assertNotNull(sa.alphabet);
System.err.println("DEBUG: the alphabet we have is "+sa.alphabet);
assertTrue(sa.alphabet.contains("val1"));
// remember that alphabet for later
Alphabet valuealphabet = sa.alphabet;
// No serialize the lfpipe
File tmpFile = File.createTempFile("LF_test",".pipe");
tmpFile.deleteOnExit();
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(tmpFile))) {
oos.writeObject(pipe);
}
LFPipe pipe2;
try ( // Now read it back and check if everything is there
ObjectInputStream ois = new ObjectInputStream (new FileInputStream(tmpFile))) {
pipe2 = (LFPipe) ois.readObject();
}
// check if the data and target alphabets match
assertTrue(pipe2.alphabetsMatch(pipe));
// Do we have a feature info?
assertNotNull(pipe2.getFeatureInfo());
// do we have attributes?
assertNotNull(pipe2.getFeatureInfo().getAttributes());
// is there exactly one attribute
assertEquals(1, pipe2.getFeatureInfo().getAttributes().size());
// does that attribute have an alphabet
assertNotNull(((FeatureSpecSimpleAttribute)pipe2.getFeatureInfo().getAttributes().get(0)).alphabet);
// is the alphabet identical to what we originally had
assertEquals(valuealphabet,((FeatureSpecSimpleAttribute)pipe2.getFeatureInfo().getAttributes().get(0)).alphabet);
}
示例5
public LDAInstanceList(FastPreferenceData<U, I> preferences) {
super(new Noop());
this.preferences = preferences;
this.alphabet = new LDAAlphabet(preferences.numItems());
}