regx json fullpath

Posted 入门到放弃

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了regx json fullpath相关的知识,希望对你有一定的参考价值。

from collections  import OrderedDict
import  jsonpath_rw
import json

from future.moves import collections

A={"c":"ddd","app":999,"phone":18676743129,"user":"张胜男","tr":{"last":{"need":False}}}
order=OrderedDict()
# print(sorted(A.items(),key=lambda x:x[0],reverse=True))

def  order_define(o):
    if isinstance(o,dict):
        orders=dict(sorted(o.items(),key=lambda x:x[0],reverse=True))
        print(orders)


# data = {
#     "glossary": {
#         "title": "example glossary",
#         "GlossDiv": {
#             "title": "S",
#             "GlossList": {
#                 "GlossEntry": {
#                     "ID": "SGML",
#                     "SortAs": "SGML",
#                     "GlossTerm": "Standard",
#                     "Acronym": "SGML",
#                     "Abbrev": "ISO ",
#                     "GlossDef": {
#                         "para": "DocBook.",
#                         "GlossSeeAlso": ["GML", "XML"]
#                     },
#                     "GlossSee": "markup"
#                 }
#             }
#         }
#     }
# }
data={
  "initiator": {
    "role": "guest",
    "party_id":9997
  },
  "job_parameters": {
    "work_mode": 1
  },
  "role": {
    "guest": [
      9997
    ],
    "host": [
      9997
    ],
    "arbiter": [
      9997
    ]
  },
  "role_parameters": {
    "guest": {
      "args": {
        "data": {
          "train_data": [
            {
              "name": "breast_guest",
              "namespace": "breast_guest"
            }
          ]
        }
      },
      "dataio_0": {
        "with_label": [True],
        "label_name": ["y"],
        "label_type": ["int"],
        "output_format": ["dense"],
        "missing_fill": [True],
        "outlier_replace": [True]
      },
      "feature_scale_0": {
        "method": ["min_max_scale"]
      },
      "hetero_feature_binning_0": {
        "method": ["quantile"],
        "compress_thres": [10000],
        "head_size": [10000],
        "error": [0.001],
        "bin_num": [10],
        "cols": [-1],
        "adjustment_factor": [0.5],
        "local_only": [False],
        "transform_param": {
          "transform_cols": [-1],
          "transform_type": ["bin_num"]
        }
      },
      "hetero_feature_selection_0": {
        "select_cols": [-1],
        "filter_methods": [[
          "unique_value",
          "iv_value_thres",
          "coefficient_of_variation_value_thres",
          "iv_percentile",
          "outlier_cols"
        ]],
        "local_only": [False],
        "unique_param": {
          "eps": [1e-6]
        },
        "iv_value_param": {
          "value_threshold": [1.0]
        },
        "iv_percentile_param": {
          "percentile_threshold": [0.9]
        },
        "variance_coe_param": {
          "value_threshold": [0.3]
        },
        "outlier_param": {
          "percentile": [0.95],
          "upper_threshold": [10]
        }
      },
      "evaluation_0": {
        "eval_type": ["binary"],
        "pos_label": [1]
      }
    },
    "host": {
      "args": {
        "data": {
          "train_data": [
            {
              "name": "breast_host",
              "namespace": "breast_host"
            }
          ]
        }
      },
      "dataio_0": {
        "with_label": [False],
        "output_format": ["dense"],
        "outlier_replace": [True]
      },
      "feature_scale_0": {
        "method": ["standard_scale"],
        "need_run": [False]
      },
      "hetero_feature_binning_0": {
        "method": ["quantile"],
        "compress_thres": [10000],
        "head_size": [10000],
        "error": [0.001],
        "bin_num": [10],
        "cols": [-1],
        "adjustment_factor": [0.5],
        "local_only": [False],
        "transform_param": {
          "transform_cols": [-1],
          "transform_type": ["bin_num"]
        }
      },
      "hetero_feature_selection_0": {
        "select_cols": [-1],
        "filter_methods": [[
          "unique_value",
          "iv_value_thres",
          "coefficient_of_variation_value_thres",
          "iv_percentile",
          "outlier_cols"
        ]],
        "local_only": [False],
        "unique_param": {
          "eps": [1e-6]
        },
        "iv_value_param": {
          "value_threshold": [1.0]
        },
        "iv_percentile_param": {
          "percentile_threshold": [0.9]
        },
        "variance_coe_param": {
          "value_threshold": [0.3]
        },
        "outlier_param": {
          "percentile": [0.95],
          "upper_threshold": [10]
        }
      },
      "evaluation_0": {
        "need_run": [True]
      }
    }
  },
  "algorithm_parameters": {
    "feature_scale_0": {
        "need_run": True
    },
    "hetero_feature_binning_0": {
      "need_run": True
    },
    "hetero_feature_selection_0": {
      "need_run": True
    },
    "hetero_lr_0": {
      "penalty": "L2",
      "optimizer": "rmsprop",
      "eps": 1e-5,
      "alpha": 0.01,
      "max_iter": 10,
      "converge_func": "diff",
      "batch_size": -1,
      "learning_rate": 0.15,
      "init_param": {
        "init_method": "random_uniform"
      },
      "cv_param": {
        "n_splits": 5,
        "shuffle": False,
        "random_seed": 103,
        "need_cv": False
      }
    }
  }
}

import collections
import warnings
warnings.filterwarnings("ignore")


def get_paths(source):
    paths = []
    if isinstance(source, collections.MutableMapping):  # found a dict-like structure...
        for k, v in source.items():  # iterate over it; Python 2.x: source.iteritems()
            paths.append([k])  # add the current child path
            paths += [[k] + x for x in get_paths(v)]  # get sub-paths, extend with the current
    # else, check if a list-like structure, remove if you don‘t want list paths included
    elif isinstance(source, collections.Sequence) and not isinstance(source, str):
        #                          Python 2.x: use basestring instead of str ^
        for i, v in enumerate(source):
            paths.append([i])
            paths += [[i] + x for x in get_paths(v)]  # get sub-paths, extend with the current
    return paths


def cast_full_path(path_list,dictvariable_name:str):
    path=""
    for i  in path_list:
        if isinstance(i,int):
            path=path+‘[{}]‘.format(i)
        else:
            path =path+"[‘%s‘]"%i
    full_path= path
    return full_path


def str_path(data):
     path_str=[]
     paths=get_paths(data)
     for i in paths:
         res=‘.‘.join([str(j) for j  in i])
         path_str.append(res)
     return path_str
     # for i in path_str:
     #     print(i)

def full_path_list(quantile_list,dictvar_name):
    paths_list=[]
    for i in quantile_list:
        v=cast_full_path(i,"%s"%dictvar_name)
        paths_list.append(v)
    return paths_list



def  judge_path(key:str,regx_index=-1):
       res=[]
       it=full_path_list(get_paths(data),"data")
       for i in it:
             var=i.replace(‘[‘,‘.‘).replace(‘]‘,‘.‘).strip(‘.‘).replace(‘..‘,‘.‘).replace("‘",‘‘).split(‘.‘)
             if key==var[-1]:
                 print("matchs join strpath is:
 %s" % ‘.‘.join(var))
                 res.append(i)
       if regx_index !=-1:
            print("last return:
%s "%res[regx_index])
            return  res[regx_index]
       elif regx_index==-1:
           print("last return:
%s " % res)
           return res
if __name__ == ‘__main__‘:
    # k=full_path_list(get_paths(data),"data")
    # for i in k:
    #     print(i)
    judge_path("name")
    # st="[‘role_parameters‘][‘guest‘][‘hetero_feature_selection_0‘][‘iv_value_param‘][‘value_threshold‘][0]"
    # aa=st.replace(‘[‘,‘.‘).replace(‘]‘,‘.‘).strip(‘.‘).replace(‘..‘,‘.‘).replace("‘",‘‘).split(‘.‘)

  .

以上是关于regx json fullpath的主要内容,如果未能解决你的问题,请参考以下文章

实用代码片段将json数据绑定到html元素 (转)

json 可视代码工作室Angular with Firebase片段

vs code 用户代码片段 html.json

错误代码:错误域 = NSCocoaErrorDomain 代码 = 3840“JSON 文本没有以数组或对象和允许未设置片段的选项开头。”

如何在android中将json数据加载到片段中

使用 json rereiver php mysql 在片段中填充列表视图