示例#1
0
    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
示例#2
0
    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
示例#3
0
 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
示例#4
0
 def find_child_classes(self, schema_class):
     """Find schema classes that inherit from the given class
     """
     return unlist(list(self.schema_nx.successors(schema_class)))