(self, entity, ref_kg_path)
| 22 | |
| 23 | @classmethod |
| 24 | def get_example(self, entity, ref_kg_path): |
| 25 | open_kg = [] |
| 26 | if entity: |
| 27 | with open(ref_kg_path, "r", encoding="utf-8") as kgfile: |
| 28 | for line in kgfile: |
| 29 | try: |
| 30 | triple = Triple(*line.strip().split("\t")) |
| 31 | if triple.head.lower() == entity.lower(): |
| 32 | open_kg.append(str(triple)) |
| 33 | except: |
| 34 | pass |
| 35 | |
| 36 | if open_kg != []: |
| 37 | logger.info(f"Load open kg triple for {entity} nums: {len(open_kg)}.") |
| 38 | else: |
| 39 | open_kg = [ |
| 40 | "<Bacterial sulfate>\t<is a type of>\t<sulfur compound\n", |
| 41 | "<Diabetes>\t<first line treatment>\t<Metformin>\n", |
| 42 | "<Insulin>\t<drug type>\t<Long-acting analog>\n", |
| 43 | ] |
| 44 | # logger.info(f"use default triples.") |
| 45 | return open_kg |
| 46 | |
| 47 | ## 对llm生成的三元组进行处理,并给出分析结果 |
| 48 | @classmethod |
no test coverage detected