ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1632043 - /ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/i2b2/api/CharacterOffsetToLineTokenConverterCtakesImpl.java
Date Wed, 15 Oct 2014 14:03:16 GMT
Author: tmill
Date: Wed Oct 15 14:03:16 2014
New Revision: 1632043

URL: http://svn.apache.org/r1632043
Log:
Fix formatting and indentation.

Modified:
    ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/i2b2/api/CharacterOffsetToLineTokenConverterCtakesImpl.java

Modified: ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/i2b2/api/CharacterOffsetToLineTokenConverterCtakesImpl.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/i2b2/api/CharacterOffsetToLineTokenConverterCtakesImpl.java?rev=1632043&r1=1632042&r2=1632043&view=diff
==============================================================================
--- ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/i2b2/api/CharacterOffsetToLineTokenConverterCtakesImpl.java
(original)
+++ ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/i2b2/api/CharacterOffsetToLineTokenConverterCtakesImpl.java
Wed Oct 15 14:03:16 2014
@@ -38,217 +38,205 @@ import org.apache.ctakes.typesystem.type
 import org.apache.ctakes.typesystem.type.syntax.NewlineToken;
 import org.apache.ctakes.typesystem.type.textspan.Sentence;
 
-public class CharacterOffsetToLineTokenConverterCtakesImpl implements CharacterOffsetToLineTokenConverter
-{
+public class CharacterOffsetToLineTokenConverterCtakesImpl implements CharacterOffsetToLineTokenConverter
{
   protected Logger logger = Logger.getLogger(CharacterOffsetToLineTokenConverterCtakesImpl.class.getName());
   protected JCas jcas;
-  
+
   protected TreeMap<Integer, Sentence> beginTreeMap;
   protected TreeSet<Integer> tokenBeginEndTreeSet;
   protected Map<Sentence, List<BaseToken>> sentenceToTokenNumberMap;
-  
-  public CharacterOffsetToLineTokenConverterCtakesImpl()
-  {
-    
+
+  public CharacterOffsetToLineTokenConverterCtakesImpl() {
+
   }
-  
-  public CharacterOffsetToLineTokenConverterCtakesImpl(JCas jcas)
-  {
+
+  public CharacterOffsetToLineTokenConverterCtakesImpl(JCas jcas) {
     this.jcas = jcas;
     buildSentenceBoundaryMap();
     buildTokenBoundaryMap();
     buildSentenceToTokenNumberMap();
   }
-  
-  public void buildSentenceBoundaryMap()
-  {
-	  beginTreeMap = new TreeMap<Integer, Sentence>();
-	  
-	  AnnotationIndex<Annotation> annotationIndex = jcas.getAnnotationIndex(Sentence.type);
-	  for (Annotation current : annotationIndex)
-	  {
-		  Sentence currentSentence = (Sentence)current;
-		  
-		  int begin = currentSentence.getBegin();
-		  beginTreeMap.put(begin, currentSentence);
-	  }
+
+  public void buildSentenceBoundaryMap() {
+    beginTreeMap = new TreeMap<Integer, Sentence>();
+
+    AnnotationIndex<Annotation> annotationIndex = jcas.getAnnotationIndex(Sentence.type);
+    for (Annotation current : annotationIndex)
+    {
+      Sentence currentSentence = (Sentence)current;
+
+      int begin = currentSentence.getBegin();
+      beginTreeMap.put(begin, currentSentence);
+    }
   }
-  
-  public void buildTokenBoundaryMap()
-  {
-	  tokenBeginEndTreeSet = new TreeSet<Integer>();
-	  
-	  AnnotationIndex<Annotation> annotationIndex = jcas.getAnnotationIndex(BaseToken.type);
-	  for (Annotation current : annotationIndex)
-	  {
-		  BaseToken bt = (BaseToken)current;
-		  // filter out NewlineToken
-		  if (!(bt instanceof NewlineToken)) {
-			  int begin = bt.getBegin();
-			  int end = bt.getEnd();
-		  	  tokenBeginEndTreeSet.add(begin);
-		  	  tokenBeginEndTreeSet.add(end);
-		  }
-	  }
+
+  public void buildTokenBoundaryMap() {
+    tokenBeginEndTreeSet = new TreeSet<Integer>();
+
+    AnnotationIndex<Annotation> annotationIndex = jcas.getAnnotationIndex(BaseToken.type);
+    for (Annotation current : annotationIndex)
+    {
+      BaseToken bt = (BaseToken)current;
+      // filter out NewlineToken
+      if (!(bt instanceof NewlineToken)) {
+        int begin = bt.getBegin();
+        int end = bt.getEnd();
+        tokenBeginEndTreeSet.add(begin);
+        tokenBeginEndTreeSet.add(end);
+      }
+    }
   }
-  
+
   protected void buildSentenceToTokenNumberMap() {
-      sentenceToTokenNumberMap = new HashMap<Sentence, List<BaseToken>>();
-      for (Sentence s : beginTreeMap.values()) {
-              FSIterator<Annotation> tokensInSentenceIterator = jcas
-                              .getAnnotationIndex(BaseToken.type).subiterator(s);
-              List<BaseToken> btList = new ArrayList<BaseToken>();
-              BaseToken bt = null;
-              while ((bt = this.getNextNonEOLToken(tokensInSentenceIterator)) != null) {
-                      btList.add(bt);
-              }
-              sentenceToTokenNumberMap.put(s, btList);
+    sentenceToTokenNumberMap = new HashMap<Sentence, List<BaseToken>>();
+    for (Sentence s : beginTreeMap.values()) {
+      FSIterator<Annotation> tokensInSentenceIterator = jcas
+          .getAnnotationIndex(BaseToken.type).subiterator(s);
+      List<BaseToken> btList = new ArrayList<BaseToken>();
+      BaseToken bt = null;
+      while ((bt = this.getNextNonEOLToken(tokensInSentenceIterator)) != null) {
+        btList.add(bt);
       }
+      sentenceToTokenNumberMap.put(s, btList);
+    }
   }
-  
-  public Sentence findPreviousOrCurrentSentence(int characterOffset)
-  {
-	  Integer floorKey = beginTreeMap.floorKey(characterOffset);
-	  if (floorKey == null)
-	  {
-		  return null;
-	  }
-	  Sentence floorEntry = beginTreeMap.get(floorKey);
-	  
-	  return floorEntry;
+
+  public Sentence findPreviousOrCurrentSentence(int characterOffset) {
+    Integer floorKey = beginTreeMap.floorKey(characterOffset);
+    if (floorKey == null)
+    {
+      return null;
+    }
+    Sentence floorEntry = beginTreeMap.get(floorKey);
+
+    return floorEntry;
   }
-  
-  public LineAndTokenPosition convert(int characterOffset)
-  {
+
+  public LineAndTokenPosition convert(int characterOffset) {
     return convertCharacterOffsetToLineToken(characterOffset);
   }
-  
-  public int adjustOffsetToBestMatch(int original)
-  {
-	  logger.debug("inside adjustOffsetToBestMatch");
-	  Integer newValue = tokenBeginEndTreeSet.floor(original);
-	  
-	  if (newValue == null)
-	  {
-		  logger.debug("no previous token begin or end found. using begin of first token.");
-		  newValue = tokenBeginEndTreeSet.first();
-	  } else
-	  {
-		  if (original == newValue)
-			  logger.debug("value not adjusted: " + original);
-		  else
-			  logger.debug("found previous token boundary. original: " + original + "; new value:
" + newValue);
-	  }
-	  
-	  if (newValue == null)
-	  {
-		  logger.info("no previous and no first token found!!");
-	  }
-	  
-	  logger.debug("end adjustOffsetToBestMatch");
-	  
-	  return newValue;
+
+  public int adjustOffsetToBestMatch(int original) {
+    logger.debug("inside adjustOffsetToBestMatch");
+    Integer newValue = tokenBeginEndTreeSet.floor(original);
+
+    if (newValue == null)
+    {
+      logger.debug("no previous token begin or end found. using begin of first token.");
+      newValue = tokenBeginEndTreeSet.first();
+    } else
+    {
+      if (original == newValue)
+        logger.debug("value not adjusted: " + original);
+      else
+        logger.debug("found previous token boundary. original: " + original + "; new value:
" + newValue);
+    }
+
+    if (newValue == null)
+    {
+      logger.info("no previous and no first token found!!");
+    }
+
+    logger.debug("end adjustOffsetToBestMatch");
+
+    return newValue;
   }
-  
-  public LineAndTokenPosition convertCharacterOffsetToLineToken(int characterOffset)
-  {
+
+  public LineAndTokenPosition convertCharacterOffsetToLineToken(int characterOffset) {
     logger.debug("entering CharacterOffsetToLineTokenConverterCtakesImpl.convertCharacterOffsetToLineToken()
with a characterOffset of: " + characterOffset);
-    
+
     logger.debug("before adjusting input character offset...");
     characterOffset = adjustOffsetToBestMatch(characterOffset);
     logger.debug("after adjusting input character offset.");
     int baseTokenTypeId = BaseToken.type;
-    
+
     ConstraintConstructorFindContainedBy constraintConstructorFindContainedBy = new ConstraintConstructorFindContainedBy(jcas);
     ConstraintConstructorFindContainedWithin constraintConstructorFindContainedWithin = new
ConstraintConstructorFindContainedWithin(jcas);
-    
+
     Type sentenceType = jcas.getTypeSystem().getType(Sentence.class.getName());
     Type baseTokenType = jcas.getTypeSystem().getType(BaseToken.class.getName());
 
-//    FSIterator<Annotation> filteredIterator =
-//        constraintConstructorFindContainedBy.createFilteredIterator(
-//          characterOffset, characterOffset, sentenceType);
-//
-//    if (!filteredIterator.hasNext())
-//    {
-//      throw new RuntimeException("Surrounding sentence annotation not found[" + characterOffset
+ "]!!");
-//    }
-//    Annotation sentenceAnnotation = filteredIterator.next();
-//    Sentence sentence = (Sentence)sentenceAnnotation;
-    
+    //    FSIterator<Annotation> filteredIterator =
+    //        constraintConstructorFindContainedBy.createFilteredIterator(
+    //          characterOffset, characterOffset, sentenceType);
+    //
+    //    if (!filteredIterator.hasNext())
+    //    {
+    //      throw new RuntimeException("Surrounding sentence annotation not found[" + characterOffset
+ "]!!");
+    //    }
+    //    Annotation sentenceAnnotation = filteredIterator.next();
+    //    Sentence sentence = (Sentence)sentenceAnnotation;
+
     logger.debug("finding current or previous sentence for character offset " + characterOffset);
     Sentence sentence = findPreviousOrCurrentSentence(characterOffset);
     if (sentence == null)
     {
-    	logger.info("current or previous sentence IS NULL!");
+      logger.info("current or previous sentence IS NULL!");
     } else
     {
-    	logger.debug("current or previous sentence -- id: " + sentence.getAddress() +
-    			"; begin: " + sentence.getBegin() + 
-    			"; end: " + sentence.getEnd());
+      logger.debug("current or previous sentence -- id: " + sentence.getAddress() +
+          "; begin: " + sentence.getBegin() + 
+          "; end: " + sentence.getEnd());
     }
-    
+
     int lineNumber = sentence.getSentenceNumber() + 1;
-    
-    
+
+
     FSIterator<Annotation> beginTokenInSentenceIterator = constraintConstructorFindContainedBy
-            .createFilteredIterator(characterOffset, characterOffset,
-                            baseTokenType);
-	BaseToken beginToken = this
-	            .getNextNonEOLToken(beginTokenInSentenceIterator);
-	int beginTokenWordNumber = this.sentenceToTokenNumberMap.get(sentence)
-	            .indexOf(beginToken);
-	LineAndTokenPosition b = new LineAndTokenPosition();
-	b.setLine(lineNumber);
-	b.setTokenOffset(beginTokenWordNumber);
-	
-	return b;
+        .createFilteredIterator(characterOffset, characterOffset,
+            baseTokenType);
+    BaseToken beginToken = this
+        .getNextNonEOLToken(beginTokenInSentenceIterator);
+    int beginTokenWordNumber = this.sentenceToTokenNumberMap.get(sentence)
+        .indexOf(beginToken);
+    LineAndTokenPosition b = new LineAndTokenPosition();
+    b.setLine(lineNumber);
+    b.setTokenOffset(beginTokenWordNumber);
+
+    return b;
   }
-  
+
   public BaseToken getNextNonEOLToken(
-          FSIterator<Annotation> tokensInSentenceIterator) {
-	  while (tokensInSentenceIterator.hasNext()) {
-	          BaseToken bt = (BaseToken) tokensInSentenceIterator.next();
-	          if (!(bt instanceof NewlineToken)) {
-	                  return bt;
-	          }
-	  }
-	  return null;
+      FSIterator<Annotation> tokensInSentenceIterator) {
+    while (tokensInSentenceIterator.hasNext()) {
+      BaseToken bt = (BaseToken) tokensInSentenceIterator.next();
+      if (!(bt instanceof NewlineToken)) {
+        return bt;
+      }
+    }
+    return null;
   }
 
   public List<LineAndTokenPosition> calculateBeginAndEndOfConcept
-    (ApiConcept problem)
+  (ApiConcept problem)
   {
     return calculateBeginAndEndOfConcept(problem.getBegin(), problem.getEnd());
   }
-  
+
   public List<LineAndTokenPosition> calculateBeginAndEndOfConcept(
-      int problemBegin, int problemEnd)
-  {
-      // int externalId = problem.getExternalId();
-      // int sentenceTypeId = Sentence.type;
-      int baseTokenTypeId = BaseToken.type;
-      // jcas.getAnnotationIndex(sentenceTypeId);
-
-      ConstraintConstructorFindContainedBy constraintConstructorFindContainedBy = new ConstraintConstructorFindContainedBy(
-                      jcas);
-      ConstraintConstructorFindContainedWithin constraintConstructorFindContainedWithin =
new ConstraintConstructorFindContainedWithin(
-                      jcas);
-
-      // AnnotationIndex<Annotation> sentenceAnnotationIndex =
-      // jcas.getAnnotationIndex(sentenceTypeId);
-      Type sentenceType = jcas.getTypeSystem().getType(
-                      Sentence.class.getName());
-      Type baseTokenType = jcas.getTypeSystem().getType(
-                      BaseToken.class.getName());
-      // /
-      FSIterator<Annotation> filteredIterator = constraintConstructorFindContainedBy
-                      .createFilteredIterator(problemBegin, problemEnd, sentenceType);
-      // /
-      if (!filteredIterator.hasNext()) {
-              throw new RuntimeException(
-                              "Surrounding sentence annotation not found!!");
-      }
+      int problemBegin, int problemEnd) {
+    // int externalId = problem.getExternalId();
+    // int sentenceTypeId = Sentence.type;
+    int baseTokenTypeId = BaseToken.type;
+    // jcas.getAnnotationIndex(sentenceTypeId);
+
+    ConstraintConstructorFindContainedBy constraintConstructorFindContainedBy = new ConstraintConstructorFindContainedBy(
+        jcas);
+    ConstraintConstructorFindContainedWithin constraintConstructorFindContainedWithin = new
ConstraintConstructorFindContainedWithin(
+        jcas);
+
+    // AnnotationIndex<Annotation> sentenceAnnotationIndex =
+    // jcas.getAnnotationIndex(sentenceTypeId);
+    Type sentenceType = jcas.getTypeSystem().getType(
+        Sentence.class.getName());
+    Type baseTokenType = jcas.getTypeSystem().getType(
+        BaseToken.class.getName());
+    // /
+    FSIterator<Annotation> filteredIterator = constraintConstructorFindContainedBy
+        .createFilteredIterator(problemBegin, problemEnd, sentenceType);
+    // /
+    ArrayList<LineAndTokenPosition> list = new ArrayList<LineAndTokenPosition>();
+    if (filteredIterator.hasNext()) {
       Annotation sentenceAnnotation = filteredIterator.next();
       Sentence sentence = (Sentence) sentenceAnnotation;
       int lineNumber = sentence.getSentenceNumber() + 1;
@@ -264,7 +252,7 @@ public class CharacterOffsetToLineTokenC
       // int firstTokenInSentenceNumber = firstToken.getTokenNumber();
 
       FSIterator<Annotation> beginTokenInSentenceIterator = constraintConstructorFindContainedWithin
-                      .createFilteredIterator(problemBegin, problemEnd, baseTokenType);
+          .createFilteredIterator(problemBegin, problemEnd, baseTokenType);
 
       // if (!beginTokenInSentenceIterator.hasNext()) {
       // throw new RuntimeException("First token in sentence not found!!");
@@ -276,22 +264,21 @@ public class CharacterOffsetToLineTokenC
       // int beginTokenWordNumber = beginTokenNumber
       // - firstTokenInSentenceNumber;
       BaseToken beginToken = this
-                      .getNextNonEOLToken(beginTokenInSentenceIterator);
+          .getNextNonEOLToken(beginTokenInSentenceIterator);
       int beginTokenWordNumber = this.sentenceToTokenNumberMap.get(sentence)
-                      .indexOf(beginToken);
+          .indexOf(beginToken);
 
       beginTokenInSentenceIterator.moveToLast();
       if (!beginTokenInSentenceIterator.hasNext()) {
-              throw new RuntimeException("First token in sentence not found!!");
+        throw new RuntimeException("First token in sentence not found!!");
       }
       Annotation endTokenAnnotation = beginTokenInSentenceIterator.next();
       BaseToken endToken = (BaseToken) endTokenAnnotation;
       // int endTokenNumber = endToken.getTokenNumber();
       // int endTokenWordNumber = endTokenNumber - firstTokenInSentenceNumber;
       int endTokenWordNumber = this.sentenceToTokenNumberMap.get(sentence)
-                      .indexOf(endToken);
+          .indexOf(endToken);
 
-      ArrayList<LineAndTokenPosition> list = new ArrayList<LineAndTokenPosition>();
       LineAndTokenPosition b = new LineAndTokenPosition();
       b.setLine(lineNumber);
       b.setTokenOffset(beginTokenWordNumber);
@@ -300,9 +287,9 @@ public class CharacterOffsetToLineTokenC
       e.setLine(lineNumber);
       e.setTokenOffset(endTokenWordNumber);
       list.add(e);
-      return list;
+    }
+    return list;
   }
-
 }
 
 



Mime
View raw message