@@ -329,6 +329,7 @@ public boolean isCompleteForTEI() {
329329
330330 public String toTEI (GrobidAnalysisConfig config , Document doc , TEIFormatter formatter , List <MarkerType > markerTypes ) {
331331 if (!isCompleteForTEI ()) {
332+ LOGGER .warn ("Found a figure that is badly formatted but it should have been spotted before. We ignore it now." );
332333 return null ;
333334 }
334335 Element figureElement = XmlBuilderUtils .teiElement ("figure" );
@@ -339,18 +340,18 @@ public String toTEI(GrobidAnalysisConfig config, Document doc, TEIFormatter form
339340 if (config .isGenerateTeiCoordinates ("figure" )) {
340341 List <BoundingBox > theBoxes = null ;
341342 // non graphic elements
342- if (getLayoutTokens () != null && getLayoutTokens (). size () > 0 ) {
343+ if (CollectionUtils . isNotEmpty ( getLayoutTokens ()) ) {
343344 theBoxes = BoundingBoxCalculator .calculate (getLayoutTokens ());
344345 }
345346
346347 // if (getBitmapGraphicObjects() != null && !getBitmapGraphicObjects().isEmpty()) {
347348 // -> note: this was restricted to the bitmap objects only... the bounding box calculation
348349 // with vector graphics might need some double check
349350
350- // here we bound all figure graphics in one single box (given that we can have hundred graphics
351+ // here we bound all figure graphics in one single box (given that we can have a hundred graphics
351352 // in a single figure)
352353 BoundingBox theGraphicsBox = null ;
353- if (( graphicObjects != null ) && ( graphicObjects . size () > 0 )) {
354+ if (CollectionUtils . isNotEmpty ( graphicObjects )) {
354355 for (GraphicObject graphicObject : graphicObjects ) {
355356 if (theGraphicsBox == null ) {
356357 theGraphicsBox = graphicObject .getBoundingBox ();
@@ -366,24 +367,24 @@ public String toTEI(GrobidAnalysisConfig config, Document doc, TEIFormatter form
366367 theBoxes .add (theGraphicsBox );
367368 }
368369
369- if (theBoxes != null && theBoxes . size () > 0 ) {
370+ if (CollectionUtils . isNotEmpty ( theBoxes ) ) {
370371 String coords = Joiner .on (";" ).join (theBoxes );
371372 XmlBuilderUtils .addCoords (figureElement , coords );
372373 }
373374 }
374- if (header != null ) {
375+
376+ if (StringUtils .isNotBlank (header )) {
375377 Element head = XmlBuilderUtils .teiElement ("head" ,
376378 LayoutTokensUtil .normalizeText (header .toString ()));
377379 figureElement .appendChild (head );
378-
379380 }
380- if (label != null ) {
381+
382+ if (StringUtils .isNotBlank (label )) {
381383 Element labelEl = XmlBuilderUtils .teiElement ("label" ,
382384 LayoutTokensUtil .normalizeText (label .toString ()));
383385 figureElement .appendChild (labelEl );
384386 }
385- if (caption != null ) {
386-
387+ if (StringUtils .isNotBlank (caption )) {
387388 Element desc = XmlBuilderUtils .teiElement ("figDesc" );
388389 if (config .isGenerateTeiIds ()) {
389390 String divID = KeyGen .getKey ().substring (0 , 7 );
@@ -392,12 +393,12 @@ public String toTEI(GrobidAnalysisConfig config, Document doc, TEIFormatter form
392393
393394 // if the segment has been parsed with the full text model we further extract the clusters
394395 // to get the bibliographical references
395- if ( (labeledCaption != null ) && ( labeledCaption . length () > 0 ) ) {
396+ if (StringUtils . isNotBlank (labeledCaption ) ) {
396397 TaggingTokenClusteror clusteror = new TaggingTokenClusteror (GrobidModels .FULLTEXT , labeledCaption , captionLayoutTokens );
397398 List <TaggingTokenCluster > clusters = clusteror .cluster ();
398399
399400 MarkerType citationMarkerType = null ;
400- if (markerTypes != null && markerTypes . size ()> 0 ) {
401+ if (CollectionUtils . isNotEmpty ( markerTypes ) ) {
401402 citationMarkerType = markerTypes .get (0 );
402403 }
403404
@@ -453,7 +454,7 @@ public String toTEI(GrobidAnalysisConfig config, Document doc, TEIFormatter form
453454
454455 figureElement .appendChild (desc );
455456 }
456- if (( graphicObjects != null ) && ( graphicObjects . size () > 0 )) {
457+ if (CollectionUtils . isNotEmpty ( graphicObjects )) {
457458 for (GraphicObject graphicObject : graphicObjects ) {
458459 Element go = XmlBuilderUtils .teiElement ("graphic" );
459460 String uri = graphicObject .getURI ();
0 commit comments