66import sys
77import urllib
88import xml .etree .ElementTree as ET
9+ from abc import ABC , abstractmethod
910from functools import wraps
1011
1112import idutils
@@ -63,53 +64,7 @@ def wrapper(plugin, **kwargs):
6364 return wrapper
6465
6566
66- class ConfigTerms (property ):
67- def __init__ (self , term_id ):
68- self .term_id = term_id
69-
70- def __call__ (self , wrapped_func ):
71- @wraps (wrapped_func )
72- def wrapper (plugin , ** kwargs ):
73- metadata = plugin .metadata
74- has_metadata = True
75-
76- term_list = ast .literal_eval (plugin .config [plugin .name ][self .term_id ])
77- # Get values in config for the given term
78- if not term_list :
79- msg = (
80- "Cannot find any value for term <%s> in configuration"
81- % self .term_id
82- )
83- has_metadata = False
84- else :
85- # Get metadata associated with the term ID
86- term_metadata = pd .DataFrame (
87- term_list , columns = ["element" , "qualifier" ]
88- )
89- term_metadata = ut .check_metadata_terms_with_values (
90- metadata , term_metadata
91- )
92- if term_metadata .empty :
93- msg = (
94- "No access information can be found in the metadata for: %s. Please double-check the value/s provided for '%s' configuration parameter"
95- % (term_list , self .term_id )
96- )
97- has_metadata = False
98-
99- if not has_metadata :
100- logger .warning (msg )
101- return (0 , [{"message" : msg , "points" : 0 }])
102-
103- # Update kwargs with collected metadata for the required terms
104- kwargs .update (
105- {self .term_id : {"list" : term_list , "metadata" : term_metadata }}
106- )
107- return wrapped_func (plugin , ** kwargs )
108-
109- return wrapper
110-
111-
112- class Evaluator (object ):
67+ class EvaluatorBase (ABC ):
11368 """A class used to define FAIR indicators tests. It contains all the references to all the tests
11469
11570 ...
@@ -126,115 +81,79 @@ class Evaluator(object):
12681 lang : Language
12782 """
12883
129- def __init__ (self , item_id , oai_base = None , lang = "en" , plugin = None , config = None ):
84+ def __init__ (self , item_id , oai_base = None , lang = "en" , config = None , name = None ):
13085 self .item_id = item_id
13186 self .oai_base = oai_base
13287 self .metadata = None
133- self .access_protocols = []
13488 self .cvs = []
135- self .config = config
136- # configuration terms
137- self .terms_access_metadata = pd .DataFrame ()
138- self .terms_license_metadata = pd .DataFrame ()
139-
140- logger .debug ("OAI_BASE IN evaluator: %s" % oai_base )
141- if oai_base is not None and oai_base != "" and self .metadata is None :
142- metadataFormats = ut .oai_metadataFormats (oai_base )
143- dc_prefix = ""
144- for e in metadataFormats :
145- if metadataFormats [e ] == "http://www.openarchives.org/OAI/2.0/oai_dc/" :
146- dc_prefix = e
147- logger .debug ("DC_PREFIX: %s" % dc_prefix )
148-
149- try :
150- id_type = idutils .detect_identifier_schemes (self .item_id )[0 ]
151- except Exception as e :
152- id_type = "internal"
153-
154- logger .debug ("Trying to get metadata" )
155- try :
156- item_metadata = ut .oai_get_metadata (
157- ut .oai_check_record_url (oai_base , dc_prefix , self .item_id )
158- ).find (".//{http://www.openarchives.org/OAI/2.0/}metadata" )
159- except Exception as e :
160- logger .error ("Problem getting metadata: %s" % e )
161- item_metadata = ET .fromstring ("<metadata></metadata>" )
162- data = []
163- for tags in item_metadata .findall (".//" ):
164- metadata_schema = tags .tag [0 : tags .tag .rfind ("}" ) + 1 ]
165- element = tags .tag [tags .tag .rfind ("}" ) + 1 : len (tags .tag )]
166- text_value = tags .text
167- qualifier = None
168- data .append ([metadata_schema , element , text_value , qualifier ])
169- self .metadata = pd .DataFrame (
170- data , columns = ["metadata_schema" , "element" , "text_value" , "qualifier" ]
171- )
172-
173- if self .metadata is not None :
174- if len (self .metadata ) > 0 :
175- self .access_protocols = ["http" , "oai-pmh" ]
17689
17790 # Config attributes
178- self .name = plugin
179- if self .name == None :
180- self .name = "oai-pmh"
181- try :
182- self .identifier_term = ast .literal_eval (
183- self .config [self .name ]["identifier_term" ]
184- )
185- self .terms_quali_generic = ast .literal_eval (
186- self .config [self .name ]["terms_quali_generic" ]
187- )
188- self .terms_quali_disciplinar = ast .literal_eval (
189- self .config [self .name ]["terms_quali_disciplinar" ]
190- )
191- self .terms_access = ast .literal_eval (self .config [self .name ]["terms_access" ])
192- self .terms_cv = ast .literal_eval (self .config [self .name ]["terms_cv" ])
193- self .supported_data_formats = ast .literal_eval (
194- self .config [self .name ]["supported_data_formats" ]
195- )
196- self .terms_qualified_references = ast .literal_eval (
197- self .config [self .name ]["terms_qualified_references" ]
198- )
199- self .terms_relations = ast .literal_eval (
200- self .config [self .name ]["terms_relations" ]
201- )
202- self .terms_license = ast .literal_eval (
203- self .config [self .name ]["terms_license" ]
204- )
205- self .metadata_quality = 100 # Value for metadata quality
206- self .terms_access_protocols = ast .literal_eval (
207- self .config [self .name ]["terms_access_protocols" ]
208- )
209- self .metadata_standard = ast .literal_eval (
210- self .config [self .name ]["metadata_standard" ]
211- )
212- self .fairsharing_username = ast .literal_eval (
213- self .config ["fairsharing" ]["username" ]
214- )
91+ self .identifier_term = ast .literal_eval (
92+ self .config [self .name ]["identifier_term" ]
93+ )
94+ self .terms_quali_generic = ast .literal_eval (
95+ self .config [self .name ]["terms_quali_generic" ]
96+ )
97+ self .terms_quali_disciplinar = ast .literal_eval (
98+ self .config [self .name ]["terms_quali_disciplinar" ]
99+ )
100+ self .terms_cv = ast .literal_eval (self .config [self .name ]["terms_cv" ])
101+ self .supported_data_formats = ast .literal_eval (
102+ self .config [self .name ]["supported_data_formats" ]
103+ )
104+ self .terms_qualified_references = ast .literal_eval (
105+ self .config [self .name ]["terms_qualified_references" ]
106+ )
107+ self .terms_relations = ast .literal_eval (
108+ self .config [self .name ]["terms_relations" ]
109+ )
110+ self .metadata_access_manual = ast .literal_eval (
111+ self .config [self .name ]["metadata_access_manual" ]
112+ )
113+ self .data_access_manual = ast .literal_eval (
114+ self .config [self .name ]["data_access_manual" ]
115+ )
116+ self .terms_access_protocols = ast .literal_eval (
117+ self .config [self .name ]["terms_access_protocols" ]
118+ )
215119
216- self .fairsharing_password = ast .literal_eval (
217- self .config ["fairsharing" ]["password" ]
218- )
219- self .fairsharing_metadata_path = ast .literal_eval (
220- self .config ["fairsharing" ]["metadata_path" ]
221- )
222- self .fairsharing_formats_path = ast .literal_eval (
223- self .config ["fairsharing" ]["formats_path" ]
224- )
225- self .internet_media_types_path = ast .literal_eval (
226- self .config ["internet media types" ]["path" ]
227- )
228- self .metadata_schemas = ast .literal_eval (
229- self .config [self .name ]["metadata_schemas" ]
230- )
231- except Exception as e :
232- logger .error ("Problem loading plugin config: %s" % e )
120+ # self.vocabularies = ast.literal_eval(self.config[self.name]["vocabularies"])
233121
234- # Translations
235- self .lang = lang
236- logger .debug ("El idioma es: %s" % self .lang )
237- logger .debug ("METAdata: %s" % self .metadata )
122+ self .dict_vocabularies = ast .literal_eval (
123+ self .config [self .name ]["dict_vocabularies" ]
124+ )
125+
126+ self .vocabularies = list (self .dict_vocabularies .keys ())
127+ self .metadata_standard = ast .literal_eval (
128+ self .config [self .name ]["metadata_standard" ]
129+ )
130+
131+ self .metadata_authentication = ast .literal_eval (
132+ self .config [self .name ]["metadata_authentication" ]
133+ )
134+ self .metadata_persistence = ast .literal_eval (
135+ self .config [self .name ]["metadata_persistence" ]
136+ )
137+ self .terms_vocabularies = ast .literal_eval (
138+ self .config [self .name ]["terms_vocabularies" ]
139+ )
140+
141+ self .fairsharing_username = ast .literal_eval (
142+ self .config ["fairsharing" ]["username" ]
143+ )
144+
145+ self .fairsharing_password = ast .literal_eval (
146+ self .config ["fairsharing" ]["password" ]
147+ )
148+ self .fairsharing_metadata_path = ast .literal_eval (
149+ self .config ["fairsharing" ]["metadata_path" ]
150+ )
151+ self .fairsharing_formats_path = ast .literal_eval (
152+ self .config ["fairsharing" ]["formats_path" ]
153+ )
154+ self .internet_media_types_path = ast .literal_eval (
155+ self .config ["internet media types" ]["path" ]
156+ )
238157 global _
239158 _ = self .translation ()
240159
@@ -267,6 +186,11 @@ def eval_persistency(self, id_list, data_or_metadata="(meta)data"):
267186
268187 return (points , msg_list )
269188
189+ @abstractmethod
190+ def get_metadata (self ):
191+ """Method to be implemented by plugins."""
192+ raise NotImplementedError ("Derived class mus implement get_metadata method" )
193+
270194 def eval_uniqueness (self , id_list , data_or_metadata = "(meta)data" ):
271195 points = 0
272196 msg_list = []
@@ -2066,49 +1990,3 @@ def check_standard_license(self, license_id_or_url):
20661990 % _url
20671991 )
20681992 return license_name
2069-
2070-
2071- class ConfigTerms (property ):
2072- def __init__ (self , term_id ):
2073- self .term_id = term_id
2074-
2075- def __call__ (self , wrapped_func ):
2076- @wraps (wrapped_func )
2077- def wrapper (plugin , ** kwargs ):
2078- metadata = plugin .metadata
2079- has_metadata = True
2080-
2081- term_list = ast .literal_eval (plugin .config [plugin .name ][self .term_id ])
2082- # Get values in config for the given term
2083- if not term_list :
2084- msg = (
2085- "Cannot find any value for term <%s> in configuration"
2086- % self .term_id
2087- )
2088- has_metadata = False
2089- else :
2090- # Get metadata associated with the term ID
2091- term_metadata = pd .DataFrame (
2092- term_list , columns = ["element" , "qualifier" ]
2093- )
2094- term_metadata = ut .check_metadata_terms_with_values (
2095- metadata , term_metadata
2096- )
2097- if term_metadata .empty :
2098- msg = (
2099- "No access information can be found in the metadata for: %s. Please double-check the value/s provided for '%s' configuration parameter"
2100- % (term_list , self .term_id )
2101- )
2102- has_metadata = False
2103-
2104- if not has_metadata :
2105- logger .warning (msg )
2106- return (0 , msg )
2107-
2108- # Update kwargs with collected metadata for the required terms
2109- kwargs .update (
2110- {self .term_id : {"list" : term_list , "metadata" : term_metadata }}
2111- )
2112- return wrapped_func (plugin , ** kwargs )
2113-
2114- return wrapper
0 commit comments