Example #1
0
        public void Prune_WhenNoSubsumptions_ReturnsSameArray()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var nets    = fixture.CreateMany <IComparatorNetwork>(3).ToArray();
            var pruner  = new Pruner();

            // Act
            var result = pruner.Prune(nets);

            // Assert
            Assert.AreEqual(nets.Length, result.Count);
        }
 public SimpleBreadthFirstSearchManager(Linguist linguist, Pruner pruner, AcousticScorer scorer, ActiveListFactory activeListFactory, bool showTokenCount, double relativeWordBeamWidth, int growSkipInterval, bool wantEntryPruning)
 {
     this.name                     = Object.instancehelper_getClass(this).getName();
     this.logger                   = Logger.getLogger(this.name);
     this.logMath                  = LogMath.getLogMath();
     this.linguist                 = linguist;
     this.pruner                   = pruner;
     this.scorer                   = scorer;
     this.activeListFactory        = activeListFactory;
     this._showTokenCount          = showTokenCount;
     this.growSkipInterval         = growSkipInterval;
     this.wantEntryPruning         = wantEntryPruning;
     this.logRelativeWordBeamWidth = this.logMath.linearToLog(relativeWordBeamWidth);
     this.keepAllTokens            = true;
 }
Example #3
0
        public void Prune_When1SubsumptionInSecondElement_Prunes1Element()
        {
            // Arrange
            var fixture  = new Fixture().Customize(new AutoMoqCustomization());
            var netMocks = fixture.CreateMany <Mock <IComparatorNetwork> >(3).ToArray();
            var pruner   = new Pruner();

            netMocks[1].Setup(x => x.IsSubsumed(netMocks[0].Object)).Returns(true);

            var nets = netMocks.Select(x => x.Object).ToArray();

            // Act
            var result = pruner.Prune(nets);

            // Assert
            Assert.AreEqual(2, result.Count);
        }
 public WordPruningBreadthFirstSearchManager(Linguist linguist, Pruner pruner, AcousticScorer scorer, ActiveListManager activeListManager, bool showTokenCount, double relativeWordBeamWidth, int growSkipInterval, bool checkStateOrder, bool buildWordLattice, int maxLatticeEdges, float acousticLookaheadFrames, bool keepAllTokens)
 {
     this.maxLatticeEdges         = 100;
     this.logger                  = Logger.getLogger(Object.instancehelper_getClass(this).getName());
     this.logMath                 = LogMath.getLogMath();
     this.linguist                = linguist;
     this.pruner                  = pruner;
     this.scorer                  = scorer;
     this.activeListManager       = activeListManager;
     this._showTokenCount         = showTokenCount;
     this.growSkipInterval        = growSkipInterval;
     this._checkStateOrder        = checkStateOrder;
     this.buildWordLattice        = buildWordLattice;
     this.maxLatticeEdges         = maxLatticeEdges;
     this.acousticLookaheadFrames = acousticLookaheadFrames;
     this.keepAllTokens           = keepAllTokens;
     this.relativeBeamWidth       = this.logMath.linearToLog(relativeWordBeamWidth);
 }
Example #5
0
 /// <summary>
 /// Calls provided <seealso cref="Pruner"/> to prune entries.  The
 ///  entries are passed to the Pruner in sorted (newest to
 ///  oldest IndexSearcher) order.
 ///
 ///  <p><b>NOTE</b>: you must peridiocally call this, ideally
 ///  from the same background thread that opens new
 ///  searchers.
 /// </summary>
 public virtual void Prune(Pruner pruner)
 {
     lock (this)
     {
         // Cannot just pass searchers.values() to ArrayList ctor
         // (not thread-safe since the values can change while
         // ArrayList is init'ing itself); must instead iterate
         // ourselves:
         List <SearcherTracker> trackers = new List <SearcherTracker>();
         foreach (SearcherTracker tracker in Searchers.Values)
         {
             trackers.Add(tracker);
         }
         trackers.Sort();
         double lastRecordTimeSec = 0.0;
         double now = DateTime.Now.ToFileTime() / 100.0d / NANOS_PER_SEC;
         foreach (SearcherTracker tracker in trackers)
         {
             double ageSec;
             if (lastRecordTimeSec == 0.0)
             {
                 ageSec = 0.0;
             }
             else
             {
                 ageSec = now - lastRecordTimeSec;
             }
             // First tracker is always age 0.0 sec, since it's
             // still "live"; second tracker's age (= seconds since
             // it was "live") is now minus first tracker's
             // recordTime, etc:
             if (pruner.DoPrune(ageSec, tracker.Searcher))
             {
                 //System.out.println("PRUNE version=" + tracker.version + " age=" + ageSec + " ms=" + System.currentTimeMillis());
                 Searchers.Remove(tracker.Version);
                 tracker.Dispose();
             }
             lastRecordTimeSec = tracker.RecordTimeSec;
         }
     }
 }
 /**
  *
  * @param logMath
  * @param linguist
  * @param pruner
  * @param scorer
  * @param activeListFactory
  * @param showTokenCount
  * @param relativeWordBeamWidth
  * @param growSkipInterval
  * @param wantEntryPruning
  */
 public AlignerSearchManager(LogMath logMath, edu.cmu.sphinx.linguist.Linguist linguist,
                             Pruner pruner, AcousticScorer scorer,
                             ActiveListFactory activeListFactory, bool showTokenCount,
                             double relativeWordBeamWidth, int growSkipInterval,
                             bool wantEntryPruning)
 {
     this.name                     = getClass().getName();
     this.logger                   = LogManager.GetLogger(name);
     this.logMath                  = logMath;
     this.linguist                 = linguist;
     this.pruner                   = pruner;
     this.scorer                   = scorer;
     this.activeListFactory        = activeListFactory;
     this.showTokenCountP          = showTokenCount;
     this.growSkipInterval         = growSkipInterval;
     this.wantEntryPruning         = wantEntryPruning;
     this.logRelativeWordBeamWidth = logMath
                                     .linearToLog(relativeWordBeamWidth);
     this.keepAllTokens  = false;
     this.phraseWordList = new List <String>();
 }
Example #7
0
        public IReadOnlyList <IComparatorNetwork> Prune <T>(IReadOnlyList <T> nets)
        {
            var pruner = new Pruner();

            if (nets.Count == 1)
            {
                return(pruner.Prune((IReadOnlyList <IComparatorNetwork>)nets[0]));
            }
            var netsAfterPrune = new IReadOnlyList <IComparatorNetwork> [nets.Count];

            var tasks = Enumerable.Range(0, nets.Count)
                        .Select(i => Task.Run(() =>
            {
                var net           = nets[i] as List <IComparatorNetwork>;
                netsAfterPrune[i] = pruner.Prune(net);
            })).ToArray();

            Task.WaitAll(tasks);

            for (var i = 0; i < nets.Count; i++)
            {
                var index       = i;
                var removeTasks = Enumerable.Range(0, nets.Count)
                                  .Select(j => Task.Run(() =>
                {
                    var s1 = netsAfterPrune[index];
                    if (s1 != null && index != j)
                    {
                        var s2            = netsAfterPrune[j];
                        netsAfterPrune[j] = pruner.Remove(s1, s2);
                    }
                })).ToArray();

                Task.WaitAll(removeTasks);
            }

            return(netsAfterPrune
                   .SelectMany(x => x).ToList());
        }
        //@Override
        public override void newProperties(PropertySheet ps)
        {
            base.newProperties(ps);

            //logger = ps.getLogger();
            name = ps.getInstanceName();

            logMath = (LogMath)ps.getComponent(PROP_LOG_MATH);

            linguist          = (edu.cmu.sphinx.linguist.Linguist)ps.getComponent(PROP_LINGUIST);
            pruner            = (Pruner)ps.getComponent(PROP_PRUNER);
            scorer            = (AcousticScorer)ps.getComponent(PROP_SCORER);
            activeListFactory = (ActiveListFactory)ps
                                .getComponent(PROP_ACTIVE_LIST_FACTORY);
            showTokenCountP = JavaToCs.ConvertBool(ps.getBoolean(PROP_SHOW_TOKEN_COUNT));

            double relativeWordBeamWidth = ps.getDouble(PROP_RELATIVE_WORD_BEAM_WIDTH);

            growSkipInterval         = ps.getInt(PROP_GROW_SKIP_INTERVAL);
            wantEntryPruning         = JavaToCs.ConvertBool(ps.getBoolean(PROP_WANT_ENTRY_PRUNING));
            logRelativeWordBeamWidth = logMath.linearToLog(relativeWordBeamWidth);

            this.keepAllTokens = true;
        }
Example #9
0
 /// <summary>
 /// Removes unpromising branches from the fast match active list.
 /// </summary>
 protected void PruneFastMatchBranches()
 {
     PruneTimer.Start();
     FastmatchActiveList = Pruner.Prune(FastmatchActiveList);
     PruneTimer.Stop();
 }
Example #10
0
        public WordPruningBreadthFirstLookaheadSearchManager(Linguist linguist, Linguist fastmatchLinguist, Loader loader, Pruner pruner, AcousticScorer scorer, ActiveListManager activeListManager, ActiveListFactory fastmatchActiveListFactory, bool showTokenCount, double relativeWordBeamWidth, int growSkipInterval, bool checkStateOrder, bool buildWordLattice, int lookaheadWindow, float lookaheadWeight, int maxLatticeEdges, float acousticLookaheadFrames, bool keepAllTokens) : base(linguist, pruner, scorer, activeListManager, showTokenCount, relativeWordBeamWidth, growSkipInterval, checkStateOrder, buildWordLattice, maxLatticeEdges, acousticLookaheadFrames, keepAllTokens)
        {
            this.loader                     = loader;
            this.fastmatchLinguist          = fastmatchLinguist;
            this.fastmatchActiveListFactory = fastmatchActiveListFactory;
            this.lookaheadWindow            = lookaheadWindow;
            this.lookaheadWeight            = lookaheadWeight;
            if (lookaheadWindow < 1 || lookaheadWindow > 10)
            {
                string text = new StringBuilder().append("Unsupported lookahead window size: ").append(lookaheadWindow).append(". Value in range [1..10] is expected").toString();

                throw new IllegalArgumentException(text);
            }
            this.ciScores  = new LinkedList();
            this.penalties = new HashMap();
            if (loader is Sphinx3Loader && ((Sphinx3Loader)loader).hasTiedMixtures())
            {
                ((Sphinx3Loader)loader).setGauScoresQueueLength(lookaheadWindow + 2);
            }
        }