3using System.Threading.Tasks;
16 #region Converting a GraphViz diagram to an image
109 return await Runtime.IO.Files.ReadAllBytesAsync(Graph.FileName);
114 #region Converting semantic graphs to a GraphViz diagram
136 if (ResultSet is
null)
139 StringBuilder sb =
new StringBuilder();
140 Dictionary<string, string> NodeNames =
new Dictionary<string, string>();
142 sb.AppendLine(
"digraph G {");
143 sb.AppendLine(
"\trankdir=LR");
144 sb.AppendLine(
"\tbgcolor=\"transparent\"");
145 sb.AppendLine(
"\tnode [style=filled,fillcolor=white]");
147 if (!
string.IsNullOrEmpty(Title))
149 sb.Append(
"\tlabel=\"");
152 sb.AppendLine(
"\tlabelloc=\"t\"");
153 sb.AppendLine(
"\tfontsize=20");
156 int LiteralIndex = 0;
160 AddShortName(ResultSet, Triple.
Subject, NodeNames, sb, ref LiteralIndex);
161 AddShortName(ResultSet, Triple.
Object, NodeNames, sb, ref LiteralIndex);
169 sb.Append(GetNodeName(ResultSet, Triple.
Subject, NodeNames,
false, ref LiteralIndex));
171 sb.Append(GetNodeName(ResultSet, Triple.
Object, NodeNames,
false, ref LiteralIndex));
172 sb.Append(
" [label=\"");
173 sb.Append(
JSON.
Encode(GetNodeName(ResultSet, Triple.
Predicate,
null,
true, ref LiteralIndex)));
174 sb.AppendLine(
"\"]");
179 return sb.ToString();
183 Dictionary<string, string> NodeNames,
bool IgnoreLiteral, ref
int LiteralIndex)
194 return "\"" + Element.ToString().Replace(
"\"",
"\\\"") +
"\"";
196 return "L" + (++LiteralIndex).
ToString();
199 Name = Element.ToString();
201 if (NodeNames is
null)
204 return NodeNames[Name];
208 Dictionary<string, string> NodeNames, StringBuilder sb, ref
int LiteralIndex)
211 string NodeName =
null;
212 string AdditionalStyle =
null;
217 AdditionalStyle =
",fillcolor=azure";
222 AdditionalStyle =
",fillcolor=lightgray";
229 NodeName =
"L" + (++LiteralIndex).
ToString();
230 AdditionalStyle =
",fillcolor=honeydew,shape=box,style=\"rounded,filled\",margin=\"0.2,0\",height=0.35";
232 if (ShortType == Type)
233 Name = Element.ToString();
246 Name = Element.ToString();
248 if (
string.IsNullOrEmpty(NodeName))
250 NodeName =
"N" + (NodeNames.Count + 1).
ToString();
251 if (NodeNames.ContainsKey(Name))
254 NodeNames[Name] = NodeName;
259 sb.Append(
" [label=\"");
263 if (!
string.IsNullOrEmpty(AdditionalStyle))
264 sb.Append(AdditionalStyle);
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Class managing GraphViz integration into Markdown documents.
GraphViz conversion utilities.
static Task< byte[]> DotToImage(string GraphText, ResultType ResultType)
Converts a GraphViz dot graph description to an image.
static Task< byte[]> CircoToImage(string GraphText, ResultType ResultType)
Converts a GraphViz circo graph description to an image.
static string GenerateGraph(SparqlResultSet ResultSet, ISemanticModel Graph, string Title)
Generates a GraphViz dot graph from a semantic graph.
static string GenerateGraph(ISemanticModel Graph, string Title)
Generates a GraphViz dot graph from a semantic graph.
static Task< byte[]> TwoPiToImage(string GraphText, ResultType ResultType)
Converts a GraphViz twopi graph description to an image.
static Task< byte[]> NeatoToImage(string GraphText, ResultType ResultType)
Converts a GraphViz neato graph description to an image.
static async Task< byte[]> GraphVizToImage(string Language, string GraphText, ResultType ResultType, Variables Variables)
Converts a GraphViz graph description to an image.
static Task< byte[]> FdpToImage(string GraphText, ResultType ResultType)
Converts a GraphViz fdp graph description to an image.
static Task< byte[]> GraphVizToImage(string Language, string GraphText, ResultType ResultType)
Converts a GraphViz graph description to an image.
static Task< byte[]> SfdpToImage(string GraphText, ResultType ResultType)
Converts a GraphViz sfdp graph description to an image.
Represents a custom literal.
override string ToString()
string Language
Language of string.
Abstract base class for semantic literal values.
abstract string StringType
Type name (or null if literal value is a string)
string StringValue
String representation of value.
Contains the results of a SPARQL query. https://www.w3.org/TR/2023/WD-sparql12-results-xml-20230516/ ...
string GetShortBlankNodeLabel(BlankNode Node)
Gets a short blank node label for the given blank node.
string GetShortUri(UriNode Node)
Gets a short URI label for the given uri node.
Interface for semantic nodes.
Interface for semantic models.
Interface for semantic triples.
ISemanticElement Object
Object element
ISemanticElement Predicate
Predicate element
ISemanticElement Subject
Subject element
ResultType
Image types supported by GraphViz
delegate string ToString(IElement Element)
Delegate for callback methods that convert an element value to a string.