1using System.Collections.Generic;
2using System.Threading.Tasks;
12 private SortedDictionary<ISemanticElement, InMemorySemanticPlane> subjects =
null;
13 private SortedDictionary<ISemanticElement, InMemorySemanticPlane> predicates =
null;
14 private SortedDictionary<ISemanticElement, InMemorySemanticPlane> objects =
null;
34 await Result.Add(Model);
48 this.predicates =
null;
58 IEnumerator<ISemanticTriple> e = Model.GetEnumerator();
62 while (await eAsync.MoveNextAsync())
79 this.CheckSubjectsOrdered();
94 this.CheckPredicatesOrdered();
109 this.CheckObjectsOrdered();
125 this.CheckSubjectsOrdered();
130 return Plane.GetTriplesByX(Predicate);
141 this.CheckSubjectsOrdered();
146 return Plane.GetTriplesByY(Object);
157 this.CheckPredicatesOrdered();
162 return Plane.GetTriplesByX(Subject);
173 this.CheckPredicatesOrdered();
178 return Plane.GetTriplesByY(Object);
189 this.CheckObjectsOrdered();
194 return Plane.GetTriplesByX(Subject);
205 this.CheckObjectsOrdered();
210 return Plane.GetTriplesByY(Predicate);
222 this.CheckSubjectsOrdered();
225 return Task.FromResult<IEnumerable<ISemanticTriple>>(
null);
227 return Plane.GetTriplesByXAndY(Predicate, Object);
236 this.CheckSubjectsOrdered();
238 return Task.FromResult<IEnumerator<ISemanticElement>>(this.subjects.Keys.GetEnumerator());
247 this.CheckPredicatesOrdered();
249 return Task.FromResult<IEnumerator<ISemanticElement>>(this.predicates.Keys.GetEnumerator());
258 this.CheckObjectsOrdered();
260 return Task.FromResult<IEnumerator<ISemanticElement>>(this.objects.Keys.GetEnumerator());
263 private void CheckSubjectsOrdered()
265 if (this.subjects is
null)
267 SortedDictionary<ISemanticElement, InMemorySemanticPlane> Ordered =
268 new SortedDictionary<ISemanticElement, InMemorySemanticPlane>();
274 if ((LastPoint is
null || !LastPoint.Equals(T.
Subject)) &&
275 !Ordered.TryGetValue(T.
Subject, out Last))
284 this.subjects = Ordered;
288 private void CheckPredicatesOrdered()
290 if (this.predicates is
null)
292 SortedDictionary<ISemanticElement, InMemorySemanticPlane> Ordered =
293 new SortedDictionary<ISemanticElement, InMemorySemanticPlane>();
294 ISemanticElement LastPoint =
null;
295 InMemorySemanticPlane Last =
null;
297 foreach (ISemanticTriple T
in this.triples)
299 if ((LastPoint is
null || !LastPoint.Equals(T.Predicate)) &&
300 !Ordered.TryGetValue(T.Predicate, out Last))
302 Last =
new InMemorySemanticPlane(T.Predicate);
303 Ordered[T.Predicate] = Last;
306 Last.Add(T.Subject, T.Object, T);
309 this.predicates = Ordered;
313 private void CheckObjectsOrdered()
315 if (this.objects is
null)
317 SortedDictionary<ISemanticElement, InMemorySemanticPlane> Ordered =
318 new SortedDictionary<ISemanticElement, InMemorySemanticPlane>();
319 ISemanticElement LastPoint =
null;
320 InMemorySemanticPlane Last =
null;
322 foreach (ISemanticTriple T
in this.triples)
324 if ((LastPoint is
null || !LastPoint.Equals(T.Object)) &&
325 !Ordered.TryGetValue(T.Object, out Last))
327 Last =
new InMemorySemanticPlane(T.Object);
328 Ordered[T.Object] = Last;
331 Last.Add(T.Subject, T.Predicate, T);
334 this.objects = Ordered;
351 default:
return null;
366 if (Axis1Index == Axis2Index)
368 if (Value1.Equals(Value2))
369 return await this.
GetTriples(Value1, Axis1Index);
async Task< IEnumerable< ISemanticTriple > > GetTriples(ISemanticElement Value, int AxisIndex)
Gets available triples in the cube, having a given value, along a given axis.
Task< IEnumerable< ISemanticTriple > > GetTriplesBySubjectAndPredicateAndObject(ISemanticElement Subject, ISemanticElement Predicate, ISemanticElement Object)
Gets available triples in the cube, having a given subject, predicate and object.
InMemorySemanticCube()
In-memory semantic cube.
Task< ISemanticLine > GetTriplesBySubjectAndPredicate(ISemanticElement Subject, ISemanticElement Predicate)
Gets available triples in the cube, having a given subject and predicate.
Task< IEnumerator< ISemanticElement > > GetObjectEnumerator()
Gets an enumerator of all objects.
Task< ISemanticLine > GetTriplesByPredicateAndObject(ISemanticElement Predicate, ISemanticElement Object)
Gets available triples in the cube, having a given predicate and object.
Task< IEnumerator< ISemanticElement > > GetPredicateEnumerator()
Gets an enumerator of all predicates.
static async Task< InMemorySemanticCube > Create(ISemanticModel Model)
Creates an in-memory semantic cube from a semantic model.
override void Add(ISemanticTriple Triple)
Adds a triple to the cube.
Task< ISemanticPlane > GetTriplesByPredicate(ISemanticElement Predicate)
Gets available triples in the cube, having a given predicate.
virtual async Task Add(ISemanticModel Model)
Adds a model to the cube.
Task< ISemanticPlane > GetTriplesBySubject(ISemanticElement Subject)
Gets available triples in the cube, having a given subject.
Task< ISemanticLine > GetTriplesByObjectAndSubject(ISemanticElement Object, ISemanticElement Subject)
Gets available triples in the cube, having a given object and subject.
Task< IEnumerator< ISemanticElement > > GetSubjectEnumerator()
Gets an enumerator of all subjects.
Task< ISemanticLine > GetTriplesBySubjectAndObject(ISemanticElement Subject, ISemanticElement Object)
Gets available triples in the cube, having a given subject and object.
Task< ISemanticLine > GetTriplesByPredicateAndSubject(ISemanticElement Predicate, ISemanticElement Subject)
Gets available triples in the cube, having a given predicate and subject.
async Task< IEnumerable< ISemanticTriple > > GetTriples(ISemanticElement Value1, int Axis1Index, ISemanticElement Value2, int Axis2Index)
Gets available triples in the cube, having two given values, along two given axes.
Task< ISemanticLine > GetTriplesByObjectAndPredicate(ISemanticElement Object, ISemanticElement Predicate)
Gets available triples in the cube, having a given object and predicate.
Task< ISemanticPlane > GetTriplesByObject(ISemanticElement Object)
Gets available triples in the cube, having a given object.
In-memory semantic model.
readonly LinkedList< ISemanticTriple > triples
Triples in model.
In-memory semantic plane.
Interface for semantic cubes.
Interface for semantic nodes.
Interface for semantic lines.
Interface for semantic models.
Interface for semantic planes.
Interface for semantic triples.
ISemanticElement Object
Object element
ISemanticElement Predicate
Predicate element
ISemanticElement Subject
Subject element
Interface for asynchronous enumerators.