def explore_property(self, schema_property): """Find details about a specific property TODO: refactor so that explore class and explore property reuse logic - they are *very* similar """ property_info = {} for record in self.schema["@graph"]: if record["@type"] == "rdf:Property": if record["rdfs:label"] == schema_property: property_info["id"] = record["rdfs:label"] property_info["description"] = record["rdfs:comment"] property_info["uri"] = curie2uri(record["@id"], namespaces) p_domain = dict2list(record["schema:domainIncludes"]) property_info["domain"] = unlist( [self.uri2label(record["@id"]) for record in p_domain]) if "schema:rangeIncludes" in record: p_range = dict2list(record["schema:rangeIncludes"]) property_info["range"] = [ self.uri2label(record["@id"]) for record in p_range ] else: property_info["range"] = [] if "sms:required" in record: if "sms:true" == record["sms:required"]: property_info["required"] = True else: property_info["required"] = False validation_rules = [] if "sms:validationRules" in record: property_info["validation_rules"] = record[ "sms:validationRules"] if "sms:requiresDependency" in record: p_dependencies = dict2list( record["sms:requiresDependency"]) property_info["dependencies"] = [ self.uri2label(record["@id"]) for record in p_dependencies ] else: property_info["dependencies"] = [] if "sms:displayName" in record: property_info["displayName"] = record[ "sms:displayName"] break # check if properties are added multiple times return property_info
def validate_rangeIncludes_field(self, rangeincludes_value): """Check if the value of "rangeincludes" is included in the schema file """ rangeincludes_value = dict2list(rangeincludes_value) for record in rangeincludes_value: assert record["@id"] in self.all_classes
def test_dict2list_with_list(self): # mock_dict = {'foo': 'bar'} mock_list = [{'foo': 'bar'}] test_list = general.dict2list(mock_list) assert test_list == mock_list
def test_dict2list_with_dict(self): mock_dict = {"foo": "bar"} mock_list = [{"foo": "bar"}] test_list = general.dict2list(mock_dict) assert test_list == mock_list
def validate_domainIncludes_field(self, domainincludes_value): """ Check if the value of "domainincludes" is included in the schema file """ domainincludes_value = dict2list(domainincludes_value) for record in domainincludes_value: assert record[ "@id"] in self.all_classes, "value of domainincludes not recorded in schema: %r" % domainincludes_value
def get_class_by_property(self, property_display_name): schema_property = self.get_property_label_from_display_name(property_display_name) for record in self.schema["@graph"]: if record["@type"] == "rdf:Property": if record["rdfs:label"] == schema_property: p_domain = dict2list(record["schema:domainIncludes"]) return unlist([self.uri2label(schema_class["@id"]) for schema_class in p_domain]) return None
def find_class_usages(self, schema_class): """Find where a given class is used as a value of a property """ usages = [] schema_uri = self.schema_nx.nodes[schema_class]["uri"] for record in self.schema["@graph"]: usage = {} if record["@type"] == "rdf:Property": if "schema:rangeIncludes" in record: p_range = dict2list(record["schema:rangeIncludes"]) for _doc in p_range: if _doc['@id'] == schema_uri: usage["property"] = record["rdfs:label"] p_domain = dict2list(record["schema:domainIncludes"]) usage["property_used_on_class"] = unlist([self.uri2label(record["@id"]) for record in p_domain]) usage["description"] = record["rdfs:comment"] if usage: usages.append(usage) return usages
def validate_subclassof_field(self, subclassof_value): """Check if the value of "subclassof" is included in the schema file""" subclassof_value = dict2list(subclassof_value) for record in subclassof_value: assert record["@id"] in self.all_classes