from extraction.core import ExtractionRunner
from extraction.runnables import Extractor, RunnableError, Filter, ExtractorResult
import os
import sys
import grobid
import pdfbox
import filters

if __name__ == '__main__':

   runner = ExtractionRunner()
   runner.add_runnable(pdfbox.PDFBoxPlainTextExtractor)
   runner.add_runnable(filters.AcademicPaperFilter)

   argc = len(sys.argv)
   if argc == 2:
      runner.run_from_file(sys.argv[1])
   elif argc == 3:
      runner.run_from_file(sys.argv[1], output_dir = sys.argv[2])
   else:
      print("USAGE: python {0} path_to_pdf [output_directory]")



from extraction.core import ExtractionRunner
from extraction.runnables import Extractor, RunnableError, Filter, ExtractorResult
import os
import sys
import grobid
import pdfbox
import filters

def get_extraction_runner():

   runner = ExtractionRunner()

   runner.add_runnable(grobid.GrobidPlainTextExtractor)
   # OR
   # runner.add_runnable(pdfbox.PDFBoxPlainTextExtractor)

   runner.add_runnable(filters.AcademicPaperFilter)

   return runner


if __name__ == '__main__':
   runner = get_extraction_runner()

   argc = len(sys.argv)
   if argc == 2:
      runner.run_from_file(sys.argv[1])
   elif argc == 3:
      runner.run_from_file(sys.argv[1], output_dir = sys.argv[2])
   else:
      print("USAGE: python {0} path_to_pdf [output_directory]")



Make code a little cleaner
Make code a little cleaner

  from extraction.core import ExtractionRunner
  from extraction.runnables import Extractor, RunnableError, Filter, ExtractorResult
  import os
  import sys
  import grobid
  import pdfbox
  import filters
  
- if __name__ == '__main__':
+ def get_extraction_runner():
  
     runner = ExtractionRunner()
+ 
+    runner.add_runnable(grobid.GrobidPlainTextExtractor)
+    # OR
-    runner.add_runnable(pdfbox.PDFBoxPlainTextExtractor)
+    # runner.add_runnable(pdfbox.PDFBoxPlainTextExtractor)
+ 
     runner.add_runnable(filters.AcademicPaperFilter)
+ 
+    return runner
+ 
+ 
+ if __name__ == '__main__':
+    runner = get_extraction_runner()
  
     argc = len(sys.argv)
     if argc == 2:
        runner.run_from_file(sys.argv[1])
     elif argc == 3:
        runner.run_from_file(sys.argv[1], output_dir = sys.argv[2])
     else:
        print("USAGE: python {0} path_to_pdf [output_directory]")
  
  
  
Make code a little cleaner
## Code Before:
from extraction.core import ExtractionRunner
from extraction.runnables import Extractor, RunnableError, Filter, ExtractorResult
import os
import sys
import grobid
import pdfbox
import filters

if __name__ == '__main__':

   runner = ExtractionRunner()
   runner.add_runnable(pdfbox.PDFBoxPlainTextExtractor)
   runner.add_runnable(filters.AcademicPaperFilter)

   argc = len(sys.argv)
   if argc == 2:
      runner.run_from_file(sys.argv[1])
   elif argc == 3:
      runner.run_from_file(sys.argv[1], output_dir = sys.argv[2])
   else:
      print("USAGE: python {0} path_to_pdf [output_directory]")



## Instruction:
Make code a little cleaner
## Code After:
from extraction.core import ExtractionRunner
from extraction.runnables import Extractor, RunnableError, Filter, ExtractorResult
import os
import sys
import grobid
import pdfbox
import filters

def get_extraction_runner():

   runner = ExtractionRunner()

   runner.add_runnable(grobid.GrobidPlainTextExtractor)
   # OR
   # runner.add_runnable(pdfbox.PDFBoxPlainTextExtractor)

   runner.add_runnable(filters.AcademicPaperFilter)

   return runner


if __name__ == '__main__':
   runner = get_extraction_runner()

   argc = len(sys.argv)
   if argc == 2:
      runner.run_from_file(sys.argv[1])
   elif argc == 3:
      runner.run_from_file(sys.argv[1], output_dir = sys.argv[2])
   else:
      print("USAGE: python {0} path_to_pdf [output_directory]")


