orbitkit 0.8.47__tar.gz → 0.8.48__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. {orbitkit-0.8.47/orbitkit.egg-info → orbitkit-0.8.48}/PKG-INFO +1 -1
  2. orbitkit-0.8.48/orbitkit/VERSION +1 -0
  3. orbitkit-0.8.48/orbitkit/orbit_type/__init__.py +1 -0
  4. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/orbit_type/orbit_type_simple.py +277 -1
  5. {orbitkit-0.8.47 → orbitkit-0.8.48/orbitkit.egg-info}/PKG-INFO +1 -1
  6. orbitkit-0.8.47/orbitkit/VERSION +0 -1
  7. orbitkit-0.8.47/orbitkit/orbit_type/__init__.py +0 -1
  8. {orbitkit-0.8.47 → orbitkit-0.8.48}/LICENSE +0 -0
  9. {orbitkit-0.8.47 → orbitkit-0.8.48}/MANIFEST.in +0 -0
  10. {orbitkit-0.8.47 → orbitkit-0.8.48}/README.md +0 -0
  11. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/__init__.py +0 -0
  12. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/airflow_handler/__init__.py +0 -0
  13. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/airflow_handler/data_preprocessing.py +0 -0
  14. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/airflow_handler/file_flow_entry_process.py +0 -0
  15. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/airflow_handler/file_flow_exit_process.py +0 -0
  16. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/airflow_handler/file_handler.py +0 -0
  17. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/airflow_handler/file_handler_v2.py +0 -0
  18. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/audio_transcoder/__init__.py +0 -0
  19. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/audio_transcoder/netmind_extract_v1.py +0 -0
  20. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/constant/__init__.py +0 -0
  21. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/constant/report_schema.py +0 -0
  22. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/id_srv/__init__.py +0 -0
  23. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/id_srv/id_gen.py +0 -0
  24. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/id_srv/id_perm_like.py +0 -0
  25. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/lark_send/__init__.py +0 -0
  26. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/lark_send/lark.py +0 -0
  27. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/llm_tools/__init__.py +0 -0
  28. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/llm_tools/quick_rag_chat.py +0 -0
  29. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/orbit_type/doc_4_compile_rule.py +0 -0
  30. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/orbit_type/tools.py +0 -0
  31. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_embedding/__init__.py +0 -0
  32. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_embedding/pdf_txt_embedding.py +0 -0
  33. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_embedding/pdf_txt_embedding_v2.py +0 -0
  34. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/__init__.py +0 -0
  35. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/a_stock_extractor_v1.py +0 -0
  36. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/exceptions.py +0 -0
  37. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/pdf_block_extractor_base.py +0 -0
  38. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/pdf_block_extractor_v1.py +0 -0
  39. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/pdf_block_extractor_v2.py +0 -0
  40. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/pdf_extractor_azure.py +0 -0
  41. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/pdf_extractor_minerU_v1.py +0 -0
  42. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/pdf_extractor_netmind_v1.py +0 -0
  43. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/pdf_extractor_netmind_v2.py +0 -0
  44. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/pdf_extractor_netmind_v3.py +0 -0
  45. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor/pdf_extractor_orbit.py +0 -0
  46. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor_simple/__init__.py +0 -0
  47. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor_simple/base.py +0 -0
  48. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor_simple/cloud_provider.py +0 -0
  49. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor_simple/core.py +0 -0
  50. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor_simple/exceptions.py +0 -0
  51. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor_simple/extractors.py +0 -0
  52. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_extractor_simple/utils.py +0 -0
  53. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_writer/__init__.py +0 -0
  54. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/pdf_writer/pdf_writer_simple.py +0 -0
  55. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/__init__.py +0 -0
  56. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/cache_asset_downloader.py +0 -0
  57. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/common.py +0 -0
  58. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/customize_regix_manager.py +0 -0
  59. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/secret_manager.py +0 -0
  60. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_aliyun.py +0 -0
  61. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_aliyun_oss_simple.py +0 -0
  62. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_aws.py +0 -0
  63. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_aws_s3_wrapper.py +0 -0
  64. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_date.py +0 -0
  65. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_html.py +0 -0
  66. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_kafka.py +0 -0
  67. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_md5.py +0 -0
  68. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_selenium.py +0 -0
  69. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_simple_timer.py +0 -0
  70. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_str.py +0 -0
  71. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_type_mapping.py +0 -0
  72. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit/util/util_url.py +0 -0
  73. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit.egg-info/SOURCES.txt +0 -0
  74. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit.egg-info/dependency_links.txt +0 -0
  75. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit.egg-info/not-zip-safe +0 -0
  76. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit.egg-info/requires.txt +0 -0
  77. {orbitkit-0.8.47 → orbitkit-0.8.48}/orbitkit.egg-info/top_level.txt +0 -0
  78. {orbitkit-0.8.47 → orbitkit-0.8.48}/setup.cfg +0 -0
  79. {orbitkit-0.8.47 → orbitkit-0.8.48}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orbitkit
3
- Version: 0.8.47
3
+ Version: 0.8.48
4
4
  Summary: This project is only for Orbit Tech internal use.
5
5
  Home-page: https://github.com/clown-0726/orbitkit
6
6
  Author: Lilu Cao
@@ -0,0 +1 @@
1
+ 0.8.48
@@ -0,0 +1 @@
1
+ from .orbit_type_simple import OrbitTypeMatcher, OrbitTypeMatcherAsync
@@ -2,9 +2,10 @@ import abc
2
2
  import json
3
3
  import logging
4
4
  import re
5
- from typing import List, Literal
5
+ from typing import List, Literal, Optional
6
6
  from botocore.exceptions import ClientError
7
7
  import boto3
8
+ import aioboto3
8
9
 
9
10
  logger = logging.getLogger(__name__)
10
11
 
@@ -459,6 +460,281 @@ class OrbitTypeMatcher:
459
460
  }
460
461
 
461
462
 
463
+ class OrbitTypeMatcherAsync:
464
+ """
465
+ OrbitTypeMatcher 的异步版本
466
+ 使用 aioboto3 进行异步 S3 操作,提升性能
467
+ """
468
+
469
+ def __init__(
470
+ self,
471
+ aws_access_key_id: Optional[str] = None,
472
+ aws_secret_access_key: Optional[str] = None,
473
+ file_bucket: str = 'ot-cdn',
474
+ key_prefix: str = 'orbit-typing/typing-prod'
475
+ ):
476
+ """
477
+ 初始化异步类型匹配器
478
+
479
+ :param aws_access_key_id: AWS access key ID(可选,不提供则使用默认凭证链)
480
+ :param aws_secret_access_key: AWS secret access key(可选)
481
+ :param file_bucket: S3 bucket 名称
482
+ :param key_prefix: S3 key 前缀
483
+ """
484
+ # 创建 aioboto3 session
485
+ if aws_access_key_id and aws_secret_access_key:
486
+ self.session = aioboto3.Session(
487
+ aws_access_key_id=aws_access_key_id,
488
+ aws_secret_access_key=aws_secret_access_key
489
+ )
490
+ else:
491
+ # 使用默认凭证链(环境变量、AWS CLI 配置、IAM 角色等)
492
+ self.session = aioboto3.Session()
493
+
494
+ self.file_bucket = file_bucket
495
+ self.key_prefix = key_prefix
496
+ self.matcher = None
497
+ self.json_file = None
498
+ self.version = None
499
+
500
+ @classmethod
501
+ async def create(
502
+ cls,
503
+ aws_access_key_id: Optional[str] = None,
504
+ aws_secret_access_key: Optional[str] = None,
505
+ file_bucket: str = 'ot-cdn',
506
+ key_prefix: str = 'orbit-typing/typing-prod',
507
+ version: Optional[str] = None
508
+ ):
509
+ """
510
+ 异步工厂方法,用于创建已初始化的 OrbitTypeMatcherAsync 实例
511
+
512
+ :param aws_access_key_id: AWS access key ID(可选)
513
+ :param aws_secret_access_key: AWS secret access key(可选)
514
+ :param file_bucket: S3 bucket 名称
515
+ :param key_prefix: S3 key 前缀
516
+ :param version: 类型版本号(可选,不提供则使用最新版本)
517
+ :return: 已初始化的 OrbitTypeMatcherAsync 实例
518
+
519
+ 示例:
520
+ matcher = await OrbitTypeMatcherAsync.create(version='0.3.4')
521
+ result = matcher.match_type(title='Press Release')
522
+ """
523
+ instance = cls(
524
+ aws_access_key_id=aws_access_key_id,
525
+ aws_secret_access_key=aws_secret_access_key,
526
+ file_bucket=file_bucket,
527
+ key_prefix=key_prefix
528
+ )
529
+
530
+ # 异步加载版本和配置文件
531
+ if not version:
532
+ version = await instance.get_newest_version()
533
+
534
+ source_key = f'{key_prefix}/{version}.json'
535
+ json_file = await instance.read_s3_file(
536
+ bucket_name=file_bucket,
537
+ file_name=source_key
538
+ )
539
+
540
+ if not json_file:
541
+ raise Exception(f'该 S3 文件不存在: {source_key}')
542
+
543
+ instance.json_file = json_file
544
+ instance.matcher = L3RuleListMatcher(json_file)
545
+ instance.version = version
546
+
547
+ return instance
548
+
549
+ async def read_s3_file(self, bucket_name: str, file_name: str):
550
+ """
551
+ 异步读取 S3 中的 JSON 文件
552
+
553
+ :param bucket_name: S3 bucket 名称
554
+ :param file_name: 文件路径
555
+ :return: JSON 数据或 None
556
+ """
557
+ try:
558
+ async with self.session.client('s3') as s3_client:
559
+ file_obj = await s3_client.get_object(Bucket=bucket_name, Key=file_name)
560
+ content = await file_obj['Body'].read()
561
+ lines = content.decode('utf-8')
562
+ json_data = json.loads(lines)
563
+ return json_data
564
+ except ClientError as e:
565
+ logger.error(f"读取 S3 文件失败: {bucket_name}/{file_name}, 错误: {e}")
566
+ return None
567
+
568
+ async def get_newest_version(self):
569
+ """
570
+ 异步获取最新的类型版本号
571
+
572
+ :return: 最新版本号字符串
573
+ """
574
+ async with self.session.client('s3') as s3_client:
575
+ response = await s3_client.list_objects_v2(
576
+ Bucket=self.file_bucket,
577
+ Prefix=self.key_prefix
578
+ )
579
+
580
+ # 遍历存储桶中的对象,获取文件名
581
+ file_names = []
582
+ for obj in response.get('Contents', []):
583
+ key = obj['Key']
584
+ if key.endswith('/'): # 排除文件夹本身
585
+ continue
586
+ file_names.append(key.split('/')[-1]) # 获取文件名部分
587
+
588
+ result = []
589
+ for key in file_names:
590
+ if 'tmp.json' in key:
591
+ continue
592
+ if '.json' not in key:
593
+ continue
594
+ result.append(key.replace('.json', ''))
595
+
596
+ def sort_vision_json_file(filename):
597
+ parts = filename.replace('.json', '').split('.')
598
+ return tuple(int(part) for part in parts)
599
+
600
+ sorted_versions = sorted(result, key=sort_vision_json_file, reverse=True)
601
+ return sorted_versions[0]
602
+
603
+ def get_full_type_list(self):
604
+ """
605
+ 获取完整包含 1、2、3 级类型的列表
606
+ 注意:此方法是同步的,因为它只进行内存操作
607
+
608
+ :return: 完整类型列表
609
+ """
610
+ lv1_list = self.json_file['lv1_list']
611
+ lv1_dict = {}
612
+ for row in lv1_list:
613
+ lv1_id = row['lv1_id']
614
+ name = row['lv1_name']
615
+ lv1_dict[lv1_id] = name
616
+
617
+ lv2_list = self.json_file['lv2_list']
618
+ lv2_dict = {}
619
+ for row in lv2_list:
620
+ lv1_id = row['lv1_id']
621
+ lv2_id = row['lv2_id']
622
+ name = row['lv2_name']
623
+ lv2_dict[lv2_id] = {
624
+ 'lv2_id': lv2_id,
625
+ 'lv2_name': name,
626
+ 'lv1_id': lv1_id,
627
+ 'lv1_name': lv1_dict[lv1_id]
628
+ }
629
+
630
+ lv3_list = self.json_file['lv3_list']
631
+ lv3_data = []
632
+ for row in lv3_list:
633
+ lv2_id = row['level_2_id']
634
+ this_dict = {
635
+ 'lv3_id': row['lv3_id'],
636
+ 'lv3_name': row['lv3_name']
637
+ }
638
+ this_dict.update(lv2_dict[lv2_id])
639
+ lv3_data.append(this_dict)
640
+
641
+ sorted_list = sorted(
642
+ lv3_data,
643
+ key=lambda x: (int(x['lv3_id']), int(x['lv2_id']), int(x['lv1_id']))
644
+ )
645
+ return sorted_list
646
+
647
+ def match_type(self, match_flag: Literal['in_order', 'match_all'] = 'in_order', **match_kwargs):
648
+ """
649
+ 用于匹配的函数,可以传入 n 个匹配参数
650
+ 注意:此方法是同步的,因为匹配操作只涉及内存操作,不需要 I/O
651
+
652
+ :param match_flag: 匹配模式
653
+ - 'in_order': 按顺序依次匹配,匹配到结果就停止
654
+ - 'match_all': 匹配全部的项,并将结果合并
655
+ :param match_kwargs: 匹配参数(如 title='...', url='...', description='...')
656
+ :return: 匹配结果
657
+
658
+ 示例:
659
+ # 按顺序匹配
660
+ key, result = matcher.match_type(
661
+ match_flag='in_order',
662
+ title='Press Release',
663
+ description='Company news'
664
+ )
665
+
666
+ # 匹配所有
667
+ result = matcher.match_type(
668
+ match_flag='match_all',
669
+ title='Press Release',
670
+ url='https://example.com/news/press-release'
671
+ )
672
+ """
673
+ if match_flag not in ['in_order', 'match_all']:
674
+ raise ValueError('match_flag 参数必须是 "in_order" 或 "match_all"')
675
+ if not match_kwargs:
676
+ raise ValueError('必须传入匹配关键词!')
677
+
678
+ default_result = [{'lv3_id': '19999', 'lv3_name': 'Miscellaneous'}]
679
+
680
+ def match_url(url: str):
681
+ split_url = url.replace('http://', '').replace('https://', '').split('/')
682
+ split_url = [x.strip().replace('%20', ' ') for x in split_url if len(x.strip()) > 4]
683
+ for part in reversed(split_url):
684
+ match_result = self.matcher.start_match_all(part)
685
+ if match_result:
686
+ match_key = f'url#{part}'
687
+ return match_key, match_result
688
+ return None, None
689
+
690
+ if match_flag == 'in_order':
691
+ for key, value in match_kwargs.items():
692
+ if key == 'url':
693
+ url_key, match_result = match_url(value)
694
+ if match_result:
695
+ return url_key, match_result
696
+ else:
697
+ match_result = self.matcher.start_match_all(value)
698
+ if match_result:
699
+ return key, match_result
700
+ return None, default_result
701
+
702
+ elif match_flag == 'match_all':
703
+ overall_results = []
704
+ match_detail = {}
705
+ for key, value in match_kwargs.items():
706
+ if key == 'url':
707
+ url_key, match_result = match_url(value)
708
+ if match_result:
709
+ overall_results += match_result
710
+ match_detail[url_key] = match_result
711
+ else:
712
+ match_result = self.matcher.start_match_all(value)
713
+ if match_result:
714
+ overall_results += match_result
715
+ match_detail[key] = match_result
716
+
717
+ if not overall_results:
718
+ overall_results = default_result
719
+
720
+ unique_dict = {d['lv3_id']: d for d in overall_results}
721
+ sorted_results = sorted(unique_dict.values(), key=lambda x: int(x['lv3_id']))
722
+
723
+ return {
724
+ 'results': sorted_results,
725
+ 'match_detail': match_detail
726
+ }
727
+
728
+
462
729
  if __name__ == '__main__':
730
+ # 同步版本示例
463
731
  matcher = OrbitTypeMatcher(version='0.2.1')
464
732
  matcher.match_type(title='asdf')
733
+
734
+ # 异步版本示例
735
+ # import asyncio
736
+ # async def test_async():
737
+ # matcher = await OrbitTypeMatcherAsync.create(version='0.3.4')
738
+ # result = matcher.match_type(match_flag='in_order', title='Press Release')
739
+ # print(result)
740
+ # asyncio.run(test_async())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orbitkit
3
- Version: 0.8.47
3
+ Version: 0.8.48
4
4
  Summary: This project is only for Orbit Tech internal use.
5
5
  Home-page: https://github.com/clown-0726/orbitkit
6
6
  Author: Lilu Cao
@@ -1 +0,0 @@
1
- 0.8.47
@@ -1 +0,0 @@
1
- from .orbit_type_simple import OrbitTypeMatcher
File without changes
File without changes
File without changes
File without changes
File without changes