|
25 | 25 | import org.aksw.gerbil.annotator.D2KBAnnotator; |
26 | 26 | import org.aksw.gerbil.annotator.EntityRecognizer; |
27 | 27 | import org.aksw.gerbil.annotator.EntityTyper; |
| 28 | +import org.aksw.gerbil.annotator.OKE2018Task4Annotator; |
28 | 29 | import org.aksw.gerbil.annotator.OKETask1Annotator; |
29 | 30 | import org.aksw.gerbil.annotator.OKETask2Annotator; |
| 31 | +import org.aksw.gerbil.annotator.REAnnotator; |
30 | 32 | import org.aksw.gerbil.annotator.RT2KBAnnotator; |
31 | 33 | import org.aksw.gerbil.datatypes.ErrorTypes; |
32 | 34 | import org.aksw.gerbil.datatypes.ExperimentType; |
|
38 | 40 | import org.aksw.gerbil.transfer.nif.Marking; |
39 | 41 | import org.aksw.gerbil.transfer.nif.Meaning; |
40 | 42 | import org.aksw.gerbil.transfer.nif.MeaningSpan; |
| 43 | +import org.aksw.gerbil.transfer.nif.Relation; |
41 | 44 | import org.aksw.gerbil.transfer.nif.Span; |
42 | 45 | import org.aksw.gerbil.transfer.nif.TypedSpan; |
43 | 46 | import org.aksw.gerbil.transfer.nif.data.TypedNamedEntity; |
@@ -85,6 +88,10 @@ public static ErrorCountingAnnotatorDecorator createDecorator(ExperimentType typ |
85 | 88 | return new ErrorCountingOKETask2Annotator((OKETask2Annotator) annotator, maxErrors); |
86 | 89 | case RT2KB: |
87 | 90 | return new ErrorCountingRT2KBAnnotator((RT2KBAnnotator) annotator, maxErrors); |
| 91 | + case RE: |
| 92 | + return new ErrorCountingREAnnotator((REAnnotator) annotator, maxErrors); |
| 93 | + case OKE2018Task4: |
| 94 | + return new ErrorCountingOKE2018Task4Annotator((OKE2018Task4Annotator) annotator, maxErrors); |
88 | 95 | case Rc2KB: |
89 | 96 | break; |
90 | 97 | case Sa2KB: |
@@ -141,6 +148,59 @@ public List<Span> performRecognition(Document document) throws GerbilException { |
141 | 148 | } |
142 | 149 | } |
143 | 150 |
|
| 151 | + private static class ErrorCountingOKE2018Task4Annotator extends ErrorCountingAnnotatorDecorator implements OKE2018Task4Annotator { |
| 152 | + |
| 153 | + protected ErrorCountingOKE2018Task4Annotator(Annotator decoratedAnnotator, int maxErrors) { |
| 154 | + super(decoratedAnnotator, maxErrors); |
| 155 | + } |
| 156 | + |
| 157 | + @Override |
| 158 | + public List<Relation> performRETask(Document document) throws GerbilException { |
| 159 | + return ErrorCountingAnnotatorDecorator.performRE(this, document); |
| 160 | + } |
| 161 | + |
| 162 | + @Override |
| 163 | + public List<Span> performRecognition(Document document) throws GerbilException { |
| 164 | + return ErrorCountingAnnotatorDecorator.performRecognition(this, document); |
| 165 | + |
| 166 | + } |
| 167 | + |
| 168 | + @Override |
| 169 | + public List<Marking> performOKE2018Task4(Document document) throws GerbilException { |
| 170 | + return ErrorCountingAnnotatorDecorator.performOKE2018Task4(this, document); |
| 171 | + |
| 172 | + } |
| 173 | + |
| 174 | + @Override |
| 175 | + public List<MeaningSpan> performA2KBTask(Document document) throws GerbilException { |
| 176 | + return ErrorCountingAnnotatorDecorator.performExtraction(this, document); |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + public List<MeaningSpan> performD2KBTask(Document document) throws GerbilException { |
| 181 | + return ErrorCountingAnnotatorDecorator.performD2KBTask(this, document); |
| 182 | + } |
| 183 | + |
| 184 | + @Override |
| 185 | + public List<Meaning> performC2KB(Document document) throws GerbilException { |
| 186 | + return ErrorCountingAnnotatorDecorator.performC2KB(this, document); |
| 187 | + } |
| 188 | + |
| 189 | + } |
| 190 | + |
| 191 | + private static class ErrorCountingREAnnotator extends ErrorCountingAnnotatorDecorator implements REAnnotator { |
| 192 | + |
| 193 | + protected ErrorCountingREAnnotator(Annotator decoratedAnnotator, int maxErrors) { |
| 194 | + super(decoratedAnnotator, maxErrors); |
| 195 | + } |
| 196 | + |
| 197 | + @Override |
| 198 | + public List<Relation> performRETask(Document document) throws GerbilException { |
| 199 | + return ErrorCountingAnnotatorDecorator.performRE(this, document); |
| 200 | + } |
| 201 | + |
| 202 | + } |
| 203 | + |
144 | 204 | private static class ErrorCountingA2KBAnnotator extends ErrorCountingD2KBAnnotator implements A2KBAnnotator { |
145 | 205 |
|
146 | 206 | public ErrorCountingA2KBAnnotator(A2KBAnnotator decoratedAnnotator, int maxErrors) { |
@@ -247,7 +307,53 @@ protected static void logResult(List<? extends Marking> result, String annotator |
247 | 307 | LOGGER.debug(builder.toString()); |
248 | 308 | } |
249 | 309 |
|
250 | | - protected static List<Meaning> performC2KB(ErrorCountingAnnotatorDecorator errorCounter, Document document) |
| 310 | + public static List<Relation> performRE(ErrorCountingAnnotatorDecorator errorCounter, |
| 311 | + Document document) throws GerbilException { |
| 312 | + List<Relation> result = null; |
| 313 | + try { |
| 314 | + result = ((REAnnotator) errorCounter.getDecoratedAnnotator()).performRETask(document); |
| 315 | + } catch (Exception e) { |
| 316 | + if (errorCounter.getErrorCount() == 0) { |
| 317 | + // Log only the first exception completely |
| 318 | + LOGGER.error("Got an Exception from the annotator (" + errorCounter.getName() + ")", e); |
| 319 | + } else { |
| 320 | + // Log only the Exception message without the stack trace |
| 321 | + LOGGER.error("Got an Exception from the annotator (" + errorCounter.getName() + "): " |
| 322 | + + e.getLocalizedMessage()); |
| 323 | + } |
| 324 | + errorCounter.increaseErrorCount(); |
| 325 | + return new ArrayList<Relation>(0); |
| 326 | + } |
| 327 | + if (printDebugMsg && LOGGER.isDebugEnabled()) { |
| 328 | + logResult(result, errorCounter.getName(), "Relation"); |
| 329 | + } |
| 330 | + return result; |
| 331 | + } |
| 332 | + |
| 333 | + public static List<Marking> performOKE2018Task4(ErrorCountingAnnotatorDecorator errorCounter, |
| 334 | + Document document) throws GerbilException { |
| 335 | + List<Marking> result = null; |
| 336 | + try { |
| 337 | + result = ((OKE2018Task4Annotator) errorCounter.getDecoratedAnnotator()).performOKE2018Task4(document); |
| 338 | + } catch (Exception e) { |
| 339 | + if (errorCounter.getErrorCount() == 0) { |
| 340 | + // Log only the first exception completely |
| 341 | + LOGGER.error("Got an Exception from the annotator (" + errorCounter.getName() + ")", e); |
| 342 | + } else { |
| 343 | + // Log only the Exception message without the stack trace |
| 344 | + LOGGER.error("Got an Exception from the annotator (" + errorCounter.getName() + "): " |
| 345 | + + e.getLocalizedMessage()); |
| 346 | + } |
| 347 | + errorCounter.increaseErrorCount(); |
| 348 | + return new ArrayList<Marking>(0); |
| 349 | + } |
| 350 | + if (printDebugMsg && LOGGER.isDebugEnabled()) { |
| 351 | + logResult(result, errorCounter.getName(), "Meaning"); |
| 352 | + } |
| 353 | + return result; |
| 354 | + } |
| 355 | + |
| 356 | + protected static List<Meaning> performC2KB(ErrorCountingAnnotatorDecorator errorCounter, Document document) |
251 | 357 | throws GerbilException { |
252 | 358 | List<Meaning> result = null; |
253 | 359 | try { |
|
0 commit comments