Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
InMemorySemanticModel.cs
1using System.Collections;
2using System.Collections.Generic;
7
9{
14 {
18 protected readonly LinkedList<ISemanticTriple> triples;
19
24 {
25 this.triples = new LinkedList<ISemanticTriple>();
26 }
27
32 public InMemorySemanticModel(IEnumerable<ISemanticTriple> Triples)
33 {
34 this.triples = Triples as LinkedList<ISemanticTriple>;
35
36 if (this.triples is null)
37 {
38 this.triples = new LinkedList<ISemanticTriple>();
39
40 foreach (ISemanticTriple Triple in Triples)
41 this.triples.AddLast(Triple);
42 }
43 }
44
49 public IEnumerator<ISemanticTriple> GetEnumerator()
50 {
51 return this.triples.GetEnumerator();
52 }
53
58 IEnumerator IEnumerable.GetEnumerator()
59 {
60 return this.triples.GetEnumerator();
61 }
62
67 public virtual void Add(ISemanticTriple Triple)
68 {
69 this.triples.AddLast(Triple);
70 }
71
77 {
78 LinkedList<IElement> Elements = new LinkedList<IElement>();
79 int Rows = 0;
80
81 foreach (ISemanticTriple T in this.triples)
82 {
83 Elements.AddLast(T.Subject);
84 Elements.AddLast(T.Predicate);
85 Elements.AddLast(T.Object);
86 Rows++;
87 }
88
89 return new ObjectMatrix(Rows, 3, Elements)
90 {
91 ColumnNames = new string[] { "Subject", "Predicate", "Object" }
92 };
93 }
94
100 {
101 return VectorDefinition.Encapsulate(this.triples, false, null);
102 }
103 }
104}
IEnumerator< ISemanticTriple > GetEnumerator()
Gets an enumerator of available triples.
IElement ToVector()
Converts the object to a vector.
readonly LinkedList< ISemanticTriple > triples
Triples in model.
virtual void Add(ISemanticTriple Triple)
Adds a triple to the model.
InMemorySemanticModel(IEnumerable< ISemanticTriple > Triples)
In-memory semantic model.
IMatrix ToMatrix()
Converts the object to a matrix.
static IElement Encapsulate(Array Elements, bool CanEncapsulateAsMatrix, ScriptNode Node)
Encapsulates the elements of a vector.
Interface for semantic models.
Interface for semantic triples.
ISemanticElement Object
Object element
ISemanticElement Predicate
Predicate element
ISemanticElement Subject
Subject element
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for matrices.
Definition: IMatrix.cs:9
Interface for objects that can be converted into matrices.
Definition: IToMatrix.cs:9
Interface for objects that can be converted into matrices.
Definition: IToVector.cs:9