You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by ja...@apache.org on 2012/10/31 06:26:55 UTC

svn commit: r1403989 [4/28] - in /incubator/ctakes/branches/SHARPn-cTAKES: Constituency Parser/src/org/chboston/cnlp/ctakes/parser/ Constituency Parser/src/org/chboston/cnlp/ctakes/parser/uima/ae/ Constituency Parser/src/org/chboston/cnlp/ctakes/parser...

Modified: incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/src/edu/mayo/bmi/uima/pad/util/JCasUtil.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/PAD%20term%20spotter/src/edu/mayo/bmi/uima/pad/util/JCasUtil.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/src/edu/mayo/bmi/uima/pad/util/JCasUtil.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/src/edu/mayo/bmi/uima/pad/util/JCasUtil.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed 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
- * 
+ * 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
@@ -21,34 +14,34 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.uima.pad.util;
-
-import java.lang.reflect.Field;
-import org.apache.uima.jcas.cas.TOP;
-import org.apache.uima.jcas.tcas.Annotation;
-
-
-public class JCasUtil {
-
-	public static int getType(String className) {
-		try {
-			Class<?> cls = Class.forName(className);
-			Class<? extends TOP> annotationCls = cls.asSubclass(Annotation.class);
-			return JCasUtil.getType(annotationCls);
-		} catch (Exception e) {
-			throw new IllegalArgumentException(e);
-		}
-	}
-	
-	public static int getType(Class<? extends TOP> cls) {
-		try {
-			Field typeField = cls.getDeclaredField("type");
-			// return value of static field
-			return typeField.getInt(null);
-		} catch (Exception e) {
-			throw new IllegalArgumentException(e);
-		}
-
+package edu.mayo.bmi.uima.pad.util;
+
+import java.lang.reflect.Field;
+import org.apache.uima.jcas.cas.TOP;
+import org.apache.uima.jcas.tcas.Annotation;
+
+
+public class JCasUtil {
+
+	public static int getType(String className) {
+		try {
+			Class<?> cls = Class.forName(className);
+			Class<? extends TOP> annotationCls = cls.asSubclass(Annotation.class);
+			return JCasUtil.getType(annotationCls);
+		} catch (Exception e) {
+			throw new IllegalArgumentException(e);
+		}
+	}
+	
+	public static int getType(Class<? extends TOP> cls) {
+		try {
+			Field typeField = cls.getDeclaredField("type");
+			// return value of static field
+			return typeField.getInt(null);
+		} catch (Exception e) {
+			throw new IllegalArgumentException(e);
+		}
+
 	}
 
 	public synchronized static boolean isInstanceOf(String jcasObjClassName,
@@ -56,5 +49,5 @@ public class JCasUtil {
 			IllegalAccessException {
 		Class c = Class.forName(jcasObjClassName);
 		return c.isInstance(obj);
-	}
-}
+	}
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/src/edu/mayo/bmi/uima/termspotter/cr/RadiologyRecordsCollectionReader.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/PAD%20term%20spotter/src/edu/mayo/bmi/uima/termspotter/cr/RadiologyRecordsCollectionReader.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/src/edu/mayo/bmi/uima/termspotter/cr/RadiologyRecordsCollectionReader.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/src/edu/mayo/bmi/uima/termspotter/cr/RadiologyRecordsCollectionReader.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed 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
- * 
+ * 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
@@ -21,82 +14,82 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.uima.termspotter.cr;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.List;
-
+package edu.mayo.bmi.uima.termspotter.cr;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-
-import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.CASException;
-import org.apache.uima.collection.CollectionException;
-import org.apache.uima.collection.CollectionReader_ImplBase;
-import org.apache.uima.jcas.JCas;
-import org.apache.uima.jcas.tcas.DocumentAnnotation;
-import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.util.Progress;
-import org.apache.uima.util.ProgressImpl;
-
-import edu.mayo.bmi.uima.core.type.structured.DocumentID;
-
-/**
- * 
- * The original code was copied from org.apache.uima.examples.cpe.FileSystemCollectionReader
- * and modified for Mayo use.
- *
- * This collection reader facilitates reading "documents" from a single file.  Each
- * line in the document will be considered an entity to be analyzed by the CPE.  That
- * is each line will be treated as a "document" and will have its own CAS.
- * 
- * Extremely large files will require large memory resources as each line is read into
- * memory upon initialization.  This was done to simplify implementation.  
- * 
- * @author Mayo Clinic
- *
- */
-
-public class RadiologyRecordsCollectionReader extends CollectionReader_ImplBase {
-
-	/**
-	 * This parameter will be used the descriptor file to specify the location of the
-	 * file that will be run through this collection reader.
-	 */
-	public static final String PARAM_INPUT_FILE_NAME = "InputFileName";
-	/**
-	 * Optional parameter specifies a comment string.  Any line that begins with the string
-	 * will be ignored and not be added as a "document" to the CPE. 
-	 */
-	public static final String PARAM_COMMENT_STRING = "CommentString";
-	/**
-	 * Optional parameter determines whether a blank line will be processed as a document or
-	 * will be ignored.  The default will be set to 'true'.  
-	 */
-	public static final String PARAM_IGNORE_BLANK_LINES = "IgnoreBlankLines";
-	
-  /**
-   * Name of optional configuration parameter that contains the language of
-   * the documents in the input directory.  If specified this information will
-   * be added to the CAS.
-   */
-    public static final String PARAM_LANGUAGE = "Language";
-    
-    /**
-     * Name of optional configuration parameter that specifies a character (or string) that delimits
-     * the id of the document from the text of the document.  For example, if the parameter is 
-     * set to '|' then the following line from a file:
-     * <code>1234|this is some text</code>
-     * would have an id of 1234 and text <code>this is some text</code>.  
-     * If this parameter is not set, then
-     * the id of a document will be its line number in the file.      
-     */
-
+import org.apache.log4j.Logger;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.collection.CollectionException;
+import org.apache.uima.collection.CollectionReader_ImplBase;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.DocumentAnnotation;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.Progress;
+import org.apache.uima.util.ProgressImpl;
+
+import edu.mayo.bmi.uima.core.type.structured.DocumentID;
+
+/**
+ * 
+ * The original code was copied from org.apache.uima.examples.cpe.FileSystemCollectionReader
+ * and modified for Mayo use.
+ *
+ * This collection reader facilitates reading "documents" from a single file.  Each
+ * line in the document will be considered an entity to be analyzed by the CPE.  That
+ * is each line will be treated as a "document" and will have its own CAS.
+ * 
+ * Extremely large files will require large memory resources as each line is read into
+ * memory upon initialization.  This was done to simplify implementation.  
+ * 
+ * @author Mayo Clinic
+ *
+ */
+
+public class RadiologyRecordsCollectionReader extends CollectionReader_ImplBase {
+
+	/**
+	 * This parameter will be used the descriptor file to specify the location of the
+	 * file that will be run through this collection reader.
+	 */
+	public static final String PARAM_INPUT_FILE_NAME = "InputFileName";
+	/**
+	 * Optional parameter specifies a comment string.  Any line that begins with the string
+	 * will be ignored and not be added as a "document" to the CPE. 
+	 */
+	public static final String PARAM_COMMENT_STRING = "CommentString";
+	/**
+	 * Optional parameter determines whether a blank line will be processed as a document or
+	 * will be ignored.  The default will be set to 'true'.  
+	 */
+	public static final String PARAM_IGNORE_BLANK_LINES = "IgnoreBlankLines";
+	
+  /**
+   * Name of optional configuration parameter that contains the language of
+   * the documents in the input directory.  If specified this information will
+   * be added to the CAS.
+   */
+    public static final String PARAM_LANGUAGE = "Language";
+    
+    /**
+     * Name of optional configuration parameter that specifies a character (or string) that delimits
+     * the id of the document from the text of the document.  For example, if the parameter is 
+     * set to '|' then the following line from a file:
+     * <code>1234|this is some text</code>
+     * would have an id of 1234 and text <code>this is some text</code>.  
+     * If this parameter is not set, then
+     * the id of a document will be its line number in the file.      
+     */
+
     public static final String PARAM_ID_DELIMETER = "IdDelimeter";
     
     /**
@@ -114,82 +107,82 @@ public class RadiologyRecordsCollectionR
     
     /**
      * The column number of the input file that contains the compare string to parse applicable exam types.
-     */
+     */
     
     public static final String PARAM_EXAM_COLUMN = "FilterExamColumnNumber";
-    
-	List iv_linesFromFile;
-	int iv_currentIndex = 0;
-	String iv_language; 
-	String iv_delimeter;
+    
+	List iv_linesFromFile;
+	int iv_currentIndex = 0;
+	String iv_language; 
+	String iv_delimeter;
 	Integer numberOfColumns;
 	String filterExamTypes;
 	Integer filterColunmNumber;
-	
-	private Logger iv_logger = Logger.getLogger(getClass().getName());
-
-	public void initialize() throws ResourceInitializationException
-	{
-		BufferedReader fileReader = null;
-		try
+	
+	private Logger iv_logger = Logger.getLogger(getClass().getName());
+
+	public void initialize() throws ResourceInitializationException
+	{
+		BufferedReader fileReader = null;
+		try
 		{
-			numberOfColumns = (Integer) getConfigParameterValue(PARAM_TOTAL_COLUMNS);
-			String fileLocation = (String) getConfigParameterValue(PARAM_INPUT_FILE_NAME);
-			String commentSeq = (String)getConfigParameterValue(PARAM_COMMENT_STRING);
-			iv_language = (String)getConfigParameterValue(PARAM_LANGUAGE);
+			numberOfColumns = (Integer) getConfigParameterValue(PARAM_TOTAL_COLUMNS);
+			String fileLocation = (String) getConfigParameterValue(PARAM_INPUT_FILE_NAME);
+			String commentSeq = (String)getConfigParameterValue(PARAM_COMMENT_STRING);
+			iv_language = (String)getConfigParameterValue(PARAM_LANGUAGE);
 			Boolean paramValue = (Boolean)getConfigParameterValue(PARAM_IGNORE_BLANK_LINES);
 			filterExamTypes = (String) getConfigParameterValue(PARAM_FILTER_EXAMS);
-			filterColunmNumber = (Integer) getConfigParameterValue(PARAM_EXAM_COLUMN);
-			boolean ignoreBlankLines = true;
-			if(paramValue != null) 
-			{
-				ignoreBlankLines = paramValue.booleanValue();
-			}
-			iv_delimeter =  (String)getConfigParameterValue(PARAM_ID_DELIMETER);
-				
-			iv_linesFromFile = new ArrayList();
+			filterColunmNumber = (Integer) getConfigParameterValue(PARAM_EXAM_COLUMN);
+			boolean ignoreBlankLines = true;
+			if(paramValue != null) 
+			{
+				ignoreBlankLines = paramValue.booleanValue();
+			}
+			iv_delimeter =  (String)getConfigParameterValue(PARAM_ID_DELIMETER);
+				
+			iv_linesFromFile = new ArrayList();
 			fileReader = new BufferedReader(new FileReader(fileLocation));
 
-			
+			
 			String line;
-	
-			while((line = fileReader.readLine()) != null)
-			{
-				if(commentSeq != null)
-				{
-					if(line.startsWith(commentSeq)) continue;
-				}
+	
+			while((line = fileReader.readLine()) != null)
+			{
+				if(commentSeq != null)
+				{
+					if(line.startsWith(commentSeq)) continue;
+				}
 				if(ignoreBlankLines && line.trim().length() == 0) continue;
-
-				iv_linesFromFile.add(line);
-			}
-		}
-		catch(IOException fnfe)
-		{
-			throw new ResourceInitializationException(fnfe);
-		}
-		finally
-		{
-			if(fileReader != null)
-			try { fileReader.close(); } catch(IOException ioe) {}
-		}
-	}
-	
-	public void getNext(CAS cas) throws IOException, CollectionException 
-	{
-	  	JCas jcas;
-	  	try
-	    {
-	  		jcas = cas.getJCas();
-	  	    boolean foundLine = false;
-		  	String line = (String) iv_linesFromFile.get(iv_currentIndex);
-		  	int lineNumber = iv_currentIndex + 1;
-		  	String id;
+
+				iv_linesFromFile.add(line);
+			}
+		}
+		catch(IOException fnfe)
+		{
+			throw new ResourceInitializationException(fnfe);
+		}
+		finally
+		{
+			if(fileReader != null)
+			try { fileReader.close(); } catch(IOException ioe) {}
+		}
+	}
+	
+	public void getNext(CAS cas) throws IOException, CollectionException 
+	{
+	  	JCas jcas;
+	  	try
+	    {
+	  		jcas = cas.getJCas();
+	  	    boolean foundLine = false;
+		  	String line = (String) iv_linesFromFile.get(iv_currentIndex);
+		  	int lineNumber = iv_currentIndex + 1;
+		  	String id;
 		  	String text, filterLine;
 			BufferedReader filterExamTypesFile = null;
 			if (filterExamTypes != null && filterExamTypes != "")
-				filterExamTypesFile = new BufferedReader(new FileReader(filterExamTypes));
-		  	if(iv_delimeter != null)
+				filterExamTypesFile = new BufferedReader(new FileReader(filterExamTypes));
+		  	if(iv_delimeter != null)
 			{
 		  		String [] delimitedColumns = line.split(iv_delimeter);
 				if (filterExamTypesFile != null) {
@@ -200,12 +193,12 @@ public class RadiologyRecordsCollectionR
 							foundLine=true;
 					}
 				}
-				
-				int delimeterLoc = line.indexOf(iv_delimeter);
-				if(delimeterLoc <= 0)
-					throw new CollectionException(new Exception("Line in file number "+lineNumber+" is not well formatted.  " +
-							"\nIt should have the format:" +
-							"\n<doc_id>"+iv_delimeter+"<doc_text>"));
+				
+				int delimeterLoc = line.indexOf(iv_delimeter);
+				if(delimeterLoc <= 0)
+					throw new CollectionException(new Exception("Line in file number "+lineNumber+" is not well formatted.  " +
+							"\nIt should have the format:" +
+							"\n<doc_id>"+iv_delimeter+"<doc_text>"));
 				id = line.substring(0,delimeterLoc);
 				if (foundLine) {
 					if (numberOfColumns.intValue() > 0 && iv_delimeter != null
@@ -218,76 +211,76 @@ public class RadiologyRecordsCollectionR
 				} else {
 			  		id = line.substring(0,delimeterLoc); 
 			  		text = "";
-				}
-			}
-		  	else
-		  	{
-		  		id = Integer.toString(lineNumber); //id will one more than its index into iv_linesFromFile (iv_currentIndex has already been incremented)
-		  		text = line;
-		  	}
-	  		
-
-		  	iv_logger.debug("id="+id);
-		  	iv_logger.debug("text="+text);
-		  	
-			//if there's a CAS Initializer, call it	
-			if (getCasInitializer() != null)
-			{
-				Reader reader = new StringReader(text);
-				getCasInitializer().initializeCas(reader, cas);
-				reader.close();
-			}
-			else  //No CAS Initiliazer, so read file and set document text ourselves
-			{				
-				jcas.setDocumentText(text);
-			}
-		   
-		    //set language if it was explicitly specified as a configuration parameter
-		    if (iv_language != null)
-		    {
-		      ((DocumentAnnotation)jcas.getDocumentAnnotationFs()).setLanguage(iv_language);
-		    }
-		    
-		    
-		    DocumentID documentIDAnnotation = new DocumentID(jcas);
-		    documentIDAnnotation.setDocumentID(id);
-		    documentIDAnnotation.addToIndexes();
-
+				}
+			}
+		  	else
+		  	{
+		  		id = Integer.toString(lineNumber); //id will one more than its index into iv_linesFromFile (iv_currentIndex has already been incremented)
+		  		text = line;
+		  	}
+	  		
+
+		  	iv_logger.debug("id="+id);
+		  	iv_logger.debug("text="+text);
+		  	
+			//if there's a CAS Initializer, call it	
+			if (getCasInitializer() != null)
+			{
+				Reader reader = new StringReader(text);
+				getCasInitializer().initializeCas(reader, cas);
+				reader.close();
+			}
+			else  //No CAS Initiliazer, so read file and set document text ourselves
+			{				
+				jcas.setDocumentText(text);
+			}
+		   
+		    //set language if it was explicitly specified as a configuration parameter
+		    if (iv_language != null)
+		    {
+		      ((DocumentAnnotation)jcas.getDocumentAnnotationFs()).setLanguage(iv_language);
+		    }
+		    
+		    
+		    DocumentID documentIDAnnotation = new DocumentID(jcas);
+		    documentIDAnnotation.setDocumentID(id);
+		    documentIDAnnotation.addToIndexes();
+
 	    } 
 	  	catch (ArrayIndexOutOfBoundsException aioobe) {
 	  		iv_logger.log(Level.ERROR, "Radiology input file corrupt or some record row contents are not valid.");
 	  		throw new CollectionException(aioobe);
-	  	}
-	    catch (CASException e)
-	    {
-	      throw new CollectionException(e);
-	    }
-	    finally
-	    {
-	    	iv_currentIndex++;
-	    }
-	    
-	}
-
-	public boolean hasNext() throws IOException, CollectionException 
-	{
-		return iv_currentIndex < iv_linesFromFile.size();
-	}
-
-	public Progress[] getProgress() {
-	    return new Progress[]{
-	    	       new ProgressImpl(iv_currentIndex, iv_linesFromFile.size(),Progress.ENTITIES)};
-	}
-
-	 /**
-	   * Gets the total number of documents that will be returned by this
-	   * collection reader.  
-	   * @return the number of documents in the collection
-	   */
-	  public int getNumberOfDocuments()
-	  {
-	    return iv_linesFromFile.size();
-	  }
-	  
-	public void close() throws IOException {}
-}
+	  	}
+	    catch (CASException e)
+	    {
+	      throw new CollectionException(e);
+	    }
+	    finally
+	    {
+	    	iv_currentIndex++;
+	    }
+	    
+	}
+
+	public boolean hasNext() throws IOException, CollectionException 
+	{
+		return iv_currentIndex < iv_linesFromFile.size();
+	}
+
+	public Progress[] getProgress() {
+	    return new Progress[]{
+	    	       new ProgressImpl(iv_currentIndex, iv_linesFromFile.size(),Progress.ENTITIES)};
+	}
+
+	 /**
+	   * Gets the total number of documents that will be returned by this
+	   * collection reader.  
+	   * @return the number of documents in the collection
+	   */
+	  public int getNumberOfDocuments()
+	  {
+	    return iv_linesFromFile.size();
+	  }
+	  
+	public void close() throws IOException {}
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/Compare.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/PAD%20term%20spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/Compare.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/Compare.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/Compare.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed 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
- * 
+ * 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
@@ -21,37 +14,37 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.utils.xcas_comparison;
-import java.io.*;
-
-/**
- * This class illustrates the basic usage of this tool.
- * @author Mayo Clinic
- *
- */
-public class Compare {
-
-	public static void main(String[] args) {
-//		Prepare the list of attributes to ignore when comparing elements
-		Const.init();
-//		Initialize a processor
-		XcasProcessor p = new XcasProcessor();
-//		Process/parse the two files specified in args[0] and args[1]
-		File f1 = new File(args[0]);
-		if (!f1.exists()) { System.err.println(args[0]+" not exist!"); System.exit(1); }
-		File f2 = new File(args[1]);
-		if (!f2.exists()) { System.err.println(args[2]+" not exist!"); System.exit(1); }
-		XcasFile xf1 = p.process(f1);
-		XcasFile xf2 = p.process(f2);
-//		Construct an XcasDiff object from the two XcasFiles
-		XcasDiff d = new XcasDiff(xf1, xf2);
-//		Print differences to stdout
-		d.printDiff();
-//		Print an HTML summary to file specified in args[2]
-		try {
-			d.printHTML(new FileWriter(args[2]));
-			System.out.println();
-			System.out.println("HTML summary written to "+args[2]);
-		} catch (IOException e) { e.printStackTrace(); }
-	}
-}
+package edu.mayo.bmi.utils.xcas_comparison;
+import java.io.*;
+
+/**
+ * This class illustrates the basic usage of this tool.
+ * @author Mayo Clinic
+ *
+ */
+public class Compare {
+
+	public static void main(String[] args) {
+//		Prepare the list of attributes to ignore when comparing elements
+		Const.init();
+//		Initialize a processor
+		XcasProcessor p = new XcasProcessor();
+//		Process/parse the two files specified in args[0] and args[1]
+		File f1 = new File(args[0]);
+		if (!f1.exists()) { System.err.println(args[0]+" not exist!"); System.exit(1); }
+		File f2 = new File(args[1]);
+		if (!f2.exists()) { System.err.println(args[2]+" not exist!"); System.exit(1); }
+		XcasFile xf1 = p.process(f1);
+		XcasFile xf2 = p.process(f2);
+//		Construct an XcasDiff object from the two XcasFiles
+		XcasDiff d = new XcasDiff(xf1, xf2);
+//		Print differences to stdout
+		d.printDiff();
+//		Print an HTML summary to file specified in args[2]
+		try {
+			d.printHTML(new FileWriter(args[2]));
+			System.out.println();
+			System.out.println("HTML summary written to "+args[2]);
+		} catch (IOException e) { e.printStackTrace(); }
+	}
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/Const.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/PAD%20term%20spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/Const.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/Const.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/Const.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed 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
- * 
+ * 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
@@ -21,47 +14,47 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.utils.xcas_comparison;
-
-import java.util.HashSet;
-import java.util.Properties;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-public abstract class Const {
-	public static String UIMA_TCAS_DOCUMENT = "uima.tcas.Document";
-	public static String UIMA_FSARRAY = "uima.cas.FSArray";
-	public static String UIMA_INTARRAY = "uima.cas.IntegerArray";
-	public static String UIMA_NONEMPTY_FSLIST = "uima.cas.NonEmptyFSList";
-	public static String UIMA_EMPTY_FSLIST = "uima.cas.EmptyFSList";
-	public static String ID = "_id";
-	public static String REF_PREFIX = "_ref_";
-	public static String UIMA_ARRAY_INDEX_KEYWORD = "i";
-	public static String UIMA_ARRAY_SIZE_KEYWORD = "size";
-	public static String UIMA_LIST_HEAD_KEYWORD = "_ref_head";
-	public static String UIMA_LIST_TAIL_KEYWORD = "_ref_tail";
-	public static String UIMA_CAS = "CAS";
-	public static String UIMA_REF_SOFA = "_ref_Sofa";
-	public static String UIMA_SOFA = "uima.cas.Sofa";
-	public static String UIMA_SOFA_STRING = "sofaString";
-	public static String HIDDEN_TEXT = "...";
-	public static HashSet<String> ATTRIBUTES_TO_IGNORE = new HashSet<String>();
-
-	public static void init() {
-		// uid is always ignored;
-		ATTRIBUTES_TO_IGNORE.add("uid");
-		// read in attributes from file
-		File f = new File("attributes_to_ignore.properties");
-		if (!f.exists()) return;
-		Properties p = new Properties();
-		try {
-			p.load(new FileInputStream(f));
-			String s = p.getProperty("ATTRIBUTES_TO_IGNORE");
-			if (s!=null) {
-				String[] a = s.split(";");
-				for (String i : a) ATTRIBUTES_TO_IGNORE.add(i);
-			}
-		} catch (IOException e) {}
-	}
-}
+package edu.mayo.bmi.utils.xcas_comparison;
+
+import java.util.HashSet;
+import java.util.Properties;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+public abstract class Const {
+	public static String UIMA_TCAS_DOCUMENT = "uima.tcas.Document";
+	public static String UIMA_FSARRAY = "uima.cas.FSArray";
+	public static String UIMA_INTARRAY = "uima.cas.IntegerArray";
+	public static String UIMA_NONEMPTY_FSLIST = "uima.cas.NonEmptyFSList";
+	public static String UIMA_EMPTY_FSLIST = "uima.cas.EmptyFSList";
+	public static String ID = "_id";
+	public static String REF_PREFIX = "_ref_";
+	public static String UIMA_ARRAY_INDEX_KEYWORD = "i";
+	public static String UIMA_ARRAY_SIZE_KEYWORD = "size";
+	public static String UIMA_LIST_HEAD_KEYWORD = "_ref_head";
+	public static String UIMA_LIST_TAIL_KEYWORD = "_ref_tail";
+	public static String UIMA_CAS = "CAS";
+	public static String UIMA_REF_SOFA = "_ref_Sofa";
+	public static String UIMA_SOFA = "uima.cas.Sofa";
+	public static String UIMA_SOFA_STRING = "sofaString";
+	public static String HIDDEN_TEXT = "...";
+	public static HashSet<String> ATTRIBUTES_TO_IGNORE = new HashSet<String>();
+
+	public static void init() {
+		// uid is always ignored;
+		ATTRIBUTES_TO_IGNORE.add("uid");
+		// read in attributes from file
+		File f = new File("attributes_to_ignore.properties");
+		if (!f.exists()) return;
+		Properties p = new Properties();
+		try {
+			p.load(new FileInputStream(f));
+			String s = p.getProperty("ATTRIBUTES_TO_IGNORE");
+			if (s!=null) {
+				String[] a = s.split(";");
+				for (String i : a) ATTRIBUTES_TO_IGNORE.add(i);
+			}
+		} catch (IOException e) {}
+	}
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/ConvertAndCompare.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/PAD%20term%20spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/ConvertAndCompare.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/ConvertAndCompare.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/ConvertAndCompare.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed 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
- * 
+ * 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
@@ -21,111 +14,111 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.utils.xcas_comparison;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.Hashtable;
-
-
-public class ConvertAndCompare {
-
-
-	public static void main(String[] args) {
-		// key = cni, value = open source
-		Hashtable<String, String> map = new Hashtable<String, String>();
-		map.put("edu.mayo.bmi.uima.common.type.DocumentID",
-				"edu.mayo.bmi.uima.common.types.DocumentIDAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.textspan.LookupWindowAnnotation",
-				"edu.mayo.bmi.uima.lookup.types.LookupWindowAnnotation");
-//		Specify your mappings here
-/*		map.put("",
-				"uima.tt.MCAnnotation");
-		map.put("",
-				"uima.tt.TCAnnotation");
-		map.put("",
-				"uima.tt.WHPAnnotation");
-		map.put("",
-				"uima.tt.OBJAnnotation");
-		map.put("",
-				"uima.tt.PSUBAnnotation");
-		map.put("",
-				"uima.tt.SUBAnnotation");
-		map.put("",
-				"uima.tt.AdjAnnotation");
-		map.put("",
-				"uima.tt.CNPAnnotation");
-		map.put("",
-				"uima.tt.NPAnnotation");
-		map.put("",
-				"uima.tt.NPListAnnotation");
-		map.put("",
-				"uima.tt.NPPAnnotation");
-		map.put("",
-				"uima.tt.PPAnnotation");
-		map.put("",
-				"uima.tt.PVGAnnotation");
-		map.put("",
-				"uima.tt.VGAnnotation");
-*/
-		map.put("edu.mayo.bmi.uima.cdt.type.RomanNumeralAnnotation",
-				"edu.mayo.bmi.uima.cdt.types.RomanNumeralAnnotation");
-		map.put("edu.mayo.bmi.uima.cdt.type.FractionAnnotation",
-				"edu.mayo.bmi.uima.cdt.types.FractionAnnotation");
-		map.put("edu.mayo.bmi.uima.cdt.type.DateAnnotation",
-				"edu.mayo.bmi.uima.cdt.types.DateAnnotation");
-		map.put("edu.mayo.bmi.uima.cdt.type.ProblemListAnnotation",
-				"edu.mayo.bmi.uima.cdt.types.ProblemListAnnotation");
-		map.put("edu.mayo.bmi.uima.cdt.type.MeasurementAnnotation",
-				"edu.mayo.bmi.uima.cdt.types.MeasurementAnnotation");
-		map.put("edu.mayo.bmi.uima.cdt.type.PersonTitleAnnotation",
-				"edu.mayo.bmi.uima.cdt.types.PersonTitleAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.textspan.Segment",
-				"edu.mayo.bmi.uima.common.types.SegmentAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.textspan.Sentence",
-				"edu.mayo.bmi.uima.common.types.SentenceAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.syntax.WordToken",
-				"edu.mayo.bmi.uima.common.types.WordTokenAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.NumToken",
-				"edu.mayo.bmi.uima.common.types.NumTokenAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.PunctuationToken",
-				"edu.mayo.bmi.uima.common.types.PunctTokenAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.SymbolToken",
-				"edu.mayo.bmi.uima.common.types.SymbolTokenAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.NewlineToken",
-				"edu.mayo.bmi.uima.common.types.NewlineTokenAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.textsem.IdentifiedAnnotation",
-				"edu.mayo.bmi.uima.common.types.NamedEntityAnnotation");
-		map.put("edu.mayo.bmi.uima.core.type.UmlsConcept",
-				"edu.mayo.bmi.uima.common.types.UmlsConcept");
-		map.put("edu.mayo.bmi.uima.core.type.OntologyConcept",
-				"edu.mayo.bmi.uima.common.types.OntologyConcept");
-
-//		Prepare the list of attributes to ignore when comparing elements
-		Const.init();
-//		Initialize a processor
-		XcasProcessor p = new XcasProcessor();
-//		Process/parse the two files specified in args[0] and args[1]
-		File f1 = new File(args[0]);
-		if (!f1.exists()) { System.err.println(args[0]+" not exist!"); System.exit(1); }
-		File f2 = new File(args[1]);
-		if (!f2.exists()) { System.err.println(args[2]+" not exist!"); System.exit(1); }
-		XcasFile xf1 = p.process(f1);
-		XcasFile xf2 = p.process(f2);
-//		Change xf1 to xf2 if the second command line argument is the open source output
-		for (XcasAnnotation a : xf1.getAllAnnotations())
-			if (map.containsKey(a.getType()))
-					a.setType(map.get(a.getType()));
-//		Construct an XcasDiff object from the two XcasFiles
-		XcasDiff d = new XcasDiff(xf1, xf2);
-//		Print differences to stdout
-		d.printDiff();
-//		Print an HTML summary to file specified in args[2]
-		try {
-			d.printHTML(new FileWriter(args[2]));
-			System.out.println();
-			System.out.println("HTML summary written to "+args[2]);
-		} catch (IOException e) { e.printStackTrace(); }
-	}
-
-}
+package edu.mayo.bmi.utils.xcas_comparison;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Hashtable;
+
+
+public class ConvertAndCompare {
+
+
+	public static void main(String[] args) {
+		// key = cni, value = open source
+		Hashtable<String, String> map = new Hashtable<String, String>();
+		map.put("edu.mayo.bmi.uima.common.type.DocumentID",
+				"edu.mayo.bmi.uima.common.types.DocumentIDAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.textspan.LookupWindowAnnotation",
+				"edu.mayo.bmi.uima.lookup.types.LookupWindowAnnotation");
+//		Specify your mappings here
+/*		map.put("",
+				"uima.tt.MCAnnotation");
+		map.put("",
+				"uima.tt.TCAnnotation");
+		map.put("",
+				"uima.tt.WHPAnnotation");
+		map.put("",
+				"uima.tt.OBJAnnotation");
+		map.put("",
+				"uima.tt.PSUBAnnotation");
+		map.put("",
+				"uima.tt.SUBAnnotation");
+		map.put("",
+				"uima.tt.AdjAnnotation");
+		map.put("",
+				"uima.tt.CNPAnnotation");
+		map.put("",
+				"uima.tt.NPAnnotation");
+		map.put("",
+				"uima.tt.NPListAnnotation");
+		map.put("",
+				"uima.tt.NPPAnnotation");
+		map.put("",
+				"uima.tt.PPAnnotation");
+		map.put("",
+				"uima.tt.PVGAnnotation");
+		map.put("",
+				"uima.tt.VGAnnotation");
+*/
+		map.put("edu.mayo.bmi.uima.cdt.type.RomanNumeralAnnotation",
+				"edu.mayo.bmi.uima.cdt.types.RomanNumeralAnnotation");
+		map.put("edu.mayo.bmi.uima.cdt.type.FractionAnnotation",
+				"edu.mayo.bmi.uima.cdt.types.FractionAnnotation");
+		map.put("edu.mayo.bmi.uima.cdt.type.DateAnnotation",
+				"edu.mayo.bmi.uima.cdt.types.DateAnnotation");
+		map.put("edu.mayo.bmi.uima.cdt.type.ProblemListAnnotation",
+				"edu.mayo.bmi.uima.cdt.types.ProblemListAnnotation");
+		map.put("edu.mayo.bmi.uima.cdt.type.MeasurementAnnotation",
+				"edu.mayo.bmi.uima.cdt.types.MeasurementAnnotation");
+		map.put("edu.mayo.bmi.uima.cdt.type.PersonTitleAnnotation",
+				"edu.mayo.bmi.uima.cdt.types.PersonTitleAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.textspan.Segment",
+				"edu.mayo.bmi.uima.common.types.SegmentAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.textspan.Sentence",
+				"edu.mayo.bmi.uima.common.types.SentenceAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.syntax.WordToken",
+				"edu.mayo.bmi.uima.common.types.WordTokenAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.NumToken",
+				"edu.mayo.bmi.uima.common.types.NumTokenAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.PunctuationToken",
+				"edu.mayo.bmi.uima.common.types.PunctTokenAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.SymbolToken",
+				"edu.mayo.bmi.uima.common.types.SymbolTokenAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.NewlineToken",
+				"edu.mayo.bmi.uima.common.types.NewlineTokenAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.textsem.IdentifiedAnnotation",
+				"edu.mayo.bmi.uima.common.types.NamedEntityAnnotation");
+		map.put("edu.mayo.bmi.uima.core.type.UmlsConcept",
+				"edu.mayo.bmi.uima.common.types.UmlsConcept");
+		map.put("edu.mayo.bmi.uima.core.type.OntologyConcept",
+				"edu.mayo.bmi.uima.common.types.OntologyConcept");
+
+//		Prepare the list of attributes to ignore when comparing elements
+		Const.init();
+//		Initialize a processor
+		XcasProcessor p = new XcasProcessor();
+//		Process/parse the two files specified in args[0] and args[1]
+		File f1 = new File(args[0]);
+		if (!f1.exists()) { System.err.println(args[0]+" not exist!"); System.exit(1); }
+		File f2 = new File(args[1]);
+		if (!f2.exists()) { System.err.println(args[2]+" not exist!"); System.exit(1); }
+		XcasFile xf1 = p.process(f1);
+		XcasFile xf2 = p.process(f2);
+//		Change xf1 to xf2 if the second command line argument is the open source output
+		for (XcasAnnotation a : xf1.getAllAnnotations())
+			if (map.containsKey(a.getType()))
+					a.setType(map.get(a.getType()));
+//		Construct an XcasDiff object from the two XcasFiles
+		XcasDiff d = new XcasDiff(xf1, xf2);
+//		Print differences to stdout
+		d.printDiff();
+//		Print an HTML summary to file specified in args[2]
+		try {
+			d.printHTML(new FileWriter(args[2]));
+			System.out.println();
+			System.out.println("HTML summary written to "+args[2]);
+		} catch (IOException e) { e.printStackTrace(); }
+	}
+
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasAnnotation.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/PAD%20term%20spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasAnnotation.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasAnnotation.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasAnnotation.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed 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
- * 
+ * 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
@@ -21,233 +14,233 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.utils.xcas_comparison;
-import java.util.Collection;
-import java.util.Vector;
-import java.util.Hashtable;
-import java.util.Collections;
-
-/**
- * An <code>XcasAnnotation</code> object represents an element under the <code>CAS</code>
- * tag in an XCAS file. It provides members and methods to store and access
- * its type, attributes,and references.
- * <p>
- * Note: this class has a natural ordering that is inconsistent with equals.
- * It is strongly recommended that the use of {@link #compareTo(XcasAnnotation)}
- * be strictly limited to the purpose of an orderly display of multiple objects.
- * @author Mayo Clinic
- *
- */
-public class XcasAnnotation implements Cloneable, Comparable<XcasAnnotation> {
-
-	private class MyVector extends Vector<XcasAnnotation> implements Cloneable {
-		private static final long serialVersionUID = -8717810064045790243L;
-		public MyVector () { super(); }
-		public boolean contains (Object obj) {
-			if (obj.getClass()!=XcasAnnotation.class) return false;
-			for (XcasAnnotation a : this) if (a.equals(obj)) return true;
-			return false;
-		}
-		public boolean containsAll (Collection<?> c) {
-			if (c==this || c.size()==0) return true;
-			for (Object o : c)
-				if (o.getClass()!=XcasAnnotation.class || !contains(o)) return false;
-			return true;
-		}
-		public boolean equals (Object obj) {
-			if (obj.getClass()!=getClass() || ((MyVector)obj).size()!=size()) return false;
-			return containsAll((MyVector)obj);
-		}
-		public String toString () {
-			StringBuffer ret = new StringBuffer("[");
-			Collections.sort(this);
-			for (XcasAnnotation a : this)
-				ret.append(a.type.equalsIgnoreCase(Const.UIMA_SOFA) ? Const.HIDDEN_TEXT : a.description()).append(",");
-			if (size()>0) ret.deleteCharAt(ret.length()-1);
-			return ret.append("]").toString();
-		}
-		public Object clone () {
-			MyVector o = null;
-			try {
-				o = (MyVector)super.clone();
-				o.clear();
-				for (XcasAnnotation a : this) //TODO is the order guaranteed to be the same?
-					o.add((XcasAnnotation)a.clone());
-			} catch (Exception e) { e.printStackTrace(); }
-			return o;
-		}
-	}
-
-	protected String type;
-	protected Hashtable<String, String> attributes;
-	protected Hashtable<String, MyVector> references;
-	protected Hashtable<String, Vector<Integer>> refIntArrays;
-
-	/**
-	 * Default constructor. Its type is initialized to empty.
-	 */
-	public XcasAnnotation () {
-		type = "";
-		attributes = new Hashtable<String, String>();
-		references = new Hashtable<String, MyVector>();
-		refIntArrays = new Hashtable<String, Vector<Integer>>();
-	}
-
-	/**
-	 * Constructs an object with the specified type.
-	 * @param t Type of the <code>XcasAnnotation</code> object to be created.
-	 */
-	public XcasAnnotation (String t) { this(); type = t; }
-
-	/**
-	 * Sets the type name of this annotation.
-	 * @param t Type to be set.
-	 */
-	public void setType (String t) { type = t; }
-
-	/**
-	 * Inserts an (attribute, value) pair to this <code>XcasAnnotation</code>.
-	 * @param k Name of the attribute.
-	 * @param v Value of the attribute.
-	 */
-	public void insertAttribute (String k, String v) { attributes.put(k, v); }
-	//TODO Check for loop in references
-	public void insertReference (String k, XcasAnnotation a) {
-		if (references.containsKey(k))
-			references.get(k).add(a);
-		else {
-			MyVector v = new MyVector();
-			v.add(a);
-			references.put(k, v);
-		}
-	}
-
-	public void insertIntReference (String k, int[] a) {
-		Vector<Integer> v = new Vector<Integer>(a.length);
-		for (int i : a) v.add(i);
-		refIntArrays.put(k, v);
-	}
-
-	/**
-	 * Returns the value of the specified attribute.
-	 * @param name Name of the attribute.
-	 * @return Value of the specified attribute. 
-	 */
-	public String getAttribute (String name) { return attributes.get(name); }
-
-	/**
-	 * Returns the referenced <code>XcasAnnotation</code>s of the specified attribute.
-	 * @param name Name of an attribute that references to other <code>XcasAnnotation</code>.
-	 * @return A <code>HashSet</code> of referenced <XcasAnnotation</code> objects.
-	 */
-	public Vector<XcasAnnotation> getReference (String name) { return references.get(name); }
-
-	/**
-	 * Determines whether the specified object equals to this one. Specifically,
-	 * an <code>XcasAnnotation a</code> equals to another one <code>o</code>
-	 * if and only if <code>o</code> is also an <code>XcasAnnotation</code> object
-	 * and <code>a.type.equals(o.type) &&  a.attributes.equals(o.attributes) &&
-	 * a.references.equals(o.references)</code>.
-	 * @param obj An object to compare with this one.
-	 * @return <code>true</code> if the specified object equals this one,
-	 *         <code>false</code> otherwise.
-	 */
-	public boolean equals (Object obj) {
-		return this==obj || ( obj.getClass()==getClass() &&
-				((XcasAnnotation)obj).type.equals(type) &&
-				((XcasAnnotation)obj).attributes.equals(attributes) &&
-				((XcasAnnotation)obj).references.equals(references) &&
-				((XcasAnnotation)obj).refIntArrays.equals(refIntArrays)
-				);
-	}
-
-	public String getType () { return type; }
-	/**
-	 * Returns a short description of this <code>XcasAnnotation</code>'s type,
-	 * specifically, the last segment as separated by dots.
-	 * @return A short type name.
-	 */
-	public String shortType () { return type.substring(type.lastIndexOf('.')+1); }
-
-	/**
-	 * Returns a string representation of all the attributes and references.
-	 * Some long values are shortened to ellipses.
-	 * @return A string containing all attributes, references and their values.
-	 */
-	public String allFieldsValues () {
-		StringBuffer ret = new StringBuffer("Attributes {");
-		Vector<String> v = new Vector<String>(attributes.keySet());
-		Collections.sort(v);
-		for (String s : v)
-			ret.append(s+"="+attributes.get(s)+", ");
-		if (v.size()>0) ret.replace(ret.length()-2, ret.length(), "}  References {");
-		v.clear();
-		v.addAll(references.keySet());
-		v.addAll(refIntArrays.keySet());
-		Collections.sort(v);
-		for (String s : v)
-			ret.append(s+"="+(references.containsKey(s)?references.get(s):refIntArrays.get(s))+", ");
-		if (v.size()>0) ret.delete(ret.length()-2, ret.length());
-		ret.append("}");
-		return ret.toString();
-//		return "Attributes "+attributes.toString()+"  References "+references.toString();
-	}
-
-	/**
-	 * Returns a String representation of this object, including its type, and
-	 * all attributes and references. Named such so as not to override
-	 * the default much shorter String representation
-	 * @return A string containing the type and all attributes, references information.
-	 */
-	public String description () { return shortType()+"  "+allFieldsValues(); }
-
-	/**
-	 * Clones this object and its attributes, but leave references blank.
-	 * @return
-	 */
-	private final XcasAnnotation prepareCopy () {
-		XcasAnnotation o = null;
-		try {
-			o = (XcasAnnotation)super.clone();
-			o.attributes = new Hashtable<String, String>();
-			o.attributes.putAll(attributes);
-			o.references = new Hashtable<String, MyVector>();
-			o.refIntArrays = new Hashtable<String, Vector<Integer>>();
-			for (String s : refIntArrays.keySet())
-				o.refIntArrays.put(s, new Vector<Integer>(refIntArrays.get(s)));
-		} catch (Exception e) { e.printStackTrace(); }
-		return o;
-	}
-
-	/**
-	 * Recursive, deep copy of this object, including attributes and references.
-	 */
-	public Object clone () {
-		XcasAnnotation o = prepareCopy();
-		for (String s : references.keySet())
-			o.references.put(s, (MyVector)references.get(s).clone());
-		return o;
-	}
-
-	/**
-	 * Clones this object, its attributes, and reference keys.
-	 * @return A shallow copy of this object.
-	 */
-	public final XcasAnnotation shallowCopy () {
-		XcasAnnotation o = prepareCopy();
-		for (String s : references.keySet())
-			o.references.put(s, new MyVector());
-		return o;
-	}
-
-	/**
-	 * Determines the order of this and the specified <code>XcasAnnotation</code>.
-	 * Note: It is strongly recommended that the use of this method be strictly
-	 * limited to the purpose of an orderly display of multiple objects.
-	 * To determine the equality of two objects, use {@link #equals(Object)}.
-	 * @see #equals(Object)
-	 */
-	public int compareTo(XcasAnnotation o) {
-		return description().compareTo(o.description());
-	}
-}
+package edu.mayo.bmi.utils.xcas_comparison;
+import java.util.Collection;
+import java.util.Vector;
+import java.util.Hashtable;
+import java.util.Collections;
+
+/**
+ * An <code>XcasAnnotation</code> object represents an element under the <code>CAS</code>
+ * tag in an XCAS file. It provides members and methods to store and access
+ * its type, attributes,and references.
+ * <p>
+ * Note: this class has a natural ordering that is inconsistent with equals.
+ * It is strongly recommended that the use of {@link #compareTo(XcasAnnotation)}
+ * be strictly limited to the purpose of an orderly display of multiple objects.
+ * @author Mayo Clinic
+ *
+ */
+public class XcasAnnotation implements Cloneable, Comparable<XcasAnnotation> {
+
+	private class MyVector extends Vector<XcasAnnotation> implements Cloneable {
+		private static final long serialVersionUID = -8717810064045790243L;
+		public MyVector () { super(); }
+		public boolean contains (Object obj) {
+			if (obj.getClass()!=XcasAnnotation.class) return false;
+			for (XcasAnnotation a : this) if (a.equals(obj)) return true;
+			return false;
+		}
+		public boolean containsAll (Collection<?> c) {
+			if (c==this || c.size()==0) return true;
+			for (Object o : c)
+				if (o.getClass()!=XcasAnnotation.class || !contains(o)) return false;
+			return true;
+		}
+		public boolean equals (Object obj) {
+			if (obj.getClass()!=getClass() || ((MyVector)obj).size()!=size()) return false;
+			return containsAll((MyVector)obj);
+		}
+		public String toString () {
+			StringBuffer ret = new StringBuffer("[");
+			Collections.sort(this);
+			for (XcasAnnotation a : this)
+				ret.append(a.type.equalsIgnoreCase(Const.UIMA_SOFA) ? Const.HIDDEN_TEXT : a.description()).append(",");
+			if (size()>0) ret.deleteCharAt(ret.length()-1);
+			return ret.append("]").toString();
+		}
+		public Object clone () {
+			MyVector o = null;
+			try {
+				o = (MyVector)super.clone();
+				o.clear();
+				for (XcasAnnotation a : this) //TODO is the order guaranteed to be the same?
+					o.add((XcasAnnotation)a.clone());
+			} catch (Exception e) { e.printStackTrace(); }
+			return o;
+		}
+	}
+
+	protected String type;
+	protected Hashtable<String, String> attributes;
+	protected Hashtable<String, MyVector> references;
+	protected Hashtable<String, Vector<Integer>> refIntArrays;
+
+	/**
+	 * Default constructor. Its type is initialized to empty.
+	 */
+	public XcasAnnotation () {
+		type = "";
+		attributes = new Hashtable<String, String>();
+		references = new Hashtable<String, MyVector>();
+		refIntArrays = new Hashtable<String, Vector<Integer>>();
+	}
+
+	/**
+	 * Constructs an object with the specified type.
+	 * @param t Type of the <code>XcasAnnotation</code> object to be created.
+	 */
+	public XcasAnnotation (String t) { this(); type = t; }
+
+	/**
+	 * Sets the type name of this annotation.
+	 * @param t Type to be set.
+	 */
+	public void setType (String t) { type = t; }
+
+	/**
+	 * Inserts an (attribute, value) pair to this <code>XcasAnnotation</code>.
+	 * @param k Name of the attribute.
+	 * @param v Value of the attribute.
+	 */
+	public void insertAttribute (String k, String v) { attributes.put(k, v); }
+	//TODO Check for loop in references
+	public void insertReference (String k, XcasAnnotation a) {
+		if (references.containsKey(k))
+			references.get(k).add(a);
+		else {
+			MyVector v = new MyVector();
+			v.add(a);
+			references.put(k, v);
+		}
+	}
+
+	public void insertIntReference (String k, int[] a) {
+		Vector<Integer> v = new Vector<Integer>(a.length);
+		for (int i : a) v.add(i);
+		refIntArrays.put(k, v);
+	}
+
+	/**
+	 * Returns the value of the specified attribute.
+	 * @param name Name of the attribute.
+	 * @return Value of the specified attribute. 
+	 */
+	public String getAttribute (String name) { return attributes.get(name); }
+
+	/**
+	 * Returns the referenced <code>XcasAnnotation</code>s of the specified attribute.
+	 * @param name Name of an attribute that references to other <code>XcasAnnotation</code>.
+	 * @return A <code>HashSet</code> of referenced <XcasAnnotation</code> objects.
+	 */
+	public Vector<XcasAnnotation> getReference (String name) { return references.get(name); }
+
+	/**
+	 * Determines whether the specified object equals to this one. Specifically,
+	 * an <code>XcasAnnotation a</code> equals to another one <code>o</code>
+	 * if and only if <code>o</code> is also an <code>XcasAnnotation</code> object
+	 * and <code>a.type.equals(o.type) &&  a.attributes.equals(o.attributes) &&
+	 * a.references.equals(o.references)</code>.
+	 * @param obj An object to compare with this one.
+	 * @return <code>true</code> if the specified object equals this one,
+	 *         <code>false</code> otherwise.
+	 */
+	public boolean equals (Object obj) {
+		return this==obj || ( obj.getClass()==getClass() &&
+				((XcasAnnotation)obj).type.equals(type) &&
+				((XcasAnnotation)obj).attributes.equals(attributes) &&
+				((XcasAnnotation)obj).references.equals(references) &&
+				((XcasAnnotation)obj).refIntArrays.equals(refIntArrays)
+				);
+	}
+
+	public String getType () { return type; }
+	/**
+	 * Returns a short description of this <code>XcasAnnotation</code>'s type,
+	 * specifically, the last segment as separated by dots.
+	 * @return A short type name.
+	 */
+	public String shortType () { return type.substring(type.lastIndexOf('.')+1); }
+
+	/**
+	 * Returns a string representation of all the attributes and references.
+	 * Some long values are shortened to ellipses.
+	 * @return A string containing all attributes, references and their values.
+	 */
+	public String allFieldsValues () {
+		StringBuffer ret = new StringBuffer("Attributes {");
+		Vector<String> v = new Vector<String>(attributes.keySet());
+		Collections.sort(v);
+		for (String s : v)
+			ret.append(s+"="+attributes.get(s)+", ");
+		if (v.size()>0) ret.replace(ret.length()-2, ret.length(), "}  References {");
+		v.clear();
+		v.addAll(references.keySet());
+		v.addAll(refIntArrays.keySet());
+		Collections.sort(v);
+		for (String s : v)
+			ret.append(s+"="+(references.containsKey(s)?references.get(s):refIntArrays.get(s))+", ");
+		if (v.size()>0) ret.delete(ret.length()-2, ret.length());
+		ret.append("}");
+		return ret.toString();
+//		return "Attributes "+attributes.toString()+"  References "+references.toString();
+	}
+
+	/**
+	 * Returns a String representation of this object, including its type, and
+	 * all attributes and references. Named such so as not to override
+	 * the default much shorter String representation
+	 * @return A string containing the type and all attributes, references information.
+	 */
+	public String description () { return shortType()+"  "+allFieldsValues(); }
+
+	/**
+	 * Clones this object and its attributes, but leave references blank.
+	 * @return
+	 */
+	private final XcasAnnotation prepareCopy () {
+		XcasAnnotation o = null;
+		try {
+			o = (XcasAnnotation)super.clone();
+			o.attributes = new Hashtable<String, String>();
+			o.attributes.putAll(attributes);
+			o.references = new Hashtable<String, MyVector>();
+			o.refIntArrays = new Hashtable<String, Vector<Integer>>();
+			for (String s : refIntArrays.keySet())
+				o.refIntArrays.put(s, new Vector<Integer>(refIntArrays.get(s)));
+		} catch (Exception e) { e.printStackTrace(); }
+		return o;
+	}
+
+	/**
+	 * Recursive, deep copy of this object, including attributes and references.
+	 */
+	public Object clone () {
+		XcasAnnotation o = prepareCopy();
+		for (String s : references.keySet())
+			o.references.put(s, (MyVector)references.get(s).clone());
+		return o;
+	}
+
+	/**
+	 * Clones this object, its attributes, and reference keys.
+	 * @return A shallow copy of this object.
+	 */
+	public final XcasAnnotation shallowCopy () {
+		XcasAnnotation o = prepareCopy();
+		for (String s : references.keySet())
+			o.references.put(s, new MyVector());
+		return o;
+	}
+
+	/**
+	 * Determines the order of this and the specified <code>XcasAnnotation</code>.
+	 * Note: It is strongly recommended that the use of this method be strictly
+	 * limited to the purpose of an orderly display of multiple objects.
+	 * To determine the equality of two objects, use {@link #equals(Object)}.
+	 * @see #equals(Object)
+	 */
+	public int compareTo(XcasAnnotation o) {
+		return description().compareTo(o.description());
+	}
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasDiff.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/PAD%20term%20spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasDiff.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasDiff.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/PAD term spotter/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasDiff.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed 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
- * 
+ * 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
@@ -21,199 +14,199 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.utils.xcas_comparison;
-import java.util.LinkedList;
-import java.util.Collections;
-import java.io.Writer;
-import java.io.BufferedWriter;
-import java.io.IOException;
-
-/**
- * An <code>XcasDiff</code> object represents the comparison results of
- * two XCAS files. It also provides methods to output these results.
- * @author Mayo Clinic
- *
- */
-public class XcasDiff {
-
-	private XcasFile f1, f2;
-	private LinkedList<XcasAnnotation> f1_uniq;
-	private LinkedList<XcasAnnotation> f2_uniq;
-	private LinkedList<XcasAnnotation> common;
-
-	/**
-	 * Default constructor.
-	 */
-	public XcasDiff () {
-		f1_uniq = new LinkedList<XcasAnnotation>();
-		f2_uniq = new LinkedList<XcasAnnotation>();
-		common = new LinkedList<XcasAnnotation>();
-	}
-
-	/**
-	 * Construct an <code>XCASDiff</code> object from two <code>XcasFile</code>
-	 * objects.
-	 * @param xf1 An <code>XcasFile</code> object.
-	 * @param xf2 Another <code>XcasFile</code> object.
-	 */
-	public XcasDiff (XcasFile xf1, XcasFile xf2) {
-		this();
-		f1 = xf1;
-		f2 = xf2;
-		recalculate();
-	}
-
-	/**
-	 * Calculates the differences or recalculates after the two files are updated.
-	 * Works on an copy of the original annotations. Original objects are not touched.
-	 * Must be called if the original XcasFile is modified elsewhere.
-	 */
-	public final void recalculate () {
-		f1_uniq.clear();
-		f2_uniq.clear();
-		common.clear();
-		LinkedList<XcasAnnotation> l1 = f1.annotationsClone();
-		LinkedList<XcasAnnotation> l2 = f2.annotationsClone();
-		for (XcasAnnotation a : l1) {
-			if (l2.contains(a)) { common.add(a); l2.remove(a); }
-			else f1_uniq.add(a);
-		}
-		f2_uniq.addAll(l2);
-		Collections.sort(f1_uniq);
-		Collections.sort(f2_uniq);
-		Collections.sort(common);
-	}
-
-	/**
-	 * Prints common elements along with their attributes in the two XCAS files
-	 * to <code>stdout</code>.
-	 */
-	public void printCommon () {
-		for (XcasAnnotation a : common)
-			System.out.println(a.description());
-	}
-
-	/**
-	 * Prints elements that are unique to each XCAS file to <code>stdout</code>.
-	 */
-	public void printDiff () {
-		try {
-			System.out.println("-------- Unique to "+f1.f.getCanonicalFile().toString()+" --------");
-			printUniq(1);
-			System.out.println("-------- Unique to "+f2.f.getCanonicalFile().toString()+" --------");
-			printUniq(2);
-		} catch (Exception e) { e.printStackTrace(); }
-	}
-
-	/**
-	 * Prints elements that are unique to XCAS file <code>i</code>.
-	 * @param i XCAS file number, specified when constructing this object,
-	 *          can only be 1 or 2.
-	 */
-	public void printUniq (int i) {
-		LinkedList<XcasAnnotation> toPrint;
-		XcasFile f;
-		if (i==1) { toPrint = f1_uniq; f = f1; }
-		else if (i==2) { toPrint = f2_uniq; f = f2; }
-		else { System.err.println("Not a legal file number: "+i); return; }
-		for (XcasAnnotation a : toPrint)
-			System.out.println(a.shortType()+" ~@"+f.getPositionOther(a)+"  "+(a.shortType().equals(Const.UIMA_SOFA)?Const.HIDDEN_TEXT:a.allFieldsValues()));
-	}
-
-	/**
-	 * Writes an HTML summary of the comparison of the two XCAS files.
-	 * @param w An {@link java.io.Writer} object to write to.
-	 */
-	public void printHTML (Writer w) {
-		BufferedWriter bw = new BufferedWriter(w);
-		try {
-			String fName1 = f1.f.getCanonicalFile().toString();
-			String fName2 = f2.f.getCanonicalFile().toString();
-			bw.write("<html>"); bw.newLine();
-			bw.write("  <head>"); bw.newLine();
-			bw.write("    <title>Comparison of "+fName1+" and "+fName2+"</title>"); bw.newLine();
-			bw.write("    <script language=\"javascript\">"); bw.newLine();
-			bw.write("      function toggle_agreements() {"); bw.newLine();
-			bw.write("        var ele = document.getElementById('xcasdiff');"); bw.newLine();
-			bw.write("        if ((ele.rows[1].style.display=='none')) {"); bw.newLine();
-			bw.write("          for (i=1;i<"+(common.size()+1)+";i++) ele.rows[i].style.display='';"); bw.newLine();
-			bw.write("        } else {"); bw.newLine();
-			bw.write("          for (i=1;i<"+(common.size()+1)+";i++) ele.rows[i].style.display='none';"); bw.newLine();
-			bw.write("        }"); bw.newLine();
-			bw.write("      }"); bw.newLine();
-			bw.write("    </script>"); bw.newLine();
-			bw.write("  </head>"); bw.newLine();
-			bw.write("<body>"); bw.newLine();
-			bw.write("<p><button onClick=\"toggle_agreements()\">Toggle Aggreements</button> Click this button to show or hide agreements.</p>"); bw.newLine();
-			bw.write("<p>Positions are <i>approximate</i> line and column numbers of the element in a file. Yellow background cells indicate a similar element in a file without an exact match. A \"null\" means no similar match found.</p>"); bw.newLine();
-			bw.write("<p>File 1: <a href=\"file://"+fName1+"\">"+fName1+"</a><br>"); bw.newLine();
-			bw.write("File 2: <a href=\"file://"+fName2+"\">"+fName2+"</a></p>"); bw.newLine();
-			bw.write("<p>Agreed on "+common.size()+" elements."); bw.newLine();
-			bw.write("File 1 has "+f1_uniq.size()+" unique elements, and file 2 has "+f2_uniq.size()+" unique elements.</p>"); bw.newLine();
-			bw.write("<table border=\"1\" id=\"xcasdiff\">"); bw.newLine();
-			bw.write("<tr>"); bw.newLine();
-			bw.write("<th></th>"); bw.newLine();
-			bw.write("<th>Element</th>"); bw.newLine();
-			bw.write("<th>Attributes</th>"); bw.newLine();
-			bw.write("<th>Position in File 1</th>"); bw.newLine();
-			bw.write("<th>Position in File 2</th>"); bw.newLine();
-			bw.write("</tr>"); bw.newLine();
-			int i = 0;
-			for (XcasAnnotation a : common) {
-				bw.write("<tr>"); bw.newLine();
-				if (i++==0) { bw.write("<th rowspan=\""+common.size()+"\">Agreements</th>"); bw.newLine(); }
-				bw.write("<td>"+a.shortType()+"</td>"); bw.newLine();
-				bw.write("<td>"+(a.type.equals(Const.UIMA_SOFA)?Const.HIDDEN_TEXT:a.allFieldsValues())+"</td>"); bw.newLine();
-				bw.write("<td>"+f1.getPositionOther(a)+"</td>"); bw.newLine();
-				bw.write("<td>"+f2.getPositionOther(a)+"</td>"); bw.newLine();
-			}
-			if (i>0) { bw.write("</tr>"); bw.newLine(); i=0; }
-			for (XcasAnnotation a : f1_uniq) {
-				bw.write("<tr>"); bw.newLine();
-				if (i++==0) { bw.write("<th rowspan=\""+(f1_uniq.size()+f2_uniq.size())+"\">Disagreements</th>"); bw.newLine(); }
-				bw.write("<td>"+a.shortType()+"</td>"); bw.newLine();
-				bw.write("<td>"+(a.type.equals(Const.UIMA_SOFA)?Const.HIDDEN_TEXT:a.allFieldsValues())+"</td>"); bw.newLine();
-				bw.write("<td>"+f1.getPositionOther(a)+"</td>"); bw.newLine();
-				bw.write("<td bgcolor=\"yellow\">"+f2.getPositionSimilar(a)+"</td>"); bw.newLine();
-			}
-			for (XcasAnnotation a : f2_uniq) {
-				bw.write("<tr>"); bw.newLine();
-				bw.write("<td>"+a.shortType()+"</td>"); bw.newLine();
-				bw.write("<td>"+(a.type.equals(Const.UIMA_SOFA)?Const.HIDDEN_TEXT:a.allFieldsValues())+"</td>"); bw.newLine();
-				bw.write("<td bgcolor=\"yellow\">"+f1.getPositionSimilar(a)+"</td>"); bw.newLine();
-				bw.write("<td>"+f2.getPositionOther(a)+"</td>"); bw.newLine();
-			}
-			if (i>0) { bw.write("</tr>"); bw.newLine(); }
-			bw.write("</table>"); bw.newLine();
-			bw.write("</body>"); bw.newLine();
-			bw.write("</html>"); bw.newLine();
-			bw.close();
-		} catch (IOException e) { e.printStackTrace(); }
-	}
-
-	/**
-	 * Prints elements that are unique to each XCAS file to <code>stdout</code>.
-	 * First constructs an anonymous <code>XcasDiff</code> object, and calls its
-	 * {@link #printDiff()}. Avoid using this method if you plan to use
-	 * <code>XcasDiff</code> object later.
-	 * @param f1 An <code>XcasFile</code> object.
-	 * @param f2 Another <code>XcasFile</code> object.
-	 * @see #printDiff()
-	 */
-	public static void printDiff (XcasFile f1, XcasFile f2) {
-		new XcasDiff(f1, f2).printDiff();
-	}
-
-	/**
-	 * Writes an HTML summary of the comparison of the two specified XCAS files.
-	 * First constructs an anonymous <code>XcasDiff</code> object, and calls its
-	 * {@link #printHTML(Writer)}. Avoid using this method if you plan to use
-	 * <code>XcasDiff</code> object later.
-	 * @param f1 An <code>XcasFile</code> object.
-	 * @param f2 Another <code>XcasFile</code> object.
-	 * @param w An {@link java.io.Writer} object to write to.
-	 */
-	public static void printHTML (XcasFile f1, XcasFile f2, Writer w) {
-		new XcasDiff(f1, f2).printHTML(w);
-	}
-}
+package edu.mayo.bmi.utils.xcas_comparison;
+import java.util.LinkedList;
+import java.util.Collections;
+import java.io.Writer;
+import java.io.BufferedWriter;
+import java.io.IOException;
+
+/**
+ * An <code>XcasDiff</code> object represents the comparison results of
+ * two XCAS files. It also provides methods to output these results.
+ * @author Mayo Clinic
+ *
+ */
+public class XcasDiff {
+
+	private XcasFile f1, f2;
+	private LinkedList<XcasAnnotation> f1_uniq;
+	private LinkedList<XcasAnnotation> f2_uniq;
+	private LinkedList<XcasAnnotation> common;
+
+	/**
+	 * Default constructor.
+	 */
+	public XcasDiff () {
+		f1_uniq = new LinkedList<XcasAnnotation>();
+		f2_uniq = new LinkedList<XcasAnnotation>();
+		common = new LinkedList<XcasAnnotation>();
+	}
+
+	/**
+	 * Construct an <code>XCASDiff</code> object from two <code>XcasFile</code>
+	 * objects.
+	 * @param xf1 An <code>XcasFile</code> object.
+	 * @param xf2 Another <code>XcasFile</code> object.
+	 */
+	public XcasDiff (XcasFile xf1, XcasFile xf2) {
+		this();
+		f1 = xf1;
+		f2 = xf2;
+		recalculate();
+	}
+
+	/**
+	 * Calculates the differences or recalculates after the two files are updated.
+	 * Works on an copy of the original annotations. Original objects are not touched.
+	 * Must be called if the original XcasFile is modified elsewhere.
+	 */
+	public final void recalculate () {
+		f1_uniq.clear();
+		f2_uniq.clear();
+		common.clear();
+		LinkedList<XcasAnnotation> l1 = f1.annotationsClone();
+		LinkedList<XcasAnnotation> l2 = f2.annotationsClone();
+		for (XcasAnnotation a : l1) {
+			if (l2.contains(a)) { common.add(a); l2.remove(a); }
+			else f1_uniq.add(a);
+		}
+		f2_uniq.addAll(l2);
+		Collections.sort(f1_uniq);
+		Collections.sort(f2_uniq);
+		Collections.sort(common);
+	}
+
+	/**
+	 * Prints common elements along with their attributes in the two XCAS files
+	 * to <code>stdout</code>.
+	 */
+	public void printCommon () {
+		for (XcasAnnotation a : common)
+			System.out.println(a.description());
+	}
+
+	/**
+	 * Prints elements that are unique to each XCAS file to <code>stdout</code>.
+	 */
+	public void printDiff () {
+		try {
+			System.out.println("-------- Unique to "+f1.f.getCanonicalFile().toString()+" --------");
+			printUniq(1);
+			System.out.println("-------- Unique to "+f2.f.getCanonicalFile().toString()+" --------");
+			printUniq(2);
+		} catch (Exception e) { e.printStackTrace(); }
+	}
+
+	/**
+	 * Prints elements that are unique to XCAS file <code>i</code>.
+	 * @param i XCAS file number, specified when constructing this object,
+	 *          can only be 1 or 2.
+	 */
+	public void printUniq (int i) {
+		LinkedList<XcasAnnotation> toPrint;
+		XcasFile f;
+		if (i==1) { toPrint = f1_uniq; f = f1; }
+		else if (i==2) { toPrint = f2_uniq; f = f2; }
+		else { System.err.println("Not a legal file number: "+i); return; }
+		for (XcasAnnotation a : toPrint)
+			System.out.println(a.shortType()+" ~@"+f.getPositionOther(a)+"  "+(a.shortType().equals(Const.UIMA_SOFA)?Const.HIDDEN_TEXT:a.allFieldsValues()));
+	}
+
+	/**
+	 * Writes an HTML summary of the comparison of the two XCAS files.
+	 * @param w An {@link java.io.Writer} object to write to.
+	 */
+	public void printHTML (Writer w) {
+		BufferedWriter bw = new BufferedWriter(w);
+		try {
+			String fName1 = f1.f.getCanonicalFile().toString();
+			String fName2 = f2.f.getCanonicalFile().toString();
+			bw.write("<html>"); bw.newLine();
+			bw.write("  <head>"); bw.newLine();
+			bw.write("    <title>Comparison of "+fName1+" and "+fName2+"</title>"); bw.newLine();
+			bw.write("    <script language=\"javascript\">"); bw.newLine();
+			bw.write("      function toggle_agreements() {"); bw.newLine();
+			bw.write("        var ele = document.getElementById('xcasdiff');"); bw.newLine();
+			bw.write("        if ((ele.rows[1].style.display=='none')) {"); bw.newLine();
+			bw.write("          for (i=1;i<"+(common.size()+1)+";i++) ele.rows[i].style.display='';"); bw.newLine();
+			bw.write("        } else {"); bw.newLine();
+			bw.write("          for (i=1;i<"+(common.size()+1)+";i++) ele.rows[i].style.display='none';"); bw.newLine();
+			bw.write("        }"); bw.newLine();
+			bw.write("      }"); bw.newLine();
+			bw.write("    </script>"); bw.newLine();
+			bw.write("  </head>"); bw.newLine();
+			bw.write("<body>"); bw.newLine();
+			bw.write("<p><button onClick=\"toggle_agreements()\">Toggle Aggreements</button> Click this button to show or hide agreements.</p>"); bw.newLine();
+			bw.write("<p>Positions are <i>approximate</i> line and column numbers of the element in a file. Yellow background cells indicate a similar element in a file without an exact match. A \"null\" means no similar match found.</p>"); bw.newLine();
+			bw.write("<p>File 1: <a href=\"file://"+fName1+"\">"+fName1+"</a><br>"); bw.newLine();
+			bw.write("File 2: <a href=\"file://"+fName2+"\">"+fName2+"</a></p>"); bw.newLine();
+			bw.write("<p>Agreed on "+common.size()+" elements."); bw.newLine();
+			bw.write("File 1 has "+f1_uniq.size()+" unique elements, and file 2 has "+f2_uniq.size()+" unique elements.</p>"); bw.newLine();
+			bw.write("<table border=\"1\" id=\"xcasdiff\">"); bw.newLine();
+			bw.write("<tr>"); bw.newLine();
+			bw.write("<th></th>"); bw.newLine();
+			bw.write("<th>Element</th>"); bw.newLine();
+			bw.write("<th>Attributes</th>"); bw.newLine();
+			bw.write("<th>Position in File 1</th>"); bw.newLine();
+			bw.write("<th>Position in File 2</th>"); bw.newLine();
+			bw.write("</tr>"); bw.newLine();
+			int i = 0;
+			for (XcasAnnotation a : common) {
+				bw.write("<tr>"); bw.newLine();
+				if (i++==0) { bw.write("<th rowspan=\""+common.size()+"\">Agreements</th>"); bw.newLine(); }
+				bw.write("<td>"+a.shortType()+"</td>"); bw.newLine();
+				bw.write("<td>"+(a.type.equals(Const.UIMA_SOFA)?Const.HIDDEN_TEXT:a.allFieldsValues())+"</td>"); bw.newLine();
+				bw.write("<td>"+f1.getPositionOther(a)+"</td>"); bw.newLine();
+				bw.write("<td>"+f2.getPositionOther(a)+"</td>"); bw.newLine();
+			}
+			if (i>0) { bw.write("</tr>"); bw.newLine(); i=0; }
+			for (XcasAnnotation a : f1_uniq) {
+				bw.write("<tr>"); bw.newLine();
+				if (i++==0) { bw.write("<th rowspan=\""+(f1_uniq.size()+f2_uniq.size())+"\">Disagreements</th>"); bw.newLine(); }
+				bw.write("<td>"+a.shortType()+"</td>"); bw.newLine();
+				bw.write("<td>"+(a.type.equals(Const.UIMA_SOFA)?Const.HIDDEN_TEXT:a.allFieldsValues())+"</td>"); bw.newLine();
+				bw.write("<td>"+f1.getPositionOther(a)+"</td>"); bw.newLine();
+				bw.write("<td bgcolor=\"yellow\">"+f2.getPositionSimilar(a)+"</td>"); bw.newLine();
+			}
+			for (XcasAnnotation a : f2_uniq) {
+				bw.write("<tr>"); bw.newLine();
+				bw.write("<td>"+a.shortType()+"</td>"); bw.newLine();
+				bw.write("<td>"+(a.type.equals(Const.UIMA_SOFA)?Const.HIDDEN_TEXT:a.allFieldsValues())+"</td>"); bw.newLine();
+				bw.write("<td bgcolor=\"yellow\">"+f1.getPositionSimilar(a)+"</td>"); bw.newLine();
+				bw.write("<td>"+f2.getPositionOther(a)+"</td>"); bw.newLine();
+			}
+			if (i>0) { bw.write("</tr>"); bw.newLine(); }
+			bw.write("</table>"); bw.newLine();
+			bw.write("</body>"); bw.newLine();
+			bw.write("</html>"); bw.newLine();
+			bw.close();
+		} catch (IOException e) { e.printStackTrace(); }
+	}
+
+	/**
+	 * Prints elements that are unique to each XCAS file to <code>stdout</code>.
+	 * First constructs an anonymous <code>XcasDiff</code> object, and calls its
+	 * {@link #printDiff()}. Avoid using this method if you plan to use
+	 * <code>XcasDiff</code> object later.
+	 * @param f1 An <code>XcasFile</code> object.
+	 * @param f2 Another <code>XcasFile</code> object.
+	 * @see #printDiff()
+	 */
+	public static void printDiff (XcasFile f1, XcasFile f2) {
+		new XcasDiff(f1, f2).printDiff();
+	}
+
+	/**
+	 * Writes an HTML summary of the comparison of the two specified XCAS files.
+	 * First constructs an anonymous <code>XcasDiff</code> object, and calls its
+	 * {@link #printHTML(Writer)}. Avoid using this method if you plan to use
+	 * <code>XcasDiff</code> object later.
+	 * @param f1 An <code>XcasFile</code> object.
+	 * @param f2 Another <code>XcasFile</code> object.
+	 * @param w An {@link java.io.Writer} object to write to.
+	 */
+	public static void printHTML (XcasFile f1, XcasFile f2, Writer w) {
+		new XcasDiff(f1, f2).printHTML(w);
+	}
+}