/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package network.aika.neuron.activation.linker;

import network.aika.Config;
import network.aika.Document;
import network.aika.Model;
import network.aika.neuron.INeuron;
import network.aika.neuron.activation.Activation;

import static network.aika.neuron.activation.linker.Mode.INDUCTION;


/**
 *
 * @author Lukas Molzberger
 */
public class LTargetNode<N extends INeuron> extends LNode<N> {

    public LTargetNode(Class<N> neuronClass, Boolean isMature, String label) {
        super(neuronClass, isMature, label);
    }

    public Activation follow(Mode m, INeuron n, Activation act, LLink from, Activation startAct) {
        if(n == null && m == INDUCTION) {
            try {
                Model model = startAct.getNeuron().getModel();
                n = neuronClass.getConstructor(Model.class, String.class)
                        .newInstance(model, "");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        if(act == null) {
            Document doc = startAct.getDocument();
            act = new Activation(doc.getNewActivationId(), doc, n);
        }

        return act;
    }
}

@@ -847,36 +847,8 @@
 r;%0A%0A
-import network.aika.Config;%0A
 impo
@@ -1448,13 +1448,62 @@
     
-try %7B
+n = createNeuron(startAct.getNeuron().getModel(), %22%22);
 %0A   
@@ -1507,24 +1507,27 @@
         
+%7D%0A%0A
         
 Model mo
@@ -1522,59 +1522,274 @@
     
-Model model = startAct.getNeuron().getModel();%0A    
+if(act == null) %7B%0A            Document doc = startAct.getDocument();%0A            act = new Activation(doc.getNewActivationId(), doc, n);%0A        %7D%0A%0A        return act;%0A    %7D%0A%0A    private INeuron createNeuron(Model m, String label) %7B%0A        INeuron n;%0A        try %7B%0A
     
@@ -1874,20 +1874,16 @@
         
-    
 .newInst
@@ -1892,23 +1892,18 @@
 ce(m
-odel, %22%22);%0A    
+, label);%0A
     
@@ -1942,20 +1942,16 @@
         
-   
- 
 throw ne
@@ -1981,20 +1981,16 @@
         
-    
 %7D%0A      
@@ -1995,185 +1995,16 @@
     
-%7D%0A%0A        if(act == null) %7B%0A            Document doc = startAct.getDocument();%0A            act = new Activation(doc.getNewActivationId(), doc, n);%0A        %7D%0A%0A        return act
+return n
 ;%0A  

work on induction