11package model
22
33import (
4+ "bytes"
45 "sort"
56 "strings"
7+ "time"
68
9+ "github.com/google/uuid"
710 "github.com/maartyman/rdfgo"
811 "github.com/sirupsen/logrus"
912)
@@ -22,11 +25,12 @@ func FnOC(id string) rdfgo.INamedNode {
2225 return rdfgo .NewNamedNode (`https://w3id.org/function/vocabulary/composition#` + id )
2326}
2427
25- type Execution struct {
26- URI string
27- Transformation * Transformation
28- Params map [string ]rdfgo.ITerm
29- Outputs map [string ]rdfgo.ITerm
28+ func Dcat (id string ) rdfgo.INamedNode {
29+ return rdfgo .NewNamedNode (`http://www.w3.org/ns/dcat#` + id )
30+ }
31+
32+ func Prov (id string ) rdfgo.INamedNode {
33+ return rdfgo .NewNamedNode (`http://www.w3.org/ns/prov#` + id )
3034}
3135
3236type Application struct {
@@ -149,3 +153,160 @@ func RDFListToSlice(store rdfgo.Store, headNode rdfgo.ITerm) []rdfgo.ITerm {
149153
150154 return elements
151155}
156+
157+ func (service * Service ) FnORepresentation () ([]byte , error ) {
158+ stream := rdfgo .NewStream ()
159+ svcNode := rdfgo .NewNamedNode (service .URI )
160+
161+ go func () {
162+ defer close (stream )
163+
164+ // service is a agg:Service
165+ quad , err := rdfgo .NewQuad (
166+ svcNode ,
167+ rdfgo .IRI .RDF .Type ,
168+ Agg ("Service" ),
169+ nil ,
170+ )
171+ if err != nil {
172+ return
173+ }
174+ stream <- quad
175+ // service is a dcat:DataService
176+ quad , err = rdfgo .NewQuad (
177+ svcNode ,
178+ rdfgo .IRI .RDF .Type ,
179+ Dcat ("DataService" ),
180+ nil ,
181+ )
182+ if err != nil {
183+ return
184+ }
185+ stream <- quad
186+ // service is a prov:SoftwareAgent
187+ quad , err = rdfgo .NewQuad (
188+ svcNode ,
189+ rdfgo .IRI .RDF .Type ,
190+ Prov ("SoftwareAgent" ),
191+ nil ,
192+ )
193+ if err != nil {
194+ return
195+ }
196+ stream <- quad
197+
198+ // SERVICE DETAILS
199+ // service status
200+ quad , err = rdfgo .NewQuad (
201+ svcNode ,
202+ Agg ("status" ),
203+ rdfgo .NewStringLiteral (service .Status (), "en" ),
204+ nil ,
205+ )
206+ if err != nil {
207+ return
208+ }
209+ stream <- quad
210+
211+ // service createdAt
212+ quad , err = rdfgo .NewQuad (
213+ svcNode ,
214+ Agg ("createdAt" ),
215+ rdfgo .NewLiteral (service .CreatedAt .Format (time .RFC3339 ), "" , DateTime ),
216+ nil ,
217+ )
218+ if err != nil {
219+ return
220+ }
221+ stream <- quad
222+
223+ // service performs
224+ quad , err = rdfgo .NewQuad (
225+ svcNode ,
226+ Agg ("performs" ),
227+ rdfgo .NewNamedNode (service .Application .Transformation .URI ),
228+ nil ,
229+ )
230+ if err != nil {
231+ return
232+ }
233+ stream <- quad
234+
235+ // service applies
236+ appNode := rdfgo .NewBlankNode (uuid .New ().String ())
237+ quad , err = rdfgo .NewQuad (
238+ svcNode ,
239+ Agg ("applies" ),
240+ appNode ,
241+ nil ,
242+ )
243+ if err != nil {
244+ return
245+ }
246+ stream <- quad
247+
248+ // Application details
249+ // application applies transformation
250+ quad , err = rdfgo .NewQuad (
251+ appNode ,
252+ FnOC ("applies" ),
253+ rdfgo .NewNamedNode (service .Application .Transformation .URI ),
254+ nil ,
255+ )
256+ if err != nil {
257+ return
258+ }
259+ stream <- quad
260+
261+ // application binds parameters
262+ for param , value := range service .Application .Params {
263+ bindingNode := rdfgo .NewBlankNode (uuid .New ().String ())
264+ quad , err = rdfgo .NewQuad (
265+ bindingNode ,
266+ FnOC ("parameterBinding" ),
267+ value ,
268+ nil ,
269+ )
270+ if err != nil {
271+ return
272+ }
273+ stream <- quad
274+
275+ // application parameterBinding boundParameter
276+ quad , err = rdfgo .NewQuad (
277+ bindingNode ,
278+ FnOC ("boundParameter" ),
279+ rdfgo .NewNamedNode (param ),
280+ nil ,
281+ )
282+ if err != nil {
283+ return
284+ }
285+ stream <- quad
286+
287+ // application parameterBinding boundToTerm
288+ quad , err = rdfgo .NewQuad (
289+ bindingNode ,
290+ FnOC ("boundToTerm" ),
291+ value ,
292+ nil ,
293+ )
294+ if err != nil {
295+ return
296+ }
297+ stream <- quad
298+ }
299+
300+ // outputs
301+
302+ }()
303+
304+ // serialize to turtle
305+ var buf bytes.Buffer
306+ _ , err := rdfgo .Write (stream .ToIStream (), & buf , rdfgo.WriterOptions {Format : "turtle" })
307+ if err != nil {
308+ return nil , err
309+ }
310+
311+ return buf .Bytes (), nil
312+ }
0 commit comments