procedure Add(Feed_Back : in Vertex; Network : in out T_Network; Input : in T_Sentence; Last_Vertex : out Vertex) is
Current_Node : Node_Access := Network.Root;
The_Arc : Arc;
Init, Vertex_A, Vertex_B : Vertex;
The_Neuron : Neuron_Access;
Done : Boolean := False;
begin
if Input'Length = 1 then
if Current_Node.Neuron.Width = 1 and Current_Node.Neuron.Keyword = Input(1) then
Add(Current_Node.Neuron.all, Input(1..1));
Train(Current_Node.Neuron.all);
Vertex_A := Current_Node.The_Vertex;
else
while Current_Node.Next /= null loop
Current_Node := Current_Node.Next;
if Current_Node.Neuron.Width = 1 and Current_Node.Neuron.Keyword = Input(1) then
Add(Current_Node.Neuron.all, Input(1..1));
Train(Current_Node.Neuron.all);
Last_Vertex := Current_Node.The_Vertex;
return;
end if;
end loop;
Vertex_A := New_Vertex;
The_Neuron := new T_Neuron(1, Input(1));
Make(The_Neuron.all);
Add(The_Neuron.all, Input(1..1));
Current_Node.Next := new T_Node ' (Vertex_A, The_Neuron, null);
Train(Current_Node.Next.Neuron.all);
Add(Vertex_A, Network.The_Graph);
Current_Node := Current_Node.Next;
end if;
Last_Vertex := Vertex_A;
The_Arc := New_Arc(Feed_back, Vertex_A);
Add(The_Arc, Network.The_Graph);
else
if Current_Node.Neuron.Width = 2 and Current_Node.Neuron.Keyword = Input(2) then
Vertex_A := Current_Node.The_Vertex;
Add(Current_Node.Neuron.all, Input(1..1));
Train(Current_Node.Neuron.all);
else
while Current_Node.Next /= null loop
Current_Node := Current_Node.Next;
if Current_Node.Neuron.Width = 2 and Current_Node.Neuron.Keyword = Input(2) then
Vertex_A := Current_Node.The_Vertex;
Add(Current_Node.Neuron.all, Input(1..1));
Train(Current_Node.Neuron.all);
Done := True;
exit;
end if;
end loop;
if not Done then
Vertex_A := New_Vertex;
The_Neuron := new T_Neuron(2, Input(2));
Make(The_Neuron.all);
Add(The_Neuron.all, Input(1..1));
Current_Node.Next := new T_Node ' (Vertex_A, The_Neuron, null);
Train(Current_Node.Next.Neuron.all);
Add(Vertex_A, Network.The_Graph);
end if;
end if;
The_Arc := New_Arc(Feed_back, Vertex_A);
begin
Add(The_Arc, Network.The_Graph);
exception
when VERTEX_NOT_IN_GRAPH =>
Text_Io.Put("VERTEX_NOT_IN_GRAPH" );
delay 1.0;
when others =>
Text_Io.Put("Other Error !!" );
delay 1.0;
end;
Last_Vertex := Vertex_A;
if Input'Length > 2 then
Current_Node := Network.Root;
if Current_Node.Neuron.Width = 3 and Current_Node.Neuron.Keyword = Input(3) then
Vertex_B := Current_Node.The_Vertex;
Add(Current_Node.Neuron.all, Input(1..2));
Train(Current_Node.Neuron.all);
else
Done := False;
while Current_Node.Next /= null loop
Current_Node := Current_Node.Next;
if Current_Node.Neuron.Width = 3 and Current_Node.Neuron.Keyword = Input(3) then
Vertex_B := Current_Node.The_Vertex;
Add(Current_Node.Neuron.all, Input(1..2));
Train(Current_Node.Neuron.all);
Done := True;
exit;
end if;
end loop;
if not Done then
Vertex_B := New_Vertex;
The_Neuron := new T_Neuron(3, Input(3));
Make(The_Neuron.all);
Add(The_Neuron.all, Input(1..2));
Current_Node.Next := new T_Node ' (Vertex_B, The_Neuron, null);
Train(Current_Node.Next.Neuron.all);
Add(Vertex_B, Network.The_Graph);
end if;
end if;
The_Arc := New_Arc(Vertex_A, Vertex_B);
Add(The_Arc, Network.The_Graph);
Last_Vertex := Vertex_B;
end if;
if Input'Length > 3 then
for I in 4..Input'Length loop
Current_Node := Network.Root;
Vertex_A := Vertex_B;
if Current_Node.Neuron.Width = I and Current_Node.Neuron.Keyword = Input(I) then
Vertex_B := Current_Node.The_Vertex;
Add(Current_Node.Neuron.all, Input(1..I-1));
Train(Current_Node.Neuron.all);
else
Done := False;
while Current_Node.Next /= null loop
Current_Node := Current_Node.Next;
if Current_Node.Neuron.Width = I and Current_Node.Neuron.Keyword = Input(I) then
Vertex_B := Current_Node.The_Vertex;
Add(Current_Node.Neuron.all, Input(1..I-1));
Train(Current_Node.Neuron.all);
Done := True;
exit;
end if;
end loop;
if not Done then
Vertex_B := New_Vertex;
The_Neuron := new T_Neuron(I, Input(I));
Make(The_Neuron.all);
Add(The_Neuron.all, Input(1..I-1));
Current_Node.Next := new T_Node ' (Vertex_B, The_Neuron, null);
Train(Current_Node.Next.Neuron.all);
Add(Vertex_B, Network.The_Graph);
end if;
end if;
The_Arc := New_Arc(Vertex_A, Vertex_B);
Add(The_Arc, Network.The_Graph);
Last_Vertex := Vertex_B;
end loop;
end if;
end if;
end Add;