4444from textractor .visualizers .entitylist import EntityList
4545from textractor .entities .linearizable import Linearizable
4646
47+ logger = logging .getLogger (__name__ )
4748
4849class Page (SpatialObject , Linearizable ):
4950 """
@@ -409,7 +410,7 @@ def filter_checkboxes(
409410 :rtype: EntityList[KeyValue]
410411 """
411412 if not self .checkboxes :
412- logging .warning (f"This document does not contain checkboxes" )
413+ logger .warning (f"This document does not contain checkboxes" )
413414 return []
414415 else :
415416 if selected and not_selected :
@@ -450,7 +451,7 @@ def get_words_by_type(
450451 )
451452
452453 if not self .words :
453- logging . warn ("Document contains no word entities." )
454+ logger . warning ("Document contains no word entities." )
454455 return []
455456
456457 filtered_words = [word for word in self .words if word .text_type == text_type ]
@@ -724,11 +725,11 @@ def get(
724725 lowest_similarity = top_n [- 1 ][1 ]
725726
726727 if not top_n :
727- logging .warning (
728+ logger .warning (
728729 f"Query key does not match any existing keys in the document.{ os .linesep } { self .keys ()} "
729730 )
730731
731- logging .info (f"Query key matched { len (top_n )} key-values in the document." )
732+ logger .info (f"Query key matched { len (top_n )} key-values in the document." )
732733
733734 return EntityList ([value [0 ] for value in top_n ])
734735
@@ -755,14 +756,14 @@ def export_kv_to_csv(
755756 keys = []
756757 values = []
757758 if include_kv and not self .key_values :
758- logging .warning ("Document does not contain key-values." )
759+ logger .warning ("Document does not contain key-values." )
759760 elif include_kv :
760761 for kv in self .key_values :
761762 keys .append (kv .key .__repr__ ())
762763 values .append (kv .value .__repr__ ())
763764
764765 if include_checkboxes and not self .checkboxes :
765- logging .warning ("Document does not contain checkbox elements." )
766+ logger .warning ("Document does not contain checkbox elements." )
766767 elif include_checkboxes :
767768 for kv in self .checkboxes :
768769 keys .append (kv .key .__repr__ ())
@@ -773,7 +774,7 @@ def export_kv_to_csv(
773774 for k , v in zip (keys , values ):
774775 f .write (f"{ k } { sep } { v } { os .linesep } " )
775776
776- logging .info (
777+ logger .info (
777778 f"csv file stored at location { os .path .join (os .getcwd (), filepath )} "
778779 )
779780
@@ -796,7 +797,7 @@ def export_kv_to_txt(
796797 export_str = []
797798 index = 1
798799 if include_kv and not self .key_values :
799- logging .warning ("Document does not contain key-values." )
800+ logger .warning ("Document does not contain key-values." )
800801 elif include_kv :
801802 for kv in self .key_values :
802803 export_str .append (
@@ -805,7 +806,7 @@ def export_kv_to_txt(
805806 index += 1
806807
807808 if include_checkboxes and not self .checkboxes :
808- logging .warning ("Document does not contain checkbox elements." )
809+ logger .warning ("Document does not contain checkbox elements." )
809810 elif include_checkboxes :
810811 for kv in self .checkboxes :
811812 export_str .append (
@@ -815,7 +816,7 @@ def export_kv_to_txt(
815816
816817 with open (filepath , "w" ) as text_file :
817818 text_file .write ("" .join (export_str ))
818- logging .info (
819+ logger .info (
819820 f"txt file stored at location { os .path .join (os .getcwd (),filepath )} "
820821 )
821822
@@ -825,7 +826,7 @@ def independent_words(self) -> EntityList[Word]:
825826 :rtype: EntityList[Word]
826827 """
827828 if not self .words :
828- logging .warning ("Words have not been assigned to this Document object." )
829+ logger .warning ("Words have not been assigned to this Document object." )
829830 return []
830831
831832 else :
@@ -848,7 +849,7 @@ def export_tables_to_excel(self, filepath):
848849 :type filepath: str, required
849850 """
850851 if not filepath :
851- logging .error ("Filepath required to store excel file." )
852+ logger .error ("Filepath required to store excel file." )
852853 workbook = xlsxwriter .Workbook (filepath )
853854 for table in self .tables :
854855 workbook = table .to_excel (
@@ -1018,7 +1019,7 @@ def _get_coords(self, word_1, word_2, direction):
10181019 )
10191020
10201021 if not word_1_objects :
1021- logging .warning (f"{ word_1 } not found in page" )
1022+ logger .warning (f"{ word_1 } not found in page" )
10221023 return - 1 , - 1 , - 1 , - 1
10231024 else :
10241025 word_1_obj = word_1_objects [0 ]
@@ -1033,7 +1034,7 @@ def _get_coords(self, word_1, word_2, direction):
10331034 )
10341035
10351036 if not word_2_objects :
1036- logging .warning (f"{ word_2 } not found in page" )
1037+ logger .warning (f"{ word_2 } not found in page" )
10371038 return - 1 , - 1 , - 1 , - 1
10381039 else :
10391040 word_2_obj = word_2_objects [0 ]
0 commit comments