コード例 #1
0
ファイル: copy_rdf.py プロジェクト: getshameer/Chaste
def Run(originalModelPath, newModelPath, outputModelPath):
    original_model = LoadModel(originalModelPath)
    new_model = LoadModel(newModelPath)
    # Copy all cmeta:ids to the new model
    vars = original_model.model.xml_xpath(u'cml:component/cml:variable[@cmeta:id]')
    for var in vars:
        try:
            new_var = new_model.model.get_variable_by_name(var.component.name, var.name)
        except:
            continue # No matching variable in the new model
        meta_id = var.cmeta_id
        new_var.xml_set_attribute((u'cmeta:id', translators.NSS['cmeta']), meta_id)
    # Also copy the model's cmeta:id, if any
    model_id = original_model.model.getAttributeNS(translators.NSS['cmeta'], u'id')
    if model_id:
        new_model.model.xml_set_attribute((u'cmeta:id', translators.NSS['cmeta']), model_id)
    # Get the RDF from the original model, and copy to the new one
    for triple in cellml_metadata.get_all_rdf(original_model.model):
        cellml_metadata.add_statement(new_model.model, *triple)
    cellml_metadata.update_serialized_rdf(new_model.model)
    # Write out to a new file
    stream = translators.open_output_stream(outputModelPath)
    new_model.xml(indent=u'yes', stream=stream)
    translators.close_output_stream(stream)
    # Tidy up nicely
    cellml_metadata.remove_model(original_model.model)
    cellml_metadata.remove_model(new_model.model)
コード例 #2
0
def Run(originalModelPath, newModelPath, outputModelPath):
    original_model = LoadModel(originalModelPath)
    new_model = LoadModel(newModelPath)
    # Copy all cmeta:ids to the new model
    vars = original_model.model.xml_xpath(
        u'cml:component/cml:variable[@cmeta:id]')
    for var in vars:
        try:
            new_var = new_model.model.get_variable_by_name(
                var.component.name, var.name)
        except:
            continue  # No matching variable in the new model
        meta_id = var.cmeta_id
        new_var.xml_set_attribute((u'cmeta:id', translators.NSS['cmeta']),
                                  meta_id)
    # Also copy the model's cmeta:id, if any
    model_id = original_model.model.getAttributeNS(translators.NSS['cmeta'],
                                                   u'id')
    if model_id:
        new_model.model.xml_set_attribute(
            (u'cmeta:id', translators.NSS['cmeta']), model_id)
    # Get the RDF from the original model, and copy to the new one
    for triple in cellml_metadata.get_all_rdf(original_model.model):
        cellml_metadata.add_statement(new_model.model, *triple)
    cellml_metadata.update_serialized_rdf(new_model.model)
    # Write out to a new file
    stream = translators.open_output_stream(outputModelPath)
    new_model.xml(indent=u'yes', stream=stream)
    translators.close_output_stream(stream)
    # Tidy up nicely
    cellml_metadata.remove_model(original_model.model)
    cellml_metadata.remove_model(new_model.model)
コード例 #3
0
ファイル: TestRdfCopier.py プロジェクト: getshameer/Chaste
 def _CompareRdf(self, referenceFilePath, outputFilePath):
     """Helper method to compare the RDF content of two CellML files."""
     ref_model = LoadModel(referenceFilePath)
     output_model = LoadModel(outputFilePath)
     ref_rdf = list(cellml_metadata.get_all_rdf(ref_model.model))
     output_rdf = list(cellml_metadata.get_all_rdf(output_model.model))
     self.assertEqual(len(ref_rdf), len(output_rdf))
     # Tidy up for Redland
     cellml_metadata.remove_model(ref_model.model)
     cellml_metadata.remove_model(output_model.model)
コード例 #4
0
ファイル: TestRdfCopier.py プロジェクト: zmhou/Chaste
 def _CompareRdf(self, referenceFilePath, outputFilePath):
     """Helper method to compare the RDF content of two CellML files."""
     ref_model = LoadModel(referenceFilePath)
     output_model = LoadModel(outputFilePath)
     ref_rdf = list(cellml_metadata.get_all_rdf(ref_model.model))
     output_rdf = list(cellml_metadata.get_all_rdf(output_model.model))
     self.assertEqual(len(ref_rdf), len(output_rdf))
     # Tidy up for Redland
     cellml_metadata.remove_model(ref_model.model)
     cellml_metadata.remove_model(output_model.model)