Files
smartguide/service/src/main/inse/models/source.py
T
Kazgatari 16d99d7dca
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev Build started...
Full refactor
2026-05-29 19:07:08 +02:00

155 lines
7.9 KiB
Python

# coding: utf-8
"""
OpenAlex API
The OpenAlex API provides access to a comprehensive catalog of scholarly works, authors, sources, institutions, topics, keywords, publishers, and funders. OpenAlex indexes over 250 million scholarly works.
The version of the OpenAPI document: 1.0.0
Contact: support@openalex.org
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from datetime import date, datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from inse.models.author_counts_by_year_inner import AuthorCountsByYearInner
from inse.models.author_summary_stats import AuthorSummaryStats
from inse.models.source_ids import SourceIds
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python
class Source(BaseModel):
"""
A journal, repository, or other venue for scholarly works
""" # noqa: E501
id: Optional[StrictStr] = Field(default=None, description="The OpenAlex ID for this source.")
issn_l: Optional[StrictStr] = Field(default=None, description="The ISSN-L (linking ISSN) for this source. This is the Canonical External ID for sources.")
issn: Optional[List[StrictStr]] = Field(default=None, description="All ISSNs used by this source. Many publications have multiple ISSNs.")
display_name: Optional[StrictStr] = Field(default=None, description="The name of the source.")
type: Optional[StrictStr] = Field(default=None, description="The type of source: `journal`, `repository`, `conference`, `ebook platform`, `book series`, `metadata`, or `other`.")
host_organization: Optional[StrictStr] = Field(default=None, description="The host organization as an OpenAlex ID. This will be an Institution ID if the source is a repository, or a Publisher ID if it's a journal/conference.")
host_organization_name: Optional[StrictStr] = Field(default=None, description="The display_name of the host organization.")
host_organization_lineage: Optional[List[StrictStr]] = Field(default=None, description="OpenAlex IDs of parent publishers (only for publisher-hosted sources).")
is_oa: Optional[StrictBool] = Field(default=None, description="Whether this is currently a fully open-access source.")
is_in_doaj: Optional[StrictBool] = Field(default=None, description="Whether this journal is listed in the Directory of Open Access Journals.")
works_count: Optional[StrictInt] = Field(default=None, description="The number of works this source hosts.")
cited_by_count: Optional[StrictInt] = Field(default=None, description="Total citations to works hosted in this source.")
summary_stats: Optional[AuthorSummaryStats] = None
apc_usd: Optional[StrictInt] = Field(default=None, description="The source's article processing charge in USD.")
homepage_url: Optional[StrictStr] = Field(default=None, description="The homepage URL for this source.")
ids: Optional[SourceIds] = None
counts_by_year: Optional[List[AuthorCountsByYearInner]] = Field(default=None, description="`works_count` and `cited_by_count` for each of the last ten years.")
works_api_url: Optional[StrictStr] = Field(default=None, description="A URL that will get you a list of all this source's works.")
created_date: Optional[date] = Field(default=None, description="When this source was added to OpenAlex (ISO 8601 date).")
updated_date: Optional[datetime] = Field(default=None, description="When this source was last updated (ISO 8601 datetime).")
__properties: ClassVar[List[str]] = ["id", "issn_l", "issn", "display_name", "type", "host_organization", "host_organization_name", "host_organization_lineage", "is_oa", "is_in_doaj", "works_count", "cited_by_count", "summary_stats", "apc_usd", "homepage_url", "ids", "counts_by_year", "works_api_url", "created_date", "updated_date"]
@field_validator('type')
def type_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
return value
if value not in set(['journal', 'repository', 'conference', 'ebook platform', 'book series']):
raise ValueError("must be one of enum values ('journal', 'repository', 'conference', 'ebook platform', 'book series')")
return value
model_config = ConfigDict(
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
return json.dumps(to_jsonable_python(self.to_dict()))
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of Source from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of summary_stats
if self.summary_stats:
_dict['summary_stats'] = self.summary_stats.to_dict()
# override the default output from pydantic by calling `to_dict()` of ids
if self.ids:
_dict['ids'] = self.ids.to_dict()
# override the default output from pydantic by calling `to_dict()` of each item in counts_by_year (list)
_items = []
if self.counts_by_year:
for _item_counts_by_year in self.counts_by_year:
if _item_counts_by_year:
_items.append(_item_counts_by_year.to_dict())
_dict['counts_by_year'] = _items
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Source from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"id": obj.get("id"),
"issn_l": obj.get("issn_l"),
"issn": obj.get("issn"),
"display_name": obj.get("display_name"),
"type": obj.get("type"),
"host_organization": obj.get("host_organization"),
"host_organization_name": obj.get("host_organization_name"),
"host_organization_lineage": obj.get("host_organization_lineage"),
"is_oa": obj.get("is_oa"),
"is_in_doaj": obj.get("is_in_doaj"),
"works_count": obj.get("works_count"),
"cited_by_count": obj.get("cited_by_count"),
"summary_stats": AuthorSummaryStats.from_dict(obj["summary_stats"]) if obj.get("summary_stats") is not None else None,
"apc_usd": obj.get("apc_usd"),
"homepage_url": obj.get("homepage_url"),
"ids": SourceIds.from_dict(obj["ids"]) if obj.get("ids") is not None else None,
"counts_by_year": [AuthorCountsByYearInner.from_dict(_item) for _item in obj["counts_by_year"]] if obj.get("counts_by_year") is not None else None,
"works_api_url": obj.get("works_api_url"),
"created_date": obj.get("created_date"),
"updated_date": obj.get("updated_date")
})
return _obj