private static void WriteTriple(Triple triple, BaseWriterContext context, bool collapseLiterals) { // Output Node lines for Literal Node so we show them as Boxes // This is in keeping with Standard Graph representation of RDF // Literals are shown in Boxes, Uri Nodes in ellipses (GraphViz's default shape) var subjectId = GraphVizWriter.ProcessNode(triple, TripleSegment.Subject, context, collapseLiterals); var objectId = GraphVizWriter.ProcessNode(triple, TripleSegment.Object, context, collapseLiterals); // Output the actual lines that state the relationship between the Nodes // We use the Predicate as the Label on the relationship var predicateLabel = GraphVizWriter.ReduceToQName((triple.Predicate as IUriNode).Uri, context); GraphVizWriter.Prettify(DOT.Tab, context); GraphVizWriter.WriteQuoted(subjectId, context); GraphVizWriter.Prettify(DOT.Space, context); context.Output.Write(DOT.Arrow); GraphVizWriter.Prettify(DOT.Space, context); GraphVizWriter.WriteQuoted(objectId, context); GraphVizWriter.Prettify(DOT.Space, context); context.Output.Write(DOT.OpenSquare); context.Output.Write(DOT.Label); GraphVizWriter.Prettify(DOT.Space, context); context.Output.Write(DOT.Equal); GraphVizWriter.Prettify(DOT.Space, context); GraphVizWriter.WriteQuoted(predicateLabel, context); context.Output.Write(DOT.CloseSquare); context.Output.Write(DOT.Semicolon); GraphVizWriter.Prettify(DOT.NewLine, context); }
private static string ProcessNode(Triple t, TripleSegment segment, BaseWriterContext context, bool collapseLiterals) { var node = GraphVizWriter.GetNode(t, segment); switch (node) { case ILiteralNode literalnode: return(GraphVizWriter.WriteLiteralNode(literalnode, t, context, collapseLiterals)); case IUriNode uriNode: return(GraphVizWriter.ReduceToQName(uriNode.Uri, context)); case IBlankNode blankNode: return(blankNode.ToString()); default: throw new RdfOutputException("Only Uri nodes, literal nodes and blank nodes can be converted to GraphViz DOT Format."); } }
private static void WriteGraph(BaseWriterContext context, bool collapseLiterals) { context.Output.Write(DOT.Digraph); if (context.Graph.BaseUri != null) { var graphId = GraphVizWriter.ReduceToQName(context.Graph.BaseUri, context); GraphVizWriter.Prettify(DOT.Space, context); GraphVizWriter.WriteQuoted(graphId, context); } GraphVizWriter.Prettify(DOT.Space, context); context.Output.Write(DOT.OpenCurly); GraphVizWriter.Prettify(DOT.NewLine, context); foreach (var t in context.Graph.Triples) { GraphVizWriter.WriteTriple(t, context, collapseLiterals); } context.Output.Write(DOT.CloseCurly); }
private static void WriteLiteralNodeLabel(ILiteralNode literalnode, BaseWriterContext context) { var nodeValue = GraphVizWriter.Escape(literalnode.Value); context.Output.Write(DOT.Quote); context.Output.Write(nodeValue); if (!string.IsNullOrEmpty(literalnode.Language)) { context.Output.Write("@"); context.Output.Write(literalnode.Language); } if (literalnode.DataType != null) { string datatype = GraphVizWriter.ReduceToQName(literalnode.DataType, context); context.Output.Write("^^"); context.Output.Write(datatype); } context.Output.Write(DOT.Quote); }