Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Prevent phantom books from crashing queries
Browse files Browse the repository at this point in the history
This is a partial fix for #57
  • Loading branch information
c-w committed Feb 19, 2017
1 parent 46b77c7 commit a8e0c6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion gutenberg/query/api.py
Expand Up @@ -9,6 +9,7 @@
from six import with_metaclass
from rdflib.term import URIRef

from gutenberg._domain_model.exceptions import InvalidEtextIdException
from gutenberg._domain_model.exceptions import UnsupportedFeatureException
from gutenberg._domain_model.types import validate_etextno
from gutenberg._util.abc import abstractclassmethod
Expand Down Expand Up @@ -114,7 +115,10 @@ def _uri_to_etext(cls, uri_ref):
meta-data RDF graph to a human-friendly integer text identifier.
"""
return validate_etextno(int(os.path.basename(uri_ref.toPython())))
try:
return validate_etextno(int(os.path.basename(uri_ref.toPython())))
except InvalidEtextIdException:
return None

@staticmethod
def __find_implementations():
Expand Down
3 changes: 2 additions & 1 deletion gutenberg/query/extractors.py
Expand Up @@ -40,7 +40,8 @@ def get_metadata(cls, etextno):
@classmethod
def get_etexts(cls, requested_value):
query = cls._metadata()[:cls.predicate():cls.contains(requested_value)]
return frozenset(cls._uri_to_etext(result) for result in query)
results = (cls._uri_to_etext(result) for result in query)
return frozenset(result for result in results if result is not None)


class AuthorExtractor(_SimplePredicateRelationshipExtractor):
Expand Down

0 comments on commit a8e0c6a

Please sign in to comment.