Introduction to Python

Projekt: Einführung in Python (2)

Prof. Dr. Gerit Wagner
Introduction to Python

Switch the data directory

To use the typical CoLRev environments (objects), we switch to an existing CoLRev project:

cd ~
git clone https://github.com/CoLRev-Environment/example.git
cd example
colrev status

Briefly check the last commits of the project.

Prof. Dr. Gerit Wagner
Introduction to Python

Overview of the tutorial

center

Prof. Dr. Gerit Wagner
Introduction to Python

Object-oriented programming

Our next goal is to implement the previous example (adding the journal impact factor to the records) using Python objects/methods, and using the CoLRev infrastructure.

As a first step, create the JIFLabeler class, instantiate an object, and add the add_jif() method (based on the Python objects/methods syntax). Run and revise the code (if necessary).

Note: Also adapt the path of the records to data/records.bib. This is where CoLRev projects store the main records file.

To checkout the solution, run:

git reset --hard 19f283870f7abf20f7e52e1783b94cc6bcf330a6
Prof. Dr. Gerit Wagner
Introduction to Python

center

Prof. Dr. Gerit Wagner
Introduction to Python

Using CoLRev infrastructure

To use the CoLRev infrastructure, take a look at the API reference and find the classes and methods that can be used to load and save records.

Prof. Dr. Gerit Wagner
Introduction to Python

Upon instantiating the JIFLabeler, we would like to instantiate a ReviewManager object and keep it as an object variable.

When calling the main method, the records should be loaded by using the ReviewManager's dataset methods.

Note: Remember to import the required modules. Test your code, run the linters, and try to address potential warnings.

To checkout the solution, run:

git reset --hard 34a59a63e0d02fa49d1963dda6f065a66e3be2cd
Prof. Dr. Gerit Wagner
Introduction to Python

Before completing the task, we need to implement two changes:

  • Instead of print() statement, it is recommended to use the ReviewManager's logger.
  • Instead of using the record dicts, it is recommended to work with the Record class and its update_field() method.

To checkout the solution, run:

git reset --hard 0ae830b4c77d7a19d3beb7bc6b7485d3d871dbe9
Prof. Dr. Gerit Wagner
Introduction to Python

center

Prof. Dr. Gerit Wagner
Introduction to Python

Save and commit changes

Finally, we need to save the records (using the dataset attribute of ReviewManager) and create a commit (using the ReviewManager).

Review the commit and its content.

To checkout the solution, run:

git reset --hard 402d602b91e4eff1cdd1499a5fbd7b5bf816d743
Prof. Dr. Gerit Wagner
Introduction to Python

center

Prof. Dr. Gerit Wagner
Introduction to Python

Resources

Introductory:

More advanced:

Prof. Dr. Gerit Wagner
Introduction to Python

Next: Best practice and hacking sessions (per group)

  • Read the CoLRev-Enhancement Prposal on SearchSources CEP-002, and raise questions in the issue feed (if any)
  • Take notes on key challenges and questions (for the best practice session)
  • Attend consultation sessions: schedule a session via calendly (May 27-31: e-mail/remote only)
Prof. Dr. Gerit Wagner

See how far we get...

In the last session, we: - [x] Created and run a Python package command - [x] Created and modify a dictionary data structure - [x] Used an external library to read BibTeX records (as dicts) In this session (2x90 min), we will: - [ ] Refactor to object-oriented code - [ ] Switch to a real CoLRev project and load the records using the CoLRev classes - [ ] Save changes and create commit

Important: try to program using objects (instead of procedural programming) if record["journal"] == "MIS Quarterly": KeyError: 'journal' -> if statement (better: if "jounal" not in record: return) Notice: when creating the run() method, the jif_labeler_instance switches to "self".

go to API reference navigate through the classes / dataset

-> switch to review_manager ()

run the pre-commit hooks a few times to illustrate the typing information

TBD: - search: run an api-search example, examine the commit message (settings changed! -> reference implementation) -> we add a query -> docs: interface definitions: searchsource.add_endpoint(), run_search() -> see interfaces (standardized function parameters/names) - where to find the built_in reference implementation (docs/architecture and directories), how to add/remove in the settings -> see package_endpoint definitions (package_manager, docs) continue: prep/validation continue to data: show advice? later: show debugging

add resources on learning/practicing Python (introductory, advanced) check:

Pair-programming which CoLRev-objects or libraries will be needed, which steps are required - Create a fork for the team, give access to team members, and add a note to the issue feed - All team members: clone the fork (using `git clone git@github.com:CoLRev-Environment/colrev.git`) - Check the resources provided with the issue, discuss the project, and make plans