Наследование: OsirisSerializable
Пример #1
0
        public override void MakeScript(TextWriter writer, Story story, Tuple tuple)
        {
            var adaptedTuple = story.Adapters[AdapterRef.AdapterIndex].Adapt(tuple);
            story.Nodes[ParentRef.NodeIndex].MakeScript(writer, story, adaptedTuple);
            writer.WriteLine("AND");

            if (Value1Index != -1)
                adaptedTuple.Logical[Value1Index].MakeScript(writer, story, tuple);
            else
                Value1.MakeScript(writer, story, tuple);

            switch (RelOp)
            {
                case RelOpType.Less: writer.Write(" < "); break;
                case RelOpType.LessOrEqual: writer.Write(" <= "); break;
                case RelOpType.Greater: writer.Write(" > "); break;
                case RelOpType.GreaterOrEqual: writer.Write(" >= "); break;
                case RelOpType.Equal: writer.Write(" == "); break;
                case RelOpType.NotEqual: writer.Write(" != "); break;
            }

            if (Value2Index != -1)
                adaptedTuple.Logical[Value2Index].MakeScript(writer, story, tuple);
            else
                Value2.MakeScript(writer, story, tuple);
            writer.WriteLine();
        }
Пример #2
0
        public void Read(OsiReader reader)
        {
            Constants = new Tuple();
            Constants.Read(reader);

            LogicalIndices = new List<sbyte>();
            var count = reader.ReadByte();
            while (count-- > 0)
            {
                LogicalIndices.Add(reader.ReadSByte());
            }

            LogicalToPhysicalMap = new Dictionary<byte, byte>();
            count = reader.ReadByte();
            while (count-- > 0)
            {
                var key = reader.ReadByte();
                var value = reader.ReadByte();
                LogicalToPhysicalMap.Add(key, value);
            }
        }
Пример #3
0
        public Tuple Adapt(Tuple columns)
        {
            var result = new Tuple();
            for (var i = 0; i < LogicalIndices.Count; i++)
            {
                var index = LogicalIndices[i];
                // If a logical index is present, emit an attribute from the input tuple
                if (index != -1)
                {
                    var value = columns.Logical[index];
                    result.Physical.Add(value);
                }
                // Otherwise check if a constant is mapped to the specified logical index
                else if (Constants.Logical.ContainsKey(i))
                {
                    var value = Constants.Logical[i];
                    result.Physical.Add(value);
                }
                // If we haven't found a constant, emit a null variable
                else
                {
                    var nullValue = new Variable();
                    nullValue.TypeId = (uint)Value.Type.Unknown;
                    nullValue.Unused = true;
                    result.Physical.Add(nullValue);
                }
            }

            // Generate logical => physical mappings for the output tuple
            foreach (var map in LogicalToPhysicalMap)
            {
                result.Logical.Add(map.Key, result.Physical[map.Value]);
            }

            return result;
        }
Пример #4
0
 public override void MakeScript(TextWriter writer, Story story, Tuple tuple)
 {
     writer.Write("{0}(", Name);
     tuple.MakeScript(writer, story);
     writer.WriteLine(")");
 }
Пример #5
0
        public void MakeScript(TextWriter writer, Story story, Tuple tuple)
        {
            if (Name.Length > 0)
            {
                if (Negate) writer.Write("NOT ");
                writer.Write("{0}(", Name);
                if (Parameters != null)
                {
                    for (var i = 0; i < Parameters.Count; i++)
                    {
                        var param = Parameters[i];
                        param.MakeScript(writer, story, tuple);
                        if (i < Parameters.Count - 1)
                            writer.Write(", ");
                    }
                }

                writer.Write(")");
            }

            if (GoalIdOrDebugHook > 0)
            {
                writer.Write("GoalCompleted;");
            }
        }
Пример #6
0
        public override void MakeScript(TextWriter writer, Story story, Tuple tuple, bool printTypes = false)
        {
            if (Unused)
            {
                writer.Write("_");
            }
            else if (Adapted)
            {
                if (VariableName != null && VariableName.Length > 0)
                {
                    if (printTypes)
                    {
                        writer.Write("({0})", story.Types[TypeId].Name);
                    }

                    writer.Write(VariableName);
                }
                else
                {
                    tuple.Logical[Index].MakeScript(writer, story, null);
                }
            }
            else
            {
                base.MakeScript(writer, story, tuple);
            }
        }
Пример #7
0
        public virtual void MakeScript(TextWriter writer, Story story, Tuple tuple, bool printTypes = false)
        {
            switch ((Type)TypeId)
            {
                case Type.Unknown:
                    throw new InvalidDataException("Script cannot contain unknown values");

                case Type.Integer:
                    writer.Write(IntValue);
                    break;

                case Type.Float:
                    writer.Write(FloatValue);
                    break;

                case Type.String:
                    writer.Write("\"{0}\"", StringValue);
                    break;

                default:
                    writer.Write(StringValue);
                    break;
            }
        }
Пример #8
0
        public override void MakeScript(TextWriter writer, Story story, Tuple tuple)
        {
            switch (GetRuleType(story))
            {
                case RuleType.Proc: writer.WriteLine("PROC"); break;
                case RuleType.Query: writer.WriteLine("QRY"); break;
                case RuleType.Rule: writer.WriteLine("IF"); break;
            }

            var initialTuple = MakeInitialTuple();
            story.Nodes[ParentRef.NodeIndex].MakeScript(writer, story, initialTuple);
            writer.WriteLine("THEN");
            foreach (var call in Calls)
            {
                call.MakeScript(writer, story, initialTuple);
                writer.WriteLine();
            }
        }
Пример #9
0
        public Tuple MakeInitialTuple()
        {
            var tuple = new Tuple();
            for (int i = 0; i < Variables.Count; i++)
            {
                tuple.Physical.Add(Variables[i]);
                tuple.Logical.Add(i, Variables[i]);
            }

            return tuple;
        }
Пример #10
0
 public abstract void MakeScript(TextWriter writer, Story story, Tuple tuple, bool printTypes = false);
Пример #11
0
 abstract public void MakeScript(TextWriter writer, Story story, Tuple tuple);
Пример #12
0
        public void MakeScript(TextWriter writer, Story story)
        {
            writer.WriteLine("Version 1");
            writer.WriteLine("SubGoalCombiner SGC_AND");
            writer.WriteLine();
            writer.WriteLine("INITSECTION");

            var nullTuple = new Tuple();
            foreach (var call in InitCalls)
            {
                call.MakeScript(writer, story, nullTuple);
                writer.WriteLine();
            }

            writer.WriteLine();
            writer.WriteLine("KBSECTION");

            foreach (var node in story.Nodes)
            {
                if (node.Value is RuleNode)
                {
                    var rule = node.Value as RuleNode;
                    if (rule.DerivedGoalId == Index)
                    {
                        node.Value.MakeScript(writer, story, nullTuple);
                        writer.WriteLine();
                    }
                }
            }

            writer.WriteLine();
            writer.WriteLine("EXITSECTION");

            foreach (var call in ExitCalls)
            {
                call.MakeScript(writer, story, nullTuple);
                writer.WriteLine();
            }

            writer.WriteLine("ENDEXITSECTION");
            writer.WriteLine();

            foreach (var goalId in SubGoals)
            {
                var goal = story.Goals[goalId];
                writer.WriteLine("ParentTargetEdge \"{0}\"", goal.Name);
            }

            foreach (var goalId in ParentGoals)
            {
                var goal = story.Goals[goalId];
                writer.WriteLine("TargetEdge \"{0}\"", goal.Name);
            }
        }
Пример #13
0
 public override void MakeScript(TextWriter writer, Story story, Tuple tuple)
 {
     var leftTuple = story.Adapters[Adapter1Ref.AdapterIndex].Adapt(tuple);
     story.Nodes[LeftParentRef.NodeIndex].MakeScript(writer, story, leftTuple);
     writer.WriteLine("AND NOT");
     var rightTuple = story.Adapters[Adapter2Ref.AdapterIndex].Adapt(tuple);
     story.Nodes[RightParentRef.NodeIndex].MakeScript(writer, story, rightTuple);
 }