Factiva parser and NLP pipeline for news articles related to COVID-19


This bit of code was written quick and dirty to parse news articles retrieved from Dow Jones’ Factiva and feed them in a simple NLP pipeline. It works, it was fun to develop it, use it, recycle parts of the code, have fun 🙂

Parser:

Takes as input files numerically ordered in a folder. This is not fundamental (in case of multiple retrieves from Factiva) because the parser orders the article by date using the date field contained in each of the articles. Nevertheless, it is important to reduce duplicates (because they increase the computational time needed for processing the corpus), so before adding new articles in the folder, be sure to retrieve them from a timepoint that does not overlap with the articles already retrieved.

In any case, in the last phase the dataframe is checked for duplicates, that are counted and removed, but still the articles are processed by the parser and this takes computational time.

The parser removes search summaries, segments the text, and cleans it using regex rules. The resulting text is exported in a complete dataframe as a CSV file; a subset containing only title and text is exported as TXT, ready to be fed to the NLP pipeline.

The parser is language agnostic; just change the path to the folder containing the documents to parse. 

NLP pipeline

The NLP pipeline imports the files generated by the parser (divided by month to put less load on the memory) and analyses them. It is not language agnostic: correct linguistic settings must be specified in “setting up”, “NLP” and “additional rules”.

First some additional rules for NER are defined. Some are general, some are language-specific, as specified in the relevant section.

The files are opened and preprocessed, then lemma frequency and NE frequency are calculated per each month and in the whole corpus.

All the dataframes are exported as CSV files for further analysis or for data visualization.

This code is optimized for English, German, French and Italian. Nevertheless, being based on spaCy, which provides several other models ( https://spacy.io/models ) could easily be adapted to other languages.

The whole software is structured in Jupyter-lab notebooks, heavily commented for future reference.

The code’s here

https://zenodo.org/record/4792669#.YqDqxahBwdU