2727import org .aksw .gerbil .annotator .EntityTyper ;
2828import org .aksw .gerbil .annotator .OKETask1Annotator ;
2929import org .aksw .gerbil .annotator .OKETask2Annotator ;
30+ import org .aksw .gerbil .annotator .RT2KBAnnotator ;
3031import org .aksw .gerbil .datatypes .ErrorTypes ;
3132import org .aksw .gerbil .datatypes .ExperimentType ;
3233import org .aksw .gerbil .evaluate .EvaluationResultContainer ;
5253 * @author Michael Röder ([email protected] ) 5354 *
5455 */
55- public abstract class ErrorCountingAnnotatorDecorator extends AbstractAnnotatorDecorator
56- implements Evaluator < Marking >, ErrorCounter {
56+ public abstract class ErrorCountingAnnotatorDecorator extends AbstractAnnotatorDecorator implements Evaluator < Marking >,
57+ ErrorCounter {
5758
5859 private static final Logger LOGGER = LoggerFactory .getLogger (ErrorCountingAnnotatorDecorator .class );
5960
@@ -82,6 +83,8 @@ public static ErrorCountingAnnotatorDecorator createDecorator(ExperimentType typ
8283 return new ErrorCountingOKETask1Annotator ((OKETask1Annotator ) annotator , maxErrors );
8384 case OKE_Task2 :
8485 return new ErrorCountingOKETask2Annotator ((OKETask2Annotator ) annotator , maxErrors );
86+ case RT2KB :
87+ return new ErrorCountingRT2KBAnnotator ((RT2KBAnnotator ) annotator , maxErrors );
8588 case Rc2KB :
8689 break ;
8790 case Sa2KB :
@@ -125,8 +128,8 @@ public List<MeaningSpan> performD2KBTask(Document document) throws GerbilExcepti
125128 }
126129 }
127130
128- private static class ErrorCountingEntityRecognizer extends ErrorCountingAnnotatorDecorator
129- implements EntityRecognizer {
131+ private static class ErrorCountingEntityRecognizer extends ErrorCountingAnnotatorDecorator implements
132+ EntityRecognizer {
130133
131134 public ErrorCountingEntityRecognizer (EntityRecognizer decoratedAnnotator , int maxErrors ) {
132135 super (decoratedAnnotator , maxErrors );
@@ -173,8 +176,24 @@ public List<TypedSpan> performTyping(Document document) throws GerbilException {
173176 }
174177 }
175178
176- private static class ErrorCountingOKETask1Annotator extends ErrorCountingA2KBAnnotator
177- implements OKETask1Annotator {
179+ private static class ErrorCountingRT2KBAnnotator extends ErrorCountingEntityRecognizer implements RT2KBAnnotator {
180+
181+ protected ErrorCountingRT2KBAnnotator (RT2KBAnnotator decoratedAnnotator , int maxErrors ) {
182+ super (decoratedAnnotator , maxErrors );
183+ }
184+
185+ @ Override
186+ public List <TypedSpan > performTyping (Document document ) throws GerbilException {
187+ return ErrorCountingAnnotatorDecorator .performTyping (this , document );
188+ }
189+
190+ @ Override
191+ public List <TypedSpan > performRT2KBTask (Document document ) throws GerbilException {
192+ return ErrorCountingAnnotatorDecorator .performRT2KBTask (this , document );
193+ }
194+ }
195+
196+ private static class ErrorCountingOKETask1Annotator extends ErrorCountingA2KBAnnotator implements OKETask1Annotator {
178197
179198 protected ErrorCountingOKETask1Annotator (OKETask1Annotator decoratedAnnotator , int maxErrors ) {
180199 super (decoratedAnnotator , maxErrors );
@@ -185,14 +204,19 @@ public List<TypedSpan> performTyping(Document document) throws GerbilException {
185204 return ErrorCountingAnnotatorDecorator .performTyping (this , document );
186205 }
187206
207+ @ Override
208+ public List <TypedSpan > performRT2KBTask (Document document ) throws GerbilException {
209+ return ErrorCountingAnnotatorDecorator .performRT2KBTask (this , document );
210+ }
211+
188212 @ Override
189213 public List <TypedNamedEntity > performTask1 (Document document ) throws GerbilException {
190214 return ErrorCountingAnnotatorDecorator .performOKETask1 (this , document );
191215 }
192216 }
193217
194- private static class ErrorCountingOKETask2Annotator extends ErrorCountingAnnotatorDecorator
195- implements OKETask2Annotator {
218+ private static class ErrorCountingOKETask2Annotator extends ErrorCountingAnnotatorDecorator implements
219+ OKETask2Annotator {
196220
197221 protected ErrorCountingOKETask2Annotator (OKETask2Annotator decoratedAnnotator , int maxErrors ) {
198222 super (decoratedAnnotator , maxErrors );
@@ -269,8 +293,8 @@ protected static List<MeaningSpan> performD2KBTask(ErrorCountingAnnotatorDecorat
269293 return result ;
270294 }
271295
272- protected static List <MeaningSpan > performExtraction (ErrorCountingAnnotatorDecorator errorCounter ,
273- Document document ) throws GerbilException {
296+ protected static List <MeaningSpan > performExtraction (ErrorCountingAnnotatorDecorator errorCounter , Document document )
297+ throws GerbilException {
274298 List <MeaningSpan > result = null ;
275299 try {
276300 result = ((A2KBAnnotator ) errorCounter .getDecoratedAnnotator ()).performA2KBTask (document );
@@ -384,6 +408,29 @@ protected static List<TypedNamedEntity> performOKETask2(ErrorCountingAnnotatorDe
384408 return result ;
385409 }
386410
411+ public static List <TypedSpan > performRT2KBTask (ErrorCountingAnnotatorDecorator errorCounter , Document document )
412+ throws GerbilException {
413+ List <TypedSpan > result = null ;
414+ try {
415+ result = ((RT2KBAnnotator ) errorCounter .getDecoratedAnnotator ()).performRT2KBTask (document );
416+ } catch (Exception e ) {
417+ if (errorCounter .getErrorCount () == 0 ) {
418+ // Log only the first exception completely
419+ LOGGER .error ("Got an Exception from the annotator (" + errorCounter .getName () + ")" , e );
420+ } else {
421+ // Log only the Exception message without the stack trace
422+ LOGGER .error ("Got an Exception from the annotator (" + errorCounter .getName () + "): "
423+ + e .getLocalizedMessage ());
424+ }
425+ errorCounter .increaseErrorCount ();
426+ return new ArrayList <TypedSpan >(0 );
427+ }
428+ if (printDebugMsg && LOGGER .isDebugEnabled ()) {
429+ logResult (result , errorCounter .getName (), "TypedNamedEntity" );
430+ }
431+ return result ;
432+ }
433+
387434 protected int errorCount = 0 ;
388435 protected int maxErrors ;
389436
0 commit comments