Skip to main content

SciELO Publishing Schema XML document front matter metadata reader/sanitizer

Project description

Clea

This project is an XML front matter metadata reader for documents that almost follows the SciELO Publishing Schema, extracting and sanitizing the values regarding the affiliations.

Installation

Installation with minimal requirements, intended for use within Python, as an imported package:

pip install scielo-clea

Installation for use as a server (mainly for testing):

pip install scielo-clea[server]

Running the testing server

You can run the development server using the flask CLI. For example, for listening at 8080 from every host:

FLASK_APP=clea.server flask run -h 0.0.0.0 -p 8080

In a production server with 4 worker processes for handling requests, you can, for example:

  • Install gunicorn (it's not a dependency)
  • Run gunicorn -b 0.0.0.0:8080 -w 4 clea.server:app

Clea as a library

A simple example to see all the extracted data is:

from clea.core import Article
from pprint import pprint

art = Article("some_file.xml")
pprint(art.data_full)

That's a dictionary of lists with all the "raw" extracted data. Using art.data instead of art.data_full should get the first item of the lists, or an empty string if it's empty (the same applies to branches and sub-articles).

More simple stuff that can be done:

len(art.aff)              # Number of <aff> entries
len(art.sub_article)      # Number of <sub-article>
art.contrib[0].data_full  # Data from the first contributor as a dict

# Something like {"type": "translation", "lang": "en"},
# the content from <sub-article> attributes
art.sub_article[0].article[0].data

The extracted information is not exhaustive! Its result should not be seen as a replacement of the raw XML.

One of the goals of this library was to help on creating a tabular data from a given XML with as many rows as required to have a pair of a matching <aff> and <contrib> in each row. These are the functions that does that matching:

  • clea.join.aff_contrib_inner_gen(article)
  • clea.join.aff_contrib_full_gen(article)
  • clea.join.aff_contrib_inner(article)
  • clea.join.aff_contrib_full(article)

The ones with the _gen suffix are generator functions that yields a tuple with two Branch entries (or None), the other ones return a list of merged dictionaries in an almost tabular format (dictionary of lists of strings). Each list regarding these elements for these specific elements should usually have at most one string, but that's not always the case even for these specific elements, then one should be careful when using the data property.

The inner and full in the names regards to INNER JOIN and FULL OUTER JOIN from SQL, meaning the unmatched elements (all <aff> and <contrib> unreferred nodes) are discarded in the former strategy, whereas they're forcefully matched with None in the latter.

To print all the extracted data from a XML including both the INNER JOIN and FULL OUTER JOIN of matching <aff> and <contrib> pairs, similar to the test server response:

from clea.join import aff_contrib_inner, aff_contrib_full

pprint({**article.data_full,
    "aff_contrib_full": aff_contrib_full(article),
    "aff_contrib_inner": aff_contrib_inner(article),
})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scielo-clea-0.2.2.tar.gz (10.8 kB view details)

Uploaded Source

File details

Details for the file scielo-clea-0.2.2.tar.gz.

File metadata

  • Download URL: scielo-clea-0.2.2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for scielo-clea-0.2.2.tar.gz
Algorithm Hash digest
SHA256 699a0b73b8fab47c213ff364a96fd96f3eca49a20ff7223a38de8b17c00f40c9
MD5 66973121c4c609f64f5cec0bddb4ed68
BLAKE2b-256 351c815855ccce3e054e08dd8acd70eba3956d1fac5fc1f06d677f5708239879

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page