示例#1
0
        private static string WriteLiteralNode(ILiteralNode literalnode, Triple t, BaseWriterContext context, bool collapseLiterals)
        {
            // Example output:
            //     "h" [label = "v", shape = box];
            // where h is the hash of the triple containing the literal node
            // and v is value of literal node

            // Literal nodes are identified either by their value or by their containing triple.
            // When identified by value, there will be a single node representing all literals with the same value.
            // When identified by triple, there will be a separate node representing each triple that has an object with that value.
            var idObject = collapseLiterals ? literalnode as object : t as object;
            var nodeId   = idObject.GetHashCode().ToString();

            GraphVizWriter.Prettify(DOT.Tab, context);
            GraphVizWriter.WriteQuoted(nodeId, 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.WriteLiteralNodeLabel(literalnode, context);
            context.Output.Write(DOT.Comma);
            GraphVizWriter.Prettify(DOT.Space, context);
            context.Output.Write(DOT.Shape);
            GraphVizWriter.Prettify(DOT.Space, context);
            context.Output.Write(DOT.Equal);
            GraphVizWriter.Prettify(DOT.Space, context);
            context.Output.Write(DOT.Box);
            context.Output.Write(DOT.CloseSquare);
            context.Output.Write(DOT.NewLine, context);

            return(nodeId);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }