pyegeria 5.3.8.9__py3-none-any.whl → 5.3.8.10__py3-none-any.whl

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.
pyegeria/__init__.py CHANGED
@@ -63,7 +63,8 @@ from .md_processing_utils import (extract_command, process_glossary_upsert_comma
63
63
  process_solution_component_upsert_command, process_term_list_command,
64
64
  process_glossary_list_command, process_category_list_command,
65
65
  process_term_history_command, process_glossary_structure_command,
66
- process_term_revision_history_command)
66
+ process_term_revision_history_command, process_create_term_term_relationship_command,
67
+ )
67
68
 
68
69
  #
69
70
  # The following assignments were generated by the `create_tech_guid_lists.py` utility that uses the pyegeria functions
@@ -14,7 +14,8 @@ from pyegeria import (extract_command, process_glossary_upsert_command, process_
14
14
  process_per_proj_upsert_command, command_list, EgeriaTech, process_blueprint_upsert_command,
15
15
  process_solution_component_upsert_command, dr_egeria_state, process_term_list_command,
16
16
  process_category_list_command, process_glossary_list_command, process_term_history_command,
17
- process_glossary_structure_command, process_term_revision_history_command,)
17
+ process_glossary_structure_command, process_term_revision_history_command,
18
+ process_create_term_term_relationship_command)
18
19
 
19
20
  EGERIA_METADATA_STORE = os.environ.get("EGERIA_METADATA_STORE", "active-metadata-store")
20
21
  EGERIA_KAFKA_ENDPOINT = os.environ.get("KAFKA_ENDPOINT", "localhost:9092")
@@ -92,6 +93,8 @@ def process_markdown_file(file_path: str, directive: str, server: str, url: str,
92
93
  result = process_category_upsert_command(client, current_block, directive)
93
94
  elif potential_command in ["Create Term", "Update Term"]:
94
95
  result = process_term_upsert_command(client, current_block, directive)
96
+ elif potential_command in ["Create Term-Term Relationship", "Update Term-Term Relationship"]:
97
+ result = process_create_term_term_relationship_command(client, current_block, directive)
95
98
  elif potential_command in ["List Term History", "Term History"]:
96
99
  result = process_term_history_command(client, current_block, directive)
97
100
  elif potential_command in ["List Term Update History", "List Term Revision History"]:
@@ -133,8 +133,8 @@ class GlossaryBrowser(Client):
133
133
  cat_md_qn = ''
134
134
  if type(categories) is list:
135
135
  for category in categories:
136
- cat_md_display += f"* {category['glossaryCategoryProperties'][('displayName')]}\n"
137
- cat_md_qn += f"* {category['glossaryCategoryProperties'][('qualifiedName')]}\n"
136
+ cat_md_display += f" {category['glossaryCategoryProperties'][('displayName')]},\n"
137
+ cat_md_qn += f" {category['glossaryCategoryProperties'][('qualifiedName')]},\n"
138
138
  cat_md = cat_md_display.strip()
139
139
  cat_md_qn = cat_md_qn.strip()
140
140
 
@@ -423,9 +423,10 @@ class GlossaryBrowser(Client):
423
423
  pub_version = properties.get("publishVersionIdentifier", "") or ""
424
424
  qualified_name = properties.get("qualifiedName", "") or ""
425
425
  status = element['elementHeader'].get('status', "") or ""
426
+ aliases = ", ".join(properties.get("aliases", "")) or ""
426
427
 
427
428
  return {
428
- 'guid': guid, 'properties': properties, 'display_name': display_name, 'summary': summary,
429
+ 'guid': guid, 'properties': properties, 'display_name': display_name, 'aliases': aliases, 'summary': summary,
429
430
  'description': description, 'examples': examples, 'usage': usage, 'version identifier': pub_version,
430
431
  'qualified_name': qualified_name, 'status': status
431
432
  }
@@ -506,8 +507,8 @@ class GlossaryBrowser(Client):
506
507
  str: Markdown table
507
508
  """
508
509
  columns = [{'name': 'Term Name', 'key': 'display_name'}, {'name': 'Qualified Name', 'key': 'qualified_name'},
509
- {'name': 'Summary', 'key': 'summary', 'format': True}, {'name': 'Glossary', 'key': 'glossary'},
510
- {'name': 'Categories', 'key': 'categories_str', 'format': True}]
510
+ {'name': 'Aliases', 'key': 'aliases', 'format': True}, {'name': 'Summary', 'key': 'summary', 'format': True},
511
+ {'name': 'Glossary', 'key': 'glossary'}, {'name': 'Categories', 'key': 'categories_str', 'format': True}]
511
512
 
512
513
  # Create a wrapper function to pass output_format to _get_term_table_properties
513
514
  def get_table_props_with_format(element, term_guid, output_format_param=None):
@@ -1036,6 +1037,43 @@ class GlossaryBrowser(Client):
1036
1037
  response = loop.run_until_complete(self._async_get_glossary_term_statuses())
1037
1038
  return response
1038
1039
 
1040
+ async def _async_get_term_relationship_types(self) -> [str]:
1041
+ """Return the list of term relationship types enum values. Async version.
1042
+
1043
+ Parameters
1044
+ ----------
1045
+
1046
+
1047
+ Returns
1048
+ -------
1049
+ List[str]
1050
+ A list of glossary term relationships retrieved from the server.
1051
+
1052
+ """
1053
+
1054
+ url = (f"{self.platform_url}/servers/{self.view_server}"
1055
+ f"/api/open-metadata/glossary-manager/glossaries/terms/relationships/type-names")
1056
+
1057
+ response = await self._async_make_request("GET", url)
1058
+ return response.json().get("names", [])
1059
+
1060
+ def get_term_relationship_types(self) -> [str]:
1061
+ """Return the list of term relationship type enum values.
1062
+
1063
+ Parameters
1064
+ ----------
1065
+
1066
+
1067
+ Returns
1068
+ -------
1069
+ list of str
1070
+ A list of term relationship types. Each status is represented as a string.
1071
+
1072
+ """
1073
+ loop = asyncio.get_event_loop()
1074
+ response = loop.run_until_complete(self._async_get_term_relationship_types())
1075
+ return response
1076
+
1039
1077
  #
1040
1078
  # Glossaries
1041
1079
  #
@@ -2512,10 +2550,10 @@ class GlossaryBrowser(Client):
2512
2550
 
2513
2551
  return response
2514
2552
 
2515
- async def _async_get_term_relationships(self, term_guid: str, effective_time: str = None, start_from: int = 0,
2516
- page_size: int = None, ) -> list | str:
2553
+ async def _async_get_related_terms(self, term_guid: str, effective_time: str = None, start_from: int = 0,
2554
+ page_size: int = None, output_format:str = "JSON") -> list | str:
2517
2555
  """This call retrieves details of the glossary terms linked to this glossary term.
2518
- Notice the original org 1 glossary term is linked via the "SourcedFrom" relationship..
2556
+ Notice the original org 1 glossary term is linked via the "SourcedFrom" relationship.
2519
2557
  Parameters
2520
2558
  ----------
2521
2559
  term_guid : str
@@ -2559,10 +2597,21 @@ class GlossaryBrowser(Client):
2559
2597
  else:
2560
2598
  response = await self._async_make_request("POST", url)
2561
2599
 
2562
- return response.json().get("elementList", "No terms found")
2600
+ term_elements = response.json().get("elementList", NO_TERMS_FOUND)
2601
+ if term_elements == NO_TERMS_FOUND:
2602
+ if output_format == 'JSON':
2603
+ return NO_TERMS_FOUND
2604
+ elif output_format in ['MD', 'FORM', 'REPORT', 'LIST']:
2605
+ return "\n# No Terms found.\n"
2606
+ elif output_format == 'DICT':
2607
+ return None
2608
+ if output_format != "JSON": # return a simplified markdown representation
2609
+ return self.generate_terms_md(term_elements, term_guid, output_format)
2610
+ return response.json().get("elementList", NO_TERMS_FOUND)
2563
2611
 
2564
- def get_term_relationships(self, term_guid: str, effective_time: str = None, start_from: int = 0,
2565
- page_size: int = None, ) -> list | str:
2612
+
2613
+ def get_related_terms(self, term_guid: str, effective_time: str = None, start_from: int = 0,
2614
+ page_size: int = None, output_format = "JSON") -> list | str:
2566
2615
  """This call retrieves details of the glossary terms linked to this glossary term.
2567
2616
  Notice the original org 1 glossary term is linked via the "SourcedFrom" relationship..
2568
2617
  Parameters
@@ -2595,10 +2644,37 @@ class GlossaryBrowser(Client):
2595
2644
  """
2596
2645
  loop = asyncio.get_event_loop()
2597
2646
  response = loop.run_until_complete(
2598
- self._async_get_term_relationships(term_guid, effective_time, start_from, page_size))
2647
+ self._async_get_related_terms(term_guid, effective_time, start_from,
2648
+ page_size, output_format))
2599
2649
 
2600
2650
  return response
2601
2651
 
2652
+ def get_term_details(self, term_name:str, effective_time: str = None) -> dict | str:
2653
+ """Retrieve the details of a glossary term. Including relationships and feedback
2654
+
2655
+ output_format: str, default = 'JSON'
2656
+ Type of output to produce:
2657
+ JSON - output standard json
2658
+ MD - output standard markdown with no preamble
2659
+ DICT = output a simplified DICT structure
2660
+ """
2661
+
2662
+
2663
+ # Now lets get the term details as a dict
2664
+ core = self.get_terms_by_name(term_name, effective_time, output_format="DICT")
2665
+ if not core:
2666
+ return NO_TERMS_FOUND
2667
+
2668
+ related = self.get_related_terms(core[0]['guid'], effective_time)
2669
+ if not related:
2670
+ return "NO RELATED TERMS FOUND"
2671
+
2672
+ related_term_guid = related[0]["relatedElement"]["relatedElement"]["guid"]
2673
+ related_term_qn = related[0]["relatedElement"]["relatedElement"]["uniquedName"]
2674
+
2675
+
2676
+
2677
+
2602
2678
  async def _async_get_glossary_for_term(self, term_guid: str, effective_time: str = None) -> dict | str:
2603
2679
  """Retrieve the glossary metadata element for the requested term. The optional request body allows you to
2604
2680
  specify that the glossary element should only be returned if it was effective at a particular time.
@@ -2638,8 +2714,8 @@ class GlossaryBrowser(Client):
2638
2714
  url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
2639
2715
  f"for-term/{term_guid}/retrieve")
2640
2716
 
2641
- response = await self._async_make_request("POST", url, body)
2642
- return response.json().get("element", "No glossary found")
2717
+ response = await self._async_make_request("POST", url, body_slimmer(body))
2718
+ return response.json().get("element", NO_GLOSSARIES_FOUND)
2643
2719
 
2644
2720
  def get_glossary_for_term(self, term_guid: str, effective_time: str = None) -> dict | str:
2645
2721
  """Retrieve the glossary metadata element for the requested term. The optional request body allows you to
@@ -2677,7 +2753,7 @@ class GlossaryBrowser(Client):
2677
2753
 
2678
2754
  async def _async_get_terms_by_name(self, term: str, glossary_guid: str = None, status_filter: list = [],
2679
2755
  effective_time: str = None, for_lineage: bool = False, for_duplicate_processing: bool = False,
2680
- start_from: int = 0, page_size: int = None, ) -> list:
2756
+ start_from: int = 0, page_size: int = None, output_format = "JSON") -> list:
2681
2757
  """Retrieve glossary terms by display name or qualified name. Async Version.
2682
2758
 
2683
2759
  Parameters
@@ -2700,6 +2776,13 @@ class GlossaryBrowser(Client):
2700
2776
  The index of the first term to retrieve. Default is 0.
2701
2777
  page_size : int, optional
2702
2778
  The number of terms to retrieve per page. If not provided, it will use the default page size.
2779
+ output_format: str, default = 'JSON'
2780
+ Type of output to produce:
2781
+ JSON - output standard json
2782
+ MD - output standard markdown with no preamble
2783
+ FORM - output markdown with a preamble for a form
2784
+ REPORT - output markdown with a preamble for a report
2785
+ DICT - output a simplified DICT structure
2703
2786
 
2704
2787
  Returns
2705
2788
  -------
@@ -2735,13 +2818,23 @@ class GlossaryBrowser(Client):
2735
2818
  f"&forLineage={for_lineage_s}&forDuplicateProcessing={for_duplicate_processing_s}")
2736
2819
 
2737
2820
  # print(f"\n\nURL is: \n {url}\n\nBody is: \n{body}")
2821
+ response = await self._async_make_request("POST", url, body_slimmer(body))
2822
+ term_elements = response.json().get("elementList", NO_TERMS_FOUND)
2823
+ if term_elements == NO_TERMS_FOUND:
2824
+ if output_format == 'JSON':
2825
+ return NO_TERMS_FOUND
2826
+ elif output_format in ['MD', 'FORM', 'REPORT', 'LIST']:
2827
+ return "\n# No Terms found.\n"
2828
+ elif output_format == 'DICT':
2829
+ return None
2830
+ if output_format != "JSON": # return a simplified markdown representation
2831
+ return self.generate_terms_md(term_elements, term, output_format)
2832
+ return response.json().get("elementList", NO_TERMS_FOUND)
2738
2833
 
2739
- response = await self._async_make_request("POST", url, body)
2740
- return response.json().get("elementList", "No terms found")
2741
2834
 
2742
2835
  def get_terms_by_name(self, term: str, glossary_guid: str = None, status_filter: list = [],
2743
2836
  effective_time: str = None, for_lineage: bool = False, for_duplicate_processing: bool = False,
2744
- start_from: int = 0, page_size: int = None, ) -> list:
2837
+ start_from: int = 0, page_size: int = None, output_format = "JSON") -> list:
2745
2838
  """Retrieve glossary terms by display name or qualified name.
2746
2839
 
2747
2840
  Parameters
@@ -2764,6 +2857,13 @@ class GlossaryBrowser(Client):
2764
2857
  The index of the first term to retrieve. Default is 0.
2765
2858
  page_size : int, optional
2766
2859
  The number of terms to retrieve per page. If not provided, it will use the default page size.
2860
+ output_format: str, default = 'JSON'
2861
+ Type of output to produce:
2862
+ JSON - output standard json
2863
+ MD - output standard markdown with no preamble
2864
+ FORM - output markdown with a preamble for a form
2865
+ REPORT - output markdown with a preamble for a report
2866
+ DICT - output a simplified DICT structure
2767
2867
 
2768
2868
  Returns
2769
2869
  -------
@@ -2783,7 +2883,7 @@ class GlossaryBrowser(Client):
2783
2883
  loop = asyncio.get_event_loop()
2784
2884
  response = loop.run_until_complete(
2785
2885
  self._async_get_terms_by_name(term, glossary_guid, status_filter, effective_time, for_lineage,
2786
- for_duplicate_processing, start_from, page_size, ))
2886
+ for_duplicate_processing, start_from, page_size, output_format))
2787
2887
  return response
2788
2888
 
2789
2889
  async def _async_get_term_by_guid(self, term_guid: str, output_format: str = 'JSON') -> dict | str: