You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by tm...@apache.org on 2014/10/29 15:08:54 UTC
svn commit: r1635138 - in
/ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion:
attributes/features/SubjectFeaturesExtractor.java
medfacts/cleartk/SubjectCleartkAnalysisEngine.java
Author: tmill
Date: Wed Oct 29 14:08:53 2014
New Revision: 1635138
URL: http://svn.apache.org/r1635138
Log:
CTAKES-94: Changed tabs to spaces in subject extractor code.
Modified:
ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/attributes/features/SubjectFeaturesExtractor.java
ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/SubjectCleartkAnalysisEngine.java
Modified: ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/attributes/features/SubjectFeaturesExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/attributes/features/SubjectFeaturesExtractor.java?rev=1635138&r1=1635137&r2=1635138&view=diff
==============================================================================
--- ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/attributes/features/SubjectFeaturesExtractor.java (original)
+++ ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/attributes/features/SubjectFeaturesExtractor.java Wed Oct 29 14:08:53 2014
@@ -34,47 +34,47 @@ import org.cleartk.ml.feature.extractor.
/** SubjectFeaturesExtractor
- * Ports the features and classification decisions of the first version (logic) of the subject tool
+ * Ports the features and classification decisions of the first version (logic) of the subject tool
*
* @author m081914
*
*/
public class SubjectFeaturesExtractor implements FeatureExtractor1<IdentifiedAnnotation> {
-
-
- @Override
- public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg) {
-
- List<Feature> features = new ArrayList<>();
-
- // Pull in general dependency-based features -- externalize to another extractor?
- ConllDependencyNode node = DependencyUtility.getNominalHeadNode(jCas, arg);
- if (node!= null) {
- features.add(new Feature("DEPENDENCY_HEAD", node.getCoveredText()));
- features.add(new Feature("DEPENDENCY_HEAD_deprel", node.getDeprel()));
- }
-
- HashMap<String, Boolean> featsMap = SubjectAttributeClassifier.extract(jCas, arg);
+
+
+ @Override
+ public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg) {
+
+ List<Feature> features = new ArrayList<>();
+
+ // Pull in general dependency-based features -- externalize to another extractor?
+ ConllDependencyNode node = DependencyUtility.getNominalHeadNode(jCas, arg);
+ if (node!= null) {
+ features.add(new Feature("DEPENDENCY_HEAD", node.getCoveredText()));
+ features.add(new Feature("DEPENDENCY_HEAD_deprel", node.getDeprel()));
+ }
+
+ HashMap<String, Boolean> featsMap = SubjectAttributeClassifier.extract(jCas, arg);
- if (!featsMap.isEmpty()) {
- // Pull in all the features that were used for the rule-based module
- features.addAll( hashToFeatureList(featsMap) );
- // Pull in the result of the rule-based module as well
- features.add(new Feature("SUBJECT_CLASSIFIER_LOGIC", SubjectAttributeClassifier.classifyWithLogic(featsMap)));
- }
-
- return features;
- }
+ if (!featsMap.isEmpty()) {
+ // Pull in all the features that were used for the rule-based module
+ features.addAll( hashToFeatureList(featsMap) );
+ // Pull in the result of the rule-based module as well
+ features.add(new Feature("SUBJECT_CLASSIFIER_LOGIC", SubjectAttributeClassifier.classifyWithLogic(featsMap)));
+ }
+
+ return features;
+ }
- private static Collection<? extends Feature> hashToFeatureList(
- HashMap<String, Boolean> featsIn) {
-
- Collection<Feature> featsOut = new HashSet<>();
- for (String featName : featsIn.keySet()) {
- featsOut.add(new Feature(featName,featsIn.get(featName)));
- }
-
- return featsOut;
- }
+ private static Collection<? extends Feature> hashToFeatureList(
+ HashMap<String, Boolean> featsIn) {
+
+ Collection<Feature> featsOut = new HashSet<>();
+ for (String featName : featsIn.keySet()) {
+ featsOut.add(new Feature(featName,featsIn.get(featName)));
+ }
+
+ return featsOut;
+ }
}
Modified: ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/SubjectCleartkAnalysisEngine.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/SubjectCleartkAnalysisEngine.java?rev=1635138&r1=1635137&r2=1635138&view=diff
==============================================================================
--- ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/SubjectCleartkAnalysisEngine.java (original)
+++ ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/SubjectCleartkAnalysisEngine.java Wed Oct 29 14:08:53 2014
@@ -32,68 +32,68 @@ import org.apache.uima.resource.Resource
import org.cleartk.ml.Instance;
public class SubjectCleartkAnalysisEngine extends
- AssertionCleartkAnalysisEngine {
+ AssertionCleartkAnalysisEngine {
- boolean USE_DEFAULT_EXTRACTORS = false;
-
- @Override
- public void initialize(UimaContext context) throws ResourceInitializationException {
- super.initialize(context);
- probabilityOfKeepingADefaultExample = 0.1;
-
- if (this.isTraining() && this.goldViewName == null) {
- throw new IllegalArgumentException(PARAM_GOLD_VIEW_NAME + " must be defined during training");
- }
-
- initialize_subject_extractor();
- initializeFeatureSelection();
-
- }
-
-
- private void initialize_subject_extractor() {
- this.entityFeatureExtractors.add( new SubjectFeaturesExtractor());
- }
-
- @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) {
- return new Chi2FeatureSelection<>(AssertionCleartkAnalysisEngine.FEATURE_SELECTION_NAME, threshold, false);
- }
-
- public static URI createFeatureSelectionURI(File outputDirectoryName) {
- return new File(outputDirectoryName, FEATURE_SELECTION_NAME + "_Chi2_extractor.dat").toURI();
- }
-
- @Override
- protected void initializeFeatureSelection() throws ResourceInitializationException {
- if (featureSelectionThreshold == 0) {
- this.featureSelection = null;
- } else {
- this.featureSelection = createFeatureSelection(this.featureSelectionThreshold);
- }
- }
-
+ boolean USE_DEFAULT_EXTRACTORS = false;
+
+ @Override
+ public void initialize(UimaContext context) throws ResourceInitializationException {
+ super.initialize(context);
+ probabilityOfKeepingADefaultExample = 0.1;
+
+ if (this.isTraining() && this.goldViewName == null) {
+ throw new IllegalArgumentException(PARAM_GOLD_VIEW_NAME + " must be defined during training");
+ }
+
+ initialize_subject_extractor();
+ initializeFeatureSelection();
+
+ }
+
+
+ private void initialize_subject_extractor() {
+ this.entityFeatureExtractors.add( new SubjectFeaturesExtractor());
+ }
+
+ @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) {
+ return new Chi2FeatureSelection<>(AssertionCleartkAnalysisEngine.FEATURE_SELECTION_NAME, threshold, false);
+ }
+
+ public static URI createFeatureSelectionURI(File outputDirectoryName) {
+ return new File(outputDirectoryName, FEATURE_SELECTION_NAME + "_Chi2_extractor.dat").toURI();
+ }
+
+ @Override
+ protected void initializeFeatureSelection() throws ResourceInitializationException {
+ if (featureSelectionThreshold == 0) {
+ this.featureSelection = null;
+ } else {
+ this.featureSelection = createFeatureSelection(this.featureSelectionThreshold);
+ }
+ }
+
}