Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SubQueryPattern.cs
1using System;
3using System.Threading.Tasks;
9
11{
16 {
17 private SparqlQuery subQuery;
18
24 {
25 this.subQuery = SubQuery;
26 }
27
31 public bool IsEmpty => false;
32
41 public async Task<IEnumerable<Possibility>> Search(ISemanticCube Cube,
42 Variables Variables, IEnumerable<Possibility> ExistingMatches, SparqlQuery Query)
43 {
44 IElement E = await this.subQuery.EvaluateAsync(Variables, ExistingMatches);
45 if (!(E.AssociatedObjectValue is SparqlResultSet ResultSet))
46 throw new ScriptRuntimeException("Subquery did not return a SPARQL Result Set.", this.subQuery);
47
48 if (ResultSet.BooleanResult.HasValue)
49 throw new ScriptRuntimeException("Subquery only returned a Boolean value.", this.subQuery);
50
52
53 foreach (ISparqlResultRecord Record in ResultSet.Records)
54 {
55 Possibility P = null;
56
57 foreach (ISparqlResultItem Item in Record)
58 {
59 if (P is null)
60 P = new Possibility(Item.Name, Item.Value);
61 else
62 P = new Possibility(Item.Name, Item.Value, P);
63 }
64
65 Result.Add(P);
66 }
67
68 return Result;
69 }
70
75 public void SetParent(ScriptNode Parent)
76 {
77 this.subQuery.SetParent(Parent);
78 }
79
87 public bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
88 {
89 if (Order == SearchMethod.DepthFirst)
90 this.subQuery.ForAllChildNodes(Callback, State, Order);
91
92 this.ForAll(Callback, State, Order);
93
94 if (Order == SearchMethod.BreadthFirst)
95 this.subQuery.ForAllChildNodes(Callback, State, Order);
96
97 return true;
98 }
99
107 public bool ForAll(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
108 {
109 if (!Callback(this.subQuery, out ScriptNode NewNode, State))
110 return false;
111
112 if (!(NewNode is null))
113 {
114 if (!(NewNode is SparqlQuery SubQuery))
115 throw new Exception("Expected sub-query node.");
116
117 this.subQuery = SubQuery;
118 }
119
120 return true;
121 }
122
124 public override bool Equals(object obj)
125 {
126 return obj is SubQueryPattern Typed &&
127 this.subQuery.Equals(Typed.subQuery);
128 }
129
131 public override int GetHashCode()
132 {
133 int Result = typeof(SubQueryPattern).GetHashCode();
134 Result ^= Result << 5 ^ this.subQuery.GetHashCode();
135 return Result;
136 }
137
138 }
139}
Contains the results of a SPARQL query. https://www.w3.org/TR/2023/WD-sparql12-results-xml-20230516/ ...
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
void SetParent(ScriptNode Parent)
Sets the parent node. Can only be used when expression is being parsed or created.
Definition: ScriptNode.cs:132
bool ForAll(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
Calls the callback method for all child nodes.
void SetParent(ScriptNode Parent)
Sets the parent node. Can only be used when expression is being parsed or created.
bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
Calls the callback method for all child nodes.
async Task< IEnumerable< Possibility > > Search(ISemanticCube Cube, Variables Variables, IEnumerable< Possibility > ExistingMatches, SparqlQuery Query)
Searches for the pattern on information in a semantic cube.
Represents a possible solution during SPARQL evaluation.
Definition: Possibility.cs:13
override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
Calls the callback method for all child nodes.
Definition: SparqlQuery.cs:703
override Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node asynchronously, using the variables provided in the Variables collection.
Definition: SparqlQuery.cs:162
Collection of variables.
Definition: Variables.cs:25
Interface for semantic cubes.
Interface for items in a record from the results of a SPARQL query.
string Name
Name of item in record.
ISemanticElement Value
Value of item in record.
Interface for result records of a SPARQL query.
Basic interface for all types of elements.
Definition: IElement.cs:21
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:34
delegate bool ScriptNodeEventHandler(ScriptNode Node, out ScriptNode NewNode, object State)
Delegate for ScriptNode callback methods.
SearchMethod
Method to traverse the expression structure
Definition: ScriptNode.cs:38