3using System.Threading.Tasks;
15 private readonly Dictionary<ISemanticElement, bool> nodes =
new Dictionary<ISemanticElement, bool>();
35 if (this.lastSubject is
null || !this.lastSubject.Equals(Triple.
Subject))
37 this.nodes[Triple.
Subject] =
true;
38 this.lastSubject = Triple.
Subject;
39 this.nodesStatic =
null;
46 this.nodes[Triple.
Object] =
true;
47 this.nodesStatic =
null;
58 if (this.nodesStatic is
null)
61 this.nodes.Keys.CopyTo(Result, 0);
62 this.nodesStatic = Result;
65 return this.nodesStatic;
75 StringBuilder Output =
new StringBuilder();
77 return Output.ToString();
86 Output.AppendLine(
"@startuml");
88 Dictionary<ISemanticElement, string> NodeIds =
new Dictionary<ISemanticElement, string>();
89 Dictionary<string, ChunkedList<LinkInfo>> LinksByNodeId =
new Dictionary<string, ChunkedList<LinkInfo>>();
94 if (!NodeIds.TryGetValue(Node, out
string NodeId))
97 NodeIds[Node] = NodeId;
103 string NodeId = NodeIds[Node];
107 string StereoType =
null;
110 if (!(Plane is
null))
114 while (Predicates.MoveNext())
122 IsRdfType = UriNode.Uri ==
Rdf.
type;
126 PropertyName = Predicates.Current.ToString();
134 while (Values.MoveNext())
136 if (IsRdfType && StereoType is
null)
138 if (Values.Current is
UriNode UriNode2)
139 StereoType = UriNode2.ShortName;
141 StereoType = Values.Current.ToString();
145 if (Properties is
null)
148 Properties.
Add(
new KeyValuePair<string, object>(PropertyName, Literal.StringValue));
150 else if (NodeIds.TryGetValue(Values.Current, out
string ObjectId))
155 Links.
Add(
new LinkInfo()
159 Type = Node is
BlankNode ?
"*--" :
"-->",
165 if (Properties is
null)
170 if (Values.Current is
UriNode UriNode2)
171 ValueString = UriNode2.ShortName;
173 ValueString = Values.Current.
ToString();
175 Properties.
Add(
new KeyValuePair<string, object>(PropertyName, ValueString));
182 if (Properties is
null)
184 Output.Append(
"object \"");
191 Output.Append(
"\" as ");
192 Output.Append(NodeId);
194 if (!
string.IsNullOrEmpty(StereoType))
197 Output.Append(StereoType);
205 Output.Append(
"map \"");
212 Output.Append(
"\" as ");
213 Output.Append(NodeId);
215 if (!
string.IsNullOrEmpty(StereoType))
218 Output.Append(StereoType);
222 Output.AppendLine(
" {");
224 foreach (KeyValuePair<string, object> P
in Properties)
227 Output.Append(P.Key);
228 Output.Append(
" => ");
229 Output.AppendLine(P.Value?.ToString());
232 Output.AppendLine(
"}");
235 if (!(Links is
null))
236 LinksByNodeId[NodeId] = Links;
241 foreach (LinkInfo Link
in Links)
243 Output.Append(Link.From);
245 Output.Append(Link.Type);
247 Output.Append(Link.To);
248 Output.Append(
" : ");
249 Output.AppendLine(Link.Label);
253 Output.AppendLine(
"@enduml");
256 private class LinkInfo
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Task< ISemanticPlane > GetTriplesBySubject(ISemanticElement Subject)
Gets available triples in the cube, having a given subject.
string ShortName
Short name, if available.
static readonly Uri type
URI representing rdf:type
Contains triples that form a graph.
async Task< string > ExportPlantUml()
Exports graph to PlantUML.
async Task ExportPlantUml(StringBuilder Output)
Exports graph to PlantUML.
ISemanticElement[] Nodes
Nodes in graph.
override void Add(ISemanticTriple Triple)
Adds a triple to the model.
SemanticGraph()
Contains triples that form a graph.
A chunked list is a linked list of chunks of objects of type T .
override string ToString()
void Add(T Item)
Adds an item to the collection.
Interface for semantic nodes.
bool IsLiteral
If element is a literal.
Interface for semantic lines.
Task< IEnumerator< ISemanticElement > > GetValueEnumerator()
Gets an enumerator of all values along the line.
Interface for semantic literals.
Interface for semantic planes.
Task< IEnumerator< ISemanticElement > > GetXAxisEnumerator()
Gets an enumerator of all elements along the X-axis.
Task< ISemanticLine > GetTriplesByX(ISemanticElement X)
Gets available triples in the plane, having a given X-coordinate.
Interface for semantic triples.
ISemanticElement Object
Object element
ISemanticElement Predicate
Predicate element
ISemanticElement Subject
Subject element
delegate string ToString(IElement Element)
Delegate for callback methods that convert an element value to a string.