Ejemplo n.º 1
0
        public Nametable32(Func <Stream> stream_gen)
        {
            PType tp_elem = new PTypeRecord(
                new NamedType("code", new PType(PTypeEnumeration.integer)),
                new NamedType("str", new PType(PTypeEnumeration.sstring)));

            cod_str   = new UniversalSequenceBase(tp_elem, stream_gen());
            offsets   = new UniversalSequenceBase(new PType(PTypeEnumeration.longinteger), stream_gen());
            index_str = new IndexKey32CompImmutable(stream_gen, cod_str, ob => true,
                                                    ob => Hashfunctions.HashRot13((string)((object[])ob)[1]), null);
            dyna_index = new Dictionary <string, int>();
        }
Ejemplo n.º 2
0
        public TripleStoreInt32(Func <Stream> stream_gen)
        {
            // сначала таблица имен
            nt = new Nametable32(stream_gen);
            // Тип Object Variants
            PType tp_ov = new PTypeUnion(
                new NamedType("dummy", new PType(PTypeEnumeration.none)),
                new NamedType("iri", new PType(PTypeEnumeration.integer)),
                new NamedType("str", new PType(PTypeEnumeration.sstring)),
                new NamedType("int", new PType(PTypeEnumeration.sstring)),
                new NamedType("date", new PType(PTypeEnumeration.sstring)),
                new NamedType("langstr", new PTypeRecord(
                                  new NamedType("lang", new PType(PTypeEnumeration.sstring)),
                                  new NamedType("str", new PType(PTypeEnumeration.sstring)))));
            PType tp_triple = new PTypeRecord(
                new NamedType("subj", new PType(PTypeEnumeration.integer)),
                new NamedType("pred", new PType(PTypeEnumeration.integer)),
                new NamedType("obj", tp_ov));

            // Главная последовательность кодированных триплетов
            table = new UniversalSequenceBase(tp_triple, stream_gen());

            // прямой ссылочный индекс
            s_index = new IndexKey32CompImmutable(stream_gen, table,
                                                  ob => Enumerable.Repeat <int>((int)((object[])ob)[0], 1), null);

            // Обратный ссылочный индекс
            i_index = new IndexKey32Imm(stream_gen, table, obj =>
            {
                object[] pair = (object[])((object[])obj)[2];
                int tg        = (int)pair[0];
                if (tg != 1)
                {
                    return(Enumerable.Empty <int>());
                }
                return(Enumerable.Repeat <int>((int)pair[1], 1));
            }, null);

            // Индекс по тексту объектов триплетов с предикатом http://fogid.net/o/name
            Comparer <object> comp = Comparer <object> .Create(new Comparison <object>((object a, object b) =>
            {
                return(string.Compare((string)((object[])((object[])a)[2])[1], (string)((object[])((object[])b)[2])[1]));
            }));

            int name_code = Int32.MinValue; // nt.GetSetStr("http://fogid.net/o/name"); // Такое предварительное вычисление не работает!!!

            name_index = new IndexKey32CompImmutable(stream_gen, table, obj =>
            {
                if (name_code == Int32.MinValue)
                {
                    name_code = nt.GetSetStr("http://fogid.net/o/name");
                }
                object[] tri = (object[])obj;
                //TODO: кодов имени может быть много...
                if ((int)tri[1] != name_code)
                {
                    return(Enumerable.Empty <int>());
                }
                object[] pair = (object[])tri[2];
                int tg        = (int)pair[0];
                string data   = null;
                if (tg == 2)
                {
                    data = (string)pair[1];
                }
                //else if (tg == 5) data = (string)((object[])pair[1])[1]; // пока будем работать только с простыми строками
                if (data != null)
                {
                    return(Enumerable.Repeat <int>(Hashfunctions.First4charsRu(data), 1));
                }
                return(Enumerable.Empty <int>());
            },
                                                     //new int[] { Hashfunctions.First4charsRu((string)((object[])obj)[1]) }
                                                     comp);
        }