incubator-ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From james-mas...@apache.org
Subject svn commit: r1403989 [27/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/parse...
Date Wed, 31 Oct 2012 05:26:55 GMT
Modified: incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/Compare.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/Compare.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/Compare.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/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/utils/src/edu/mayo/bmi/utils/xcas_comparison/Const.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/Const.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/Const.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/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/utils/src/edu/mayo/bmi/utils/xcas_comparison/ConvertAndCompare.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/ConvertAndCompare.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/ConvertAndCompare.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/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/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasAnnotation.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasAnnotation.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasAnnotation.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/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/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasDiff.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasDiff.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasDiff.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/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);
+	}
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasFile.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasFile.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasFile.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/utils/src/edu/mayo/bmi/utils/xcas_comparison/XcasFile.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,227 +14,227 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.utils.xcas_comparison;
-import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.Vector;
-import java.io.File;
-
-/**
- * An <code>XcasFile</code> wraps all <code>XcasAnnotations</code>s
- * in it and also contains their position information in terms of
- * line and column numbers.
- * @author Mayo Clinic
- *
- */
-public class XcasFile implements Cloneable {
-
-	protected File f;
-	protected Hashtable<Integer, XcasAnnotation> annotations;
-	protected Hashtable<XcasAnnotation, String> positions;
-
-	/**
-	 * Default constructor.
-	 */
-	public XcasFile () {
-		annotations = new Hashtable<Integer, XcasAnnotation>();
-		positions = new Hashtable<XcasAnnotation, String>();
-	}
-
-	/**
-	 * Constructs an <code>XcasFile</code> with the specified name.
-	 * @param f File name.
-	 */
-	public XcasFile (String f) { this(); this.f = new File(f); }
-
-	/**
-	 * Constructs an <code>XcasFile</code> with the specified name.
-	 * @param f A File object.
-	 */
-	public XcasFile (File f) { this(); this.f = f; }
-
-	/**
-	 * Creates a new <code>XcasFile</code> object from the specified file.
-	 * Avoid using this method if you plan to parse multiple files,
-	 * as this method creates an anonymous <code>XcasProcessor</code> instance
-	 * each time called, which could be used to parse multiple files.
-	 * @param f A string containing the XCAS file name.
-	 * @return A parsed <code>XcasFile</code> object.
-	 */
-	public static XcasFile process (String f) {
-		return (new XcasProcessor()).process(f);
-	}
-
-	/**
-	 * Inserts a new annotation with the specified internal <code>id</code>
-	 * to this <code>XcasFile</code>.
-	 * @param id UIMA CAS internal <code>_id</code>.
-	 * @param a An <code>XcasAnnotation</code> object to add.
-	 * @see #addAnnotation(int, XcasAnnotation, String)
-	 * @see #addAnnotation(int, XcasAnnotation, int, int)
-	 */
-	public void addAnnotation (int id, XcasAnnotation a) { annotations.put(id, a); }
-
-	/**
-	 * Inserts a new annotation, along with its position in the file,
-	 * to this <code>XcasFile</code> object.
-	 * @param id UIMA CAS internal <code>_id</code>.
-	 * @param a An <code>XcasAnnotation</code> object to add.
-	 * @param pos Line and column number of the specified annotation,
-	 *        in the form of <code>line_number:column_number</code>.
-	 */
-	public void addAnnotation (int id, XcasAnnotation a, String pos) { addAnnotation(id, a); positions.put(a, pos); }
-
-	/**
-	 * Inserts a new annotation, along with its position in the file,
-	 * to this <code>XcasFile</code> object.
-	 * @param id UIMA CAS internal <code>_id</code>.
-	 * @param a An <code>XcasAnnotation</code> object to add.
-	 * @param lineNum Line number of the specified annotation.
-	 * @param colNum Column number of the specified annotation.
-	 */
-	public void addAnnotation (int id, XcasAnnotation a, int lineNum, int colNum) { addAnnotation(id, a, Integer.toString(lineNum)+":"+Integer.toString(colNum)); }
-
-	/**
-	 * Returns the <code>XcasAnnotation</code> object associated with
-	 * the specified internal id.
-	 * @param id UIMA CAS internal <code>_id</code>.
-	 * @return The <code>XcasAnnotation</code> with the specified id.
-	 */
-	public XcasAnnotation getAnnotation (int id) { return annotations.get(id); }
-
-	public java.util.Collection<XcasAnnotation> getAllAnnotations () { return annotations.values(); }
-	public String getFileName () { return f.getName(); }
-
-	/**
-	 * Returns the line and column numbers of the specified <code>XcasAnnotation</code>,
-	 * which is included in this <code>XcasFile</code> object.
-	 * @param a
-	 * @return A string containing the line and column numbers of the specified object,
-	 *         in the form of <code>line_number:column_number</code>.
-	 * @see #getPositionOwn(int)
-	 * @see #getPositionOther(XcasAnnotation)
-	 */
-	public String getPositionOwn (XcasAnnotation a) { return positions.get(a); }
-
-	/**
-	 * Returns the line and column numbers of the <code>XcasAnnotation</code>,
-	 * specified by the original XCAS internal <code>_id</code> field.
-	 * @param id UIMA CAS internal <code>_id</code>.
-	 * @return A string containing the line and column numbers of the specified object,
-	 *         in the form of <code>line_number:column_number</code>.
-	 * @see #getPositionOwn(XcasAnnotation)
-	 * @see #getPositionOther(XcasAnnotation)
-	 */
-	public String getPositionOwn (int id) { return positions.get(annotations.get(id)); }
-
-	/**
-	 * Finds an <code>XcasAnnotation</code> with the same attributes as specified,
-	 * and returns its line and column numbers. 
-	 * @param a
-	 * @return A string containing the line and column numbers of the specified object,
-	 *         in the form of <code>line_number:column_number</code>.
-	 * @see #getPositionOwn(int)
-	 * @see #getPositionOwn(XcasAnnotation)
-	 */
-	public String getPositionOther (XcasAnnotation a) {
-		for (XcasAnnotation o : positions.keySet())
-			if (o.equals(a)) return positions.get(o);
-		return null;
-	}
-
-	/**
-	 * Returns the line and column numbers of the specified <code>XcasAnnotation</code>.
-	 * <p>
-	 * Do not use this method if you know the specified <code>XcasAnnotation</code>
-	 * object is in this <code>XcasFile</code>. Instead, use
-	 * {@link #getPositionOwn(XcasAnnotation)}, which is faster.
-	 * @param a An 
-	 * @return A string containing the line and column numbers of the specified object,
-	 *         in the form of <code>line_number:column_number</code>.
-	 * @see #getPositionOwn(XcasAnnotation)
-	 * @see #getPositionOther(XcasAnnotation)
-	 */
-	public String getPosition (XcasAnnotation a) {
-		if (positions.keySet().contains(a)) return positions.get(a);
-		else return getPositionOther(a);
-	}
-
-	/**
-	 * Finds an <code>XcasAnnotation</code> of the same type as specified, and
-	 * a same text span, then returns its line and column number.
-	 * @param a An <code>XcasAnnotation</code> against which a similar
-	 *          <code>XcasAnnotation</code> in this <code>XcasFile</code>
-	 *          is to be matched.
-	 * @return A string containing the line and column numbers of the specified object,
-	 *         in the form of <code>line_number:column_number</code>.
-	 * @see #getPositionOther(XcasAnnotation)
-	 */
-	public String getPositionSimilar (XcasAnnotation a) {
-		for (XcasAnnotation o : positions.keySet())
-			if (o.type.equals(a.type)) {
-				int oBegin = o.attributes.containsKey("begin") ? Integer.parseInt(o.getAttribute("begin")) : -1;
-				int oEnd = o.attributes.containsKey("end") ? Integer.parseInt(o.getAttribute("end")) : -1;
-				int aBegin = a.attributes.containsKey("begin") ? Integer.parseInt(a.getAttribute("begin")) : -2;
-				int aEnd = a.attributes.containsKey("end") ? Integer.parseInt(a.getAttribute("end")) : -2;
-				if (oBegin==aBegin && oEnd==aEnd) return positions.get(o);
-				else if (o.attributes.containsKey("key") && a.attributes.containsKey("key") && o.getAttribute("key").equals(a.getAttribute("key")))
-					return positions.get(o);
-			}
-		return null;
-	}
-
-	/**
-	 * Checks whether this XCAS file has an annotation with the specified id.
-	 * @param id UIMA CAS internal <code>_id</code>.
-	 * @return <code>true</code> if file has an annotation with the specified id,
-	 *         <code>false</code> otherwise.
-	 */
-	public boolean hasAnnotation (int id) { return annotations.containsKey(id); }
-
-	/**
-	 * Checks whether this XCAS file has the specified <code>XcasAnnotation</code>.
-	 * If there is an <code>XcasAnnotation</code> object that has exactly the same
-	 * type, attributes, and references, return <code>true</code>.
-	 * @param a An <code>XcasAnnotation</code> to check.
-	 * @return <code>true</code> if there is one <code>XcasAnnotation</code> equals
-	 *         the specified one, <code>false</code> otherwise.
-	 * @see XcasAnnotation#equals(Object)
-	 */
-	public boolean hasAnnotation (XcasAnnotation a) { return annotations.containsValue(a); }
-
-	/**
-	 * Checks whether the specified object has the same set of annotations. First check
-	 * whether the specified is an <code>XcasFile</code> object. If so, check whether
-	 * its annotation set is of the same size as in this <code>XcasFile</code>, then check
-	 * whether these two sets are equal. 
-	 * @param obj An object to compare to.
-	 * @return <code>true if the specified object is an <code>XcasFile</code> object and
-	 *         has a same set of <code>XcasAnnotations</code>, <code>false</code> otherwise.
-	 */
-	public boolean equals (Object obj) {
-		if (obj.getClass()!=getClass() || annotations.values().size()!=((XcasFile)obj).annotations.values().size()) return false;
-		return annotations.values().containsAll(((XcasFile)obj).annotations.values());
-	}
-
-	public LinkedList<XcasAnnotation> annotationsClone () {
-		LinkedList<XcasAnnotation> ret = new LinkedList<XcasAnnotation>();
-		Hashtable<XcasAnnotation, XcasAnnotation> cloneMap = new Hashtable<XcasAnnotation, XcasAnnotation>();
-		for (XcasAnnotation a : annotations.values()) {
-			XcasAnnotation c = a.shallowCopy();
-			cloneMap.put(a, c);
-			ret.add(c);
-		}
-		for (XcasAnnotation a : annotations.values())
-			for (String s : a.references.keySet())
-				for (XcasAnnotation r : (Vector<XcasAnnotation>)a.references.get(s))
-					((Vector<XcasAnnotation>)cloneMap.get(a).references.get(s)).add(cloneMap.get(r));
-		return ret;
-	}
-
-	public Object clone () {
-		return null; //TODO implement clone?
-		// Should not use XcasAnnotation.clone()
-		// otherwise, XcasAnnotation objects referenced by multiple objects will be cloned more than once.
-	}
-}
+package edu.mayo.bmi.utils.xcas_comparison;
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.Vector;
+import java.io.File;
+
+/**
+ * An <code>XcasFile</code> wraps all <code>XcasAnnotations</code>s
+ * in it and also contains their position information in terms of
+ * line and column numbers.
+ * @author Mayo Clinic
+ *
+ */
+public class XcasFile implements Cloneable {
+
+	protected File f;
+	protected Hashtable<Integer, XcasAnnotation> annotations;
+	protected Hashtable<XcasAnnotation, String> positions;
+
+	/**
+	 * Default constructor.
+	 */
+	public XcasFile () {
+		annotations = new Hashtable<Integer, XcasAnnotation>();
+		positions = new Hashtable<XcasAnnotation, String>();
+	}
+
+	/**
+	 * Constructs an <code>XcasFile</code> with the specified name.
+	 * @param f File name.
+	 */
+	public XcasFile (String f) { this(); this.f = new File(f); }
+
+	/**
+	 * Constructs an <code>XcasFile</code> with the specified name.
+	 * @param f A File object.
+	 */
+	public XcasFile (File f) { this(); this.f = f; }
+
+	/**
+	 * Creates a new <code>XcasFile</code> object from the specified file.
+	 * Avoid using this method if you plan to parse multiple files,
+	 * as this method creates an anonymous <code>XcasProcessor</code> instance
+	 * each time called, which could be used to parse multiple files.
+	 * @param f A string containing the XCAS file name.
+	 * @return A parsed <code>XcasFile</code> object.
+	 */
+	public static XcasFile process (String f) {
+		return (new XcasProcessor()).process(f);
+	}
+
+	/**
+	 * Inserts a new annotation with the specified internal <code>id</code>
+	 * to this <code>XcasFile</code>.
+	 * @param id UIMA CAS internal <code>_id</code>.
+	 * @param a An <code>XcasAnnotation</code> object to add.
+	 * @see #addAnnotation(int, XcasAnnotation, String)
+	 * @see #addAnnotation(int, XcasAnnotation, int, int)
+	 */
+	public void addAnnotation (int id, XcasAnnotation a) { annotations.put(id, a); }
+
+	/**
+	 * Inserts a new annotation, along with its position in the file,
+	 * to this <code>XcasFile</code> object.
+	 * @param id UIMA CAS internal <code>_id</code>.
+	 * @param a An <code>XcasAnnotation</code> object to add.
+	 * @param pos Line and column number of the specified annotation,
+	 *        in the form of <code>line_number:column_number</code>.
+	 */
+	public void addAnnotation (int id, XcasAnnotation a, String pos) { addAnnotation(id, a); positions.put(a, pos); }
+
+	/**
+	 * Inserts a new annotation, along with its position in the file,
+	 * to this <code>XcasFile</code> object.
+	 * @param id UIMA CAS internal <code>_id</code>.
+	 * @param a An <code>XcasAnnotation</code> object to add.
+	 * @param lineNum Line number of the specified annotation.
+	 * @param colNum Column number of the specified annotation.
+	 */
+	public void addAnnotation (int id, XcasAnnotation a, int lineNum, int colNum) { addAnnotation(id, a, Integer.toString(lineNum)+":"+Integer.toString(colNum)); }
+
+	/**
+	 * Returns the <code>XcasAnnotation</code> object associated with
+	 * the specified internal id.
+	 * @param id UIMA CAS internal <code>_id</code>.
+	 * @return The <code>XcasAnnotation</code> with the specified id.
+	 */
+	public XcasAnnotation getAnnotation (int id) { return annotations.get(id); }
+
+	public java.util.Collection<XcasAnnotation> getAllAnnotations () { return annotations.values(); }
+	public String getFileName () { return f.getName(); }
+
+	/**
+	 * Returns the line and column numbers of the specified <code>XcasAnnotation</code>,
+	 * which is included in this <code>XcasFile</code> object.
+	 * @param a
+	 * @return A string containing the line and column numbers of the specified object,
+	 *         in the form of <code>line_number:column_number</code>.
+	 * @see #getPositionOwn(int)
+	 * @see #getPositionOther(XcasAnnotation)
+	 */
+	public String getPositionOwn (XcasAnnotation a) { return positions.get(a); }
+
+	/**
+	 * Returns the line and column numbers of the <code>XcasAnnotation</code>,
+	 * specified by the original XCAS internal <code>_id</code> field.
+	 * @param id UIMA CAS internal <code>_id</code>.
+	 * @return A string containing the line and column numbers of the specified object,
+	 *         in the form of <code>line_number:column_number</code>.
+	 * @see #getPositionOwn(XcasAnnotation)
+	 * @see #getPositionOther(XcasAnnotation)
+	 */
+	public String getPositionOwn (int id) { return positions.get(annotations.get(id)); }
+
+	/**
+	 * Finds an <code>XcasAnnotation</code> with the same attributes as specified,
+	 * and returns its line and column numbers. 
+	 * @param a
+	 * @return A string containing the line and column numbers of the specified object,
+	 *         in the form of <code>line_number:column_number</code>.
+	 * @see #getPositionOwn(int)
+	 * @see #getPositionOwn(XcasAnnotation)
+	 */
+	public String getPositionOther (XcasAnnotation a) {
+		for (XcasAnnotation o : positions.keySet())
+			if (o.equals(a)) return positions.get(o);
+		return null;
+	}
+
+	/**
+	 * Returns the line and column numbers of the specified <code>XcasAnnotation</code>.
+	 * <p>
+	 * Do not use this method if you know the specified <code>XcasAnnotation</code>
+	 * object is in this <code>XcasFile</code>. Instead, use
+	 * {@link #getPositionOwn(XcasAnnotation)}, which is faster.
+	 * @param a An 
+	 * @return A string containing the line and column numbers of the specified object,
+	 *         in the form of <code>line_number:column_number</code>.
+	 * @see #getPositionOwn(XcasAnnotation)
+	 * @see #getPositionOther(XcasAnnotation)
+	 */
+	public String getPosition (XcasAnnotation a) {
+		if (positions.keySet().contains(a)) return positions.get(a);
+		else return getPositionOther(a);
+	}
+
+	/**
+	 * Finds an <code>XcasAnnotation</code> of the same type as specified, and
+	 * a same text span, then returns its line and column number.
+	 * @param a An <code>XcasAnnotation</code> against which a similar
+	 *          <code>XcasAnnotation</code> in this <code>XcasFile</code>
+	 *          is to be matched.
+	 * @return A string containing the line and column numbers of the specified object,
+	 *         in the form of <code>line_number:column_number</code>.
+	 * @see #getPositionOther(XcasAnnotation)
+	 */
+	public String getPositionSimilar (XcasAnnotation a) {
+		for (XcasAnnotation o : positions.keySet())
+			if (o.type.equals(a.type)) {
+				int oBegin = o.attributes.containsKey("begin") ? Integer.parseInt(o.getAttribute("begin")) : -1;
+				int oEnd = o.attributes.containsKey("end") ? Integer.parseInt(o.getAttribute("end")) : -1;
+				int aBegin = a.attributes.containsKey("begin") ? Integer.parseInt(a.getAttribute("begin")) : -2;
+				int aEnd = a.attributes.containsKey("end") ? Integer.parseInt(a.getAttribute("end")) : -2;
+				if (oBegin==aBegin && oEnd==aEnd) return positions.get(o);
+				else if (o.attributes.containsKey("key") && a.attributes.containsKey("key") && o.getAttribute("key").equals(a.getAttribute("key")))
+					return positions.get(o);
+			}
+		return null;
+	}
+
+	/**
+	 * Checks whether this XCAS file has an annotation with the specified id.
+	 * @param id UIMA CAS internal <code>_id</code>.
+	 * @return <code>true</code> if file has an annotation with the specified id,
+	 *         <code>false</code> otherwise.
+	 */
+	public boolean hasAnnotation (int id) { return annotations.containsKey(id); }
+
+	/**
+	 * Checks whether this XCAS file has the specified <code>XcasAnnotation</code>.
+	 * If there is an <code>XcasAnnotation</code> object that has exactly the same
+	 * type, attributes, and references, return <code>true</code>.
+	 * @param a An <code>XcasAnnotation</code> to check.
+	 * @return <code>true</code> if there is one <code>XcasAnnotation</code> equals
+	 *         the specified one, <code>false</code> otherwise.
+	 * @see XcasAnnotation#equals(Object)
+	 */
+	public boolean hasAnnotation (XcasAnnotation a) { return annotations.containsValue(a); }
+
+	/**
+	 * Checks whether the specified object has the same set of annotations. First check
+	 * whether the specified is an <code>XcasFile</code> object. If so, check whether
+	 * its annotation set is of the same size as in this <code>XcasFile</code>, then check
+	 * whether these two sets are equal. 
+	 * @param obj An object to compare to.
+	 * @return <code>true if the specified object is an <code>XcasFile</code> object and
+	 *         has a same set of <code>XcasAnnotations</code>, <code>false</code> otherwise.
+	 */
+	public boolean equals (Object obj) {
+		if (obj.getClass()!=getClass() || annotations.values().size()!=((XcasFile)obj).annotations.values().size()) return false;
+		return annotations.values().containsAll(((XcasFile)obj).annotations.values());
+	}
+
+	public LinkedList<XcasAnnotation> annotationsClone () {
+		LinkedList<XcasAnnotation> ret = new LinkedList<XcasAnnotation>();
+		Hashtable<XcasAnnotation, XcasAnnotation> cloneMap = new Hashtable<XcasAnnotation, XcasAnnotation>();
+		for (XcasAnnotation a : annotations.values()) {
+			XcasAnnotation c = a.shallowCopy();
+			cloneMap.put(a, c);
+			ret.add(c);
+		}
+		for (XcasAnnotation a : annotations.values())
+			for (String s : a.references.keySet())
+				for (XcasAnnotation r : (Vector<XcasAnnotation>)a.references.get(s))
+					((Vector<XcasAnnotation>)cloneMap.get(a).references.get(s)).add(cloneMap.get(r));
+		return ret;
+	}
+
+	public Object clone () {
+		return null; //TODO implement clone?
+		// Should not use XcasAnnotation.clone()
+		// otherwise, XcasAnnotation objects referenced by multiple objects will be cloned more than once.
+	}
+}



Mime
View raw message