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 2020/01/16 15:09:07 UTC
svn commit: r1872885 -
/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
Author: tmill
Date: Thu Jan 16 15:09:07 2020
New Revision: 1872885
URL: http://svn.apache.org/viewvc?rev=1872885&view=rev
Log:
Move relationLookup into a protected method so that implementers can do it differently (for training ML models - used by the ctakes-ade module).
Modified:
ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
Modified: ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java?rev=1872885&r1=1872884&r2=1872885&view=diff
==============================================================================
--- ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java (original)
+++ ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java Thu Jan 16 15:09:07 2020
@@ -142,23 +142,7 @@ public abstract class RelationExtractorA
public void process(JCas jCas) throws AnalysisEngineProcessException {
// lookup from pair of annotations to binary text relation
// note: assumes that there will be at most one relation per pair
- Map<List<Annotation>, BinaryTextRelation> relationLookup;
- relationLookup = new HashMap<>();
- if (this.isTraining()) {
- relationLookup = new HashMap<>();
- for (BinaryTextRelation relation : JCasUtil.select(jCas, this.getRelationClass())) {
- Annotation arg1 = relation.getArg1().getArgument();
- Annotation arg2 = relation.getArg2().getArgument();
- // The key is a list of args so we can do bi-directional lookup
- List<Annotation> key = Arrays.asList(arg1, arg2);
- if(relationLookup.containsKey(key)){
- String reln = relationLookup.get(key).getCategory();
- System.err.println("Error in: "+ ViewUriUtil.getURI(jCas).toString());
- System.err.println("Error! This attempted relation " + relation.getCategory() + " already has a relation " + reln + " at this span: " + arg1.getCoveredText() + " -- " + arg2.getCoveredText());
- }
- relationLookup.put(key, relation);
- }
- }
+ Map<List<Annotation>, BinaryTextRelation> relationLookup = this.getRelationLookup(jCas);
// walk through each sentence in the text
for (Annotation coveringAnnotation : JCasUtil.select(jCas, coveringClass)) {
@@ -227,6 +211,33 @@ public abstract class RelationExtractorA
}
/**
+ *
+ * @param jCas - UIMA document wrapper
+ * @return Mapping from a list of (2) entities to the binary relation that is captured by them. Requires a gold
+ * standard relations to be in the CAS, and is used during training.
+ * @throws AnalysisEngineProcessException
+ */
+ protected Map<List<Annotation>, BinaryTextRelation> getRelationLookup(JCas jCas) throws AnalysisEngineProcessException {
+ Map<List<Annotation>, BinaryTextRelation> relationLookup = new HashMap<>();
+ if (this.isTraining()) {
+ relationLookup = new HashMap<>();
+ for (BinaryTextRelation relation : JCasUtil.select(jCas, this.getRelationClass())) {
+ Annotation arg1 = relation.getArg1().getArgument();
+ Annotation arg2 = relation.getArg2().getArgument();
+ // The key is a list of args so we can do bi-directional lookup
+ List<Annotation> key = Arrays.asList(arg1, arg2);
+ if(relationLookup.containsKey(key)){
+ String reln = relationLookup.get(key).getCategory();
+ System.err.println("Error in: "+ ViewUriUtil.getURI(jCas).toString());
+ System.err.println("Error! This attempted relation " + relation.getCategory() + " already has a relation " + reln + " at this span: " + arg1.getCoveredText() + " -- " + arg2.getCoveredText());
+ }
+ relationLookup.put(key, relation);
+ }
+ }
+ return relationLookup;
+ }
+
+ /**
* Looks up the arguments in the specified lookup table and converts the
* relation into a label for classification
*