def check_license(self):
     license_check = FAIREvaluatorLicense(self)
     license_check.set_metric('FsF-R1.1-01M', metrics=FAIRCheck.METRICS)
     return license_check.getResult()
    def evaluate(self):
        #Focus on machine readable rights -> URIs only
        #1) http://vocabularies.coar-repositories.org/documentation/access_rights/
        #2) Eprints AccessRights Vocabulary: check for http://purl.org/eprint/accessRights/
        #3) EU publications access rights check for http://publications.europa.eu/resource/authority/access-right/NON_PUBLIC
        #4) Openaire Guidelines <dc:rights>info:eu-repo/semantics/openAccess</dc:rights>
        self.result = DataAccessLevel(self.fuji.count, metric_identifier=self.metric_identifier, metric_name=self.metric_name)
        self.output = DataAccessOutput()
        licence_evaluator = FAIREvaluatorLicense(self.fuji)
        #rights_regex = r'((\/licenses|purl.org\/coar\/access_right|purl\.org\/eprint\/accessRights|europa\.eu\/resource\/authority\/access-right)\/{1}(\S*))'
        rights_regex = r'((\/creativecommons\.org|info\:eu\-repo\/semantics|purl.org\/coar\/access_right|purl\.org\/eprint\/accessRights|europa\.eu\/resource\/authority\/access-right)\/{1}(\S*))'

        access_level = None
        access_details = {}
        score = 0
        test_status = "fail"
        exclude = []
        access_rights = self.fuji.metadata_merged.get('access_level')

        #access_rights can be None or []
        if access_rights:
            self.logger.info('FsF-A1-01M : Found access rights information in dedicated metadata element')
            access_rights = 'info:eu-repo/semantics/restrictedAccess'
            if isinstance(access_rights, str):
                access_rights = [access_rights]
            for access_right in access_rights:
                self.logger.info('FsF-A1-01M : Access information specified - {}'.format(access_right))
                if not licence_evaluator.isLicense(value=access_right, metric_id=self.metric_identifier):  # exclude license-based text from access_rights
                    rights_match = re.search(rights_regex, access_right, re.IGNORECASE)
                    if rights_match is not None:
                        last_group = len(rights_match.groups())
                        filtered_rights = rights_match[last_group]
                        for right_code, right_status in Mapper.ACCESS_RIGHT_CODES.value.items():
                            if re.search(right_code, filtered_rights, re.IGNORECASE):
                                access_level = right_status
                                access_details['access_condition'] = rights_match[1] #overwrite existing condition
                                self.logger.info('FsF-A1-01M : Access level recognized as ' + str(right_status))
                                break
                        break
                    else:
                        self.logger.info('FsF-A1-01M : Not a standardized access level')
                else:
                    self.logger.warning('FsF-A1-01M : Access condition looks like license, therefore the following is ignored - {}'.format(access_right))
                    exclude.append(access_right)
            if not access_details and access_rights:
                access_rights = set(access_rights) - set(exclude)
                if access_rights :
                    access_details['access_condition'] = ', '.join(access_rights)
        else:
            self.logger.warning('FsF-A1-01M : NO access information is available in metadata')
            score = 0

        if access_level is None:
            # fall back - use binary access
            access_free = self.fuji.metadata_merged.get('access_free')
            if access_free is not None:
                self.logger.info('FsF-A1-01M : Used \'schema.org/isAccessibleForFree\' to determine the access level (either public or restricted)')
                if access_free: # schema.org: isAccessibleForFree || free
                    access_level = "public"
                else:
                    access_level = "restricted"
                access_details['accessible_free'] = access_free
            #TODO assume access_level = restricted if access_rights provided?

        #if embargoed, publication date must be specified (for now score is not deducted, just outputs warning message)
        if access_level == 'embargoed':
            available_date = self.fuji.metadata_merged.get('publication_date')
            if available_date:
                self.logger.info('FsF-A1-01M : Embargoed access, available date - {}'.format(available_date))
                access_details['available_date'] = available_date
            else:
                self.logger.warning('FsF-A1-01M : Embargoed access, available date NOT found')

        if access_level or access_details:
            score = 1
            test_status = "pass"

        self.score.earned = score
        self.result.score = self.score
        self.result.test_status = test_status
        if access_level: #must be one of ['public', 'embargoed', 'restricted', 'closed_metadataonly']
            self.output.access_level = access_level
            self.setEvaluationCriteriumScore('FsF-A1-01M-1', 1, 'pass')
            self.logger.log(self.fuji.LOG_SUCCESS, 'FsF-A1-01M : Access level to data could successfully be determined: '+access_level)
        else:
            self.logger.warning('FsF-A1-01M : Unable to determine the access level')
        self.output.access_details = access_details
        self.result.metric_tests = self.metric_tests
        self.result.output = self.output