Beispiel #1
0
def replace_node_in_schema(schema: nx.MultiDiGraph, class_add_mod: dict) -> None:
    # part of the code that replaces the modified class in the original JSON-LD schema (not in the data/ folder though)
    for i, schema_class in enumerate(schema["@graph"]):
        if schema_class["rdfs:label"] == class_add_mod["rdfs:label"]:
            validate_class_schema(class_add_mod)    # validate that the class to be modified follows the structure for any generic class (node)

            schema["@graph"][i] = class_add_mod
            break
Beispiel #2
0
 def update_class(self, class_info):
     """Add a new class into schema
     """
     #print(class_info)
     validate_class_schema(class_info)
     self.schema["@graph"].append(class_info)
     validate_schema(self.schema)
     logger.info(f"Updated the class {class_info['rdfs:label']} successfully.")
     self.schema_nx = load_schema_into_networkx(self.schema)
Beispiel #3
0
    def edit_class(self, class_info):
        """Edit an existing class into schema
        """
        for i, schema_class in enumerate(self.schema["@graph"]):
            if schema_class["rdfs:label"] == class_info["rdfs:label"]:
                validate_class_schema(class_info)   # why are we doing this in a loop?

                self.schema["@graph"][i] = class_info
                break

        # TODO: do we actually need to validate the entire schema if a class is just edited and the class passes validation?
        #validate_schema(self.schema)
        
        logger.info(f"Edited the class {class_info['rdfs:label']} successfully.")
        self.schema_nx = load_schema_into_networkx(self.schema)
Beispiel #4
0
    def test_validate_class_schema(self, helpers):

        se_obj = helpers.get_schema_explorer("example.model.jsonld")

        mock_class = se_obj.generate_class_template()
        mock_class["@id"] = "bts:MockClass"
        mock_class["@type"] = "rdfs:Class"
        mock_class["@rdfs:comment"] = "This is a mock class"
        mock_class["@rdfs:label"] = "MockClass"
        mock_class["rdfs:subClassOf"]["@id"] = "bts:Patient"

        actual = validate_utils.validate_class_schema(mock_class)

        assert actual is None