<commit_before># Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

from __future__ import absolute_import

import copy
import retrying
import six

from orquesta import conducting
from orquesta import events
from orquesta import exceptions as orquesta_exc
from orquesta.expressions import base as expressions
from orquesta.specs import loader as specs_loader
from orquesta import states

from st2common.constants import action as ac_const
from st2common.exceptions import action as ac_exc
from st2common.exceptions import workflow as wf_exc
from st2common import log as logging
from st2common.models.db import liveaction as lv_db_models
from st2common.models.db import workflow as wf_db_models
from st2common.models.system import common as sys_models
from st2common.models.utils import action_param_utils
from st2common.persistence import liveaction as lv_db_access
from st2common.persistence import execution as ex_db_access
from st2common.persistence import workflow as wf_db_access
from st2common.services import action as ac_svc
from st2common.services import executions as ex_svc
from st2common.util import action_db as action_utils
from st2common.util import date as date_utils
from st2common.util import param as param_utils


LOG = logging.getLogger(__name__)


def is_action_execution_under_workflow_context(ac_ex_db):
    # The action execution is executed under the context of a workflow
    # if it contains the orquesta key in its context dictionary.
    return 'orquesta' in ac_ex_db.context


def format_inspection_result(result):
    errors = []

    categories = {
        'contents': 'content',
        'context': 'context',
        'expressions': 'expression',
        'semantics': 'semantic',
        'syntax': 'syntax'
    }

    # For context and expression errors, rename the attribute from type to language.
    for category in ['context', 'expressions']:
        for entry in result.get(category, []):
            entry['language'] = entry['type']
            del entry['type']

    # For all categories, put the category value in the type attribute.
    for category, entries in six.iteritems(result):
        for entry in entries:
            entry['type'] = categories[category]
            errors.append(entry)

    return errors

<commit_msg>Minor edit to inspection result formatting<commit_after># Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

from __future__ import absolute_import

import copy
import retrying
import six

from orquesta import conducting
from orquesta import events
from orquesta import exceptions as orquesta_exc
from orquesta.expressions import base as expressions
from orquesta.specs import loader as specs_loader
from orquesta import states

from st2common.constants import action as ac_const
from st2common.exceptions import action as ac_exc
from st2common.exceptions import workflow as wf_exc
from st2common import log as logging
from st2common.models.db import liveaction as lv_db_models
from st2common.models.db import workflow as wf_db_models
from st2common.models.system import common as sys_models
from st2common.models.utils import action_param_utils
from st2common.persistence import liveaction as lv_db_access
from st2common.persistence import execution as ex_db_access
from st2common.persistence import workflow as wf_db_access
from st2common.services import action as ac_svc
from st2common.services import executions as ex_svc
from st2common.util import action_db as action_utils
from st2common.util import date as date_utils
from st2common.util import param as param_utils


LOG = logging.getLogger(__name__)


def is_action_execution_under_workflow_context(ac_ex_db):
    # The action execution is executed under the context of a workflow
    # if it contains the orquesta key in its context dictionary.
    return 'orquesta' in ac_ex_db.context


def format_inspection_result(result):
    errors = []

    categories = {
        'contents': 'content',
        'context': 'context',
        'expressions': 'expression',
        'semantics': 'semantic',
        'syntax': 'syntax'
    }

    # For context and expression errors, rename the attribute from type to language.
    for category in ['context', 'expressions']:
        for entry in result.get(category, []):
            if 'language' not in entry:
                entry['language'] = entry['type']
                del entry['type']

    # For all categories, put the category value in the type attribute.
    for category, entries in six.iteritems(result):
        for entry in entries:
            entry['type'] = categories[category]
            errors.append(entry)

    return errors


{'fraction_non_alphanumeric': 0.05646090534979424, 'fraction_numerical': 0.006584362139917695, 'mean_word_length': 4.127426160337553, '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': '6803670', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1577, 'n_words': 688}