incubator-ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevenbeth...@apache.org
Subject svn commit: r1410308 - in /incubator/ctakes/trunk/ctakes-relation-extractor/src: main/java/org/apache/ctakes/relationextractor/ae/ main/java/org/apache/ctakes/relationextractor/ae/features/ main/java/org/apache/ctakes/relationextractor/data/ main/java/...
Date Fri, 16 Nov 2012 11:27:49 GMT
Author: stevenbethard
Date: Fri Nov 16 11:27:47 2012
New Revision: 1410308

URL: http://svn.apache.org/viewvc?rev=1410308&view=rev
Log:
Fixes various warnings in relation extractor code.

Modified:
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/EntityMentionPairRelationExtractorAnnotator.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/features/PhraseChunkingExtractor.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/CategoricalDistribution.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Splitter.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Stats.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/PreprocessAndWriteXmi.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/XMIReader.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/Span.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/EntityMentionPairRelationExtractorAnnotator.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/EntityMentionPairRelationExtractorAnnotator.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/EntityMentionPairRelationExtractorAnnotator.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/EntityMentionPairRelationExtractorAnnotator.java
Fri Nov 16 11:27:47 2012
@@ -83,34 +83,36 @@ public class EntityMentionPairRelationEx
 			IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) {
 
 		BinaryTextRelation relation = relationLookup.get(Arrays.asList(arg1, arg2));
+		String category;
 		if (this.classifyBothDirections) {
 			// if classifying both directions, we'll see {X, Y} once when X is first and
 			// once when Y is first, so just do the single direction lookup here
 			if (relation != null) {
-				return relation.getCategory();
+				category = relation.getCategory();
 			} else if (coin.nextDouble() <= this.probabilityOfKeepingANegativeExample) {
-				return NO_RELATION_CATEGORY;
+			  category = NO_RELATION_CATEGORY;
 			} else {
-				return null;
+			  category = null;
 			}
 		} else {
 			// if classifying in a single direction, we'll see {X, Y} only once,
 			// so do lookups in both directions, and change the category name for
 			// the relations in the reverse order
 			if (relation != null) {
-				return relation.getCategory();
+			  category = relation.getCategory();
 			} else {
 				relation = relationLookup.get(Arrays.asList(arg2, arg1));
 				if (relation != null) {
 					// Change category name to show reverse order
-					return relation.getCategory() + "-1";
+				  category = relation.getCategory() + "-1";
 				} else if (coin.nextDouble() <= this.probabilityOfKeepingANegativeExample) {
-					return NO_RELATION_CATEGORY;
+				  category = NO_RELATION_CATEGORY;
 				} else {
-					return null;
+				  category = null;
 				}
 			}
 		}
+		return category;
 	}
 
 }

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
Fri Nov 16 11:27:47 2012
@@ -290,7 +290,7 @@ public abstract class RelationExtractorA
    * @param relationView
    * @return
    */
-  private Map<List<Annotation>, BinaryTextRelation> createRelationLookup(
+  private static Map<List<Annotation>, BinaryTextRelation> createRelationLookup(
 		  JCas relationView) {
 	  Map<List<Annotation>, BinaryTextRelation> relationLookup;
 	  relationLookup = new HashMap<List<Annotation>, BinaryTextRelation>();
@@ -315,7 +315,7 @@ public abstract class RelationExtractorA
    * @param goldView
    * @return
    */
-  private HashMap<HashableArguments, String> createCategoryLookup(JCas goldView) {
+  private static HashMap<HashableArguments, String> createCategoryLookup(JCas goldView)
{
 	  // save gold relations for lookup during error analysis; normalize order of arguments
 	  HashMap<HashableArguments, String> categoryLookup = new HashMap<HashableArguments,
String>();
 	  for (BinaryTextRelation relation : JCasUtil.select(goldView, BinaryTextRelation.class))
{
@@ -380,16 +380,16 @@ public abstract class RelationExtractorA
 
 	@Override
 	public boolean equals(Object otherObject) {
+	  boolean result = false;
 		if (otherObject instanceof HashableArguments) {
 			HashableArguments other = (HashableArguments) otherObject;
-			return (this.getClass() == other.getClass() && 
+			result = (this.getClass() == other.getClass() && 
 					this.arg1begin == other.arg1begin && 
 					this.arg1end == other.arg1end && 
 					this.arg2begin == other.arg2begin && 
 					this.arg2end == other.arg2end);
-		} else {
-			return false;
 		}
+		return result;
 	}
 	
     @Override

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/features/PhraseChunkingExtractor.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/features/PhraseChunkingExtractor.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/features/PhraseChunkingExtractor.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/features/PhraseChunkingExtractor.java
Fri Nov 16 11:27:47 2012
@@ -31,7 +31,7 @@ import org.apache.ctakes.typesystem.type
 
 public class PhraseChunkingExtractor implements RelationFeaturesExtractor {
 	  
-	  List<TerminalTreebankNode> extractPhraseHeadByTreenode(JCas jCas, List<TreebankNode>
treenodesList) throws AnalysisEngineProcessException {
+	  List<TerminalTreebankNode> extractPhraseHeadByTreenode(JCas jCas, List<TreebankNode>
treenodesList) {
 		  List<TerminalTreebankNode> rTNodeList = new ArrayList<TerminalTreebankNode>();
 		  // get head index from phrase
 		  for(TreebankNode tb : treenodesList) {
@@ -39,7 +39,7 @@ public class PhraseChunkingExtractor imp
 				  	int headIndex = tb.getHeadIndex();
 				  	for(TerminalTreebankNode ttb : JCasUtil.selectCovered(jCas, TerminalTreebankNode.class,
tb)) {
 				  		if(ttb.getIndex() == headIndex) {
-				  			this.addPhraseHead(rTNodeList, ttb);
+				  			addPhraseHead(rTNodeList, ttb);
 				  			break;
 				  		}
 				  	}		  
@@ -48,7 +48,7 @@ public class PhraseChunkingExtractor imp
 		  return rTNodeList;
 	  }
 	  
-		private void addPhraseHead(List<TerminalTreebankNode> headList,
+		private static void addPhraseHead(List<TerminalTreebankNode> headList,
 				TerminalTreebankNode newHead) {
 			
 			int insertPos = 0;

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/CategoricalDistribution.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/CategoricalDistribution.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/CategoricalDistribution.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/CategoricalDistribution.java
Fri Nov 16 11:27:47 2012
@@ -61,9 +61,7 @@ public class CategoricalDistribution {
 		if(r >= p1 + p2) {
 			return OUTCOME3;
 		}
-		else {
-			return -1; // shouldn't happen
-		}
+		throw new RuntimeException("should be impossible");
 	}
 	
 	public static void main(String[] args) {

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Splitter.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Splitter.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Splitter.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Splitter.java
Fri Nov 16 11:27:47 2012
@@ -51,12 +51,12 @@ public class Splitter {
 	/**
 	 * Specify percentages of the split.
 	 */
-	public Splitter(double trainProportion, double devProportion, double testProportion) {
+	public Splitter(double trainProportion, double devProportion) {
 
 		File dir = new File(ALLFILELOC);
 		
 		FilenameFilter filter = new FilenameFilter() {
-			public boolean accept(File dir, String name) {
+			public boolean accept(File fileDir, String name) {
 				return name.endsWith(".xml");
 			}
 		};
@@ -79,7 +79,7 @@ public class Splitter {
 		File dir = new File(ALLFILELOC);
 		
 		FilenameFilter filter = new FilenameFilter() {
-			public boolean accept(File dir, String name) {
+			public boolean accept(File fileDir, String name) {
 				return name.endsWith(".xml");
 			}
 		};

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Stats.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Stats.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Stats.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/Stats.java
Fri Nov 16 11:27:47 2012
@@ -54,7 +54,7 @@ public class Stats {
 		int totalEntityCount = 0;
 
 		FilenameFilter filter = new FilenameFilter() {
-			public boolean accept(File dir, String name) {
+			public boolean accept(File fileDir, String name) {
 				return name.endsWith(".xml");
 			}
 		};
@@ -95,7 +95,7 @@ public class Stats {
 	  int totalRelationCount = 0;
 		
 	  FilenameFilter filter = new FilenameFilter() {
-			public boolean accept(File dir, String name) {
+			public boolean accept(File fileDir, String name) {
 				return name.endsWith(".xml");
 			}
 		};

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/PreprocessAndWriteXmi.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/PreprocessAndWriteXmi.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/PreprocessAndWriteXmi.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/PreprocessAndWriteXmi.java
Fri Nov 16 11:27:47 2012
@@ -19,7 +19,6 @@
 package org.apache.ctakes.relationextractor.eval;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
@@ -31,7 +30,6 @@ import org.apache.uima.analysis_engine.A
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
-import org.apache.uima.cas.CASRuntimeException;
 import org.apache.uima.cas.impl.XmiCasSerializer;
 import org.apache.uima.collection.CollectionReader;
 import org.apache.uima.jcas.JCas;
@@ -185,17 +183,20 @@ public class PreprocessAndWriteXmi {
 			  if (documentID == null) {
 			    throw new IllegalArgumentException("No documentID for CAS:\n" + jCas);
 			  }
-			   File outFile = new File(this.outputDirectory, documentID + ".xmi");
-			   ContentHandler handler = new XMLSerializer(new FileOutputStream(outFile)).getContentHandler();
-				new XmiCasSerializer(jCas.getTypeSystem()).serialize(jCas.getCas(), handler);
-			} catch (CASRuntimeException e) {
+        File outFile = new File(this.outputDirectory, documentID + ".xmi");
+        FileOutputStream stream = new FileOutputStream(outFile);
+        try {
+          ContentHandler handler = new XMLSerializer(stream).getContentHandler();
+          new XmiCasSerializer(jCas.getTypeSystem()).serialize(jCas.getCas(), handler);
+        } finally {
+          stream.close();
+        }
+			} catch (UIMAException e) {
 				throw new AnalysisEngineProcessException(e);
 			} catch (SAXException e) {
 				throw new AnalysisEngineProcessException(e);
-			} catch (FileNotFoundException e) {
+			} catch (IOException e) {
 				throw new AnalysisEngineProcessException(e);
-			} catch (CASException e) {
-			  throw new AnalysisEngineProcessException(e);
       }	
 		}
 		

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
Fri Nov 16 11:27:47 2012
@@ -301,6 +301,7 @@ public class RelationExtractorEvaluation
     HideOutput hider = new HideOutput();
     JarClassifierBuilder.trainAndPackage(directory, this.trainingArguments);
     hider.restoreOutput();
+    hider.close(); // workaround for https://code.google.com/p/uimafit/issues/detail?id=129
   }
 
   @Override

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/XMIReader.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/XMIReader.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/XMIReader.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/XMIReader.java
Fri Nov 16 11:27:47 2012
@@ -77,8 +77,9 @@ public class XMIReader extends JCasColle
       XmiCasDeserializer.deserialize(new BufferedInputStream(inputStream), jCas.getCas());
     } catch (SAXException e) {
       throw new CollectionException(e);
+    } finally {
+      inputStream.close();
     }
-    inputStream.close();
     this.completed += 1;
   }
 

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/Span.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/Span.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/Span.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/Span.java
Fri Nov 16 11:27:47 2012
@@ -55,6 +55,7 @@ public class Span {
   	return Objects.hashCode(start, end);
   }
 	
+	@Override
 	public String toString() {
 		return String.format("%d -- %d", start, end);
 	}

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java?rev=1410308&r1=1410307&r2=1410308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java
Fri Nov 16 11:27:47 2012
@@ -48,9 +48,9 @@ public class RelationExtractorAnnotators
   public void test() throws Exception {
     // create the pipeline
     AggregateBuilder builder = new AggregateBuilder();
-    builder.add(this.findDescription(ModifierExtractorAnnotator.class));
-    builder.add(this.findDescription(DegreeOfRelationExtractorAnnotator.class));
-    builder.add(this.findDescription(EntityMentionPairRelationExtractorAnnotator.class));
+    builder.add(findDescription(ModifierExtractorAnnotator.class));
+    builder.add(findDescription(DegreeOfRelationExtractorAnnotator.class));
+    builder.add(findDescription(EntityMentionPairRelationExtractorAnnotator.class));
     AnalysisEngine engine = builder.createAggregate();
     JCas jCas = engine.newJCas();
 
@@ -99,7 +99,7 @@ public class RelationExtractorAnnotators
     assertEquals(fracture, fractureFibula.getArg2().getArgument());
   }
 
-  private AnalysisEngineDescription findDescription(Class<? extends JCasAnnotator_ImplBase>
cls)
+  private static AnalysisEngineDescription findDescription(Class<? extends JCasAnnotator_ImplBase>
cls)
       throws Exception {
     File directory = new File("desc/analysis_engine");
     File file = new File(directory, cls.getSimpleName() + ".xml");



Mime
View raw message