本文整理汇总了Java中org.cleartk.ml.Feature类的典型用法代码示例。如果您正苦于以下问题:Java Feature类的具体用法?Java Feature怎么用?Java Feature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Feature类属于org.cleartk.ml包,在下文中一共展示了Feature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.cleartk.ml.Feature; //导入依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
for (Figure figure : JCasUtil.select(jcas, Figure.class)) {
List<Feature> features = extractor.extract(jcas, figure);
features.addAll(contextExtractor.extract(jcas, figure, null, Token.class, tokenExtractor));
if (this.isTraining()) {
String outcome = figure.getGender();
if (outcome != null)
this.dataWriter.write(new Instance<String>(outcome, features));
} else {
String category = this.classifier.classify(features);
figure.setGender(category);
}
}
}
示例2: createExtractor
import org.cleartk.ml.Feature; //导入依赖的package包/类
public static <T extends Annotation> NamedFeatureExtractor1<T> createExtractor(
PatternType patternType) {
final CharacterCategoryPatternFunction<T> ccpf = new CharacterCategoryPatternFunction<T>(
patternType);
return new NamedFeatureExtractor1<T>() {
@Override
public List<Feature> extract(JCas view, Annotation focusAnnotation)
throws CleartkExtractorException {
String text = focusAnnotation.getCoveredText();
return ccpf.apply(new Feature(null, text));
}
@Override
public String getFeatureName() {
return ccpf.getFeatureName();
}
};
}
示例3: extract
import org.cleartk.ml.Feature; //导入依赖的package包/类
public List<Feature> extract(JCas jCas, Annotation annotation1, Annotation annotation2) {
Annotation firstAnnotation, secondAnnotation;
if (annotation1.getBegin() <= annotation2.getBegin()) {
firstAnnotation = annotation1;
secondAnnotation = annotation2;
} else {
firstAnnotation = annotation2;
secondAnnotation = annotation1;
}
String featureName = Feature.createName(this.name, "Distance", this.unitClass.getSimpleName());
int featureValue;
if (secondAnnotation.getBegin() <= firstAnnotation.getEnd()) {
featureValue = 0;
} else {
List<? extends Annotation> annotations = JCasUtil.selectCovered(
jCas,
unitClass,
firstAnnotation.getEnd(),
secondAnnotation.getBegin());
featureValue = annotations.size();
}
return Collections.singletonList(new Feature(featureName, featureValue));
}
示例4: process
import org.cleartk.ml.Feature; //导入依赖的package包/类
public void process(JCas cas) throws AnalysisEngineProcessException {
List<Feature> features = Arrays.asList(
new Feature("pos", "NN"),
new Feature("distance", 3.0),
new Feature("precision", 1.234));
Instance<String> instance = new Instance<String>("A", features);
this.dataWriter.write(instance);
features = Arrays.asList(new Feature("name", "2PO"), new Feature("p's", 2));
instance = new Instance<String>("B", features);
this.dataWriter.write(instance);
instance = new Instance<String>("Z");
this.dataWriter.write(instance);
features = Arrays.asList(new Feature("A_B", "AB"));
instance = new Instance<String>("A", features);
this.dataWriter.write(instance);
}
示例5: generateBooleanInstances
import org.cleartk.ml.Feature; //导入依赖的package包/类
private static List<Instance<Boolean>> generateBooleanInstances(int n) {
Random random = new Random(42);
List<Instance<Boolean>> instances = new ArrayList<Instance<Boolean>>();
for (int i = 0; i < n; i++) {
Instance<Boolean> instance = new Instance<Boolean>();
if (random.nextInt(2) == 0) {
instance.setOutcome(true);
instance.add(new TreeFeature("TK_tree1", "(S (NP I) (VB ran) (. .))"));
instance.add(new Feature("hello", random.nextInt(100) + 1000));
instance.add(new Feature("goodbye", 500));
} else {
instance.setOutcome(false);
instance.add(new TreeFeature("TK_tree1", "(S (VB I) (NP ran) (. .))"));
instance.add(new Feature("hello", random.nextInt(100)));
instance.add(new Feature("goodbye", 500));
}
instances.add(instance);
}
return instances;
}
示例6: LTCharacterNgramFeatureFunction
import org.cleartk.ml.Feature; //导入依赖的package包/类
/**
* This feature function serves up character n-grams based on StringValued features. For example,
* if you wanted trigram suffixes (e.g. 'ion' of 'emotion') for words that are of length 7 or more
* you could call the constructor with the following:
* CharacterNGramFeatureFunction(Orientation.RIGHT_TO_LEFT, 0, 3, 7, false)
*
* @param featureName
* a user-specified name for the feature function, to be included in all feature names.
* @param orientation
* must be one of LEFT_TO_RIGHT or RIGHT_TO_LEFT. The orientation determines whether
* index 0 corresponds to the first character of the string value or the last. The
* orientation does not affect the ordering of the characters in the n-gram which are
* always returned in left-to-right order.
* @param start
* the start of the n-gram (typically 0 for both orientations)
* @param end
* the end of the n-gram (typically n for both orientations)
* @param minimumValueLength
* This parameter allows you to skip string values that are too short. It must be greater
* than or equal to end.
* @param lowerCase
* if true than the n-gram used as the feature value will be lowercased.
*/
public LTCharacterNgramFeatureFunction(
String featureName,
Orientation orientation,
int start,
int end,
int minimumValueLength,
boolean lowerCase) {
name = Feature.createName(
"NGram",
orientation == Orientation.RIGHT_TO_LEFT ? "Right" : "Left",
String.valueOf(start),
String.valueOf(end),
String.valueOf(minimumValueLength),
lowerCase ? "lower" : null,
featureName);
if (minimumValueLength < end) {
throw new IllegalArgumentException(
"minimumValueLength must be greater than or equal to the parameter end.");
}
this.orientation = orientation;
this.start = start;
this.end = end;
this.minimumValueLength = minimumValueLength;
this.lowerCase = lowerCase;
}
示例7: getScoredOutcomes
import org.cleartk.ml.Feature; //导入依赖的package包/类
private Map<OUTCOME_TYPE, Double> getScoredOutcomes(List<Feature> features, Path path)
throws CleartkProcessingException {
// add the features from preceding outcomes
features = Lists.newArrayList(features);
if (path != null) {
List<Object> previousOutcomes = new ArrayList<Object>(path.outcomes);
for (OutcomeFeatureExtractor outcomeFeatureExtractor : this.outcomeFeatureExtractors) {
features.addAll(outcomeFeatureExtractor.extractFeatures(previousOutcomes));
}
}
// get the scored outcomes for this instance
Map<OUTCOME_TYPE, Double> scoredOutcomes = this.delegatedClassifier.score(features);
if (scoredOutcomes.isEmpty()) {
throw new IllegalStateException("expected at least one scored outcome, found "
+ scoredOutcomes);
}
return scoredOutcomes;
}
示例8: createExtractor
import org.cleartk.ml.Feature; //导入依赖的package包/类
public static <T extends Annotation> NamedFeatureExtractor1<T> createExtractor(
PatternType patternType)
{
final LTCharacterCategoryPatternFunction<T> ccpf = new LTCharacterCategoryPatternFunction<T>(
patternType);
return new NamedFeatureExtractor1<T>()
{
@Override
public List<Feature> extract(JCas view, Annotation focusAnnotation)
throws CleartkExtractorException
{
String text = focusAnnotation.getCoveredText();
return ccpf.apply(new Feature(null, text));
}
@Override
public String getFeatureName()
{
return ccpf.getFeatureName();
}
};
}
示例9: test
import org.cleartk.ml.Feature; //导入依赖的package包/类
@Test
public void test() {
List<String> outcomes = Arrays.asList("X", "Y", "Z");
List<Feature> features1 = Arrays.asList(new Feature("foo", 42), new Feature("bar", "a"));
List<Feature> features2 = Arrays.asList(new Feature("foo", -1), new Feature("bar", "b"));
List<Feature> features3 = Arrays.asList(new Feature("foo", 13), new Feature("bar", "c"));
List<List<Feature>> featureLists = new ArrayList<List<Feature>>();
featureLists.add(features1);
featureLists.add(features2);
featureLists.add(features3);
List<Instance<String>> expected = new ArrayList<Instance<String>>();
expected.add(new Instance<String>("X", features1));
expected.add(new Instance<String>("Y", features2));
expected.add(new Instance<String>("Z", features3));
List<Instance<String>> actual = Instances.toInstances(outcomes, featureLists);
Assert.assertEquals(expected, actual);
}
示例10: generateBooleanInstances
import org.cleartk.ml.Feature; //导入依赖的package包/类
public static List<Instance<Boolean>> generateBooleanInstances(int n) {
Random random = new Random(42);
List<Instance<Boolean>> instances = new ArrayList<Instance<Boolean>>();
for (int i = 0; i < n; i++) {
Instance<Boolean> instance = new Instance<Boolean>();
if (random.nextInt(2) == 0) {
instance.setOutcome(true);
instance.add(new Feature("hello", random.nextInt(100) + 1000));
instance.add(new Feature("goodbye", 500));
} else {
instance.setOutcome(false);
instance.add(new Feature("goodbye", 500));
instance.add(new Feature("hello", random.nextInt(100)));
}
instances.add(instance);
}
return instances;
}
示例11: apply
import org.cleartk.ml.Feature; //导入依赖的package包/类
@Override
public List<Feature> apply(Feature feature)
{
Object featureValue = feature.getValue();
try {
if (featureValue == null) {
return Collections.singletonList(new Feature("ClarkPOS", "ClarkPOS_null"));
}
return Collections.singletonList(new Feature("ClarkPOS", ClarkPosInduction.posInduction
.get(featureValue.toString())));
}
catch (Exception e) {
return Collections.singletonList(new Feature("ClarkPOS", "ClarkPOS_null"));
}
}
示例12: extract
import org.cleartk.ml.Feature; //导入依赖的package包/类
@Override
public List<Feature> extract(JCas view, FOCUS_T focusAnnotation) throws CleartkExtractorException {
List<Feature> extracted = this.subExtractor.extract(view, focusAnnotation);
List<Feature> result = new ArrayList<Feature>();
if (this.isTrained) {
// We have trained / loaded a centroid tf*idf model, so now compute
// a cosine similarity for the extracted values
Map<String, Double> extractedFeatureMap = this.featuresToFeatureMap(extracted);
result.add(new Feature(name, this.simFunction.distance(extractedFeatureMap, centroidMap)));
} else {
// We haven't trained this extractor yet, so just mark the existing features
// for future modification, by creating one mega container feature
result.add(new TransformableFeature(this.name, extracted));
}
return result;
}
示例13: classify
import org.cleartk.ml.Feature; //导入依赖的package包/类
public String classify(List<Feature> features) throws CleartkProcessingException {
FeatureVector featureVector = this.featuresEncoder.encodeAll(features);
int maxScoredIndex = 0;
double maxScore = 0;
boolean first = true;
for (int i : models.keySet()) {
double score = score(featureVector, i);
if (first || score > maxScore) {
first = false;
maxScore = score;
maxScoredIndex = i;
}
}
return outcomeEncoder.decode(maxScoredIndex);
}
示例14: extract
import org.cleartk.ml.Feature; //导入依赖的package包/类
public List<Feature> extract(JCas jCas, TreebankNode node)
throws CleartkExtractorException {
TreebankNode parent = node.getParent();
if (parent == null)
return Collections.emptyList();
List<TreebankNode> children = Lists.newArrayList(JCasUtil.select(
parent.getChildren(),
TreebankNode.class));
int index = children.indexOf(node);
int siblingIndex = index + offset;
if (siblingIndex < 0 || siblingIndex >= children.size())
return Collections.emptyList();
TreebankNode sibling = children.get(siblingIndex);
List<Feature> features = subExtractor.extract(jCas, sibling);
for (Feature feature : features) {
feature.setName(Feature.createName(name, feature.getName()));
}
return features;
}
示例15: extract
import org.cleartk.ml.Feature; //导入依赖的package包/类
public List<Feature> extract(JCas jCas, TreebankNode constituent)
throws CleartkExtractorException {
TreebankNode headNode = findHead(constituent);
List<Feature> features = new ArrayList<Feature>(extractNode(jCas, headNode, false));
if (includePPHead && constituent.getNodeType().equals("PP")) {
for (int i = 0; i < constituent.getChildren().size(); i++) {
TreebankNode child = constituent.getChildren(i);
if (child.getNodeType().equals("NP")) {
features = new ArrayList<Feature>(features);
features.addAll(extractNode(jCas, findHead(child), true));
break;
}
}
}
return features;
}