예제 #1
0
        private void iterateLines(EntityLineProcessor processor)
        {
            var totalSize = new FileInfo(_freebaseDataFile).Length;

            using (var fileStream = File.OpenRead(_freebaseDataFile))
                using (var file = new StreamReader(fileStream))
                {
                    var currentLine = 0;
                    while (!file.EndOfStream)
                    {
                        ++currentLine;
                        if (currentLine % 100000 == 0)
                        {
                            var currentPosition = fileStream.Position;
                            Console.WriteLine("{0:0.00}", 100.0 * currentPosition / totalSize);
                        }


                        var line    = file.ReadLine();
                        var parts   = line.Split('\t');
                        var entity1 = getId(parts[0]);
                        var edge    = FreebaseDbProvider.GetShortEdgeName(parts[1]);

                        var targetMids     = parts[2].Split(' ');
                        var targetEntities = new string[targetMids.Length];
                        for (var i = 0; i < targetMids.Length; ++i)
                        {
                            targetEntities[i] = getId(intern(targetMids[i]));
                        }
                        processor(intern(entity1), intern(edge), targetEntities);
                    }
                }
        }
예제 #2
0
        internal string GetLabel(string mid)
        {
            var entry = GetEntryFromId(FreebaseDbProvider.GetId(mid));

            if (entry == null)
            {
                return(null);
            }
            return(entry.Label);
        }
예제 #3
0
 internal FreebaseGraphLayer(FreebaseDbProvider db)
 {
     _db = db;
 }
예제 #4
0
 internal void AddTargetMid(string mid)
 {
     TargetIds.Add(FreebaseDbProvider.GetId(mid));
 }
예제 #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));
        }
예제 #6
0
 private string getId(string id)
 {
     return(FreebaseDbProvider.GetId(id));
 }