<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import abc <EOL> import os <EOL> from six import with_metaclass <EOL> from rdflib . term import URIRef <EOL> from gutenberg . _domain_model . exceptions import UnsupportedFeatureException <EOL> from gutenberg . _domain_model . types import validate_etextno <EOL> from gutenberg . _util . abc import abstractclassmethod <EOL> from gutenberg . _util . objects import all_subclasses <EOL> from gutenberg . acquire . metadata import load_metadata <EOL> def get_metadata ( feature_name , etextno ) : <EOL> """<STR_LIT>""" <EOL> metadata_values = MetadataExtractor . get ( feature_name ) . get_metadata ( etextno ) <EOL> return frozenset ( metadata_values ) <EOL> def get_etexts ( feature_name , value ) : <EOL> """<STR_LIT>""" <EOL> matching_etexts = MetadataExtractor . get ( feature_name ) . get_etexts ( value ) <EOL> return frozenset ( matching_etexts ) <EOL> class MetadataExtractor ( with_metaclass ( abc . ABCMeta , object ) ) : <EOL> """<STR_LIT>""" <EOL> @ abstractclassmethod <EOL> def feature_name ( cls ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> @ abstractclassmethod <EOL> def get_metadata ( cls , etextno ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> @ abstractclassmethod <EOL> def get_etexts ( cls , value ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> @ classmethod <EOL> def _metadata ( cls ) : <EOL> """<STR_LIT>""" <EOL> return load_metadata ( ) <EOL> @ classmethod <EOL> def _etext_to_uri ( cls , etextno ) : <EOL> """<STR_LIT>""" <EOL> uri = r'<STR_LIT>' . format ( etextno ) <EOL> return URIRef ( uri ) <EOL> @ classmethod <EOL> def _uri_to_etext ( cls , uri_ref ) : <EOL> """<STR_LIT>""" <EOL> return validate_etextno ( int ( os . path . basename ( uri_ref . toPython ( ) ) ) ) <EOL> @ staticmethod <EOL> def __find_implementations ( ) : <EOL> """<STR_LIT>""" <EOL> implementations = { } <EOL> for implementation in all_subclasses ( MetadataExtractor ) : <EOL> try : <EOL> implementations [ implementation . feature_name ( ) ] = implementation <EOL> except NotImplementedError : <EOL> pass <EOL> return implementations <EOL> @ staticmethod <EOL> def get ( feature_name ) : <EOL> """<STR_LIT>""" <EOL> implementations = MetadataExtractor . __find_implementations ( ) <EOL> try : <EOL> return implementations [ feature_name ] <EOL> except KeyError : <EOL> raise UnsupportedFeatureException ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( feature_name = feature_name , <EOL> supported_features = '<STR_LIT:U+002CU+0020>' . join ( sorted ( implementations ) ) ) ) </s>
