Beispiel #1
0
 def check_key(self, key):
     if key not in self.stdref:
         err = _error("{0} - invalid parsely-page field", key,
                      doc_lines=self.doc_lines)
         return ValidationWarning(ValidationResult.ERROR, err['err'], err['line'], err['num'])
     if key in ["link", "image_url"]:
         if not self.url_validator(self.data[key]):
             err = _error("{0} - invalid url for field '{1}'", self.data[key], key,
                          doc_lines=self.doc_lines)
             return ValidationWarning(ValidationResult.ERROR, err['err'], err['line'], err['num'])
     return None
Beispiel #2
0
 def _validate_class(self, cl):
     """return error if class `cl` is not found in the ontology"""
     if cl not in self.schema_def.attributes_by_class.keys():
         search_string = self._build_search_string(cl)
         err = self.err("{0} - invalid class",
                        self._field_name_from_uri(cl),
                        search_string=search_string)
         return ValidationWarning(ValidationResult.ERROR, err['err'],
                                  err['line'], err['num'])
Beispiel #3
0
 def _validate_class(self, cl):
     if cl not in self.schema_def.attributes_by_class.keys():
         search_string = str(cl)
         err = _error("{0} - invalid class",
                      self._field_name_from_uri(cl),
                      search_string=search_string,
                      doc_lines=self.doc_lines)
         return ValidationWarning(ValidationResult.ERROR, err['err'],
                                  err['line'], err['num'])
Beispiel #4
0
    def _validate_member(self, member, classes, instanceof):
        """return error if `member` is not a member of any class in `classes`"""
        log.info("Validating member %s" % member)

        stripped = self._get_stripped_attributes(member, classes)
        if self._field_name_from_uri(member) in stripped:
            all_class_members = sum(
                [self.schema_def.attributes_by_class[cl] for cl in classes],
                [])
            if member in all_class_members:
                return
            if self._namespace_from_uri(member) in self.allowed_namespaces:
                err = self.err("Unoficially allowed namespace {0}",
                               self._namespace_from_uri(member))
                return ValidationWarning(ValidationResult.WARNING, err['err'],
                                         err['line'], err['num'])
        else:
            err = self.err("{0} - invalid member of {1}",
                           self._field_name_from_uri(member),
                           self._field_name_from_uri(instanceof))
            return ValidationWarning(ValidationResult.ERROR, err['err'],
                                     err['line'], err['num'])
Beispiel #5
0
    def _validate_member(self, member, classes, instanceof):
        """return error if `member` is not a member of any class in `classes`"""
        log.info("Validating member %s" % member)

        # TODO - recalculating this list for every member is inefficient
        # calculate it once at the beginning, or consider replacing
        # attributes_by_class with it somehow
        stripped_attribute_names = []
        for cl in classes:
            sublist = []
            for attr in self.schema_def.attributes_by_class[cl]:
                sublist.append(attr)
            for field in sublist:
                sublist[sublist.index(field)] = self._field_name_from_uri(
                    field)
            stripped_attribute_names.append(sublist)

        if self._field_name_from_uri(member) in sum(stripped_attribute_names,
                                                    []):
            if member in sum(
                [self.schema_def.attributes_by_class[cl] for cl in classes],
                []):
                log.info("success")
                return None
            elif self._namespace_from_uri(member) in self.allowed_namespaces:
                log.info("warning - unofficially allowed namespace")
                err = _error("Unoficially allowed namespace {0}",
                             self._namespace_from_uri(member),
                             doc_lines=self.doc_lines)
                return ValidationWarning(ValidationResult.WARNING, err['err'],
                                         err['line'], err['num'])
        else:
            log.info("failure")
            err = _error("{0} - invalid member of {1}",
                         self._field_name_from_uri(member),
                         self._field_name_from_uri(instanceof),
                         doc_lines=self.doc_lines)
            return ValidationWarning(ValidationResult.ERROR, err['err'],
                                     err['line'], err['num'])
Beispiel #6
0
                                         err['line'], err['num'])
        else:
            err = self.err("{0} - invalid member of {1}",
                           self._field_name_from_uri(member),
                           self._field_name_from_uri(instanceof))
            return ValidationWarning(ValidationResult.ERROR, err['err'],
                                     err['line'], err['num'])

    def _validate_duplication(self, (subj, pred), cl):
        """returns error if we've already seen the member `pred` on `subj`"""
        log.info("Validating duplication of member %s" % pred)
        if (subj, pred) in self.checked_attributes:
            err = self.err("{0} - duplicated member of {1}",
                           self._field_name_from_uri(pred),
                           self._field_name_from_uri(cl))
            return ValidationWarning(ValidationResult.WARNING, err['err'],
                                     err['line'], err['num'])

    def _superclasses_for_subject(self, graph, typeof):
        """helper, returns a list of all superclasses of a given class"""
        # TODO - this might be replacing a fairly simple graph API query where
        # it doesn't need to
        classes = []
        superclass = typeof
        while True:
            found = False
            for p, o in self.schema_def.ontology[superclass]:
                if self.schema_def.lexicon['subclass'] == str(p):
                    found = True
                    classes.append(o)
                    superclass = o
            if not found: