Exemplo n.º 1
0
        private FreebaseEntry loadEntry(DbPointer pointer)
        {
            _dbReader.BaseStream.Seek(pointer.Offset, SeekOrigin.Begin);
            _dbReader.DiscardBufferedData();
            var entryLine = _dbReader.ReadLine();

            return(DumpLoader.ParseEntry(entryLine));
        }
Exemplo n.º 2
0
        internal FreebaseEntry GetEntry(DbPointer pointer)
        {
            FreebaseEntry entry;

            if (!_entryCache.TryGetValue(pointer, out entry))
            {
                _entryCache[pointer] = entry = loadEntry(pointer);
            }

            return(entry);
        }
Exemplo n.º 3
0
        private void loadIndex(string indexPath)
        {
            if (File.Exists(indexPath + "._idIndex"))
            {
                Console.WriteLine("Loading index");
                _idIndex    = deserializePointers(indexPath, "_idIndex");
                _aliasIndex = deserializePointerArrays(indexPath, "_aliasIndex", StringComparer.InvariantCultureIgnoreCase);
                Console.WriteLine("\tfinished.");
                return;
            }

            Console.WriteLine("DB index creation");
            var currentPosition = 0u;

            while (!_dbReader.EndOfStream)
            {
                var pointer    = new DbPointer(currentPosition);
                var line       = _dbReader.ReadLine();
                var lineLength = _dbReader.CurrentEncoding.GetBytes(line).Length;
                currentPosition += (uint)(lineLength + 1);

                string id;
                var    aliases = DumpLoader.ParseLabels(line, out id);
                foreach (var alias in aliases)
                {
                    if (_aliasIndex.ContainsKey(alias))
                    {
                        _aliasIndex[alias] = _aliasIndex[alias].Concat(new[] { pointer }).ToArray();
                    }
                    else
                    {
                        _aliasIndex[alias] = new[] { pointer }
                    };
                }

                _idIndex[id] = pointer;
            }
            Console.WriteLine("\tserializing");
            serialize(indexPath, "_aliasIndex", _aliasIndex);
            serialize(indexPath, "_idIndex", _idIndex);
            Console.WriteLine("\tfinished.");
        }
Exemplo n.º 4
0
        public Dictionary <string, DbPointer[]> deserializePointerArrays(string dbFile, string index, StringComparer comparer = null)
        {
            var file = dbFile + "." + index;

            using (var reader = new BinaryReader(new FileStream(file, FileMode.Open)))
            {
                var count      = reader.ReadInt32();
                var dictionary = new Dictionary <string, DbPointer[]>(count, comparer);
                for (int n = 0; n < count; n++)
                {
                    var key       = reader.ReadString();
                    var arraySize = reader.ReadInt32();
                    var array     = new DbPointer[arraySize];
                    for (var i = 0; i < array.Length; ++i)
                    {
                        array[i] = new DbPointer(reader.ReadUInt32());
                    }
                    dictionary.Add(key, array);
                }
                return(dictionary);
            }
        }
Exemplo n.º 5
0
        internal EntityInfo GetEntity(DbPointer pointer)
        {
            var entry = GetEntry(pointer);

            return(new EntityInfo(FreebaseDbProvider.GetMid(entry.Id), entry.Label, entry.Targets.Where(t => !t.Item1.IsOutcoming).Count(), entry.Targets.Where(t => t.Item1.IsOutcoming).Count(), entry.Description));
        }
Exemplo n.º 6
0
 internal string GetId(DbPointer pointer)
 {
     return(GetEntry(pointer).Id);
 }
Exemplo n.º 7
0
 internal string GetMid(DbPointer pointer)
 {
     return(IdPrefix + GetId(pointer));
 }