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 using (IEnumerator<ISemanticTriple> e = Model.GetEnumerator())
62 while (await eAsync.MoveNextAsync())
80 this.CheckSubjectsOrdered();
95 this.CheckPredicatesOrdered();
110 this.CheckObjectsOrdered();
126 this.CheckSubjectsOrdered();
131 return Plane.GetTriplesByX(Predicate);
142 this.CheckSubjectsOrdered();
147 return Plane.GetTriplesByY(Object);
158 this.CheckPredicatesOrdered();
163 return Plane.GetTriplesByX(Subject);
174 this.CheckPredicatesOrdered();
179 return Plane.GetTriplesByY(Object);
190 this.CheckObjectsOrdered();
195 return Plane.GetTriplesByX(Subject);
206 this.CheckObjectsOrdered();
211 return Plane.GetTriplesByY(Predicate);
223 this.CheckSubjectsOrdered();
226 return Task.FromResult<IEnumerable<ISemanticTriple>>(
null);
228 return Plane.GetTriplesByXAndY(Predicate, Object);
237 this.CheckSubjectsOrdered();
239 return Task.FromResult<IEnumerator<ISemanticElement>>(this.subjects.Keys.GetEnumerator());
248 this.CheckPredicatesOrdered();
250 return Task.FromResult<IEnumerator<ISemanticElement>>(this.predicates.Keys.GetEnumerator());
259 this.CheckObjectsOrdered();
261 return Task.FromResult<IEnumerator<ISemanticElement>>(this.objects.Keys.GetEnumerator());
264 private void CheckSubjectsOrdered()
266 if (this.subjects is
null)
268 SortedDictionary<ISemanticElement, InMemorySemanticPlane> Ordered =
269 new SortedDictionary<ISemanticElement, InMemorySemanticPlane>();
275 if ((LastPoint is
null || !LastPoint.Equals(T.
Subject)) &&
276 !Ordered.TryGetValue(T.
Subject, out Last))
285 this.subjects = Ordered;
289 private void CheckPredicatesOrdered()
291 if (this.predicates is
null)
293 SortedDictionary<ISemanticElement, InMemorySemanticPlane> Ordered =
294 new SortedDictionary<ISemanticElement, InMemorySemanticPlane>();
295 ISemanticElement LastPoint =
null;
296 InMemorySemanticPlane Last =
null;
298 foreach (ISemanticTriple T
in this.triples)
300 if ((LastPoint is
null || !LastPoint.Equals(T.Predicate)) &&
301 !Ordered.TryGetValue(T.Predicate, out Last))
303 Last =
new InMemorySemanticPlane(T.Predicate);
304 Ordered[T.Predicate] = Last;
307 Last.Add(T.Subject, T.Object, T);
310 this.predicates = Ordered;
314 private void CheckObjectsOrdered()
316 if (this.objects is
null)
318 SortedDictionary<ISemanticElement, InMemorySemanticPlane> Ordered =
319 new SortedDictionary<ISemanticElement, InMemorySemanticPlane>();
320 ISemanticElement LastPoint =
null;
321 InMemorySemanticPlane Last =
null;
323 foreach (ISemanticTriple T
in this.triples)
325 if ((LastPoint is
null || !LastPoint.Equals(T.Object)) &&
326 !Ordered.TryGetValue(T.Object, out Last))
328 Last =
new InMemorySemanticPlane(T.Object);
329 Ordered[T.Object] = Last;
332 Last.Add(T.Subject, T.Predicate, T);
335 this.objects = Ordered;
352 default:
return null;
367 if (Axis1Index == Axis2Index)
369 if (Value1.Equals(Value2))
370 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.
ChunkedList< 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.