pyEuropePMC

EuropePMCParser API Reference

The EuropePMCParser handles parsing and normalization of Europe PMC API responses.

Class Overview

from pyeuropepmc.processing.search_parser import EuropePMCParser

class EuropePMCParser:
    """Parser for Europe PMC API responses."""

Constructor

EuropePMCParser()

Create a new EuropePMCParser instance.

Methods

parse_search_results(response_data)

Parse raw search API response into structured data.

Parameters:

Returns:

Example:

from pyeuropepmc.processing.search_parser import EuropePMCParser

parser = EuropePMCParser()
raw_response = client.search("cancer", format="json")
papers = parser.parse_search_results(raw_response)

for paper in papers:
    print(f"Title: {paper.get('title')}")
    print(f"DOI: {paper.get('doi')}")

normalize_paper_data(paper_dict)

Normalize a single paper’s data structure.

Parameters:

Returns:

extract_authors(paper_dict)

Extract and normalize author information.

Parameters:

Returns:

extract_journal_info(paper_dict)

Extract journal and publication information.

Parameters:

Returns:

Static Methods

normalize_doi(doi_string)

Normalize DOI format.

Parameters:

Returns:

Example:

normalized = EuropePMCParser.normalize_doi("HTTPS://DOI.ORG/10.1234/TEST")
print(normalized)  # "10.1234/test"

parse_date(date_string)

Parse various date formats into standardized format.

Parameters:

Returns:

Usage Examples

Parse Search Results

from pyeuropepmc.search import SearchClient
from pyeuropepmc.processing.search_parser import EuropePMCParser

with SearchClient() as client:
    # Get raw response
    response = client.search("machine learning", pageSize=50)

    # Parse results
    parser = EuropePMCParser()
    papers = parser.parse_search_results(response)

    # Process parsed data
    for paper in papers:
        print(f"Title: {paper.get('title')}")
        print(f"Year: {paper.get('pub_year')}")
        print(f"Citations: {paper.get('citedByCount', 0)}")

Manual Data Normalization

# Raw paper data from API
raw_paper = {
    "title": "Example Paper",
    "doi": "HTTPS://DOI.ORG/10.1234/EXAMPLE",
    "pubYear": "2023",
    "authorString": "Smith J, Doe J"
}

parser = EuropePMCParser()
normalized = parser.normalize_paper_data(raw_paper)

print(f"DOI: {normalized.get('doi')}")  # "10.1234/example"

Author Extraction

paper_data = {
    "authorString": "Smith John, Doe Jane, Brown Bob",
    "authorList": {
        "author": [
            {"fullName": "Smith John", "firstName": "John", "lastName": "Smith"},
            {"fullName": "Doe Jane", "firstName": "Jane", "lastName": "Doe"}
        ]
    }
}

authors = parser.extract_authors(paper_data)
for author in authors:
    print(f"Name: {author.get('full_name')}")
    print(f"First: {author.get('first_name')}")
    print(f"Last: {author.get('last_name')}")

Data Structure

Normalized Paper Dictionary

{
    "pmid": "12345678",
    "pmcid": "PMC1234567",
    "doi": "10.1234/example",
    "title": "Example Paper Title",
    "abstract": "Abstract text...",
    "pub_year": 2023,
    "journal": "Nature",
    "authors": ["Smith J", "Doe J"],
    "citedByCount": 42,
    "isOpenAccess": "Y",
    # ... additional fields
}

Author Dictionary

{
    "full_name": "Smith John",
    "first_name": "John",
    "last_name": "Smith",
    "affiliation": "University of Example",
    "orcid": "0000-0001-2345-6789"
}

Error Handling

The parser is designed to be robust and handle missing or malformed data:

# Safe access patterns
title = paper.get('title', 'No title available')
year = paper.get('pub_year', 'Unknown year')
citations = paper.get('citedByCount', 0)

Performance Notes