unstick r1872885

Revision 1872885

Date:
2020/01/16 15:09:07
Author:
tmill
Revision Log:
Move relationLookup into a protected method so that implementers can do it differently (for training ML models - used by the ctakes-ade module).
Files:

Legend:

 
Added
 
Removed
 
Modified
  • ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java

     
    142 142 public void process(JCas jCas) throws AnalysisEngineProcessException {
    143 143 // lookup from pair of annotations to binary text relation
    144 144 // note: assumes that there will be at most one relation per pair
    145 Map<List<Annotation>, BinaryTextRelation> relationLookup;
    146 relationLookup = new HashMap<>();
    147 if (this.isTraining()) {
    148 relationLookup = new HashMap<>();
    149 for (BinaryTextRelation relation : JCasUtil.select(jCas, this.getRelationClass())) {
    150 Annotation arg1 = relation.getArg1().getArgument();
    151 Annotation arg2 = relation.getArg2().getArgument();
    152 // The key is a list of args so we can do bi-directional lookup
    153 List<Annotation> key = Arrays.asList(arg1, arg2);
    154 if(relationLookup.containsKey(key)){
    155 String reln = relationLookup.get(key).getCategory();
    156 System.err.println("Error in: "+ ViewUriUtil.getURI(jCas).toString());
    157 System.err.println("Error! This attempted relation " + relation.getCategory() + " already has a relation " + reln + " at this span: " + arg1.getCoveredText() + " -- " + arg2.getCoveredText());
    158 }
    159 relationLookup.put(key, relation);
    160 }
    161 }
    145 Map<List<Annotation>, BinaryTextRelation> relationLookup = this.getRelationLookup(jCas);
    162 146
    163 147 // walk through each sentence in the text
    164 148 for (Annotation coveringAnnotation : JCasUtil.select(jCas, coveringClass)) {
     
    227 211 }
    228 212
    229 213 /**
    214 *
    215 * @param jCas - UIMA document wrapper
    216 * @return Mapping from a list of (2) entities to the binary relation that is captured by them. Requires a gold
    217 * standard relations to be in the CAS, and is used during training.
    218 * @throws AnalysisEngineProcessException
    219 */
    220 protected Map<List<Annotation>, BinaryTextRelation> getRelationLookup(JCas jCas) throws AnalysisEngineProcessException {
    221 Map<List<Annotation>, BinaryTextRelation> relationLookup = new HashMap<>();
    222 if (this.isTraining()) {
    223 relationLookup = new HashMap<>();
    224 for (BinaryTextRelation relation : JCasUtil.select(jCas, this.getRelationClass())) {
    225 Annotation arg1 = relation.getArg1().getArgument();
    226 Annotation arg2 = relation.getArg2().getArgument();
    227 // The key is a list of args so we can do bi-directional lookup
    228 List<Annotation> key = Arrays.asList(arg1, arg2);
    229 if(relationLookup.containsKey(key)){
    230 String reln = relationLookup.get(key).getCategory();
    231 System.err.println("Error in: "+ ViewUriUtil.getURI(jCas).toString());
    232 System.err.println("Error! This attempted relation " + relation.getCategory() + " already has a relation " + reln + " at this span: " + arg1.getCoveredText() + " -- " + arg2.getCoveredText());
    233 }
    234 relationLookup.put(key, relation);
    235 }
    236 }
    237 return relationLookup;
    238 }
    239
    240 /**
    230 241 * Looks up the arguments in the specified lookup table and converts the
    231 242 * relation into a label for classification
    232 243 *