def checkuser(constructlist1): user = "******" for q in constructlist1: sn = URIRef(q.service) if sn.upper() == "FOR": # print q.args user = Literal(q.args) return user
def constructnewgraph(constructlist1, user): service = URIRef('ex:service') hasService = URIRef('ex:hasService') hasArguments = URIRef('ex:hasArguments') g = ConjunctiveGraph() intentnodeString = Literal(user) intentNode = BNode(intentnodeString) for q in constructlist1: sn = URIRef(q.service) if sn.upper() != "FOR": g.add((intentNode, hasService, Literal(sn))) for r in q.args: g.add((sn, hasArguments, Literal(r))) #print "Graph constructed for intent input!" # for subj, pred, obj in g: # print subj, pred, obj dot = Digraph(comment='Input Intent') for subj, pred, obj in g: dot.node(subj, subj) dot.node(obj, obj) dot.edge(subj, obj, pred, constraint='false') # print(dot.source) dot.format = 'png' # filenameput=filerenderpath+'/inputintent-dot' dot.render('../static/inputintent-dot', view=False) print("Creating intent graph in html output....") try: fname = '../templates/userinput.html' file = open(fname, 'w') firstpart = """<!DOCTYPE html> <html> <head> <title>First graph</title> <meta name="description" content="A concept map diagram ." /> <meta charset="UTF-8"> <script src="go.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gojs/1.6.7/go-debug.js"></script> <link href="../assets/css/goSamples.css" rel="stylesheet" type="text/css" /> <script src="goSamples.js"></script> <!-- this is only for the GoJS Samples framework --> <script id="code"> function init() { if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this var $ = go.GraphObject.make; // for conciseness in defining templates myDiagram = $(go.Diagram, "myDiagramDiv", // must name or refer to the DIV HTML element {\n initialAutoScale: go.Diagram.Uniform, // an initial automatic zoom-to-fit\n contentAlignment: go.Spot.Center, // align document to the center of the viewport\n layout:\n $(go.ForceDirectedLayout, // automatically spread nodes apart\n { defaultSpringLength: 30, defaultElectricalCharge: 100 })\n });\n // define each Node's appearance\n myDiagram.nodeTemplate = $(go.Node, "Auto", // the whole node panel { locationSpot: go.Spot.Center }, // define the node's outer shape, which will surround the TextBlock\n $(go.Shape, "Rectangle", { fill: $(go.Brush, "Linear", { 0: "rgb(254, 201, 0)", 1: "rgb(254, 162, 0)" }), stroke: "black" }), $(go.TextBlock, { font: "bold 10pt helvetica, bold arial, sans-serif", margin: 4 }, new go.Binding("text", "text")) ); // replace the default Link template in the linkTemplateMap myDiagram.linkTemplate = $(go.Link, // the whole link panel $(go.Shape, // the link shape { stroke: "black" }), $(go.Shape, // the arrowhead { toArrow: "standard", stroke: null }), $(go.Panel, "Auto", $(go.Shape, // the label background, which becomes transparent around the edges { fill: $(go.Brush, "Radial", { 0: "rgb(240, 240, 240)", 0.3: "rgb(240, 240, 240)", 1: "rgba(240, 240, 240, 0)" }), stroke: null }), $(go.TextBlock, // the label text { textAlign: "center", font: "10pt helvetica, arial, sans-serif", stroke: "#555555", margin: 4 }, new go.Binding("text", "text")) )); // create the model for the concept map\n""" file.write(firstpart) cnode = 0 # create a list of ids for plotting the js graph uniqueidlist = [] for subj, pred, obj in g: flagnodefound = 0 for j in uniqueidlist: if Literal(subj) == j: flagnodefound = 1 if flagnodefound == 0: uniqueidlist.append(Literal(subj)) for subj, pred, obj in g: flagnodefound = 0 for j in uniqueidlist: if Literal(obj) == j: flagnodefound = 1 # print "found name " + j if flagnodefound == 0: # print obj uniqueidlist.append(Literal(obj)) # adding links nodeDAstring = '' linkDAstring = '' tempstr = "" for j in uniqueidlist: # print nodeDAstring # print uniqueidlist.index(j) checkcommas = j.replace("'", "") tempstr = "{ key:" + str(uniqueidlist.index(j)) + \ ", text: '" + checkcommas + "' }," # print tempstr nodeDAstring += tempstr tempstr = "" for subj, pred, obj in g: # print uniqueidlist.index(Literal(subj)), # uniqueidlist.index(Literal(obj)), pred tempstr = "{ from:" + str(uniqueidlist.index( Literal(subj))) + ", to:" + str( uniqueidlist.index( Literal(obj))) + ", text: '" + Literal(pred) + "'}," linkDAstring += tempstr file.write(""" var nodeDataArray = [""") file.write(nodeDAstring) file.write("{} ];") file.write(" var linkDataArray = [") file.write(linkDAstring) file.write("{} ];") secondpart = """ myDiagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray); } </script> </head> <body onload="init()"> <div id="sample"> <h3>User Intent</h3> <div id="myDiagramDiv" style="background-color: whitesmoke; border: solid 1px black; width: 100%; height: 700px"></div> <p> The actual user intent received by INDIRA. See also the <a href="interactiveForce.html">Interactive Force</a> sample that uses the exact same data but a different node template and a customized <a>ForceDirectedLayout</a>. </p> </div> </body> </html>""" file.write(secondpart) file.close() except: print("file writing error occured") sys.exit(0) return g