-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt_ontology.py
50 lines (41 loc) · 2.05 KB
/
prompt_ontology.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from owlready2 import *
# Function to extract all subclasses recursively
def extract_subclasses(cls):
subclasses = []
for subclass in cls.subclasses():
subclasses.append(subclass.name)
subclasses.extend(extract_subclasses(subclass))
return subclasses
# extract_concepts() function is used to extract abnormality concepts (color, shape and symptoms) from the ontology
def extract_concepts():
symptom = []
color = []
shape = []
ColorAbnormality = None
SymptomAbnormality = None
ShapeAbnormality = None
# Define the class "Abnormality"
Abnormality = onto.Abnormality
for cls in Abnormality.subclasses():
if cls.name == "ColorAbnormality":
ColorAbnormality = cls
color = extract_subclasses(ColorAbnormality)
elif cls.name == "SymptomAbnormality":
SymptomAbnormality = cls
symptom = extract_subclasses(SymptomAbnormality)
elif cls.name == "ShapeAbnormality":
ShapeAbnormality = cls
shape = extract_subclasses(ShapeAbnormality)
return symptom, color, shape
# Generate the prompt with extracted concepts
def generate_prompt(onto_path):
#
onto = get_ontology(onto_path).load()
symptom, color, shape = extract_concepts()
prompt = f"""
As an expert of rice leaves diseases, your task is to examine the given image of the rice leaf in a detailed manner to look for colors abnormalities, symptoms abnormalities and shape of symptoms abnormalities.
Alongside the image of rice leaf, you will be provided with the possible set of color abnormalities and symptoms abnormalities and the shape of these symptoms delimited by triple quote.
Return the information in the following JSON format (note xxx is a placeholder, if the information is not available in the image, put “N/A” instead):
{{"ColorAbnormality": {color}, "SymptomAbnormality": {symptom}, "ShapeOfSymptomAbnormality": {shape}}}
"""
return prompt