1- streamer class C(Int x, Monitor<C> m)
1+ // reada src/test/resources/csparql/07_stream_object.smol
2+
3+ class Observation(Int x, Int ts) end
4+
5+ streamer class C(Int x, Observation obs, Monitor<Observation> m)
26
37 Unit register()
4- Monitor<C > m = monitor("
8+ Monitor<Observation > m = monitor("
59 SELECT ?s
6- FROM STREAM %1 [RANGE 6s STEP 4s]
7- WHERE { ?s prog:C_x ?x }
10+ FROM NAMED WINDOW <win> ON %1 [RANGE PT5.001s STEP PT2s]
11+ WHERE {
12+ WINDOW ?w { ?s prog:Observation_x ?x }
13+ }
814 ", this);
915 this.m = m;
1016 end
1117
12- Unit doStream() emits(this, this.x )
18+ Unit doStream(Int ts ) emits(this.obs , this.obs.x, this.obs.ts )
1319 this.x = this.x + 1;
20+ this.obs = new Observation(this.x, ts);
1421 end
1522
1623 String windowToString()
1724 String s = "";
18- List<C > l = window(this.m);
25+ List<Observation > l = window(this.m);
1926 while l != null do
2027 s = s ++ l.content ++ " ";
2128 l = l.next;
@@ -25,29 +32,43 @@ streamer class C(Int x, Monitor<C> m)
2532end
2633
2734main
28- C o = new C(0, null);
29- o.register();
30-
35+ // configure simulation
3136 clock Int i = 100;
3237 Int endAt = 200;
3338
39+ // initialize stream
40+ C o = new C(0, null, null);
41+
42+ // initialize monitor
43+ o.register();
44+
45+ // run simulation
3446 while i < endAt do
35- o.doStream();
47+
48+ // put triples in the stream
49+ o.doStream(i);
50+
51+ // read window contents
3652 String res = o.windowToString();
3753 print(">>" ++ intToString(i) ++ ": " ++ res);
54+
55+ // advance clock (timestamp)
3856 i = i + 1;
3957 end
4058end
4159
4260// Output:
4361// >>100:
4462// >>101:
45- // >>102:
46- // >>103:
47- // >>104: obj5 obj5 obj5 obj5
48- // >>105: obj5 obj5 obj5 obj5
49- // >>106: obj5 obj5 obj5 obj5
50- // >>107: obj5 obj5 obj5 obj5
51- // >>108: obj5 obj5 obj5 obj5 obj5 obj5
52- // >>109: obj5 obj5 obj5 obj5 obj5 obj5
63+ // >>102: obj639 obj640
64+ // >>103: obj639 obj640
65+ // >>104: obj639 obj640 obj641 obj644
66+ // >>105: obj639 obj640 obj641 obj644
67+ // >>106: obj640 obj641 obj644 obj647 obj652
68+ // >>107: obj640 obj641 obj644 obj647 obj652
69+ // >>108: obj644 obj647 obj652 obj657 obj663
70+ // >>109: obj644 obj647 obj652 obj657 obj663
5371// ..
72+
73+ // Notes:
74+ // - Objects can be used as stream elements
0 commit comments