1using System.Collections.Generic;
3using System.Threading.Tasks;
14 private readonly Dictionary<ISemanticElement, bool> nodes =
new Dictionary<ISemanticElement, bool>();
34 if (this.lastSubject is
null || !this.lastSubject.Equals(Triple.
Subject))
36 this.nodes[Triple.
Subject] =
true;
37 this.lastSubject = Triple.
Subject;
38 this.nodesStatic =
null;
45 this.nodes[Triple.
Object] =
true;
46 this.nodesStatic =
null;
57 if (this.nodesStatic is
null)
60 this.nodes.Keys.CopyTo(Result, 0);
61 this.nodesStatic = Result;
64 return this.nodesStatic;
74 StringBuilder Output =
new StringBuilder();
76 return Output.ToString();
85 Output.AppendLine(
"@startuml");
87 Dictionary<ISemanticElement, string> NodeIds =
new Dictionary<ISemanticElement, string>();
88 Dictionary<string, LinkedList<LinkInfo>> LinksByNodeId =
new Dictionary<string, LinkedList<LinkInfo>>();
93 if (!NodeIds.TryGetValue(Node, out
string NodeId))
96 NodeIds[Node] = NodeId;
102 string NodeId = NodeIds[Node];
104 LinkedList<KeyValuePair<string, object>> Properties =
null;
105 LinkedList<LinkInfo> Links =
null;
106 string StereoType =
null;
109 if (!(Plane is
null))
113 while (Predicates.MoveNext())
121 IsRdfType = UriNode.Uri ==
Rdf.
Type;
125 PropertyName = Predicates.Current.ToString();
133 while (Values.MoveNext())
135 if (IsRdfType && StereoType is
null)
137 if (Values.Current is
UriNode UriNode2)
138 StereoType = UriNode2.ShortName;
140 StereoType = Values.Current.ToString();
144 if (Properties is
null)
145 Properties =
new LinkedList<KeyValuePair<string, object>>();
147 Properties.AddLast(
new KeyValuePair<string, object>(PropertyName, Literal.StringValue));
149 else if (NodeIds.TryGetValue(Values.Current, out
string ObjectId))
152 Links =
new LinkedList<LinkInfo>();
154 Links.AddLast(
new LinkInfo()
158 Type = Node is
BlankNode ?
"*--" :
"-->",
164 if (Properties is
null)
165 Properties =
new LinkedList<KeyValuePair<string, object>>();
169 if (Values.Current is
UriNode UriNode2)
170 ValueString = UriNode2.ShortName;
172 ValueString = Values.Current.ToString();
174 Properties.AddLast(
new KeyValuePair<string, object>(PropertyName, ValueString));
181 if (Properties is
null)
183 Output.Append(
"object \"");
190 Output.Append(
"\" as ");
191 Output.Append(NodeId);
193 if (!
string.IsNullOrEmpty(StereoType))
196 Output.Append(StereoType);
204 Output.Append(
"map \"");
211 Output.Append(
"\" as ");
212 Output.Append(NodeId);
214 if (!
string.IsNullOrEmpty(StereoType))
217 Output.Append(StereoType);
221 Output.AppendLine(
" {");
223 foreach (KeyValuePair<string, object> P
in Properties)
226 Output.Append(P.Key);
227 Output.Append(
" => ");
228 Output.AppendLine(P.Value?.ToString());
231 Output.AppendLine(
"}");
234 if (!(Links is
null))
235 LinksByNodeId[NodeId] = Links;
238 foreach (LinkedList<LinkInfo> Links
in LinksByNodeId.Values)
240 foreach (LinkInfo Link
in Links)
242 Output.Append(Link.From);
244 Output.Append(Link.Type);
246 Output.Append(Link.To);
247 Output.Append(
" : ");
248 Output.AppendLine(Link.Label);
252 Output.AppendLine(
"@enduml");
255 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.
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.