| Nils Diewald | 2cd1c3d | 2014-01-08 22:53:08 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.index; |
| 2 | |
| 3 | import java.util.*; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 4 | import java.nio.ByteBuffer; |
| Nils Diewald | cde6908 | 2014-01-16 15:46:48 +0000 | [diff] [blame] | 5 | import java.lang.StringBuffer; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 6 | import java.util.regex.*; |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 7 | import de.ids_mannheim.korap.response.Match; |
| Nils Diewald | 2cd1c3d | 2014-01-08 22:53:08 +0000 | [diff] [blame] | 8 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 9 | import org.slf4j.Logger; |
| 10 | import org.slf4j.LoggerFactory; |
| Nils Diewald | 2cd1c3d | 2014-01-08 22:53:08 +0000 | [diff] [blame] | 11 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 12 | public class TermInfo implements Comparable<TermInfo> { |
| 13 | |
| 14 | // Logger |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 15 | private final static Logger log = LoggerFactory.getLogger(Match.class); |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 16 | // This advices the java compiler to ignore all loggings |
| 17 | public static final boolean DEBUG = false; |
| 18 | |
| Akron | 6d2c469 | 2016-02-03 18:29:10 +0100 | [diff] [blame] | 19 | // TODO: Support various terms - including relations! |
| 20 | |
| Nils Diewald | cde6908 | 2014-01-16 15:46:48 +0000 | [diff] [blame] | 21 | private String foundry, layer, value, term, type, annotation; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 22 | // type can be "term", "pos", "span", "rel-src", "rel-target" |
| 23 | |
| Nils Diewald | 2cd1c3d | 2014-01-08 22:53:08 +0000 | [diff] [blame] | 24 | private int pos = 0; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 25 | private ByteBuffer payload; |
| 26 | private boolean analyzed = false; |
| Nils Diewald | 2cd1c3d | 2014-01-08 22:53:08 +0000 | [diff] [blame] | 27 | |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 28 | private int |
| 29 | startChar = -1, // character offset for start of span |
| 30 | endChar = -1, // character offset for end of span |
| 31 | startPos = -1, // start position of source |
| 32 | endPos = -1, // end position of source |
| 33 | targetStartPos = -1, // start position of target |
| 34 | targetEndPos = -1; // end position of target |
| Nils Diewald | 2cd1c3d | 2014-01-08 22:53:08 +0000 | [diff] [blame] | 35 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 36 | private byte depth = (byte) 0; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 37 | |
| 38 | private Pattern prefixRegex = Pattern |
| Akron | 4299355 | 2016-02-04 13:24:24 +0100 | [diff] [blame] | 39 | .compile("(?:([^/]+)/)?([^:/]+)(?::(.+?))?"); |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 40 | private Matcher matcher; |
| 41 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 42 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 43 | public TermInfo (String term, int pos, ByteBuffer payload) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 44 | this.term = term; |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 45 | this.startPos = pos; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 46 | this.endPos = pos; |
| 47 | this.payload = payload; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| Akron | 13db615 | 2016-02-19 14:08:38 +0100 | [diff] [blame] | 50 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 51 | public TermInfo analyze () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 52 | if (analyzed) |
| 53 | return this; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 54 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 55 | int ttype = 0; |
| 56 | String tterm = this.term; |
| 57 | int lastPos = this.payload.position(); |
| 58 | this.payload.rewind(); |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 59 | |
| Akron | 6d2c469 | 2016-02-03 18:29:10 +0100 | [diff] [blame] | 60 | // TODO: Use PTI! |
| Akron | b35261a | 2016-02-10 20:24:24 +0100 | [diff] [blame] | 61 | // Add TUI and REF! |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 62 | switch (tterm.charAt(0)) { |
| Akron | 4299355 | 2016-02-04 13:24:24 +0100 | [diff] [blame] | 63 | case '<': |
| 64 | // "<>:mate/l:..." |
| 65 | if (tterm.charAt(1) == '>') { |
| 66 | // span |
| 67 | this.type = "span"; |
| 68 | tterm = tterm.substring(3); |
| 69 | ttype = 2; |
| 70 | } |
| 71 | // rel-target |
| 72 | else { |
| 73 | this.type = "relTarget"; |
| 74 | tterm = tterm.substring(2); |
| 75 | ttype = 3; |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 76 | }; |
| Akron | 4299355 | 2016-02-04 13:24:24 +0100 | [diff] [blame] | 77 | break; |
| 78 | |
| 79 | case '>': |
| 80 | // rel-src |
| 81 | this.type = "relSrc"; |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 82 | tterm = tterm.substring(2); |
| 83 | ttype = 3; |
| Akron | 4299355 | 2016-02-04 13:24:24 +0100 | [diff] [blame] | 84 | break; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 85 | |
| Akron | 13db615 | 2016-02-19 14:08:38 +0100 | [diff] [blame] | 86 | case '_': |
| 87 | // pos |
| 88 | this.type = "pos"; |
| 89 | ttype = 1; |
| 90 | tterm = tterm.substring(1); |
| 91 | break; |
| Akron | b35261a | 2016-02-10 20:24:24 +0100 | [diff] [blame] | 92 | |
| Akron | 13db615 | 2016-02-19 14:08:38 +0100 | [diff] [blame] | 93 | case '@': |
| 94 | // pos |
| 95 | this.type = "attr"; |
| 96 | ttype = 4; |
| 97 | tterm = tterm.substring(1); |
| 98 | break; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 99 | |
| Akron | 4299355 | 2016-02-04 13:24:24 +0100 | [diff] [blame] | 100 | default: |
| 101 | // term |
| 102 | this.type = "term"; |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 103 | }; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 104 | |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 105 | int pti = 0; |
| 106 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 107 | // Analyze term value |
| 108 | if (ttype != 1) { |
| Akron | 5f04403 | 2015-12-18 00:35:38 +0100 | [diff] [blame] | 109 | |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 110 | pti = this.payload.get(); // Ignore PTI - temporary!!! |
| Akron | 5f04403 | 2015-12-18 00:35:38 +0100 | [diff] [blame] | 111 | |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 112 | if (DEBUG) { |
| 113 | log.trace( |
| 114 | "Check {} with {} for {}", |
| 115 | tterm, |
| 116 | pti, |
| 117 | prefixRegex.toString() |
| 118 | ); |
| 119 | }; |
| 120 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 121 | matcher = prefixRegex.matcher(tterm); |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 122 | |
| 123 | if (matcher.matches() && matcher.groupCount() == 3) { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 124 | this.annotation = tterm; |
| 125 | if (matcher.group(1) != null) |
| 126 | this.foundry = matcher.group(1); |
| 127 | else |
| 128 | this.foundry = "base"; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 129 | this.layer = matcher.group(2); |
| 130 | this.value = matcher.group(3); |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 131 | }; |
| 132 | } |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 133 | |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 134 | // for positions (aka offset tokens) |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 135 | else { |
| 136 | this.value = tterm; |
| 137 | this.startChar = this.payload.getInt(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 138 | this.endChar = this.payload.getInt(); |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 139 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 140 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 141 | // for spans |
| 142 | if (ttype == 2) { |
| 143 | this.startChar = this.payload.getInt(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 144 | this.endChar = this.payload.getInt(); |
| Akron | 9ebdfab | 2018-02-19 16:38:17 +0100 | [diff] [blame] | 145 | if (this.startChar == this.endChar) |
| 146 | this.type = "empty"; |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 147 | }; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 148 | |
| Akron | b35261a | 2016-02-10 20:24:24 +0100 | [diff] [blame] | 149 | // for spans, relations and attributes |
| 150 | if (ttype > 1 && ttype != 4) { |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 151 | |
| 152 | // relSrc |
| Akron | 6d2c469 | 2016-02-03 18:29:10 +0100 | [diff] [blame] | 153 | if (this.type.equals("relTarget")) { |
| 154 | this.endPos = this.startPos; |
| 155 | this.startPos = this.payload.getInt() - 1; |
| 156 | } |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 157 | |
| 158 | // Token-to-token relation |
| 159 | else if (pti == 32) { |
| 160 | /* |
| 161 | * 1 byte for PTI (32), |
| 162 | * 1 integer for the right part token position, |
| 163 | * 1 short for the left-part TUI, |
| 164 | * 1 short for right-part TUI and |
| 165 | * 1 short for the relation TUI. |
| 166 | */ |
| Akron | 430703a | 2017-11-16 18:32:54 +0100 | [diff] [blame] | 167 | this.targetStartPos = this.payload.getInt(); |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | // Token-to-span relation |
| 171 | else if (pti == 33) { |
| 172 | /* |
| 173 | * 1 byte for PTI (33), |
| 174 | * 1 integer for the start span offset of the right part, |
| 175 | * 1 integer for the end span offset of the right part, |
| 176 | * 1 integer for the start position of the right part, |
| 177 | * 1 integer for the end position of the right part, |
| 178 | * and 0-3 TUIs as above. |
| 179 | */ |
| 180 | // Ignore offsets |
| 181 | this.payload.getInt(); |
| 182 | this.payload.getInt(); |
| 183 | |
| 184 | this.endPos = this.startPos; |
| 185 | this.targetStartPos = this.payload.getInt(); |
| 186 | this.targetEndPos = this.payload.getInt(); |
| 187 | } |
| Akron | 652e436 | 2017-09-18 20:14:44 +0200 | [diff] [blame] | 188 | |
| 189 | // Span to token |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 190 | else if (pti == 34) { |
| 191 | /* |
| 192 | * 1 byte for PTI (34), |
| 193 | * 1 integer for the start span offset of the left part, |
| 194 | * 1 integer for the end span offset of the left part, |
| 195 | * 1 integer for end position of the left part, |
| 196 | * 1 integer for end position of the right part, and |
| 197 | * and 0-3 TUIs as above. |
| 198 | */ |
| Akron | 652e436 | 2017-09-18 20:14:44 +0200 | [diff] [blame] | 199 | |
| 200 | // Ignore offsets |
| 201 | this.payload.getInt(); |
| 202 | this.endPos = this.payload.getInt(); |
| 203 | this.targetStartPos = this.payload.getInt(); |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 204 | } |
| 205 | else if (pti == 35) { |
| 206 | /* |
| 207 | * 1 byte for PTI (35), |
| 208 | * 1 integer for the start span offset of the left part, |
| 209 | * 1 integer for the end span offset of the left part, |
| 210 | * 1 integer for the start span offset of the right part, |
| 211 | * 1 integer for the end span offset of the right part, |
| 212 | * 1 integer for end position of the left part, |
| 213 | * 1 integer for the start position of the right part, |
| 214 | * 1 integer for end position of the right part, |
| 215 | * and 0-3 TUIs as above. |
| 216 | */ |
| Akron | 652e436 | 2017-09-18 20:14:44 +0200 | [diff] [blame] | 217 | |
| 218 | // Ignore offsets |
| 219 | this.payload.getInt(); |
| 220 | this.payload.getInt(); |
| 221 | this.payload.getInt(); |
| 222 | this.payload.getInt(); |
| 223 | |
| 224 | this.endPos = this.payload.getInt(); |
| 225 | this.targetStartPos = this.payload.getInt(); |
| 226 | this.targetEndPos = this.payload.getInt(); |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 227 | } |
| Akron | 6d2c469 | 2016-02-03 18:29:10 +0100 | [diff] [blame] | 228 | else { |
| 229 | this.endPos = this.payload.getInt() - 1; |
| 230 | }; |
| Akron | 5f04403 | 2015-12-18 00:35:38 +0100 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | // Ignore link id for the moment |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 234 | if (ttype == 2 && this.payload.position() < lastPos) { |
| 235 | this.depth = this.payload.get(); |
| 236 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 237 | |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 238 | /* |
| 239 | * TODO: |
| 240 | * Analyze TUI for attributes |
| 241 | */ |
| 242 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 243 | // payloads can have different meaning |
| 244 | analyzed = true; |
| 245 | return this; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 246 | }; |
| 247 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 248 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 249 | public String getType () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 250 | return this.type; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 251 | }; |
| 252 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 253 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 254 | public int getStartChar () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 255 | return this.startChar; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 256 | }; |
| 257 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 258 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 259 | public void setStartChar (int pos) { |
| 260 | this.startChar = pos; |
| 261 | }; |
| 262 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 263 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 264 | public int getEndChar () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 265 | return this.endChar; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 266 | }; |
| 267 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 268 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 269 | public void setEndChar (int pos) { |
| 270 | this.endChar = pos; |
| 271 | }; |
| 272 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 273 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 274 | public int getStartPos () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 275 | return this.startPos; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 276 | }; |
| 277 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 278 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 279 | public int getEndPos () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 280 | return this.endPos; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 281 | }; |
| 282 | |
| Akron | a82cee2 | 2017-09-18 14:52:12 +0200 | [diff] [blame] | 283 | public int getTargetStartPos () { |
| 284 | return this.targetStartPos; |
| 285 | }; |
| 286 | |
| 287 | |
| 288 | public int getTargetEndPos () { |
| 289 | return this.targetEndPos; |
| 290 | }; |
| 291 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 292 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 293 | public byte getDepth () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 294 | return this.depth; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 295 | }; |
| 296 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 297 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 298 | public String getFoundry () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 299 | return this.foundry; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 300 | }; |
| 301 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 302 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 303 | public String getLayer () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 304 | return this.layer; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 305 | }; |
| 306 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 307 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 308 | public String getValue () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 309 | return this.value; |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 310 | }; |
| 311 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 312 | |
| Nils Diewald | cde6908 | 2014-01-16 15:46:48 +0000 | [diff] [blame] | 313 | public String getAnnotation () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 314 | return this.annotation; |
| Nils Diewald | cde6908 | 2014-01-16 15:46:48 +0000 | [diff] [blame] | 315 | }; |
| 316 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 317 | |
| Nils Diewald | 345bdc0 | 2014-01-21 21:48:57 +0000 | [diff] [blame] | 318 | public String toString () { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 319 | this.analyze(); |
| Nils Diewald | 345bdc0 | 2014-01-21 21:48:57 +0000 | [diff] [blame] | 320 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 321 | StringBuffer sb = new StringBuffer(); |
| 322 | sb.append('<').append(this.getType()).append('>'); |
| 323 | sb.append(this.getFoundry()).append('/').append(this.getLayer()); |
| Nils Diewald | 345bdc0 | 2014-01-21 21:48:57 +0000 | [diff] [blame] | 324 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 325 | if (this.getValue() != null) |
| 326 | sb.append(':').append(this.getValue()); |
| Nils Diewald | 345bdc0 | 2014-01-21 21:48:57 +0000 | [diff] [blame] | 327 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 328 | if (this.getDepth() != (byte) 0) |
| 329 | sb.append('(').append(this.getDepth()).append(')'); |
| Nils Diewald | 345bdc0 | 2014-01-21 21:48:57 +0000 | [diff] [blame] | 330 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 331 | sb.append('[').append(this.getStartPos()); |
| 332 | sb.append('-').append(this.getEndPos()).append(']'); |
| 333 | sb.append('[').append(this.getStartChar()); |
| 334 | sb.append('-').append(this.getEndChar()).append(']'); |
| Nils Diewald | 345bdc0 | 2014-01-21 21:48:57 +0000 | [diff] [blame] | 335 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 336 | return sb.toString(); |
| Nils Diewald | 345bdc0 | 2014-01-21 21:48:57 +0000 | [diff] [blame] | 337 | }; |
| 338 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 339 | |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 340 | @Override |
| Akron | 4299355 | 2016-02-04 13:24:24 +0100 | [diff] [blame] | 341 | public int compareTo (TermInfo obj) { |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 342 | this.analyze(); |
| 343 | obj.analyze(); |
| Nils Diewald | 138e5b9 | 2014-01-10 21:15:13 +0000 | [diff] [blame] | 344 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 345 | // TODO: This sorting does not seem to work! |
| 346 | // although it might only be important for depth stuff. |
| Nils Diewald | cde6908 | 2014-01-16 15:46:48 +0000 | [diff] [blame] | 347 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 348 | if (this.startChar < obj.startChar) { |
| 349 | return -1; |
| 350 | } |
| 351 | else if (this.startChar > obj.startChar) { |
| 352 | return 1; |
| 353 | } |
| 354 | else if (this.depth < obj.depth) { |
| 355 | return 1; |
| 356 | } |
| 357 | else if (this.depth > obj.depth) { |
| 358 | return -1; |
| 359 | }; |
| 360 | return 0; |
| Nils Diewald | 2cd1c3d | 2014-01-08 22:53:08 +0000 | [diff] [blame] | 361 | }; |
| 362 | }; |