def _revert_set_2bethrown(self, root_element, name, default_key):
     print("aaaa")
     if isinstance(root_element, list):
         for idx, _ in enumerate(root_element):
             if self.retour is None:
                 self._revert_set(root_element[idx], name, default_key)
     elif isinstance(root_element, dict):
         for k, v in root_element.items():
             if k == name:
                 if isinstance(v, list):
                     raise Exception(name + " cannot be a list")
                 elif isinstance(v, dict):  
                     # the elememt may have been reverted in a precedent pass
                     # It can not be reserved twice
                     try:
                         print("bbbbbbbbbbb ")
                         print(DictUtils.get_pretty_json(v))
                         newcontent = {}
                         new_key = self._get_key_for_element(v["INSTANCE"], default_key)
                         newcontent[new_key] = deepcopy(v["INSTANCE"])
                         self.retour = {'node': root_element, "newcontent": newcontent}
                     except:
                         import traceback
                         traceback.print_exc()
                         pass
             if self.retour is None:
                 self._revert_set(v, name, default_key)
Example #2
0
 def test_1(self):
     self.json_ref_path = os.path.join(
         self.data_path, "./data/test_vodml_instance_21.json")
     if self.populated is False:
         self.vodml_instance.populate_templates()
         self.vodml_instance.connect_join_iterators()
         self.populated = True
     table_mapper = self.vodml_instance.table_mappers["Results"]
     full_dict = table_mapper.get_full_instance()
     print(DictUtils.get_pretty_json(full_dict))
     sys.exit(1)
Example #3
0
    def _build_instance(self):
        '''
        Translate the MODEL_INSTANCE block into dict
        '''
        builder = JsonMappingBuilder(json_dict=self.json_block)

        builder.revert_sets("GLOBALS", default_key='globals')
        #self.builder.revert_compositions("COLLECTION")
        builder.revert_sets("TABLE_MAPPING", default_key='root')
        builder.revert_array()
        builder.revert_compositions("COLLECTION")
        builder.revert_elements("INSTANCE")
        builder.revert_elements("ATTRIBUTE")
        builder.revert_elements("MODEL")

        self.json_vodml_block = builder.json
        print(DictUtils.get_pretty_json(self.json_vodml_block))
        logger.info("JSON MODEL_INSTANCE block built")
Example #4
0
from utils.dict_utils import DictUtils

from client.inst_builder.vodml_instance import VodmlInstance

if __name__ == '__main__':
    base_path = os.path.dirname(os.path.realpath(__file__))
    votable_path = os.path.join(data_dir, "annotated_data",
                                "vizier_votable_avecActivity_Vo-dml-lite.xml")
    vodml_instance = VodmlInstance(votable_path)
    vodml_instance.populate_templates()
    vodml_instance.connect_join_iterators()

    instance = vodml_instance.get_root_element("voprov:Entity")

    print(DictUtils.get_pretty_json(instance.json))
    print("=== Mapping of the columns")
    print(instance.get_flatten_data_head())
    #print(instance.get_data_subset_keys())
    print("=== First row: flatten mode")
    while True:
        inst = instance._get_next_flatten_row()
        if inst != None:
            print(DictUtils.get_pretty_json(inst))
            break
        else:
            break

    print("=== Second row: instance mode")
    while True:
        inst = instance._get_next_row_instance()
 def save_instance(self):     
     file_path = self.json_path.replace(".json", ".inst.json")
     logger.info("save instance in %s", file_path)   
     with open(file_path, 'w') as jsonfile:
         jsonfile.write(DictUtils.get_pretty_json(self.json))
Example #6
0
        if inst != None:
            break
        else:
            break

    #BUG 2 parameters arrays are nested
    #TODO 2 be fixed
    parameters = inst["mango:MangoObject.parameters"]
    parameters = parameters[0]["mango:MangoObject.parameters"]
    parameter_map = {}
    for parameter in parameters:
        ucd = parameter["mango:Parameter.ucd"]["@value"]
        classe = parameter["mango:Parameter.measure"]["@dmtype"]
        semantic = parameter["mango:Parameter.semantic"]["@value"]
        description = parameter["mango:Parameter.description"]["@value"]
        parameter_map[classe] = {
            "class": classe,
            "ucd": ucd,
            "semantic": semantic,
            "description": description
        }
    return parameter_map


if __name__ == '__main__':
    base_path = os.path.dirname(os.path.realpath(__file__))
    for vot in ["vizier_propermotion.annot.xml", "4xmm_detections.annot.xml"]:
        votable_path = os.path.join(data_dir, "annotated_data", vot)
        parameter_map = map_measures(votable_path)
        print(DictUtils.get_pretty_json(parameter_map))
    vodml_instance.connect_join_iterators()
    table_row_instances = vodml_instance.get_root_element("mango:MangoObject")

    if len(vodml_instance.table_mappers) == 0:
        print("no table mapper")
        sys.exit(1)
    mapper_name = None
    for k, v in vodml_instance.table_mappers.items():
        print("process table mapper {}".format(k))
        mapper_name = k
        break;
    
    while True:
        inst = table_row_instances._get_next_row_instance()
        if inst != None:
            print(DictUtils.get_pretty_json(inst))
        break
    wrapper = AstropyWrapper(vodml_instance, mapper_name)
    print("Astropy space frame: {}".format(wrapper.get_space_frame(inst)))
    print("Astropy time frame: {}".format(wrapper.get_time_frame(inst)))