private void EvaluateNodeScope() { if (_autoCompleteForm != null && _autoCompleteForm.Visible) { InputNode node = _hostInterface.GetCurrentInput().GetNodeAtPosition(_hostInterface.InputPosition); if (node == null) // started empty and is empty again { _autoCompleteForm.Cancel(); } else if (_currentInputNode == null && node != null && node.ElementType != InputNodeType.Command) // command - auto complete from empty input { _autoCompleteForm.Cancel(); } else if (node.ElementType != InputNodeType.Command && _currentInputNode.ElementType == InputNodeType.Empty && node.Index == _currentInputNode.Index + 1) // ordinal parameter { return; } else if (_currentInputNode != null && node.Index != _currentInputNode.Index) // indexes no longer match, moved to a different node { _autoCompleteForm.Cancel(); } } }
private static bool NextNode(CharEnumerator enumerator, out INode node) { do { switch (enumerator.Current) { case '>': node = new MoveRightNode(); return(true); case '<': node = new MoveLeftNode(); return(true); case '+': node = new IncrementNode(); return(true); case '-': node = new DecrementNode(); return(true); case ',': node = new InputNode(); return(true); case '.': node = new OutputNode(); return(true); case '[': var nodes = new List <INode>(); while (enumerator.MoveNext()) { switch (enumerator.Current) { case ']': node = new LoopNode(nodes); return(true); default: if (NextNode(enumerator, out var nextNode)) { nodes.Add(nextNode); } break; } } throw new InvalidBFProgramException("Expected more symbols after encountering a loop begin symbol", true); case ']': throw new InvalidBFProgramException("Encountered a loop end symbol without matching loop begin", false); default: break; } }while (enumerator.MoveNext()); node = null; return(false); }
/// <summary> /// Returns the next input node from the XML document, if it is a /// child element of the specified input node. This essentially /// determines whether the end tag has been read for the specified /// node, if so then null is returned. If however the specified /// node has not had its end tag read then this returns the next /// element, if that element is a child of the that node. /// </summary> /// <param name="from"> /// this is the input node to read with /// </param> /// <returns> /// this returns the next input node from the document /// </returns> public InputNode ReadElement(InputNode from) { if (!stack.IsRelevant(from)) { return(null); } EventNode event = reader.Next();
public List <string> GetOptions(Input input, InputNode currentNode) { CommandResolver resolver = new CommandResolver(input, _hostInterface.Commands); if (string.IsNullOrWhiteSpace(input.ToString()) || currentNode.ElementType == InputNodeType.Command) // node is in leading white space or at very beginning of command or is the command node { return(GetCommandsAutoComplete(input, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.NamedParameter) { return(GetNamedParameterAutoComplete(resolver, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.NamedParameterValue) { return(GetParameterAutoComplete(resolver, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.Empty) { return(GetParameterAutoComplete(resolver, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.OrdinalParameterValue) { return(GetParameterAutoComplete(resolver, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.Switch) { return(GetSwitchAutoComplete(resolver, currentNode)); } return(null); }
/// <summary> /// Context Click selection. Here you'll need to register your own using a string identifier /// </summary> public void ContextCallback(object obj) { switch (obj.ToString()) { case "calcNode": CalcNode.Create(new Rect(mousePos.x, mousePos.y, 200, 100)); //CalcNode calcNode = CalcNode.Create (new Rect (mousePos.x, mousePos.y, 200, 100)); break; case "inputNode": InputNode.Create(new Rect(mousePos.x, mousePos.y, 100, 50)); //InputNode inputNode = InputNode.Create (new Rect (mousePos.x, mousePos.y, 100, 50)); break; case "displayNode": DisplayNode.Create(new Rect(mousePos.x, mousePos.y, 100, 50)); //DisplayNode displayNode = DisplayNode.Create (new Rect (mousePos.x, mousePos.y, 100, 50)); break; case "dialNode": DialNode.Create(new Rect(mousePos.x, mousePos.y, 200, 100)); //DialNode dialNode = DialNode.Create(new Rect(mousePos.x, mousePos.y, 200, 100)); break; case "deleteNode": Node node = NodeAtPosition(mousePos); if (node != null) { nodeCanvas.nodes.Remove(node); node.OnDelete(); } break; } }
public void should_allow_form_posts_by_default() { var inputNode = new InputNode(typeof(Address)); inputNode.AllowHttpFormPosts .ShouldBeTrue(); }
public void RejoinTest() { // i1 -> f2 -> (t3, t6) // t3 -> f4 -> t5 // t6 -> f7 -> t8 // (t5, t8) -> f9 -> t10 -> o11 InputNode i1 = new InputNode(Shape.Scalar()); VariableNode t3 = new TemporaryNode(Shape.Scalar()); VariableNode t6 = new TemporaryNode(Shape.Scalar()); FunctionNode f2 = new FunctionNode(new DummyFunction(1, 2), new VariableNode[] { i1 }, new VariableNode[] { t3, t6 }); VariableNode t5 = new TemporaryNode(Shape.Scalar()); FunctionNode f4 = new FunctionNode(new DummyFunction(1, 1), new VariableNode[] { t3 }, new VariableNode[] { t5 }); VariableNode t8 = new TemporaryNode(Shape.Scalar()); FunctionNode f7 = new FunctionNode(new DummyFunction(1, 1), new VariableNode[] { t6 }, new VariableNode[] { t8 }); VariableNode t10 = new TemporaryNode(Shape.Scalar()); FunctionNode f9 = new FunctionNode(new DummyFunction(2, 1), new VariableNode[] { t5, t8 }, new VariableNode[] { t10 }); VariableNode o11 = t10.Save(); List <Node> nodes_sorted = Flow.ExecutionOrderSort(new List <InputNode> { i1 }); CollectionAssert.AreEqual(new Node[] { i1, f2, t3, f4, t5, t6, f7, t8, f9, t10, o11 }, nodes_sorted); }
public virtual void TryAndProcess() { int c = Nodes.Count; for (int i = 0; i < c; i++) { Node n = Nodes[i]; if (OutputNodes.Contains(n.Id)) { continue; } if (InputNodes.Contains(n.Id)) { continue; } n.TryAndProcess(); } c = InputNodes.Count; for (int i = 0; i < c; i++) { Node n; if (NodeLookup.TryGetValue(InputNodes[i], out n)) { InputNode inp = (InputNode)n; inp.TryAndProcess(); } } }
public void In2Out1Test() { // i1 -> f2 -> t3 // i4 -> f5 -> t6 // (t3, t6) -> f7 -> t8 -> o9 InputNode i1 = new InputNode(Shape.Scalar()); VariableNode t3 = new TemporaryNode(Shape.Scalar()); FunctionNode f2 = new FunctionNode(new DummyFunction(1, 1), new VariableNode[] { i1 }, new VariableNode[] { t3 }); InputNode i4 = new InputNode(Shape.Scalar()); VariableNode t6 = new TemporaryNode(Shape.Scalar()); FunctionNode f5 = new FunctionNode(new DummyFunction(1, 1), new VariableNode[] { i4 }, new VariableNode[] { t6 }); VariableNode t8 = new TemporaryNode(Shape.Scalar()); FunctionNode f7 = new FunctionNode(new DummyFunction(2, 1), new VariableNode[] { t3, t6 }, new VariableNode[] { t8 }); VariableNode o9 = t8.Save(); List <Node> nodes_sorted = Flow.ExecutionOrderSort(new List <InputNode> { i1, i4 }); CollectionAssert.AreEqual(new Node[] { i1, f2, t3, i4, f5, t6, f7, t8, o9 }, nodes_sorted); }
public void In2Out2BridgeTest() { // i1 -> f2 -> t3 // i4 -> f5 -> t6 // (t3, t6) -> f7 -> t8 -> f9 -> (t10, t12) // t10 -> o11 // t12 -> o13 InputNode i1 = new InputNode(Shape.Scalar()); VariableNode t3 = new TemporaryNode(Shape.Scalar()); FunctionNode f2 = new FunctionNode(new DummyFunction(1, 1), new VariableNode[] { i1 }, new VariableNode[] { t3 }); InputNode i4 = new InputNode(Shape.Scalar()); VariableNode t6 = new TemporaryNode(Shape.Scalar()); FunctionNode f5 = new FunctionNode(new DummyFunction(1, 1), new VariableNode[] { i4 }, new VariableNode[] { t6 }); VariableNode t8 = new TemporaryNode(Shape.Scalar()); FunctionNode f7 = new FunctionNode(new DummyFunction(2, 1), new VariableNode[] { t3, t6 }, new VariableNode[] { t8 }); VariableNode t10 = new TemporaryNode(Shape.Scalar()); VariableNode t12 = new TemporaryNode(Shape.Scalar()); FunctionNode f9 = new FunctionNode(new DummyFunction(1, 2), new VariableNode[] { t8 }, new VariableNode[] { t10, t12 }); VariableNode o11 = t10.Save(); VariableNode o13 = t12.Save(); List <Node> nodes_sorted = Flow.ExecutionOrderSort(new List <InputNode> { i1, i4 }); CollectionAssert.AreEqual(new Node[] { i1, f2, t3, i4, f5, t6, f7, t8, f9, t10, o11, t12, o13 }, nodes_sorted); }
public static bool Test2() { var i1 = new InputNode(); var i2 = new InputNode(); var h1 = new Perceptron(new Heaviside(1.0)); var h2 = new Perceptron(new Heaviside(2.0)); var h3 = new Perceptron(new Heaviside(1.0)); LinearWeight.Connect(i1, h1, 1.0); LinearWeight.Connect(i1, h2, 1.0); LinearWeight.Connect(i2, h2, 1.0); LinearWeight.Connect(i2, h3, 1.0); var o = new Perceptron(new Linear()); LinearWeight.Connect(h1, o, 1.0); LinearWeight.Connect(h2, o, -2.0); LinearWeight.Connect(h3, o, 1.0); var network = new GeneralNetwork(new List <InputNode> { i1, i2 }, new List <INode> { o }); network.Forward(new[] { 0.0, 0.0 }); network.Forward(new[] { 1.0, 0.0 }); network.Forward(new[] { 0.0, 1.0 }); network.Forward(new[] { 1.0, 1.0 }); return(true); }
public void CircuitValidatesLooped() { // Later change to importing the circuit from file var c = new Circuit(); var i1 = new InputNode(); var n1 = new NotNode(); var n2 = new NotNode(); var n3 = new NotNode(); c.AddInput(i1, NodeCurrent.None); c.Add(i1); c.Add(n1); c.Add(n2); c.Add(n3); i1.AddOutput(n1); n1.AddOutput(n2); n2.AddOutput(n3); n3.AddOutput(n1); Assert.ThrowsException <CircuitInvalidException>(() => { c.Accept(new CircuitLoopValidatorVisitor()); }); }
public Entry ReadEntry(InputNode node) { InputNode key = node.getAttribute("key"); InputNode value = node.getNext("value"); return(new Entry(key.getValue(), value.getValue())); }
public void TestAttributes() { InputNode root = NodeBuilder.read(new StringReader(SOURCE)); InputNode child = root.getNext(); NodeMap <InputNode> map = child.getAttributes(); AssertEquals(root.getReference(), "default"); AssertEquals(child.getReference(), "default"); AssertEquals(map.get("attributeA").getValue(), "valueA"); AssertEquals(map.get("attributeA").getPrefix(), "a"); AssertEquals(map.get("attributeA").getReference(), "A"); AssertEquals(map.get("attributeB").getValue(), "valueB"); AssertEquals(map.get("attributeB").getPrefix(), "b"); AssertEquals(map.get("attributeB").getReference(), "B"); InputNode leaf = child.getNext(); AssertEquals(leaf.getReference(), "default"); AssertEquals(leaf.getAttribute("attributeC").getValue(), "c"); AssertEquals(leaf.getAttribute("attributeC").getPrefix(), "b"); AssertEquals(leaf.getAttribute("attributeC").getReference(), "B"); InputNode entry = root.getNext(); AssertEquals(entry.getReference(), "A"); AssertEquals(entry.getAttribute("attributeD").getValue(), "valueD"); AssertEquals(entry.getAttribute("attributeD").getPrefix(), "b"); AssertEquals(entry.getAttribute("attributeD").getReference(), "B"); }
public void ResidualConnectionTest() { // i1 -> f2 -> t3 -> f4 -> t5 -> f6 -> t7 // (t5, t7) -> f8 -> t9 // (t3, t9) -> f10 -> t11 // (i1, t11) -> f12 -> t13 -> o14 InputNode i1 = new InputNode(Shape.Scalar()); VariableNode t3 = new TemporaryNode(Shape.Scalar()); FunctionNode f2 = new FunctionNode(new DummyFunction(1, 1), new VariableNode[] { i1 }, new VariableNode[] { t3 }); VariableNode t5 = new TemporaryNode(Shape.Scalar()); FunctionNode f4 = new FunctionNode(new DummyFunction(1, 1), new VariableNode[] { t3 }, new VariableNode[] { t5 }); VariableNode t7 = new TemporaryNode(Shape.Scalar()); FunctionNode f6 = new FunctionNode(new DummyFunction(1, 1), new VariableNode[] { t5 }, new VariableNode[] { t7 }); VariableNode t9 = new TemporaryNode(Shape.Scalar()); FunctionNode f8 = new FunctionNode(new DummyFunction(2, 1), new VariableNode[] { t5, t7 }, new VariableNode[] { t9 }); VariableNode t11 = new TemporaryNode(Shape.Scalar()); FunctionNode f10 = new FunctionNode(new DummyFunction(2, 1), new VariableNode[] { t3, t9 }, new VariableNode[] { t11 }); VariableNode t13 = new TemporaryNode(Shape.Scalar()); FunctionNode f12 = new FunctionNode(new DummyFunction(2, 1), new VariableNode[] { i1, t11 }, new VariableNode[] { t13 }); VariableNode o14 = t13.Save(); List <Node> nodes_sorted = Flow.ExecutionOrderSort(new List <InputNode> { i1 }); CollectionAssert.AreEqual(new Node[] { i1, f2, t3, f4, t5, f6, t7, f8, t9, f10, t11, f12, t13, o14 }, nodes_sorted); }
public void NodeConnectionWithNotNodeTest() { var inputNode = new InputNode("in", new State(true)); var notNode = new NotNode("not"); var outputNode = new OutputNode("out"); var nodeConnections = new List <NodeConnection> { new NodeConnection(inputNode, notNode), new NodeConnection(notNode, outputNode) }; var outputs = nodeConnections.Where(x => x.OutputNode is OutputNode).ToList(); var inputIds = outputs.SelectMany(x => x.InputNodes).Select(x => x.NodeId).ToList(); var inputConnections = nodeConnections.Where(x => inputIds.Contains(x.OutputNode.NodeId)); foreach (var input in inputConnections) { input.GetResultFromOutputNode(); } //var t = nodeConnections.Where(x => x.InputNodes.Any(y => )) // Get which node connection has the not node as output // Do GetResultFromOutputNode on that node connection nodeConnections[1].GetResultFromOutputNode(); Assert.False(nodeConnections[1].OutputNode.CurrentState.LogicState); }
/// <summary> /// Constructor for the <c>InputElement</c> object. This /// is used to create an input node that will provide access to /// an XML element. All attributes associated with the element /// given are extracted and exposed via the attribute node map. /// </summary> /// <param name="parent"> /// this is the parent XML element for this /// </param> /// <param name="reader"> /// this is the reader used to read XML elements /// </param> /// <param name="node"> /// this is the XML element wrapped by this node /// </param> public InputElement(InputNode parent, NodeReader reader, EventNode node) { this.map = new InputNodeMap(this, node); this.reader = reader; this.parent = parent; this.node = node; }
/// <summary> /// Overridden.Constructs network topology. /// </summary> protected override void CreateNetwork() { nodes = new NeuroNode[NodesCount]; linksCount = NodesCount * rowsCount * columsCount; kohonenLayer = new NeuroNode[rowsCount, columsCount]; links = new NeuroLink[LinksCount]; for (var i = 0; i < NodesCount; i++) { nodes[i] = new InputNode(); } var curr = 0; for (var row = 0; row < rowsCount; row++) { for (var col = 0; col < columsCount; col++) { kohonenLayer[row, col] = new SelfOrganizingNode(learningRate); for (var i = 0; i < NodesCount; i++) { links[curr] = new SelfOrganizingLink(); nodes[i].LinkTo(kohonenLayer[row, col], links[curr]); curr++; } } } }
public void TestDefaultFirst() { InputNode node = NodeBuilder.read(new StringReader(DEFAULT_FIRST)); String reference = node.getReference(); String prefix = node.getPrefix(); assertTrue(IsEmpty(prefix)); AssertEquals(reference, "http://www.default.com/"); node = node.getNext("book"); reference = node.getReference(); prefix = node.getPrefix(); AssertEquals(prefix, "p"); AssertEquals(reference, "http://www.example.com/book"); InputNode author = node.getNext("author"); reference = author.getReference(); prefix = author.getPrefix(); assertTrue(IsEmpty(prefix)); AssertEquals(reference, "http://www.default.com/"); InputNode title = node.getNext("title"); reference = title.getReference(); prefix = title.getPrefix(); assertTrue(IsEmpty(prefix)); AssertEquals(reference, "http://www.default.com/"); InputNode isbn = node.getNext("isbn"); reference = isbn.getReference(); prefix = isbn.getPrefix(); assertTrue(IsEmpty(prefix)); AssertEquals(reference, "http://www.default.com/"); }
void CreateNode(object key) { BaseNode node = null; switch ((NodeType)key) { case NodeType.InputNode: node = new InputNode(this, _curevent.mousePosition); break; case NodeType.OutputNode: node = new OutputNode(this, _curevent.mousePosition); break; case NodeType.CalcNode: node = new CalcNode(this, _curevent.mousePosition); break; case NodeType.CompNode: node = new CompNode(this, _curevent.mousePosition); break; } if (node != null) { _nodes.Add(node); } }
private void CreateFollowMachine(Graph graph) { var bRect = _selectedNodes.BoundigRect(); _fmNode = (FollowMachineNode)graph.Editor().Repository.CreateNode( typeof(FollowMachineNode), bRect.center); if (_fmNode != null) { _fMachine = graph.Editor().Repository.CreateFollowMachine("Follow Machine"); _fmNode.FollowMachine = _fMachine; _inputNode = (InputNode)_fMachine.Editor().Repository.CreateNode(typeof(InputNode), bRect.center); _outputNode = (OutputNode)_fMachine.Editor().Repository.CreateNode(typeof(OutputNode), bRect.center); _inputNode.Editor().Move(Vector2.left * (bRect.width / 2 + 300)); _outputNode.Editor().Move(Vector2.right * (bRect.width / 2 + 200)); _fMachine.Position = graph.Position; _fMachine.Zoom = graph.Zoom; _fmNode.Editor().OnShow(); } }
static void SetAsStartInput(object p_node) { InputNode node = p_node as InputNode; node.Controller.autoStart = true; node.Controller.autoStartInput = node.Model.inputName; }
public void NotNotNodeTest() { var inputNode = new InputNode("in", new State(true)); var notNode1 = new NotNode("not1"); var notNode2 = new NotNode("not2"); var outputNode = new OutputNode("out"); var nodeConnections = new List <NodeConnection> { new NodeConnection(inputNode, notNode1), new NodeConnection(notNode1, notNode2), new NodeConnection(notNode2, outputNode) }; var inputNodes = new List <InputNode> { inputNode }; var simulation = new NodeSimulation(nodeConnections); simulation.RunSimulation(); var output = simulation.GetOutputState(); Assert.True(output["out"].LogicState); }
public void AndNodeTest() { var inputNode1 = new InputNode("in1", new State(true)); var inputNode2 = new InputNode("in2", new State(true)); var andNode = new AndNode("and"); var outputNode = new OutputNode("out"); var nodeConnections = new List <NodeConnection> { new NodeConnection( new List <NodeBase> { inputNode1, inputNode2 }, andNode), new NodeConnection(andNode, outputNode) }; var inputNodes = new List <InputNode> { inputNode1, inputNode2 }; var simulation = new NodeSimulation(nodeConnections); simulation.RunSimulation(); var output = simulation.GetOutputState(); Assert.True(output["out"].LogicState); }
public void ResetSimulationTest() { var inputNode1 = new InputNode("in1", new State(false)); var inputNode2 = new InputNode("in2", new State(true)); var orNode = new OrNode("or"); var outputNode = new OutputNode("out"); var nodeConnections = new List <NodeConnection> { new NodeConnection( new List <NodeBase> { inputNode1, inputNode2 }, orNode), new NodeConnection(orNode, outputNode) }; var inputNodes = new List <InputNode> { inputNode1, inputNode2 }; var simulation = new NodeSimulation(nodeConnections); simulation.RunSimulation(); simulation.ResetSimulation(); var output = simulation.GetOutputState(); Assert.Null(output["out"]); }
public void SetInvalidAmountInputsTest() { var inputNode1 = new InputNode("in1"); var inputNode2 = new InputNode("in2"); var orNode = new OrNode("or"); var outputNode = new OutputNode("out"); var nodeConnections = new List <NodeConnection> { new NodeConnection( new List <NodeBase> { inputNode1, inputNode2 }, orNode), new NodeConnection(orNode, outputNode) }; var inputNodes = new List <InputNode> { inputNode1, inputNode2 }; var simulation = new NodeSimulation(nodeConnections); var inputValues = new Dictionary <string, State> { { inputNode1.NodeId, new State(true) }, { inputNode2.NodeId, new State(false) }, { orNode.NodeId, new State(false) } }; Assert.Throws <ArgumentException>(() => simulation.SetInputs(inputValues)); }
public void CreateSimulationTest() { var inputNode1 = new InputNode("in1", new State(false)); var inputNode2 = new InputNode("in2", new State(true)); var orNode = new OrNode("or"); var outputNode = new OutputNode("out"); var nodeConnections = new List <NodeConnection> { new NodeConnection( new List <NodeBase> { inputNode1, inputNode2 }, orNode), new NodeConnection(orNode, outputNode) }; var inputNodes = new List <InputNode> { inputNode1, inputNode2 }; var simulation = new NodeSimulation(nodeConnections); // TODO: Is this the same as CollectionAssert? Assert.Equal(nodeConnections, simulation.NodeConnections); }
static void RemoveAsStartInput(object p_node) { InputNode node = p_node as InputNode; node.Controller.autoStart = false; node.Controller.autoStartInput = ""; }
static void SetAsOnEnableInput(object p_node) { InputNode node = p_node as InputNode; node.Controller.autoOnEnable = true; node.Controller.autoOnEnableInput = node.Model.inputName; }
static void RemoveAsOnEnableInput(object p_node) { InputNode node = p_node as InputNode; node.Controller.autoOnEnable = false; node.Controller.autoOnEnableInput = ""; }
//public Object GetInstance() { // Class type = ComponentType; // if(type != null) { // return Array.newInstance(type, 0); // } // return null; //} /// Creates the array type to use. This will use the provided /// XML element to determine the array type and provide a means /// for creating an array with the <c>Value</c> object. If /// the array size cannot be determined an exception is thrown. /// </summary> /// <param name="node"> /// this is the input node for the array element /// </param> /// <returns> /// the object array type used for the instantiation /// </returns> public Instance GetInstance(InputNode node) { Value value = getOverride(node); if(value == null) { throw new ElementException("Array length required for %s", type); } Class type = value.getType(); return GetInstance(value, type); }
/// <summary> /// This method will instantiate an object of the field type, or if /// the <c>Strategy</c> object can resolve a class from the /// XML element then this is used instead. If the resulting type is /// abstract or an interface then this method throws an exception. /// </summary> /// <param name="node"> /// this is the node to check for the override /// </param> /// <returns> /// this returns an instance of the resulting type /// </returns> public Instance GetInstance(InputNode node) { Value value = getOverride(node); Class type = getType(); if(value == null) { return context.GetInstance(type); } return new ObjectInstance(context, value); }
public Instance GetInstance(InputNode node) { Value value = getOverride(node); Class type = getType(); if(value == null) { if(!isInstantiable(type)) { throw new InstantiationException("Cannot instantiate %s", type); } return context.GetInstance(type); } return new ObjectInstance(context, value); }
/// <summary> /// This <c>read</c> method will extract the text value from /// the node and replace any template variables before converting /// it to a primitive value. This uses the <c>Context</c> /// object used for this instance of serialization to replace all /// template variables with values from the context filter. /// </summary> /// <param name="node"> /// this is the node to be converted to a primitive /// </param> /// <param name="type"> /// this is the type to read the primitive with /// </param> /// <returns> /// this returns the primitive that has been deserialized /// </returns> public Object Read(InputNode node, Class type) { String value = node.getValue(); if(value == null) { return null; } if(empty != null && value.equals(empty)) { return empty; } return ReadTemplate(value, type); }
/// <summary> /// This <c>read</c> method will extract the text value from /// the node and replace any template variables before converting /// it to a primitive value. This uses the <c>Context</c> /// object used for this instance of serialization to replace all /// template variables with values from the context filter. /// </summary> /// <param name="node"> /// this is the node to be converted to a primitive /// </param> /// <returns> /// this returns the primitive that has been deserialized /// </returns> public Object ReadElement(InputNode node) { Instance value = factory.GetInstance(node); if(!value.isReference()) { return ReadElement(node, value); } return value.GetInstance(); }
/// <summary> /// This <c>read</c> method will read the XML element map from /// the provided node and deserialize its children as entry types. /// Each entry type must contain a key and value so that the entry /// can be inserted in to the map as a pair. If either the key or /// value is composite it is read as a root object, which means its /// <c>Root</c> annotation must be present and the name of the /// object element must match that root element name. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <param name="result"> /// this is the map object that is to be populated /// </param> /// <returns> /// this returns the item to attach to the object contact /// </returns> public Object Read(InputNode node, Object result) { Instance type = factory.GetInstance(node); if(type.isReference()) { return type.Instance; } type.setInstance(result); if(result != null) { return Populate(node, result); } return result; }
/// <summary> /// This method is used to read the value object from the node. The /// value read from the node is resolved using the template filter. /// If the value data can not be found according to the annotation /// attributes then null is assumed and the node is valid. /// </summary> /// <param name="node"> /// this is the node to read the value object from /// </param> /// <param name="key"> /// this is the name of the value element /// </param> /// <returns> /// this returns true if this represents a valid value /// </returns> public bool Validate(InputNode node, String key) { String name = style.GetElement(key); InputNode next = node.getNext(name); Class expect = type.Type; if(next == null) { return true; } if(next.IsEmpty()) { return true; } return root.Validate(next, expect); }
/// <summary> /// This <c>read</c> method will read the XML element map from /// the provided node and deserialize its children as entry types. /// Each entry type must contain a key and value so that the entry /// can be inserted in to the map as a pair. If either the key or /// value is composite it is read as a root object, which means its /// <c>Root</c> annotation must be present and the name of the /// object element must match that root element name. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <returns> /// this returns the item to attach to the object contact /// </returns> public Object Read(InputNode node) { Instance type = factory.GetInstance(node); Object map = type.Instance; if(!type.isReference()) { return Populate(node, map); } return map; }
/// <summary> /// This <c>validate</c> method will validate the XML element /// map from the provided node and validate its children as entry /// types. Each entry type must contain a key and value so that the /// entry can be inserted in to the map as a pair. If either the key /// or value is composite it is read as a root object, which means its /// <c>Root</c> annotation must be present and the name of the /// object element must match that root element name. /// </summary> /// <param name="node"> /// this is the XML element that is to be validate /// </param> /// <param name="type"> /// this is the type to validate the input node against /// </param> /// <returns> /// true if the element matches the XML schema class given /// </returns> public bool Validate(InputNode node, Class type) { while(true) { InputNode next = node.getNext(); if(next == null) { return true; } if(!key.Validate(next)) { return false; } if(!value.Validate(next)) { return false; } } }
/// <summary> /// This <c>read</c> method will read the XML element map from /// the provided node and deserialize its children as entry types. /// Each entry type must contain a key and value so that the entry /// can be inserted in to the map as a pair. If either the key or /// value is composite it is read as a root object, which means its /// <c>Root</c> annotation must be present and the name of the /// object element must match that root element name. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <returns> /// this returns the item to attach to the object contact /// </returns> public Object Read(InputNode node, Object value) { Dictionary map = (Map) value; if(map != null) { return Read(node, map); } return Read(node); }
/// <summary> /// This <c>validateElement</c> method validates a primitive /// by checking the node text. If the value is a reference then /// this will not extract any value from the node. Transformation /// of the extracted value is not done as it can not account for /// template variables. Thus any text extracted is valid. /// </summary> /// <param name="node"> /// this is the node to be validated as a primitive /// </param> /// <returns> /// this returns the primitive that has been validated /// </returns> public bool ValidateElement(InputNode node) { Instance type = factory.GetInstance(node); if(!type.isReference()) { type.setInstance(null); } return true; }
/// <summary> /// This <c>read</c> method will read the XML element map from /// the provided node and deserialize its children as entry types. /// Each entry type must contain a key and value so that the entry /// can be inserted in to the map as a pair. If either the key or /// value is composite it is read as a root object, which means its /// <c>Root</c> annotation must be present and the name of the /// object element must match that root element name. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <returns> /// this returns the item to attach to the object contact /// </returns> public bool Validate(InputNode node) { InputNode from = node.getParent(); String name = node.getName(); while(node != null) { if(!key.Validate(node)) { return false; } if(!value.Validate(node)) { return false; } node = from.getNext(name); } return true; }
/// <summary> /// This <c>read</c> method will read the XML element map from /// the provided node and deserialize its children as entry types. /// Each entry type must contain a key and value so that the entry /// can be inserted in to the map as a pair. If either the key or /// value is composite it is read as a root object, which means its /// <c>Root</c> annotation must be present and the name of the /// object element must match that root element name. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <param name="map"> /// this is the map object that is to be populated /// </param> /// <returns> /// this returns the item to attach to the object contact /// </returns> public Object Read(InputNode node, Dictionary map) { InputNode from = node.getParent(); String name = node.getName(); while(node != null) { Object index = key.Read(node); Object item = value.Read(node); if(map != null) { map.put(index, item); } node = from.getNext(name); } return map; }
/// <summary> /// This is used to resolve and load a class for the given element. /// The class should be of the same type or a subclass of the class /// specified. It can be resolved using the details within the /// provided XML element, if the details used do not represent any /// serializable values they should be removed so as not to disrupt /// the deserialization process. For example the default strategy /// removes all "class" attributes from the given elements. /// </summary> /// <param name="type"> /// this is the type of the root element expected /// </param> /// <param name="node"> /// this is the element used to resolve an override /// </param> /// <returns> /// returns the type that should be used for the object /// </returns> public Value GetOverride(Type type, InputNode node) { NodeMap<InputNode> map = node.getAttributes(); if(map == null) { throw new PersistenceException("No attributes for %s", node); } return strategy.Read(type, map, session); }
/// <summary> /// This <c>validate</c> method wll validate the XML element list /// from the provided node and validate its children as entry types. /// This will validate each entry type as a primitive value. In order /// to do this the parent string provided forms the element. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <returns> /// true if the element matches the XML schema class given /// </returns> public bool Validate(InputNode node) { Instance value = factory.GetInstance(node); if(!value.isReference()) { Object result = value.setInstance(null); Class expect = value.Type; return Validate(node, expect); } return true; }
/// <summary> /// This method is used to read the value object from the node. The /// value read from the node is resolved using the template filter. /// If the value data can not be found according to the annotation /// attributes then null is assumed and the node is valid. /// </summary> /// <param name="node"> /// this is the node to read the value object from /// </param> /// <returns> /// this returns true if this represents a valid value /// </returns> public bool Validate(InputNode node) { Class expect = type.Type; String name = entry.GetValue(); if(name == null) { name = context.GetName(expect); } return Validate(node, name); }
/// <summary> /// This <c>read</c> method will extract the text value from /// the node and replace any template variables before converting /// it to a primitive value. This uses the <c>Context</c> /// object used for this instance of serialization to replace all /// template variables with values from the context filter. /// </summary> /// <param name="node"> /// this is the node to be converted to a primitive /// </param> /// <param name="value"> /// this is the instance to set the result to /// </param> /// <returns> /// this returns the primitive that has been deserialized /// </returns> public Object ReadElement(InputNode node, Instance value) { Object result = Read(node, type); if(value != null) { value.setInstance(result); } return result; }
/// <summary> /// This <c>read</c> method will read the XML element map from /// the provided node and deserialize its children as entry types. /// Each entry type must contain a key and value so that the entry /// can be inserted in to the map as a pair. If either the key or /// value is composite it is read as a root object, which means its /// <c>Root</c> annotation must be present and the name of the /// object element must match that root element name. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <returns> /// this returns the item to attach to the object contact /// </returns> public Object Read(InputNode node) { Object value = factory.Instance; Dictionary table = (Map) value; if(table != null) { return Read(node, table); } return null; }
/// <summary> /// This <c>validate</c> method will validate the primitive /// by checking the node text. If the value is a reference then /// this will not extract any value from the node. Transformation /// of the extracted value is not done as it can not account for /// template variables. Thus any text extracted is valid. /// </summary> /// <param name="node"> /// this is the node to be validated as a primitive /// </param> /// <returns> /// this returns the primitive that has been validated /// </returns> public bool Validate(InputNode node) { if(node.isElement()) { ValidateElement(node); } else { node.getValue(); } return true; }
/// <summary> /// Overridden.Constructs network topology. /// </summary> /// <remarks>Creates nodes, links and connects nodes using created links.</remarks> protected override void CreateNetwork() { nodes = new NeuroNode[NodesCount]; links = new NeuroLink[LinksCount]; for (var i = 0; i < InputNodesCount; i++) nodes[i] = new InputNode(); nodes[NodesCount - 2] = new BiasNode(1); nodes[NodesCount - 1] = new AdalineNode(LearningRate); for (var i = 0; i < LinksCount; i++) links[i] = new AdalineLink(); for (var i = 0; i < LinksCount; i++) nodes[i].LinkTo(nodes[NodesCount - 1], links[i]); }
/// <summary> /// Constructor for the <c>InputAttribute</c> object. This /// is used to create an input attribute using the provided name /// and value, all other values for this input node will be null. /// </summary> /// <param name="parent"> /// this is the parent node to this attribute /// </param> /// <param name="name"> /// this is the name for this attribute object /// </param> /// <param name="value"> /// this is the value for this attribute object /// </param> public InputAttribute(InputNode parent, String name, String value) { this.parent = parent; this.value = value; this.name = name; }
/// <summary> /// Constructor for the <c>InputAttribute</c> object. This /// is used to create an input attribute using the provided name /// and value, all other values for this input node will be null. /// </summary> /// <param name="parent"> /// this is the parent node to this attribute /// </param> /// <param name="attribute"> /// this is the attribute containing the details /// </param> public InputAttribute(InputNode parent, Attribute attribute) { this.reference = attribute.Reference; this.prefix = attribute.Prefix; this.source = attribute.Source; this.value = attribute.Value; this.name = attribute.Name; this.parent = parent; }
/// <summary> /// This <c>populate</c> method will read the XML element map /// from the provided node and deserialize its children as entry types. /// Each entry type must contain a key and value so that the entry /// can be inserted in to the map as a pair. If either the key or /// value is composite it is read as a root object, which means its /// <c>Root</c> annotation must be present and the name of the /// object element must match that root element name. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <param name="result"> /// this is the map object that is to be populated /// </param> /// <returns> /// this returns the item to attach to the object contact /// </returns> public Object Populate(InputNode node, Object result) { Dictionary map = (Map) result; while(true) { InputNode next = node.getNext(); if(next == null) { return map; } Object index = key.Read(next); Object item = value.Read(next); map.put(index, item); } }
/// <summary> /// This <c>read</c> method will extract the text value from /// the node and replace any template variables before converting /// it to a primitive value. This uses the <c>Context</c> /// object used for this instance of serialization to replace all /// template variables with values from the context filter. /// </summary> /// <param name="node"> /// this is the node to be converted to a primitive /// </param> /// <returns> /// this returns the primitive that has been deserialized /// </returns> public Object Read(InputNode node) { if(node.isElement()) { return ReadElement(node); } return Read(node, type); }
/// <summary> /// This <c>read</c> method will read the XML element list from /// the provided node and deserialize its children as entry types. /// This will deserialize each entry type as a primitive value. In /// order to do this the parent string provided forms the element. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <returns> /// this returns the item to attach to the object contact /// </returns> public Object Read(InputNode node) { Instance type = factory.GetInstance(node); Object list = type.Instance; if(!type.isReference()) { return Populate(node, list); } return list; }
/// <summary> /// This <c>read</c> method will extract the text value from /// the node and replace any template variables before converting /// it to a primitive value. This uses the <c>Context</c> /// object used for this instance of serialization to replace all /// template variables with values from the context filter. /// </summary> /// <param name="node"> /// this is the node to be converted to a primitive /// </param> /// <param name="value"> /// this is the original primitive value used /// </param> /// <returns> /// this returns the primitive that has been deserialized /// </returns> public Object Read(InputNode node, Object value) { if(value != null) { throw new PersistenceException("Can not read existing %s", type); } return Read(node); }
/// <summary> /// This <c>populate</c> method wll read the XML element list /// from the provided node and deserialize its children as entry types. /// This will deserialize each entry type as a primitive value. In /// order to do this the parent string provided forms the element. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <param name="result"> /// this is the collection that is to be populated /// </param> /// <returns> /// this returns the item to attach to the object contact /// </returns> public Object Populate(InputNode node, Object result) { Collection list = (Collection) result; while(true) { InputNode next = node.getNext(); if(next == null) { return list; } list.add(root.Read(next)); } }
/// <summary> /// This method is used to read the value object from the node. The /// value read from the node is resolved using the template filter. /// If the value data can not be found according to the annotation /// attributes then null is assumed and returned. /// </summary> /// <param name="node"> /// this is the node to read the value object from /// </param> /// <returns> /// this returns the value deserialized from the node /// </returns> public Object Read(InputNode node) { InputNode next = node.getNext(); Class expect = type.Type; if(next == null) { return null; } if(next.IsEmpty()) { return null; } return root.Read(next, expect); }
/// <summary> /// This <c>validate</c> method will validate the XML element list /// from the provided node and validate its children as entry types. /// This will validate each entry type as a primitive value. In order /// to do this the parent string provided forms the element. /// </summary> /// <param name="node"> /// this is the XML element that is to be deserialized /// </param> /// <param name="type"> /// this is the type to validate against the input node /// </param> /// <returns> /// true if the element matches the XML schema class given /// </returns> public bool Validate(InputNode node, Class type) { while(true) { InputNode next = node.getNext(); if(next == null) { return true; } root.Validate(next); } }
/// <summary> /// This method is used to read the value object from the node. The /// value read from the node is resolved using the template filter. /// If the value data can not be found according to the annotation /// attributes then null is assumed and returned. /// </summary> /// <param name="node"> /// this is the node to read the value object from /// </param> /// <param name="value"> /// this is the value to deserialize in to /// </param> /// <returns> /// this returns the value deserialized from the node /// </returns> public Object Read(InputNode node, Object value) { Class expect = type.Type; if(value != null) { throw new PersistenceException("Can not read value of %s", expect); } return Read(node); }