skyleee's picture
Upload diversa-biomedical-v1 package
7bcd860 verified
Raw History Blame Contribute Delete
6.6 kB
"""Canonical Arrow schemas for every output table (single source of truth)."""
from __future__ import annotations
import pyarrow as pa
WORKS_BASE = pa.schema([
("work_id", pa.string()),
("doi", pa.string()),
("title", pa.string()),
("publication_date", pa.string()),
("publication_year", pa.int16()),
("publication_month", pa.int8()),
("type", pa.string()),
("primary_topic_id", pa.string()),
("primary_topic_name", pa.string()),
("primary_topic_score", pa.float32()),
("field_id", pa.string()),
("field_name", pa.string()),
("subfield_id", pa.string()),
("subfield_name", pa.string()),
("domain_id", pa.string()),
("domain_name", pa.string()),
("topic_ids", pa.list_(pa.string())),
("topic_names", pa.list_(pa.string())),
("topic_count", pa.int16()),
("author_count", pa.int32()),
("author_names", pa.list_(pa.string())),
("author_ids", pa.list_(pa.string())),
("author_orcids", pa.list_(pa.string())),
("institution_count", pa.int32()),
("institution_ids", pa.list_(pa.string())),
("institution_names", pa.list_(pa.string())),
("institution_countries", pa.list_(pa.string())),
("country_codes", pa.list_(pa.string())),
("country_count", pa.int16()),
("source_id", pa.string()),
("source_name", pa.string()),
("source_type", pa.string()),
("issn_l", pa.string()),
("issns", pa.list_(pa.string())),
("publisher", pa.string()),
("cited_by_count", pa.int32()),
("recent_citations_3y", pa.int32()),
("referenced_works_count", pa.int32()),
("referenced_work_ids", pa.list_(pa.string())),
("is_oa", pa.bool_()),
("oa_status", pa.string()),
("oa_url", pa.string()),
("license", pa.string()),
("license_id", pa.string()),
("language", pa.string()),
("abstract", pa.string()),
("has_abstract", pa.bool_()),
("is_retracted", pa.bool_()),
("is_paratext", pa.bool_()),
("fwci", pa.float32()),
("openalex_citation_percentile", pa.float32()),
("created_date", pa.string()),
("updated_date", pa.string()),
("mesh_terms", pa.list_(pa.string())),
("keywords", pa.list_(pa.string())),
])
WORKS_DERIVED = pa.schema([
("paper_age_years", pa.float32()),
("citations_per_year", pa.float32()),
("citation_velocity", pa.float32()),
("international_collaboration", pa.bool_()),
("multi_institutional", pa.bool_()),
("publication_recency_score", pa.float32()),
("citation_percentile", pa.float32()),
("high_impact_flag", pa.bool_()),
("research_growth_score", pa.float32()),
("topic_growth_score", pa.float32()),
("emerging_topic_flag", pa.bool_()),
])
WORKS_FULL = pa.schema(list(WORKS_BASE) + list(WORKS_DERIVED))
WORK_AUTHORS = pa.schema([
("work_id", pa.string()),
("author_id", pa.string()),
("author_name", pa.string()),
("orcid", pa.string()),
("author_position", pa.string()),
("is_corresponding", pa.bool_()),
("institution_ids", pa.list_(pa.string())),
("country_codes", pa.list_(pa.string())),
])
WORK_INSTITUTIONS = pa.schema([
("work_id", pa.string()),
("institution_id", pa.string()),
("institution_name", pa.string()),
("country_code", pa.string()),
("institution_type", pa.string()),
])
WORK_TOPICS = pa.schema([
("work_id", pa.string()),
("topic_id", pa.string()),
("topic_name", pa.string()),
("score", pa.float32()),
("is_primary", pa.bool_()),
("subfield_id", pa.string()),
("subfield_name", pa.string()),
("field_id", pa.string()),
("field_name", pa.string()),
("domain_id", pa.string()),
("domain_name", pa.string()),
])
CITATION_EDGES = pa.schema([
("citing_work_id", pa.string()),
("cited_work_id", pa.string()),
("cited_in_dataset", pa.bool_()),
])
AUTHORS_DIM = pa.schema([
("author_id", pa.string()),
("author_name", pa.string()),
("orcid", pa.string()),
("works_count", pa.int32()),
("first_year", pa.int16()),
("last_year", pa.int16()),
("total_citations", pa.int64()),
("mean_citations", pa.float32()),
("institution_ids", pa.list_(pa.string())),
("country_codes", pa.list_(pa.string())),
("primary_field_id", pa.string()),
("primary_field_name", pa.string()),
])
INSTITUTIONS_DIM = pa.schema([
("institution_id", pa.string()),
("institution_name", pa.string()),
("country_code", pa.string()),
("works_count", pa.int32()),
("first_year", pa.int16()),
("last_year", pa.int16()),
("total_citations", pa.int64()),
("mean_citations", pa.float32()),
("primary_field_id", pa.string()),
("primary_field_name", pa.string()),
])
TOPICS_DIM = pa.schema([
("topic_id", pa.string()),
("topic_name", pa.string()),
("subfield_id", pa.string()),
("subfield_name", pa.string()),
("field_id", pa.string()),
("field_name", pa.string()),
("domain_id", pa.string()),
("domain_name", pa.string()),
("works_count", pa.int64()),
("first_year", pa.int16()),
("last_year", pa.int16()),
("total_citations", pa.int64()),
("mean_citations", pa.float32()),
])
SOURCES_DIM = pa.schema([
("source_id", pa.string()),
("source_name", pa.string()),
("source_type", pa.string()),
("issn_l", pa.string()),
("issns", pa.list_(pa.string())),
("publisher", pa.string()),
("is_oa", pa.bool_()),
("works_count", pa.int64()),
("total_citations", pa.int64()),
("mean_citations", pa.float32()),
])
TOPIC_YEAR_COUNTS = pa.schema([
("topic_id", pa.string()),
("topic_name", pa.string()),
("publication_year", pa.int16()),
("works_count", pa.int64()),
])
TOPIC_GROWTH = pa.schema([
("topic_id", pa.string()),
("topic_name", pa.string()),
("first_year", pa.int16()),
("last_year", pa.int16()),
("early_count", pa.int64()),
("late_count", pa.int64()),
("growth_ratio", pa.float32()),
("cagr", pa.float32()),
("trend_slope", pa.float32()),
("emerging_topic_flag", pa.bool_()),
])
COUNTRY_YEAR_COUNTS = pa.schema([
("country_code", pa.string()),
("publication_year", pa.int16()),
("works_count", pa.int64()),
])
COUNTRY_COLLABORATION = pa.schema([
("country_a", pa.string()),
("country_b", pa.string()),
("collaboration_count", pa.int64()),
])
INSTITUTION_ACTIVITY = pa.schema([
("institution_id", pa.string()),
("institution_name", pa.string()),
("country_code", pa.string()),
("publication_year", pa.int16()),
("works_count", pa.int64()),
("total_citations", pa.int64()),
])