Exemplo n.º 1
0
        public XElement GetItemByIdBasic(string id, bool addinverse)
        {
            PaEntry ent = id_index.GetFirst(id);

            object[] item = (object[])ent.Get();
            XElement res  = new XElement("record", new XAttribute("id", item[1]), new XAttribute("type", item[2]),
                                         ((object[])item[3]).Cast <object[]>().Select(v3 =>
                                                                                      new XElement("field", new XAttribute("prop", v3[0]),
                                                                                                   string.IsNullOrEmpty((string)v3[2])?null: new XAttribute(ONames.xmllang, v3[2]),
                                                                                                   v3[1])),
                                         ((object[])item[4]).Cast <object[]>().Select(v2 =>
                                                                                      new XElement("direct", new XAttribute("prop", v2[0]),
                                                                                                   v2[1])),
                                         null);

            if (addinverse)
            {
                var qu = inverse_index.GetAll(id).Select(en => en.Get()).Cast <object[]>()
                         .SelectMany(v5 => ((object[])v5[4]).Where(v2 => (string)((object[])v2)[1] == id).Select(v2 =>
                                                                                                                 new XElement("inverse",
                                                                                                                              new XAttribute("prop", ((object[])v2)[0]),
                                                                                                                              new XElement("record", new XAttribute("id", v5[1])))));
                res.Add(qu);
            }
            return(res);
        }
        public XElement GetItemByIdBasic(string id, bool addinverse)
        {
            PaEntry ent = id_index.GetFirst(id);

            object[] item = (object[])ent.Get();
            XElement res  = new XElement("record", new XAttribute("id", item[1]), new XAttribute("type", item[2]),
                                         ((object[])item[3]).Cast <object[]>().Select(v3 =>
                                                                                      new XElement("field", new XAttribute("prop", v3[0]),
                                                                                                   string.IsNullOrEmpty((string)v3[2]) ? null : new XAttribute(ONames.xmllang, v3[2]),
                                                                                                   v3[1])),
                                         ((object[])item[4]).Cast <object[]>().Select(v2 =>
                                                                                      new XElement("direct", new XAttribute("prop", v2[0]),
                                                                                                   v2[1])),
                                         null);

            if (addinverse)
            {
                //var qu = inverse_index.GetAll(id)
                //    .Select(pair =>
                //    {
                //        return new XElement("inverse", new XAttribute("prop", pair.stri),
                //            new XElement("record", new XAttribute("id", pair.entr.Field(1).Get())));
                //    });
                //res.Add(qu);

                string   predicate = null;
                XElement inverse   = null;
                foreach (var qq in inverse_index.GetAll(id))
                {
                    string pred = qq.stri;
                    if (pred != predicate)
                    {
                        res.Add(inverse);
                        inverse   = new XElement("inverse", new XAttribute("prop", pred));
                        predicate = pred;
                    }
                    string idd = (string)qq.entr.Field(1).Get();
                    inverse.Add(new XElement("record", new XAttribute("id", idd)));
                }
                res.Add(inverse);
            }
            return(res);
        }
Exemplo n.º 3
0
        private static void Find(FreeIndex iset_index, int sample)
        {
            var qu = iset_index.GetFirst(ent =>
            {
                int v = (int)ent.Get();
                return(v.CompareTo(sample));
            });

            if (qu.offset == Int64.MinValue)
            {
                Console.WriteLine("value not found");
            }
            else
            {
                var val = qu.GetValue();
                Console.WriteLine(val.Type.Interpret(val.Value));
            }
        }