-
Notifications
You must be signed in to change notification settings - Fork 5
/
moisture_detector.asl
61 lines (42 loc) · 2.44 KB
/
moisture_detector.asl
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
51
52
53
54
55
56
57
58
59
60
61
// moisture_detector agent
// Add your graph repo location below
repo_location("https://sandbox-graphdb.interactions.ics.unisg.ch/repositories/was-exercise-3-danai").
!start.
+!start : repo_location(KGRepo) <-
.print("Hello world");
!setup_artifacts(KGRepo);
!manage_farm.
+!setup_artifacts(KGRepo) : true <-
makeArtifact("farmKG1", "farm.FarmKG", [KGRepo], FarmKGId);
queryFarm(Farm);
+farm(Farm);
.print("Queried farm to manage: ", Farm);
queryThing(Farm, "https://was-course.interactions.ics.unisg.ch/farm-ontology#ReadSoilMoistureAffordance", ThingDescription);
.print("Queried td:Thing for reading moisture: ", ThingDescription);
makeArtifact("tractor1", "org.hyperagents.jacamo.artifacts.wot.ThingArtifact", [ThingDescription], TractorId).
+!manage_farm : farm(Farm) <-
.print("Managing farm: ", Farm);
queryFarmSections(Farm, Sections);
.print("Queried sectios of farm: ", Sections);
!monitor_section(Sections).
+!manage_farm : true <-
.print("No farm to manage").
+!monitor_section([]) : true <-
.print("All sections have been monitored.").
+!monitor_section([Section | RemainingSections]) : true <-
.print("Monitoring section: ", Section);
querySectionCoordinates(Section, Coordinates);
.print("Queried coordinates [X1,Y1,X2,Y2] of section: ", Coordinates);
invokeAction("https://was-course.interactions.ics.unisg.ch/farm-ontology#ReadSoilMoistureAffordance", ["https://www.w3.org/2019/wot/json-schema#ArraySchema"], Coordinates, ["https://was-course.interactions.ics.unisg.ch/farm-ontology#SoilMoisture"], CurrentMoistureLevel);
.print("Read moisture in section: ", CurrentMoistureLevel);
queryCropOfSection(Section, Crop);
.print("Queried crop in section: ", Crop);
queryRequiredMoisture(Crop, RequiredMoistureLevel);
.print("Queried required moisture level of crop: ", RequiredMoistureLevel);
!check_moisture_sufficiency(Coordinates, RequireMoistureLevel, CurrentMoistureLevel);
!monitor_section(RemainingSections).
+!check_moisture_sufficiency(Coordinates, RequireLevel, CurrentLevel) : RequiredLevel > CurrentLevel <-
.print("Detected low moisture in: ", Coordinates, ". Informing irrigator.");
.send(irrigator, tell, low_moisture(Coordinates)).
+!check_moisture_sufficiency(Coordinates, RequireLevel, CurrentLevel) : true <-
.print("Detected sufficient moisture in: ", Coordinates).