Giter Club home page Giter Club logo

ts-test-extractor's Introduction

ts-test-extractor

Simple script for extracting questions, answers and so on from test PDFs (for a subject called TS I have at uni) to a more usable format.

*The real test pdfs are not included as i don't have the right to publish them!
*Keep in mind that the regex patterns and formatting fixes in this project will pretty much only fit this really specific usecase, thus it will most likely only be useful as inspiration!

Setup

  • Unix
     # 1. Create virtual env:
     python3 -m venv venv
     
     # 2. Activate virtual env:
     source venv/bin/activate 
     
     # 3. Install required pkgs:
     pip install -r requirements.txt
  • Windows
     # 1. Create virtual env:
     python3 -m venv venv
     
     # 2. Activate virtual env:
     .\venv\Scripts\activate 
     
     # 3. Install required pkgs:
     pip install -r requirements.txt

Usage

  1. Place the test PDFs files in the ./pdfs/ directory (for best results they should be numbered) - an example MS Word document and it's PDF export are included
  2. Run: python3 script.py
  3. Use the output JSON file (ts.json) however you see fit

ts-test-extractor's People

Contributors

erykdarnowski avatar

Watchers

 avatar  avatar  avatar

ts-test-extractor's Issues

Update `README.md`

TODO

  • Info about input files + included example + that they should be numbered
  • Run instructions
  • That the regex patterns and formatting fixes are really specific so this repo won't be really usefull cause it was made with a really specific usecase in mind (it will most likely be only usefull as inspiration).

Fix JSON file encoding on Windows

Description

Add the encoding parameter when writing the JSON file, like was done before:
...('ts.json', 'w') as... -> ...('ts.json', 'w', encoding='utf-8')...

Check that tasks, answers etc. are correctly joined / aligned

Description

Basically compare the output JSON file of the script with the PDFs to make sure that the tasks, answers, correct answers and so on are correctly grouped / joined / aligned. In addition could also look for formatting stuff to fix that was missed previously.

Implement proper fix for Polish diacritics in text extraction

Description

The currently implemented quick & dirty fix, doesn't fully resolve the issue and in fact introduces a new one (when a word starts with a diacritic, it gets combined with the word previous to it).

The proposed solution is a switch from PyPDF2 to using fitz from PyMuPDF.
Another thing is the need for encoding="utf-8" when writing the out.txt file on Windows.

Implement data extraction with regex patterns

TODO

*Make sure each expression gets 171 matches

  • Add clean up
    • Titles: /(\s\n){0,2}(^Test\sz\s.*?)(\s\n){2,}/gms (replace)
  • Add extraction
    • Tasks: /(^[0-9]{1,}\.\n?\s?)(?![0-9])(.*?)(?=\n?\s\n[A-Z]\.)/gms (G2)
    • Answers (A, B, C): /(^[A-Z]\..*?)(?=\s\n?Odp\.)/gms (G1)
    • Correct answers: /(?<=^Odp\.)(.*?)([A-Z])(?=\.?)/gm (G2)
    • Answer expls.: /(^Odp\.(\:|\s)\s?[A-Z])(\.?\s+\n?)(.*?)(?=((^[0-9]{1,}\.\n?\s?)(?![0-9]))|(\s\n){3})/gms (G4)

Resources

Fix lack of PDF filenames sorting

Description

After messing around with the PDF files, I've noticed that when they get found by glob they don't have to be in order.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.