Skip to content

Commit ad8e032

Browse files
committed
Add JavaScriptInputNode example
1 parent c968774 commit ad8e032

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/contextmenu.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ const canvasCtxMenuItems = [
2929
},
3030
{ label: "External Turtle Files", action: "ExternalTurtleFilesInputNode" },
3131
{ label: "External SPARQL Endpoint", action: "ExternalSparqlEndpointInputNode" },
32-
{ label: "JavaScript Input", action: "JavaScriptInputNode" },
32+
{ label: "JavaScript Input", action: "JavaScriptInputNode",
33+
submenu: [
34+
{ label: "Template: JSON array to triple store", action: "ex_JavaScriptInputNode_JsonArrToTripleStore" }
35+
]
36+
},
3337
// { label: "Output Viewer with initial input", action: "OutputViewNodeWithInitialInput" },
3438
]
3539
},

src/graph/nodeFactory.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,20 @@ DELETE {
135135
} WHERE {
136136
?user a ff:Citizen ;
137137
ff:hasBirthday ?bday .
138-
}`
138+
}`,
139+
"ex_JavaScriptInputNode_JsonArrToTripleStore": `let store = newStore()
140+
const a = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
141+
const ff = function(localName) { return "https://foerderfunke.org/default#" + localName }
142+
let count = 0
143+
144+
for (let element of JSON.parse(input)) {
145+
let individual = ff("class" + (count ++))
146+
addTripleToStore(store, individual, a, ff("Class"))
147+
addTripleToStore(store, individual, ff("hasTitle"), element.Title)
148+
// ...
149+
}
150+
151+
return storeToTurtle(store)`
139152
}
140153

141154
export function factoryCreateNode(nodeClass, initialValues, graph) {

0 commit comments

Comments
 (0)