示例#1
0
 def _transform_latest(cls, document: Document) -> Optional[dict]:
     latest = document.get('latest')
     if latest is None:
         return None
     return {
         "paper_id": latest,
         "href": url_for("api.paper", paper_id=document['paper_id'],
                         version=document.get('latest_version'),
                         _external=True),
         "canonical": url_for("abs", paper_id=document['paper_id'],
                              version=document.get('latest_version')),
         "version": document.get('latest_version')
     }
示例#2
0
 def _transform_latest(document: Document) -> Optional[Dict[str, str]]:
     latest = document.get("latest")
     if latest is None:
         return None
     return {  # type:ignore
         "paper_id": latest,
         "href": url_for(
             "api.paper",
             paper_id=document["paper_id"],
             version=document.get("latest_version"),
             _external=True,
         ),
         "canonical": url_for(
             "abs",
             paper_id=document["paper_id"],
             version=document.get("latest_version"),
         ),
         "version": document.get("latest_version"),
     }
示例#3
0
    def transform_document(
        cls,
        fg: FeedGenerator,
        doc: Document,
        query: Optional[ClassicAPIQuery] = None,
    ) -> None:
        """Select a subset of :class:`Document` properties for public API."""
        entry = fg.add_entry()
        entry.id(
            url_for(
                "abs",
                paper_id=doc["paper_id"],
                version=doc["version"],
                _external=True,
            ))
        entry.title(doc["title"])
        entry.summary(doc["abstract"])
        entry.published(to_utc(doc["submitted_date"]))
        entry.updated(to_utc(doc["updated_date"]))
        entry.link({
            "href":
            url_for(
                "abs",
                paper_id=doc["paper_id"],
                version=doc["version"],
                _external=True,
            ),
            "type":
            "text/html",
        })

        entry.link({
            "href":
            url_for(
                "pdf",
                paper_id=doc["paper_id"],
                version=doc["version"],
                _external=True,
            ),
            "type":
            "application/pdf",
            "rel":
            "related",
            "title":
            "pdf",
        })

        if doc.get("comments"):
            entry.arxiv.comment(doc["comments"])

        if doc.get("journal_ref"):
            entry.arxiv.journal_ref(doc["journal_ref"])

        if doc.get("doi"):
            entry.arxiv.doi(doc["doi"])

        if doc["primary_classification"]["category"] is not None:
            entry.arxiv.primary_category(
                doc["primary_classification"]["category"]["id"])
            entry.category(
                term=doc["primary_classification"]["category"]["id"],
                scheme=ARXIV_NS,
            )

        for category in doc["secondary_classification"]:
            entry.category(term=category["category"]["id"], scheme=ARXIV_NS)

        for author in doc["authors"]:
            author_data: Dict[str, Any] = {"name": author["full_name"]}
            if author.get("affiliation"):
                author_data["affiliation"] = author["affiliation"]
            entry.arxiv.author(author_data)