How to use the arxiv.taxonomy.CATEGORIES function in arxiv

To help you get started, we’ve selected a few arxiv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arXiv / arxiv-browse / tests / test_external_refs_cits.py View on Github external
def test_inspire_config(self):
        """Ensure INSPIRE_REF_CIT_CATEGORIES categories are valid."""
        for category in INSPIRE_REF_CIT_CATEGORIES:
            self.assertIn(category, CATEGORIES)
github arXiv / arxiv-search / search / converters.py View on Github external
def to_python(self, value: str) -> Optional[List[str]]:
        """Parse URL path part to Python rep (str)."""
        valid_archives = []
        for archive in value.split(','):
            if archive not in taxonomy.ARCHIVES:
                continue
            # Support old archives.
            if archive in taxonomy.ARCHIVES_SUBSUMED:
                cat = taxonomy.CATEGORIES[taxonomy.ARCHIVES_SUBSUMED[archive]]
                archive = cat['in_archive']
            valid_archives.append(archive)
        if not valid_archives:
            raise ValidationError()
        return valid_archives
github arXiv / arxiv-search / search / controllers / advanced / __init__.py View on Github external
def group_search(args: MultiDict, groups_or_archives: str) -> Response:
    """
    Short-cut for advanced search with group or archive pre-selected.

    Note that this only supports options supported in the advanced search
    interface. Anything else will result in a 404.
    """
    logger.debug("Group search for %s", groups_or_archives)
    valid_archives = []
    for archive in groups_or_archives.split(","):
        if archive not in taxonomy.ARCHIVES:
            logger.debug("archive %s not found in taxonomy", archive)
            continue
        # Support old archives.
        if archive in taxonomy.ARCHIVES_SUBSUMED:
            category = taxonomy.CATEGORIES[taxonomy.ARCHIVES_SUBSUMED[archive]]
            archive = category["in_archive"]
        valid_archives.append(archive)

    if len(valid_archives) == 0:
        logger.debug("No valid archives in request")
        raise NotFound("No such archive.")

    logger.debug("Request for %i valid archives", len(valid_archives))
    args = args.copy()
    for archive in valid_archives:
        fld = dict(forms.ClassificationForm.ARCHIVES).get(archive)
        if fld is not None:  # Try a top-level archive first.
            args[f"classification-{fld}"] = True
        else:
            # Might be a physics archive; if so, also select the physics
            # group on the form.
github arXiv / arxiv-browse / browse / services / document / metadata.py View on Github external
arxiv_id=arxiv_id,
                version_entry_list=parsed_version_entries)

        arxiv_identifier = Identifier(arxiv_id=arxiv_id)

        # named (key-value) fields
        if not all(rf in fields for rf in REQUIRED_FIELDS):
            raise AbsParsingException(f'missing required field(s)')

        # some transformations
        category_list: List[str] = []
        primary_category = None

        if 'categories' in fields and fields['categories']:
            category_list = fields['categories'].split()
            if category_list[0] in taxonomy.CATEGORIES:
                primary_category = Category(category_list[0])
                primary_archive = \
                    Archive(
                        taxonomy.CATEGORIES[primary_category.id]['in_archive'])
            elif arxiv_identifier.is_old_id:
                primary_archive = Archive(arxiv_identifier.archive)
        elif arxiv_identifier.is_old_id:
            primary_archive = Archive(arxiv_identifier.archive) 
        else:
            raise AbsException('Cannot infer archive from identifier.')

        doc_license: License = \
            License() if 'license' not in fields else License(
                recorded_uri=fields['license'])
        raw_safe = re.sub(RE_FROM_FIELD, r'\g\g', raw, 1)
github arXiv / arxiv-browse / browse / controllers / list_page / __init__.py View on Github external
subject_or_category = request.args.get('archive')  # type: ignore
    if request.args.get('year', None):
        time_period = request.args.get('year')  # type: ignore
        month = request.args.get('month', None)
        if month and month != 'all':
            time_period = time_period + request.args.get('month')  # type: ignore

    if (not subject_or_category or
            not (time_period and
                 (time_period.isdigit() or
                  time_period in ['new', 'current', 'pastweek', 'recent']))):
        raise BadRequest

    if subject_or_category in taxonomy.CATEGORIES:
        list_type = 'category'
        list_ctx_name = taxonomy.CATEGORIES[subject_or_category]['name']
        list_ctx_id = subject_or_category
        list_ctx_in_archive = taxonomy.CATEGORIES[subject_or_category]['in_archive']
    elif subject_or_category in taxonomy.ARCHIVES:
        list_type = 'archive'
        list_ctx_id = subject_or_category
        list_ctx_name = taxonomy.ARCHIVES[subject_or_category]['name']
        list_ctx_in_archive = list_ctx_name
    else:
        raise BadRequest

    listing_service = get_listing_service()
    if not listing_service:
        raise ServiceUnavailable

    if not skip or not skip.isdigit():
        skipn = 0
github arXiv / arxiv-browse / browse / controllers / abs_page / __init__.py View on Github external
Parameters
    ----------
    arxiv_identifier : :class:`Identifier`
    primary_category : :class: `Category`

    Returns
    -------
    Dict of values to add to response_data

    """
    # Set up the context
    context = None
    if ('context' in request.args and (
            context == 'arxiv'
            or context in taxonomy.CATEGORIES
            or context in taxonomy.ARCHIVES)):
        context = request.args['context']
    elif primary_category:
        pc = primary_category.canonical or primary_category
        if not arxiv_identifier.is_old_id:  # new style IDs
            context = pc.id
        else:  # Old style id
            if pc.id in taxonomy.ARCHIVES:
                context = pc.id
            else:
                context = arxiv_identifier.archive
    else:
        context = None

    response_data['browse_context'] = context
github arXiv / arxiv-browse / browse / domain / metadata.py View on Github external
def get_browse_context_list(self) -> List[str]:
        """Get the list of archive/category IDs to generate browse context."""
        if self.arxiv_identifier.is_old_id:
            if self.arxiv_identifier.archive is not None:
                return [self.arxiv_identifier.archive]
            else:
                return []

        if self.primary_category:
            options = {
                self.primary_category.id: True,
                taxonomy.CATEGORIES[self.primary_category.id]['in_archive']: True
            }
        for category in self.secondary_categories:
            options[category.id] = True
            in_archive = taxonomy.CATEGORIES[category.id]['in_archive']
            options[in_archive] = True
        return sorted(options.keys())
github arXiv / arxiv-browse / browse / domain / category.py View on Github external
def __post_init__(self) -> None:
        """Get the full category name."""
        if self.id in taxonomy.CATEGORIES:
            self.name = taxonomy.CATEGORIES[self.id]['name']

        if self.id in taxonomy.ARCHIVES_SUBSUMED:
            self.canonical = Category(id=taxonomy.ARCHIVES_SUBSUMED[self.id])
        else:
            self.canonical = None