Ejemplo n.º 1
0
    def lookup_equivalent_isbns(self, identifier):
        """Finds NoveList data for all ISBNs equivalent to an identifier.

        :return: Metadata object or None
        """
        lookup_metadata = []
        license_sources = DataSource.license_sources_for(self._db, identifier)
        # Look up strong ISBN equivalents.
        for license_source in license_sources:
            lookup_metadata += [
                self.lookup(eq.output) for eq in identifier.equivalencies
                if (eq.data_source == license_source and eq.strength == 1
                    and eq.output.type == Identifier.ISBN)
            ]

        if not lookup_metadata:
            self.log.error(
                "Identifiers without an ISBN equivalent can't \
                be looked up with NoveList: %r", identifier)
            return None

        # Remove None values.
        lookup_metadata = [
            metadata for metadata in lookup_metadata if metadata
        ]
        if not lookup_metadata:
            return None

        best_metadata = self.choose_best_metadata(lookup_metadata, identifier)
        if not best_metadata:
            metadata, confidence = best_metadata
            if round(confidence, 2) < 0.5:
                self.log.warn(self.NO_ISBN_EQUIVALENCY, identifier)
                return None
        return metadata
Ejemplo n.º 2
0
    def lookup_equivalent_isbns(self, identifier):
        """Finds NoveList data for all ISBNs equivalent to an identifier.

        :return: Metadata object or None
        """
        lookup_metadata = []
        license_sources = DataSource.license_sources_for(self._db, identifier)
        # Look up strong ISBN equivalents.
        for license_source in license_sources:
            lookup_metadata += [self.lookup(eq.output)
                for eq in identifier.equivalencies
                if (eq.data_source==license_source and eq.strength==1
                    and eq.output.type==Identifier.ISBN)]

        if not lookup_metadata:
            self.log.error(
                "Identifiers without an ISBN equivalent can't \
                be looked up with NoveList: %r", identifier
            )
            return None

        # Remove None values.
        lookup_metadata = [metadata for metadata in lookup_metadata if metadata]
        if not lookup_metadata:
            return None

        best_metadata = self.choose_best_metadata(lookup_metadata, identifier)
        if not best_metadata:
            metadata, confidence = best_metadata
            if round(confidence, 2) < 0.5:
                self.log.warn(self.NO_ISBN_EQUIVALENCY, identifier)
                return None
        return metadata
Ejemplo n.º 3
0
    def lookup_equivalent_isbns(self, identifier):
        """Finds NoveList data for all ISBNs equivalent to an identifier.

        :return: Metadata object or None
        """
        lookup_metadata = []
        license_sources = DataSource.license_sources_for(self._db, identifier)

        # Find strong ISBN equivalents.
        isbns = list()
        for license_source in license_sources:
            isbns += [
                eq.output
                for eq in identifier.equivalencies
                if (
                    eq.data_source == license_source
                    and eq.strength == 1
                    and eq.output.type == Identifier.ISBN
                )
            ]

        if not isbns:
            self.log.warning(
                (
                    "Identifiers without an ISBN equivalent can't"
                    "be looked up with NoveList: %r"
                ),
                identifier,
            )
            return None

        # Look up metadata for all equivalent ISBNs.
        lookup_metadata = list()
        for isbn in isbns:
            metadata = self.lookup(isbn)
            if metadata:
                lookup_metadata.append(metadata)

        if not lookup_metadata:
            self.log.warning(
                (
                    "No NoveList metadata found for Identifiers without an ISBN"
                    "equivalent can't be looked up with NoveList: %r"
                ),
                identifier,
            )
            return None

        best_metadata, confidence = self.choose_best_metadata(
            lookup_metadata, identifier
        )
        if best_metadata:
            if round(confidence, 2) < 0.5:
                self.log.warning(self.NO_ISBN_EQUIVALENCY, identifier)
                return None
            return metadata
Ejemplo n.º 4
0
    def lookup_equivalent_isbns(self, identifier):
        """Finds NoveList data for all ISBNs equivalent to an identifier.

        :return: Metadata object or None
        """
        lookup_metadata = []
        license_sources = DataSource.license_sources_for(self._db, identifier)

        # Find strong ISBN equivalents.
        isbns = list()
        for license_source in license_sources:
            isbns += [eq.output for eq in identifier.equivalencies if (
                eq.data_source==license_source and
                eq.strength==1 and
                eq.output.type==Identifier.ISBN
            )]

        if not isbns:
            self.log.warn(
                ("Identifiers without an ISBN equivalent can't"
                "be looked up with NoveList: %r"), identifier
            )
            return None

        # Look up metadata for all equivalent ISBNs.
        lookup_metadata = list()
        for isbn in isbns:
            metadata = self.lookup(isbn)
            if metadata:
                lookup_metadata.append(metadata)

        if not lookup_metadata:
            self.log.warn(
                ("No NoveList metadata found for Identifiers without an ISBN"
                "equivalent can't be looked up with NoveList: %r"), identifier
            )
            return None

        best_metadata, confidence = self.choose_best_metadata(
            lookup_metadata, identifier
        )
        if best_metadata:
            if round(confidence, 2) < 0.5:
                self.log.warn(self.NO_ISBN_EQUIVALENCY, identifier)
                return None
            return metadata