示例#1
0
        private static Table ConvertStringToTable(string str)
        {
            str = str.Replace("\r", "");
            Parser    p    = new Parser(str, Parser.ReadOptions.STRING, Parser.ParseOptions.REMOVE_ONLY_TABS);
            ParseTree tree = new ParseTree(p.ParseTable);

            if (!tree.successfulParse)
            {
                return(null);
            }

            int                 size        = int.Parse(tree["<int>"][0].Data);
            string              name        = tree["<sentence>"][0].Data;
            ParseNode           relationPtr = tree["<relation_list>"];
            List <NameTypePair> ntpList     = new List <NameTypePair>();

            do
            {
                if (relationPtr.Data == "<relation_list_tail>")
                {
                    relationPtr = relationPtr[0];
                }
                NameTypePair ntp = new NameTypePair(relationPtr[0]);
                ntpList.Add(ntp);

                relationPtr = relationPtr[1];
            } while (relationPtr != null);
            Relation generatedRelation = new Relation(ntpList.ToArray());
            Table    output            = new Table(name, generatedRelation, true, size);



            var tupleListPtr = tree["<tuple_list>"];

            while (tupleListPtr != null)
            {
                if (tupleListPtr.Data == "<tuple_list_tail>")
                {
                    tupleListPtr = tupleListPtr[0];
                }
                int index = int.Parse(tupleListPtr[0][0].Data);

                output.AllLists[index].AddFirst(RADTuple.CreateFromParseNode(generatedRelation, tupleListPtr["<tuple>"]));                 // TODO: Tuple ParseNode to tuple Constructor
                var tuplePtr = tupleListPtr["<tuple_more>"];
                while (tuplePtr != null)
                {
                    ParseNode tupleNode = tuplePtr["<tuple>"];
                    RADTuple  tuple     = RADTuple.CreateFromParseNode(generatedRelation, tupleNode);
                    output.AllLists[index].AddLast(tuple);
                    tuplePtr = tuplePtr["<tuple_more>"];
                }


                tupleListPtr = tupleListPtr["<tuple_list_tail>"];
            }

            output.SecondaryIndexing.ReCreateSecondaryIndex();
            //Console.WriteLine("Created Table From File");
            return(output);
        }
示例#2
0
            public RADTuple Add(RADTuple t)
            {
                if ((Data as Table)?.Add(t) ?? false)
                {
                    return(null);
                }

                return(t);
            }
        public void Add(RADTuple tuple)
        {
            if (tuple.relation != table.Relation)
            {
                return;
            }

            for (int i = 1; i < table.Relation.Keys.Length; i++)
            {
                string secondaryName = table.Relation.Names[table.Relation.Keys[i]];
                treeDict[secondaryName].Add(tuple);
            }
        }
            public void Add(RADTuple tuple)
            {
                Element primary   = tuple[primaryIndex];
                Element secondary = tuple[secondaryIndex];

                if (_dictionary.ContainsKey(secondary))
                {
                    _dictionary[secondary].AddLast(primary);
                }
                else
                {
                    LinkedList <Element> newList = new LinkedList <Element>();
                    newList.AddFirst(primary);
                    _dictionary.Add(secondary, newList);
                }
            }
            public bool Remove(RADTuple tuple)
            {
                Element primary   = tuple[primaryIndex];
                Element secondary = tuple[secondaryIndex];

                if (_dictionary.ContainsKey(secondary))
                {
                    LinkedList <Element> list = _dictionary[secondary];
                    if (list.Count == 1)
                    {
                        return(_dictionary.Remove(secondary));
                    }
                    return(list.Remove(primary));
                }

                return(false);
            }
        public bool Remove(RADTuple tuple)
        {
            if (tuple.relation != table.Relation)
            {
                return(false);
            }

            for (int i = 1; i < table.Relation.Keys.Length; i++)
            {
                string secondaryName = table.Relation.Names[table.Relation.Keys[i]];
                bool   outcome       = treeDict[secondaryName].Remove(tuple);
                if (!outcome)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#7
0
 public CommandRADTuple(RADTuple data) : base(data)
 {
 }