Source Code Cross Referenced for QSequenceDiscardingMediaBlock.java in  » Source-Control » tmatesoft-SVN » de » regnis » q » sequence » media » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Source Control » tmatesoft SVN » de.regnis.q.sequence.media 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ====================================================================
003:         * Copyright (c) 2004 Marc Strapetz, marc.strapetz@smartsvn.com. 
004:         * All rights reserved.
005:         *
006:         * This software is licensed as described in the file COPYING, which
007:         * you should have received as part of this distribution. Use is
008:         * subject to license terms.
009:         * ====================================================================
010:         */
011:
012:        package de.regnis.q.sequence.media;
013:
014:        import de.regnis.q.sequence.core.*;
015:
016:        /**
017:         * @author Marc Strapetz
018:         */
019:        public abstract class QSequenceDiscardingMediaBlock {
020:
021:            // Abstract ===============================================================
022:
023:            protected abstract int[] getAllSymbols(QSequenceIntMedia media);
024:
025:            // Fields =================================================================
026:
027:            private final QSequenceIntMedia media;
028:            private final int[] undiscardedSymbols;
029:            private final int[] undiscardedIndices;
030:
031:            private int undiscardedSymbolCount;
032:
033:            // Setup ==================================================================
034:
035:            protected QSequenceDiscardingMediaBlock(QSequenceIntMedia media) {
036:                this .media = media;
037:                this .undiscardedSymbols = new int[getAllSymbols(media).length];
038:                this .undiscardedIndices = new int[getAllSymbols(media).length];
039:                this .undiscardedSymbolCount = 0;
040:            }
041:
042:            // Accessing ==============================================================
043:
044:            public int getUndiscardedSymbolCount() {
045:                return undiscardedSymbolCount;
046:            }
047:
048:            public int[] getUndiscardedSymbols() {
049:                return undiscardedSymbols;
050:            }
051:
052:            public int getMediaIndex(int index) {
053:                return undiscardedIndices[index];
054:            }
055:
056:            public void init(QSequenceDiscardingMediaBlock thatBlock,
057:                    QSequenceDiscardingMediaConfusionDetector confusionDetector) {
058:                QSequenceAssert.assertNotNull(confusionDetector);
059:
060:                // Set up table of which lines are going to be discarded.
061:                final int[] this AllSymbols = getAllSymbols(media);
062:                final int[] thatAllSymbols = thatBlock.getAllSymbols(media);
063:                final int[] otherEquivalences = createEquivalences(
064:                        thatAllSymbols, media);
065:                final byte[] discardableMarkers = createDiscardableMarkers(
066:                        this AllSymbols, otherEquivalences, confusionDetector);
067:
068:                // Don't really discard the provisional lines except when they occur
069:                // in a run of discardables, with nonprovisionals at the beginning
070:                // and end.
071:                //		filterDiscardableMarkers(allSymbols, discardableMarkers);
072:
073:                for (int index = 0; index < this AllSymbols.length; ++index) {
074:                    if (discardableMarkers[index] != 1) {
075:                        undiscardedSymbols[undiscardedSymbolCount] = this AllSymbols[index];
076:                        undiscardedIndices[undiscardedSymbolCount] = index;
077:                        undiscardedSymbolCount++;
078:                    }
079:                }
080:            }
081:
082:            // Utils ==================================================================
083:
084:            private static int[] createEquivalences(int[] symbols,
085:                    QSequenceIntMedia media) {
086:                final int[] equivalences = new int[media.getSymbolCount()];
087:                for (int index = 0; index < symbols.length; index++) {
088:                    equivalences[symbols[index]]++;
089:                }
090:                return equivalences;
091:            }
092:
093:            private static byte[] createDiscardableMarkers(int[] symbols,
094:                    int[] otherEquivalences,
095:                    QSequenceDiscardingMediaConfusionDetector confusionDetector) {
096:                final byte[] discardableMarkers = new byte[symbols.length];
097:                confusionDetector.init(symbols.length);
098:
099:                for (int index = 0; index < symbols.length; index++) {
100:                    final int occurences = otherEquivalences[symbols[index]];
101:                    if (confusionDetector.isAbsolute(occurences)) {
102:                        discardableMarkers[index] = 1;
103:                    } else if (confusionDetector.isProvisional(occurences)) {
104:                        discardableMarkers[index] = 2;
105:                    }
106:                }
107:
108:                return discardableMarkers;
109:            }
110:
111:            // --Commented out by Inspection START (17.06.04 15:17):
112:            //	private static void filterDiscardableMarkers(int[] symbols, byte[] discardableMarkers) {
113:            //		for (int i = 0; i < symbols.length; i++) {
114:            //			// Cancel provisional discards not in middle of run of discards.
115:            //			if (discardableMarkers[i] == 2) {
116:            //				discardableMarkers[i] = 0;
117:            //			}
118:            //			else if (discardableMarkers[i] != 0) {
119:            //				// We have found a nonprovisional discard.
120:            //				int j;
121:            //				final int length;
122:            //				int provisional = 0;
123:            //
124:            //				// Find end of this run of discardable lines.
125:            //				// Count how many are provisionally discardable.
126:            //				for (j = i; j < symbols.length; j++) {
127:            //					if (discardableMarkers[j] == 0) {
128:            //						break;
129:            //					}
130:            //					if (discardableMarkers[j] == 2) {
131:            //						provisional++;
132:            //					}
133:            //				}
134:            //
135:            //				// Cancel provisional discards at end, and shrink the run.
136:            //				while (j > i && discardableMarkers[j - 1] == 2) {
137:            //					discardableMarkers[--j] = 0;
138:            //					provisional--;
139:            //				}
140:            //
141:            //				// Now we have the length of a run of discardable lines
142:            //				// whose first and last are not provisional.
143:            //				length = j - i;
144:            //
145:            //				// If 1/4 of the lines in the run are provisional,
146:            //				// cancel discarding of all provisional lines in the run.
147:            //				if (provisional * 4 > length) {
148:            //					while (j > i) {
149:            //						if (discardableMarkers[--j] == 2) {
150:            //							discardableMarkers[j] = 0;
151:            //						}
152:            //					}
153:            //				}
154:            //				else {
155:            //					int consec;
156:            //					int minimum = 1;
157:            //					int tem = length / 4;
158:            //
159:            //					// MINIMUM is approximate square root of LENGTH/4.
160:            //					// A subrun of two or more provisionals can stand
161:            //					// when LENGTH is at least 16.
162:            //					// A subrun of 4 or more can stand when LENGTH >= 64.
163:            //					while ((tem >>= 2) > 0) {
164:            //						minimum *= 2;
165:            //					}
166:            //					minimum++;
167:            //
168:            //					// Cancel any subrun of MINIMUM or more provisionals
169:            //					// within the larger run.
170:            //					for (j = 0, consec = 0; j < length; j++) {
171:            //						if (discardableMarkers[i + j] != 2) {
172:            //							consec = 0;
173:            //						}
174:            //						else if (minimum == ++consec) {
175:            //							// Back up to start of subrun, to cancel it all.
176:            //							j -= consec;
177:            //						}
178:            //						else if (minimum < consec) {
179:            //							discardableMarkers[i + j] = 0;
180:            //						}
181:            //					}
182:            //
183:            //					// Scan from beginning of run
184:            //					// until we find 3 or more nonprovisionals in a row
185:            //					// or until the first nonprovisional at least 8 lines in.
186:            //					// Until that point, cancel any provisionals.
187:            //					for (j = 0, consec = 0; j < length; j++) {
188:            //						if (j >= 8 && discardableMarkers[i + j] == 1) {
189:            //							break;
190:            //						}
191:            //						if (discardableMarkers[i + j] == 2) {
192:            //							consec = 0;
193:            //							discardableMarkers[i + j] = 0;
194:            //						}
195:            //						else if (discardableMarkers[i + j] == 0) {
196:            //							consec = 0;
197:            //						}
198:            //						else {
199:            //							consec++;
200:            //						}
201:            //						if (consec == 3) {
202:            //							break;
203:            //						}
204:            //					}
205:            //
206:            //					// I advances to the last line of the run.
207:            //					i += length - 1;
208:            //
209:            //					// Same thing, from end.
210:            //					for (j = 0, consec = 0; j < length; j++) {
211:            //						if (j >= 8 && discardableMarkers[i - j] == 1) {
212:            //							break;
213:            //						}
214:            //						if (discardableMarkers[i - j] == 2) {
215:            //							consec = 0;
216:            //							discardableMarkers[i - j] = 0;
217:            //						}
218:            //						else if (discardableMarkers[i - j] == 0) {
219:            //							consec = 0;
220:            //						}
221:            //						else {
222:            //							consec++;
223:            //						}
224:            //						if (consec == 3) {
225:            //							break;
226:            //						}
227:            //					}
228:            //				}
229:            //			}
230:            //		}
231:            //	}
232:            // --Commented out by Inspection STOP (17.06.04 15:17)
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.