From f876815e1d253af5f769c55d2a15a3d9f58db940 Mon Sep 17 00:00:00 2001 From: dingsheng Date: Wed, 25 Sep 2024 12:32:36 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=86=E7=B1=BB=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/algclassify.py | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 src/main/algclassify.py diff --git a/src/main/algclassify.py b/src/main/algclassify.py new file mode 100755 index 0000000..45a85ee --- /dev/null +++ b/src/main/algclassify.py @@ -0,0 +1,76 @@ +#-*- coding:utf-8 -*- +""" +# ********************************************************************************** +# Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. +# [kyclassifier] licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# ********************************************************************************** +""" +import json + + +class AlgClassify(object): + """ + 分类算法模块 + """ + + @classmethod + def run(cls): + """ + 分类算法入口函数 + """ + pass + + @staticmethod + def _load_data(data_f): + """ + 加载分类数据json文件 + Args: + data_f (str): 分类数据文件路径 + + Returns: + res (dict): 初始化分类字典 + """ + with open(data_f,'r',encoding='utf-8') as f: + res = json.load(f) + return res + + @staticmethod + def _get_pkgs(data_obj): + """ + 获取所有软件包名集合 + Args: + data_obj: DataParse类对象 + + Returns: + 软件包名集合 + """ + return data_obj.pkgs_name + + @staticmethod + def _get_pkg2category_by_rpmgroup(data_obj): + """ + 通过rpmgroup获取软件包类别 + Args: + data_obj: DataParse类对象 + + Returns: + res: 分类字典 + """ + res = {} + invalid_labels = ['Unspecified',''] + pkgsinfo = data_obj.pkgs_info + for p in pkgsinfo: + name = p.get('name') + rpm_group = p.get('rpm_group') + if rpm_group not in invalid_labels: + res.update({name:rpm_group}) + else: + continue + return res \ No newline at end of file -- Gitee