ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1673847 - in /ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor: ae/CausesBringsAboutRelationExtractorAnnotator.java eval/RelationExtractorEvaluation.java
Date Wed, 15 Apr 2015 16:22:14 GMT
Author: dligach
Date: Wed Apr 15 16:22:14 2015
New Revision: 1673847

URL: http://svn.apache.org/r1673847
Log:
infrastructure for classifying causes/brings_about relation

Added:
    ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/CausesBringsAboutRelationExtractorAnnotator.java
  (with props)
Modified:
    ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java

Added: ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/CausesBringsAboutRelationExtractorAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/CausesBringsAboutRelationExtractorAnnotator.java?rev=1673847&view=auto
==============================================================================
--- ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/CausesBringsAboutRelationExtractorAnnotator.java
(added)
+++ ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/CausesBringsAboutRelationExtractorAnnotator.java
Wed Apr 15 16:22:14 2015
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ctakes.relationextractor.ae;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
+import org.apache.ctakes.typesystem.type.relation.CausesBringsAboutTextRelation;
+import org.apache.ctakes.typesystem.type.relation.ManagesTreatsTextRelation;
+import org.apache.ctakes.typesystem.type.relation.RelationArgument;
+import org.apache.ctakes.typesystem.type.textsem.AnatomicalSiteMention;
+import org.apache.ctakes.typesystem.type.textsem.DiseaseDisorderMention;
+import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
+import org.apache.ctakes.typesystem.type.textsem.MedicationMention;
+import org.apache.ctakes.typesystem.type.textsem.ProcedureMention;
+import org.apache.ctakes.typesystem.type.textsem.SignSymptomMention;
+import org.apache.ctakes.typesystem.type.textspan.Sentence;
+import org.apache.uima.fit.util.JCasUtil;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.Annotation;
+
+/**
+ * Identifies causes/brings_about relation.
+ * 
+ * In SHARP data the arguments are the following:
+ * 
+ * arg1: anatomical sites, disease/disorder, medications, procedures, signs/symptoms, entity
mentions
+ * arg2: disease/disorder, procedures, signs/symptoms, entity mentions, event mentions, labs
+ * 
+ * But for now, only considering only the most frequent cases:
+ * 
+ * arg1: procedure, medication, disease/disorder  
+ * arg2: disease/disorder, sign/symptom
+ */
+public class CausesBringsAboutRelationExtractorAnnotator extends RelationExtractorAnnotator
{
+
+  @Override
+  protected Class<? extends BinaryTextRelation> getRelationClass() {
+    return CausesBringsAboutTextRelation.class;
+  }
+
+  @Override
+  public List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs(
+      JCas identifiedAnnotationView,
+      Annotation sentence) {
+
+    List<ProcedureMention> procedures = 
+        JCasUtil.selectCovered(identifiedAnnotationView, ProcedureMention.class, sentence);
+    List<MedicationMention> medications = 
+        JCasUtil.selectCovered(identifiedAnnotationView, MedicationMention.class, sentence);

+    List<DiseaseDisorderMention> diseaseDisorders =
+        JCasUtil.selectCovered(identifiedAnnotationView, DiseaseDisorderMention.class, sentence);
+    List<SignSymptomMention> signSymptoms = 
+        JCasUtil.selectCovered(identifiedAnnotationView, SignSymptomMention.class, sentence);
+
+    List<IdentifiedAnnotation> arg1s = new ArrayList<>();
+    arg1s.addAll(procedures);
+    arg1s.addAll(medications);
+    arg1s.addAll(diseaseDisorders);
+    
+    List<IdentifiedAnnotation> arg2s = new ArrayList<>();
+    arg2s.addAll(diseaseDisorders);
+    arg2s.addAll(signSymptoms);
+    
+    List<IdentifiedAnnotationPair> pairs = new ArrayList<>();
+    for(IdentifiedAnnotation arg1 : arg1s) {
+      for(IdentifiedAnnotation arg2 : arg2s) {
+        pairs.add(new IdentifiedAnnotationPair(arg1, arg2));
+      }
+    }
+    
+    return pairs;
+  }
+
+  @Override
+  protected void createRelation(
+      JCas jCas,
+      IdentifiedAnnotation arg1,
+      IdentifiedAnnotation arg2,
+      String predictedCategory) {
+    RelationArgument relArg1 = new RelationArgument(jCas);
+    relArg1.setArgument(arg1);
+    relArg1.setRole("Argument");
+    relArg1.addToIndexes();
+    RelationArgument relArg2 = new RelationArgument(jCas);
+    relArg2.setArgument(arg2);
+    relArg2.setRole("Related_to");
+    relArg2.addToIndexes();
+    CausesBringsAboutTextRelation relation = new CausesBringsAboutTextRelation(jCas);
+    relation.setArg1(relArg1);
+    relation.setArg2(relArg2);
+    relation.setCategory(predictedCategory);
+    relation.addToIndexes();
+  }
+
+  @Override
+  protected Class<? extends Annotation> getCoveringClass() {
+    return Sentence.class;
+  }
+}

Propchange: ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/CausesBringsAboutRelationExtractorAnnotator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java?rev=1673847&r1=1673846&r2=1673847&view=diff
==============================================================================
--- ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
(original)
+++ ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
Wed Apr 15 16:22:14 2015
@@ -29,11 +29,13 @@ import java.util.Set;
 
 import javax.annotation.Nullable;
 
+import org.apache.ctakes.relationextractor.ae.CausesBringsAboutRelationExtractorAnnotator;
 import org.apache.ctakes.relationextractor.ae.DegreeOfRelationExtractorAnnotator;
 import org.apache.ctakes.relationextractor.ae.LocationOfRelationExtractorAnnotator;
 import org.apache.ctakes.relationextractor.ae.ManagesTreatsRelationExtractorAnnotator;
 import org.apache.ctakes.relationextractor.ae.RelationExtractorAnnotator;
 import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
+import org.apache.ctakes.typesystem.type.relation.CausesBringsAboutTextRelation;
 import org.apache.ctakes.typesystem.type.relation.DegreeOfTextRelation;
 import org.apache.ctakes.typesystem.type.relation.LocationOfTextRelation;
 import org.apache.ctakes.typesystem.type.relation.ManagesTreatsTextRelation;
@@ -143,6 +145,15 @@ public class RelationExtractorEvaluation
         new Object[] { RelationExtractorAnnotator.PARAM_PROBABILITY_OF_KEEPING_A_NEGATIVE_EXAMPLE,
             0.5f },
         new String[] { "-s", "0", "-c", "5.0" }));
+    
+    RELATION_CLASSES.put("causes/brings_about", CausesBringsAboutTextRelation.class);
+    ANNOTATOR_CLASSES.put(CausesBringsAboutTextRelation.class, CausesBringsAboutRelationExtractorAnnotator.class);
+    BEST_PARAMETERS.put(CausesBringsAboutTextRelation.class, new ParameterSettings(
+        LibLinearStringOutcomeDataWriter.class,
+        new Object[] { RelationExtractorAnnotator.PARAM_PROBABILITY_OF_KEEPING_A_NEGATIVE_EXAMPLE,
+            1.0f },
+        new String[] { "-s", "0", "-c", "1.0" }));
+
   }
 
   public static void main(String[] args) throws Exception {



Mime
View raw message