<commit_before># Copyright 2017 ZTE Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json

def safe_get(key_val, key):
    return key_val[key] if key in key_val else ""


def find_node_name(node_id, node_list):
    for node in node_list:
        if node['id'] == node_id:
            return node['template_name']
    raise Exception('can not find node(%s).' % node_id)


def find_node_type(node_id, node_list):
    for node in node_list:
        if node['id'] == node_id:
            return node['type_name']
    raise Exception('can not find node(%s).' % node_id)


def find_related_node(node_id, src_json_model, requirement_name):
    related_nodes = []
    for model_tpl in safe_get(src_json_model, "node_templates"):
        for rt in safe_get(model_tpl, 'requirement_templates'):
            if safe_get(rt, 'name') == requirement_name and \
                safe_get(rt, 'target_node_template_name') == node_id:
                related_nodes.append(model_tpl['name'])
    return related_nodes


def convert_props(src_node, dest_node):
    if 'properties' in src_node and src_node['properties']:
        for prop_name, prop_info in src_node['properties'].items():
            if 'value' in prop_info:
                dest_node['properties'][prop_name] = prop_info['value']   


def convert_metadata(src_json):
    return src_json['metadata'] if 'metadata' in src_json else {}

def convert_factor_unit(value):
    return "%s %s" % (value["factor"], value["unit"])

def convert_inputs(src_json):
    inputs = {}
    if 'inputs' in src_json:
        src_inputs = src_json['inputs']
        for param_name, param_info in src_inputs.items():
            input_param = {}
            if 'type_name' in param_info:
                input_param['type'] = param_info['type_name']<commit_msg>fix unit parse logic of tosca<commit_after># Copyright 2017 ZTE Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json

def safe_get(key_val, key):
    return key_val[key] if key in key_val else ""


def find_node_name(node_id, node_list):
    for node in node_list:
        if node['id'] == node_id:
            return node['template_name']
    raise Exception('can not find node(%s).' % node_id)


def find_node_type(node_id, node_list):
    for node in node_list:
        if node['id'] == node_id:
            return node['type_name']
    raise Exception('can not find node(%s).' % node_id)


def find_related_node(node_id, src_json_model, requirement_name):
    related_nodes = []
    for model_tpl in safe_get(src_json_model, "node_templates"):
        for rt in safe_get(model_tpl, 'requirement_templates'):
            if safe_get(rt, 'name') == requirement_name and \
                safe_get(rt, 'target_node_template_name') == node_id:
                related_nodes.append(model_tpl['name'])
    return related_nodes


def convert_props(src_node, dest_node):
    if 'properties' in src_node and src_node['properties']:
        for prop_name, prop_info in src_node['properties'].items():
            if 'value' in prop_info:
                dest_node['properties'][prop_name] = prop_info['value']   


def convert_metadata(src_json):
    return src_json['metadata'] if 'metadata' in src_json else {}

def convert_factor_unit(value):
    if isinstance(value, (str, unicode)):
        return value
    return "%s %s" % (value["factor"], value["unit"])

def convert_inputs(src_json):
    inputs = {}
    if 'inputs' in src_json:
        src_inputs = src_json['inputs']
        for param_name, param_info in src_inputs.items():
            input_param = {}
            if 'type_name' in param_info:
                input_param['type'] = param_info['type_name']
{'fraction_non_alphanumeric': 0.10377157468570211, 'fraction_numerical': 0.0034093330492222457, 'mean_word_length': 3.378731343283582, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1667392', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1385, 'n_words': 438}