/** * Predict an outcome given a set of features. By default, this simply * delegates to the object's <code>classifier</code>. Subclasses may override * this method to implement more complex classification procedures. * * @param features * The features to be classified. * @return The predicted outcome (label) for the features. */ protected Double classify(List<Feature> features) throws CleartkProcessingException { return this.classifier.classify(features); }
/** * Predict an outcome given a set of features. By default, this simply * delegates to the object's <code>classifier</code>. Subclasses may override * this method to implement more complex classification procedures. * * @param features * The features to be classified. * @return The predicted outcome (label) for the features. */ protected Double classify(List<Feature> features) throws CleartkProcessingException { return this.classifier.classify(features); }
/** * Predict an outcome given a set of features. By default, this simply * delegates to the object's <code>classifier</code>. Subclasses may override * this method to implement more complex classification procedures. * * @param features * The features to be classified. * @return The predicted outcome (label) for the features. */ protected String classify(List<Feature> features) throws CleartkProcessingException { return this.classifier.classify(features); }
/** * Predict an outcome given a set of features. By default, this simply * delegates to the object's <code>classifier</code>. Subclasses may override * this method to implement more complex classification procedures. * * @param features * The features to be classified. * @return The predicted outcome (label) for the features. */ protected String classify(List<Feature> features) throws CleartkProcessingException { return this.classifier.classify(features); }
/** * Predict an outcome given a set of features. By default, this simply * delegates to the object's <code>classifier</code>. Subclasses may override * this method to implement more complex classification procedures. * * @param features * The features to be classified. * @return The predicted outcome (label) for the features. */ protected String classify(List<Feature> features) throws CleartkProcessingException { return this.classifier.classify(features); }
/** * Predict an outcome given a set of features. By default, this simply * delegates to the object's <code>classifier</code>. Subclasses may override * this method to implement more complex classification procedures. * * @param features * The features to be classified. * @return The predicted outcome (label) for the features. */ protected String classify(List<Feature> features) throws CleartkProcessingException { return this.classifier.classify(features); }
@Override protected String classify(List<Feature> features) throws CleartkProcessingException { numClassifications++; String category = super.classifier.classify(features); if(this.scoreAll){ Map<String,Double> scores = super.classifier.score(features); this.lastScore = scores.get(IDENTITY_RELATION); category = IDENTITY_RELATION; } return category; }
@Override protected String classify(List<Feature> features) throws CleartkProcessingException { numClassifications++; String category = super.classifier.classify(features); if(this.scoreAll){ Map<String,Double> scores = super.classifier.score(features); this.lastScore = scores.get(IDENTITY_RELATION); category = IDENTITY_RELATION; } return category; }
@Override public void setClassLabel( IdentifiedAnnotation entityOrEventMention, Instance<String> instance ) throws AnalysisEngineProcessException { if ( this.isTraining() ) { int history = entityOrEventMention.getHistoryOf(); // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling if ( history == CONST.NE_HISTORY_OF_ABSENT && coin.nextDouble() >= this.probabilityOfKeepingADefaultExample ) { return; } instance.setOutcome( String.valueOf( history ) ); } else { String label = this.classifier.classify( instance.getFeatures() ); entityOrEventMention.setHistoryOf( Integer.parseInt( label ) ); } }
@Override public void setClassLabel( IdentifiedAnnotation entityOrEventMention, Instance<String> instance ) throws AnalysisEngineProcessException { if ( this.isTraining() ) { String subj = entityOrEventMention.getSubject(); // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling if ( "patient".equals( subj ) && coin.nextDouble() >= this.probabilityOfKeepingADefaultExample ) { return; } instance.setOutcome( subj ); logger.log( Level.DEBUG, String.format( "[%s] expected: ''; actual: ''; features: %s", this.getClass().getSimpleName(), instance.toString() ) ); } else { String label = this.classifier.classify( instance.getFeatures() ); entityOrEventMention.setSubject( label ); logger.log( Level.DEBUG, "SUBJECT is being set on an IdentifiedAnnotation: " + label + " " + entityOrEventMention.getSubject() ); } }
@Override public void setClassLabel(IdentifiedAnnotation entityOrEventMention, Instance<String> instance) throws AnalysisEngineProcessException { if (this.isTraining()) { int history = entityOrEventMention.getHistoryOf(); // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling if (history == CONST.NE_HISTORY_OF_ABSENT && coin.nextDouble() >= this.probabilityOfKeepingADefaultExample) { return; } instance.setOutcome(String.valueOf(history)); } else { String label = this.classifier.classify(instance.getFeatures()); entityOrEventMention.setHistoryOf(Integer.parseInt(label)); } } public static FeatureSelection<String> createFeatureSelection(double threshold) {
@Override public void setClassLabel(IdentifiedAnnotation entityOrEventMention, Instance<String> instance) throws AnalysisEngineProcessException { if (this.isTraining()) { String subj = entityOrEventMention.getSubject(); // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling if ("patient".equals(subj) && coin.nextDouble() >= this.probabilityOfKeepingADefaultExample) { return; } instance.setOutcome(subj); logger.log(Level.DEBUG, String.format("[%s] expected: ''; actual: ''; features: %s", this.getClass().getSimpleName(), instance.toString() )); } else { String label = this.classifier.classify(instance.getFeatures()); entityOrEventMention.setSubject(label); logger.log(Level.DEBUG, "SUBJECT is being set on an IdentifiedAnnotation: "+label+" "+entityOrEventMention.getSubject()); } } public static FeatureSelection<String> createFeatureSelection(double threshold) {
@Override public void setClassLabel( IdentifiedAnnotation entityOrEventMention, Instance<String> instance ) throws AnalysisEngineProcessException { if ( this.isTraining() ) { String uncertainty = (entityOrEventMention.getUncertainty() == CONST.NE_UNCERTAINTY_PRESENT) ? "uncertain" : "certain"; // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling if ( "certain".equals( uncertainty ) && coin.nextDouble() >= this.probabilityOfKeepingADefaultExample ) { return; } instance.setOutcome( uncertainty ); } else { String label = this.classifier.classify( instance.getFeatures() ); int uncertainty = 0; if ( label != null && label.equals( "uncertain" ) ) { uncertainty = CONST.NE_UNCERTAINTY_PRESENT; } else if ( label != null && label.equals( "certain" ) ) { uncertainty = CONST.NE_UNCERTAINTY_ABSENT; } entityOrEventMention.setUncertainty( uncertainty ); } }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { for (Time time : JCasUtil.select(jCas, Time.class)) { List<Feature> features = new ArrayList<Feature>(); for (FeatureExtractor1<Time> extractor : this.featuresExtractors) { features.addAll(extractor.extract(jCas, time)); } if (this.isTraining()) { this.dataWriter.write(new Instance<String>(time.getTimeType(), features)); } else { time.setTimeType(this.classifier.classify(features)); } } }
@Override public void setClassLabel( IdentifiedAnnotation entityOrEventMention, Instance<String> instance ) throws AnalysisEngineProcessException { if ( this.isTraining() ) { boolean generic = entityOrEventMention.getGeneric(); // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling if ( !generic && coin.nextDouble() >= this.probabilityOfKeepingADefaultExample ) { return; } instance.setOutcome( "" + generic ); } else { String label = this.classifier.classify( instance.getFeatures() ); entityOrEventMention.setGeneric( Boolean.parseBoolean( label ) ); } }
@Override public void setClassLabel( IdentifiedAnnotation entityOrEventMention, Instance<String> instance ) throws AnalysisEngineProcessException { if ( this.isTraining() ) { boolean conditional = entityOrEventMention.getConditional(); // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling if ( !conditional && coin.nextDouble() >= this.probabilityOfKeepingADefaultExample ) { return; } instance.setOutcome( "" + conditional ); } else { String label = this.classifier.classify( instance.getFeatures() ); boolean conditional = false; if ( label != null ) { conditional = Boolean.parseBoolean( label ); } entityOrEventMention.setConditional( conditional ); } }
@Override public void setClassLabel(IdentifiedAnnotation entityOrEventMention, Instance<String> instance) throws AnalysisEngineProcessException { if (this.isTraining()) { boolean generic = entityOrEventMention.getGeneric(); // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling if (!generic && coin.nextDouble() >= this.probabilityOfKeepingADefaultExample) { return; } instance.setOutcome(""+generic); } else { String label = this.classifier.classify(instance.getFeatures()); entityOrEventMention.setGeneric(Boolean.parseBoolean(label)); } } public static FeatureSelection<String> createFeatureSelection(double threshold) {
@Override public void setClassLabel(IdentifiedAnnotation entityOrEventMention, Instance<String> instance) throws AnalysisEngineProcessException { if (this.isTraining()) { boolean generic = entityOrEventMention.getGeneric(); // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling if (!generic && coin.nextDouble() >= this.probabilityOfKeepingADefaultExample) { return; } instance.setOutcome(""+generic); } else { String label = this.classifier.classify(instance.getFeatures()); entityOrEventMention.setGeneric(Boolean.parseBoolean(label)); } } public static FeatureSelection<String> createFeatureSelection(double threshold) {
public void process(JCas jCas) throws AnalysisEngineProcessException { // use the extractor to create features for the document DocumentAnnotation doc = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); List<Feature> features = this.extractor.extract(jCas, doc); // during training, get the label for this document from the CAS if (isTraining()) { UsenetDocument document = JCasUtil.selectSingle(jCas, UsenetDocument.class); this.dataWriter.write(new Instance<String>(document.getCategory(), features)); } // during classification, use the classifier's output to create a CAS annotation else { String category = this.classifier.classify(features); UsenetDocument document = new UsenetDocument(jCas, 0, jCas.getDocumentText().length()); document.setCategory(category); document.addToIndexes(); } } }
public void process(JCas jCas) throws AnalysisEngineProcessException { DocumentAnnotation doc = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); Instance<String> instance = new Instance<String>(); instance.addAll(this.extractor.extract(jCas, doc)); if (isTraining()) { UsenetDocument document = JCasUtil.selectSingle(jCas, UsenetDocument.class); instance.setOutcome(document.getCategory()); this.dataWriter.write(instance); } else { // This is classification, so classify and create UsenetDocument annotation String result = this.classifier.classify(instance.getFeatures()); UsenetDocument document = new UsenetDocument(jCas, 0, jCas.getDocumentText().length()); document.setCategory(result); document.addToIndexes(); // System.out.println("classified " + ViewURIUtil.getURI(jCas) + " as " + result + "."); } }