//don't send extra records
 /// <summary>
 /// <inheritDoc/>
 ///
 /// </summary>
 public override IList <Redwood.Record> SignalEndTrack(int newDepth, long timeOfEnd)
 {
     //(pop info)
     OutputHandler.TrackInfo childInfo = this.info;
     if (childInfo == null)
     {
         throw new InvalidOperationException("OutputHandler received endTrack() without matching startTrack() --" + "are your handlers mis-configured?");
     }
     if (trackStack.Empty())
     {
         this.info = null;
     }
     else
     {
         this.info = this.trackStack.Pop();
         this.info.numElementsPrinted += childInfo.numElementsPrinted;
     }
     //(handle track)
     if (this.queuedTracks.IsEmpty())
     {
         StringBuilder b = new StringBuilder();
         if (!this.missingOpenBracket)
         {
             //(write margin)
             for (int i = 0; i < this.leftMargin; i++)
             {
                 b.Append(' ');
             }
             //(null content)
             WriteContent(newDepth, string.Empty, b);
             //(write bracket)
             b.Append("} ");
         }
         this.missingOpenBracket = false;
         //(write matching line)
         if (childInfo.numElementsPrinted > this.minLineCountForTrackNameReminder)
         {
             b.Append("<< ").Append(childInfo.name).Append(' ');
         }
         //(write time)
         if (timeOfEnd - childInfo.beginTime > 100)
         {
             b.Append('[');
             Redwood.FormatTimeDifference(timeOfEnd - childInfo.beginTime, b);
             b.Append(']');
         }
         //(print)
         b.Append('\n');
         Print(null, this.Style(new StringBuilder(), b.ToString(), trackColor, trackStyle).ToString());
     }
     else
     {
         this.queuedTracks.RemoveLast();
     }
     return(Empty);
 }
Beispiel #2
0
        /// <summary>Create a new WikiDict annotator, with the given name and properties.</summary>
        public WikidictAnnotator(string name, Properties properties)
        {
            // it's gonna be large no matter what
            ArgumentParser.FillOptions(this, name, properties);
            long startTime = Runtime.CurrentTimeMillis();

            log.Info("Reading Wikidict from " + wikidictPath);
            try
            {
                int      i      = 0;
                string[] fields = new string[3];
                foreach (string line in IOUtils.ReadLines(wikidictPath, "UTF-8"))
                {
                    if (line[0] == '\t')
                    {
                        continue;
                    }
                    StringUtils.SplitOnChar(fields, line, '\t');
                    if (i % 1000000 == 0)
                    {
                        log.Info("Loaded " + i + " entries from Wikidict [" + SystemUtils.GetMemoryInUse() + "MB memory used; " + Redwood.FormatTimeDifference(Runtime.CurrentTimeMillis() - startTime) + " elapsed]");
                    }
                    // Check that the read entry is above the score threshold
                    if (threshold > 0.0)
                    {
                        double score = double.ParseDouble(fields[2]);
                        if (score < threshold)
                        {
                            continue;
                        }
                    }
                    string surfaceForm = fields[0];
                    if (wikidictCaseless)
                    {
                        surfaceForm = surfaceForm.ToLower();
                    }
                    string link = string.Intern(fields[1]);
                    // intern, as most entities have multiple surface forms
                    // Add the entry
                    dictionary[surfaceForm] = link;
                    i += 1;
                }
                log.Info("Done reading Wikidict (" + dictionary.Count + " links read; " + Redwood.FormatTimeDifference(Runtime.CurrentTimeMillis() - startTime) + " elapsed)");
            }
            catch (Exception e)
            {
                throw new Exception(e);
            }
        }