public void Should_allow_knock_down_10_pins_as_max() { // Arrange var scorer = new Scorer(); // Act && assert scorer.Invoking(s => s.Roll(11)).ShouldThrow<ArgumentException>() .And.Message.Should().Be("Max number of available pins is 10"); }
/// <summary> /// Construct a <code>DisjunctionScorer</code>. </summary> /// <param name="weight"> The weight to be used. </param> /// <param name="subScorers"> Array of at least two subscorers. </param> /// <param name="coord"> Table of coordination factors </param> internal DisjunctionSumScorer(Weight weight, Scorer[] subScorers, float[] coord) : base(weight, subScorers) { if (NumScorers <= 1) { throw new System.ArgumentException("There must be at least 2 subScorers"); } this.Coord = coord; }
/// <summary> Creates a new instance of DisjunctionMaxScorer /// /// </summary> /// <param name="tieBreakerMultiplier">Multiplier applied to non-maximum-scoring subqueries for a /// document as they are summed into the result. /// </param> /// <param name="similarity">-- not used since our definition involves neither coord nor terms /// directly /// </param> /// <param name="subScorers">The sub scorers this Scorer should iterate on /// </param> /// <param name="numScorers">The actual number of scorers to iterate on. Note that the array's /// length may be larger than the actual number of scorers. /// </param> public DisjunctionMaxScorer(float tieBreakerMultiplier, Similarity similarity, Scorer[] subScorers, int numScorers):base(similarity) { this.tieBreakerMultiplier = tieBreakerMultiplier; // The passed subScorers array includes only scorers which have documents // (DisjunctionMaxQuery takes care of that), and their nextDoc() was already // called. this.subScorers = subScorers; this.numScorers = numScorers; Heapify(); }
public void Robbie_State_Change_Hash_Code_Remains_Constant() { IDictionary<Situation, RobotAction> strategy = GetSimpleStrategy(RobotAction.PickUpCan); Scorer scorer = new Scorer(); Robot robbie = new Robot(strategy, scorer); var startingHashCode = robbie.GetHashCode(); robbie._scorer.Add(Robot.ActionResult.HitWall); var endingHashCode = robbie.GetHashCode(); Assert.AreEqual(startingHashCode, endingHashCode); }
public void Should_allow_addtional_20Th_roll_if_there_are_strike_in_the_last_frame_and_one_strike_before() { // Arrange var scorer = new Scorer(); // Act scorer.Roll(10); for (int i = 0; i < 17; i++) { scorer.Roll(0); } scorer.Roll(10); scorer.Roll(0); // Assert scorer.Invoking(s => s.Roll(1)).ShouldThrow<MaxNumberOfRollsExceededException>(); }
public void Should_allow_aditional_roll_if_spare_in_the_last_frame() { // Arrange var scorer = new Scorer(); // Act for (int i = 0; i < 18; i++) { scorer.Roll(0); } scorer.Roll(1); scorer.Roll(9); scorer.Roll(9); var score = scorer.CalculateScore(); // Assert score.Should().Be(19); }
private double[] _stepSize; // size of the step for each value in _data #endregion Fields #region Constructors /// <summary> /// Constructor. /// </summary> /// <param name="net">Network to perform hill climbing algorithm on.</param> /// <param name="score">Scoring object.</param> /// <param name="accel">Acceleration of step sizes.</param> /// <param name="stepSize">Initial step sizes.</param> public HillClimb(Network net, Scorer score, double accel, double stepSize) { _net = net; _scorer = score; _stepSize = new double[net.LongTermMemory.Length]; for (int i = 0; i < _stepSize.Length; i++) { _stepSize[i] = stepSize; } _candidate[0] = -accel; _candidate[1] = -(1/accel); _candidate[2] = 0; _candidate[3] = 1/accel; _candidate[4] = accel; _lastError = double.MaxValue; }
/// <summary>Returns the score of the current document matching the query. /// Initially invalid, until <see cref="NextDoc()" /> is called the first time. /// </summary> /// <returns> The score of the required scorer, eventually increased by the score /// of the optional scorer when it also matches the current document. /// </returns> public override float Score() { int curDoc = reqScorer.DocID(); float reqScore = reqScorer.Score(); if (optScorer == null) { return reqScore; } int optScorerDoc = optScorer.DocID(); if (optScorerDoc < curDoc && (optScorerDoc = optScorer.Advance(curDoc)) == NO_MORE_DOCS) { optScorer = null; return reqScore; } return optScorerDoc == curDoc?reqScore + optScorer.Score():reqScore; }
public override int NextDoc() { if (reqScorer == null) { return doc; } doc = reqScorer.NextDoc(); if (doc == NO_MORE_DOCS) { reqScorer = null; // exhausted, nothing left return doc; } if (exclDisi == null) { return doc; } return doc = ToNonExcluded(); }
/// <summary>Advance to non excluded doc. /// <br/>On entry: /// <list type="bullet"> /// <item>reqScorer != null, </item> /// <item>exclScorer != null, </item> /// <item>reqScorer was advanced once via next() or skipTo() /// and reqScorer.doc() may still be excluded.</item> /// </list> /// Advances reqScorer a non excluded required doc, if any. /// </summary> /// <returns> true iff there is a non excluded required doc. /// </returns> private int ToNonExcluded() { int exclDoc = exclDisi.DocID(); int reqDoc = reqScorer.DocID(); // may be excluded do { if (reqDoc < exclDoc) { return reqDoc; // reqScorer advanced to before exclScorer, ie. not excluded } else if (reqDoc > exclDoc) { exclDoc = exclDisi.Advance(reqDoc); if (exclDoc == NO_MORE_DOCS) { exclDisi = null; // exhausted, no more exclusions return reqDoc; } if (exclDoc > reqDoc) { return reqDoc; // not excluded } } } while ((reqDoc = reqScorer.NextDoc()) != NO_MORE_DOCS); reqScorer = null; // exhausted, nothing left return NO_MORE_DOCS; }
/// <summary>Construct a <c>ReqExclScorer</c>.</summary> /// <param name="reqScorer">The scorer that must match, except where /// </param> /// <param name="exclDisi">indicates exclusion. /// </param> public ReqExclScorer(Scorer reqScorer, DocIdSetIterator exclDisi):base(null) { // No similarity used. this.reqScorer = reqScorer; this.exclDisi = exclDisi; }
public DoubleDocValuesAnonymousInnerClassHelper(ScoreValueSource outerInstance, Scorer scorer) : base(outerInstance) { this.outerInstance = outerInstance; this.scorer = scorer; }
public void Should_Score_Category_ThreeOfAKind() { var scorer = new Scorer(); Assert.AreEqual(3, scorer.Score("ThreeOfAKind", new[] { 1, 1, 1, 8, 8 })); }
public void Should_sum_two_subsequent_rolls( int firstRoll, int secondRoll, int total) { // Arrange var scorer = new Scorer(); // Act scorer.Roll(firstRoll); scorer.Roll(secondRoll); var score = scorer.CalculateScore(); // Assert Assert.AreEqual(total, score); }
public void Should_not_allow_to_knock_down_negative_number_of_pins() { // Arrange var scorer = new Scorer(); // Act && Assert scorer.Invoking(s => s.Roll(-1)).ShouldThrow<ArgumentException>() .And.Message.Should().Be("Number of pins cannot be negative"); }
public void Should_Score_Category_FourOfAKind() { var scorer = new Scorer(); Assert.AreEqual(4, scorer.Score("FourOfAKind", new[] { 1, 1, 1, 1, 8 })); }
public Highlighter(Formatter formatter, Scorer fragmentScorer) : this(formatter, new DefaultEncoder(), fragmentScorer) { }
public Highlighter(Scorer fragmentScorer) : this(new SimpleHTMLFormatter(), fragmentScorer) { }
public void CallBefore() { _scorer = new Scorer(_player); }
/// <summary>Construct a <c>ReqExclScorer</c>.</summary> /// <param name="reqScorer">The scorer that must match, except where /// </param> /// <param name="exclDisi">indicates exclusion. /// </param> public ReqExclScorer(Scorer reqScorer, DocIdSetIterator exclDisi) : base(null) { // No similarity used. this.reqScorer = reqScorer; this.exclDisi = exclDisi; }
public virtual void Search(Weight weight, Filter filter, ICollector collector, int start, IBoboMapFunctionWrapper mapReduceWrapper) { FacetValidator validator = CreateFacetValidator(); int target = 0; IndexReader reader = this.IndexReader; IndexReaderContext indexReaderContext = reader.Context; if (filter == null) { for (int i = 0; i < m_subReaders.Length; i++) { AtomicReaderContext atomicContext = indexReaderContext.Children == null ? (AtomicReaderContext)indexReaderContext : (AtomicReaderContext)(indexReaderContext.Children.Get(i)); int docStart = start; // NOTE: This code calls an internal constructor. Apparently, this was in the same namespace as Lucene, // but was added to this project, which presumably allows you to call internal constructors in Java. // In .NET, we can just use Activator.CreateInstance. Not great, but this code will be removed // when applying commit https://github.com/senseidb/bobo/commit/924c8579d90dbb5d56103976d39b47daa2242ef3 // which includes several major changes after the 4.0.2 release. // atomicContext = AtomicReaderContextUtil.UpdateDocBase(atomicContext, docStart); object[] args = new object[] { (CompositeReaderContext)null, atomicContext.AtomicReader, 0, 0, 0, docStart }; Type[] constructorSignature = { typeof(CompositeReaderContext), typeof(AtomicReader), typeof(int), typeof(int), typeof(int), typeof(int) }; var constr = typeof(AtomicReaderContext).GetTypeInfo().DeclaredConstructors .Single(constructor => constructor.GetParameters() .Select(parameter => parameter.ParameterType) .SequenceEqual(constructorSignature)); atomicContext = (AtomicReaderContext)constr.Invoke(args); if (reader is BoboMultiReader) { docStart = start + ((BoboMultiReader)reader).SubReaderBase(i); } collector.SetNextReader(atomicContext); validator.SetNextReader(m_subReaders[i], docStart); // NOTE: The Weight.Scorer method lost the scoreDocsInOrder and topScorer parameters between // Lucene 4.3.0 and 4.8.0. They are not used by BoboBrowse anyway, so the code here diverges // from the original Java source to remove these two parameters. // Scorer scorer = weight.Scorer(atomicContext, true, true, _subReaders[i].LiveDocs); Scorer scorer = weight.GetScorer(atomicContext, m_subReaders[i].LiveDocs); if (scorer != null) { collector.SetScorer(scorer); target = scorer.NextDoc(); while (target != DocIdSetIterator.NO_MORE_DOCS) { if (validator.Validate(target)) { collector.Collect(target); target = scorer.NextDoc(); } else { target = validator.m_nextTarget; target = scorer.Advance(target); } } } if (mapReduceWrapper != null) { mapReduceWrapper.MapFullIndexReader(m_subReaders[i], validator.GetCountCollectors()); } } return; } for (int i = 0; i < m_subReaders.Length; i++) { AtomicReaderContext atomicContext = indexReaderContext.Children == null ? (AtomicReaderContext)indexReaderContext : (AtomicReaderContext)(indexReaderContext.Children.Get(i)); DocIdSet filterDocIdSet = filter.GetDocIdSet(atomicContext, m_subReaders[i].LiveDocs); if (filterDocIdSet == null) { return; //shall we use return or continue here ?? } int docStart = start; if (reader is BoboMultiReader) { docStart = start + ((BoboMultiReader)reader).SubReaderBase(i); } collector.SetNextReader(atomicContext); validator.SetNextReader(m_subReaders[i], docStart); // NOTE: The Weight.Scorer method lost the scoreDocsInOrder and topScorer parameters between // Lucene 4.3.0 and 4.8.0. They are not used by BoboBrowse anyway, so the code here diverges // from the original Java source to remove these two parameters. // Scorer scorer = weight.Scorer(atomicContext, true, false, _subReaders[i].LiveDocs); Scorer scorer = weight.GetScorer(atomicContext, m_subReaders[i].LiveDocs); if (scorer != null) { collector.SetScorer(scorer); DocIdSetIterator filterDocIdIterator = filterDocIdSet.GetIterator(); // CHECKME: use ConjunctionScorer here? if (filterDocIdIterator == null) { continue; } int doc = -1; target = filterDocIdIterator.NextDoc(); if (mapReduceWrapper == null) { while (target < DocIdSetIterator.NO_MORE_DOCS) { if (doc < target) { doc = scorer.Advance(target); } if (doc == target) // permitted by filter { if (validator.Validate(doc)) { collector.Collect(doc); target = filterDocIdIterator.NextDoc(); } else { // skip to the next possible docid target = filterDocIdIterator.Advance(validator.m_nextTarget); } } else // doc > target { if (doc == DocIdSetIterator.NO_MORE_DOCS) { break; } target = filterDocIdIterator.Advance(doc); } } } else { //MapReduce wrapper is not null while (target < DocIdSetIterator.NO_MORE_DOCS) { if (doc < target) { doc = scorer.Advance(target); } if (doc == target) // permitted by filter { if (validator.Validate(doc)) { mapReduceWrapper.MapSingleDocument(doc, m_subReaders[i]); collector.Collect(doc); target = filterDocIdIterator.NextDoc(); } else { // skip to the next possible docid target = filterDocIdIterator.Advance(validator.m_nextTarget); } } else // doc > target { if (doc == DocIdSetIterator.NO_MORE_DOCS) { break; } target = filterDocIdIterator.Advance(doc); } } mapReduceWrapper.FinalizeSegment(m_subReaders[i], validator.GetCountCollectors()); } } } }
public void Should_Score_Category_NoneOfAKind() { var scorer = new Scorer(); Assert.AreEqual(40, scorer.Score("NoneOfAKind", new[] { 1, 2, 3, 4, 5 })); }
public void Should_Score_Category_AllOfAKind() { var scorer = new Scorer(); Assert.AreEqual(50, scorer.Score("AllOfAKind", new[] { 1, 1, 1, 1, 1 })); }
public Highlighter(Formatter formatter, Encoder encoder, Scorer fragmentScorer) { this.formatter = formatter; this.encoder = encoder; this.fragmentScorer = fragmentScorer; }
private void InitializeScorer() { var scorer = new Scorer(this, "fonts/Segoe"); AddComponent(scorer, "Sprites"); }
/// <param name="">scorer /// </param> public virtual void SetFragmentScorer(Scorer scorer) { fragmentScorer = scorer; }
public void Should_return_300_for_the_perfect_game() { // Arrange var scorer = new Scorer(); // Act for (int i = 0; i < 12; i++) { scorer.Roll(10); } var score = scorer.CalculateScore(); // Assert score.Should().Be(300); }
internal HeapedScorerDoc(ScorerDocQueue enclosingInstance, Scorer s) : this(enclosingInstance, s, s.DocID()) { }
public void Should_Score_Category_Fours() { var scorer = new Scorer(); Assert.AreEqual(16, scorer.Score("Fours", new[] { 4, 4, 4, 4, 3 })); }
internal HeapedScorerDoc(ScorerDocQueue enclosingInstance, Scorer scorer, int doc) { InitBlock(enclosingInstance); this.scorer = scorer; this.doc = doc; }
public void Should_Score_Category_Fives() { var scorer = new Scorer(); Assert.AreEqual(10, scorer.Score("Fives", new[] { 4, 4, 4, 5, 5 })); }
/// <summary> Adds a Scorer to a ScorerDocQueue in log(size) time. /// If one tries to add more Scorers than maxSize /// a RuntimeException (ArrayIndexOutOfBound) is thrown. /// </summary> public void Put(Scorer scorer) { size++; heap[size] = new HeapedScorerDoc(this, scorer); UpHeap(); }
public override int Advance(int target) { if (reqScorer == null) { return doc = NO_MORE_DOCS; } if (exclDisi == null) { return doc = reqScorer.Advance(target); } if (reqScorer.Advance(target) == NO_MORE_DOCS) { reqScorer = null; return doc = NO_MORE_DOCS; } return doc = ToNonExcluded(); }
internal SingleMatchScorer(BooleanScorer2 enclosingInstance, Scorer scorer) : base(scorer.Similarity) { InitBlock(enclosingInstance); this.scorer = scorer; }
public virtual void SetScorer(Scorer scorer) { m_in.SetScorer(scorer); }
public DoubleDocValuesAnonymousInnerClassHelper(ValueSourceAnonymousInnerClassHelper outerInstance, Scorer scorer) : base(null) //todo: value source { this.outerInstance = outerInstance; this.scorer = scorer; }
/// <summary> Creates a <see cref="Scorer" /> with the given similarity and lists of required, /// prohibited and optional scorers. In no required scorers are added, at least /// one of the optional scorers will have to match during the search. /// /// </summary> /// <param name="similarity">The similarity to be used. /// </param> /// <param name="minNrShouldMatch">The minimum number of optional added scorers that should match /// during the search. In case no required scorers are added, at least /// one of the optional scorers will have to match during the search. /// </param> /// <param name="required">the list of required scorers. /// </param> /// <param name="prohibited">the list of prohibited scorers. /// </param> /// <param name="optional">the list of optional scorers. /// </param> public BooleanScorer2(Similarity similarity, int minNrShouldMatch, System.Collections.Generic.List<Scorer> required, System.Collections.Generic.List<Scorer> prohibited, System.Collections.Generic.List<Scorer> optional) : base(similarity) { if (minNrShouldMatch < 0) { throw new System.ArgumentException("Minimum number of optional scorers should not be negative"); } coordinator = new Coordinator(this); this.minNrShouldMatch = minNrShouldMatch; optionalScorers = optional; coordinator.maxCoord += optional.Count; requiredScorers = required; coordinator.maxCoord += required.Count; prohibitedScorers = prohibited; coordinator.Init(); countingSumScorer = MakeCountingSumScorer(); }
private Scorer DualConjunctionSumScorer(Scorer req1, Scorer req2) { // non counting. return new ConjunctionScorer(defaultSimilarity, new Scorer[]{req1, req2}); // All scorers match, so defaultSimilarity always has 1 as // the coordination factor. // Therefore the sum of the scores of two scorers // is used as score. }
public CustomScorer(BoostedQuery outerInstance, AtomicReaderContext readerContext, BoostedQuery.BoostedWeight w, float qWeight, Scorer scorer, ValueSource vs) : base(w) { this.outerInstance = outerInstance; this.weight = w; this.qWeight = qWeight; this.scorer = scorer; this.readerContext = readerContext; this.vals = vs.GetValues(weight.fcontext, readerContext); }
public void Should_Score_Category_Ones() { var scorer = new Scorer(); Assert.AreEqual(3, scorer.Score("Ones", new[] { 1, 1, 1, 2, 2 })); }
internal SingleMatchScorer(BooleanScorer2 enclosingInstance, Scorer scorer):base(scorer.Similarity) { InitBlock(enclosingInstance); this.scorer = scorer; }
public override void SetScorer(Scorer scorer) { }
/// <summary>Returns the scorer to be used for match counting and score summing. /// Uses the given required scorer and the prohibitedScorers. /// </summary> /// <param name="requiredCountingSumScorer">A required scorer already built. /// </param> private Scorer AddProhibitedScorers(Scorer requiredCountingSumScorer) { return (prohibitedScorers.Count == 0) ? requiredCountingSumScorer : new ReqExclScorer(requiredCountingSumScorer, ((prohibitedScorers.Count == 1) ? prohibitedScorers[0] : new DisjunctionSumScorer(prohibitedScorers))); }
public override sealed void SetScorer(Scorer scorer) { this.scorer = scorer; }
public void Should_allow_only_20_rolls() { // Arrange var scorer = new Scorer(); // Act for (int i = 0; i < 20; i++) { scorer.Roll(1); } // Assert scorer.Invoking(s => s.Roll(1)).ShouldThrow<MaxNumberOfRollsExceededException>("sdf") .And.Message.Should().Be("Maximum number of rolls exceeded", "Message should be meaningful"); }
public virtual void SetScorer(Scorer scorer) { }
public void Should_return_0_if_no_rolls() { // Arrange var scorer = new Scorer(); // Act int score = scorer.CalculateScore(); // Assert Assert.AreEqual(0, score); }
public void Should_Score_Category_Sevens() { var scorer = new Scorer(); Assert.AreEqual(21, scorer.Score("Sevens", new[] { 7, 7, 7, 3, 3 })); }
public void Should_sum_one_subsequent_roll_if_spare( int first, int second, int third, int total) { // Arrange var scorer = new Scorer(); // Act scorer.Roll(first); scorer.Roll(second); scorer.Roll(third); var score = scorer.CalculateScore(); // Assert score.Should().Be(total); }
public void Should_Score_Category_Sixes() { var scorer = new Scorer(); Assert.AreEqual(6, scorer.Score("Sixes", new[] { 6, 4, 4, 4, 3 })); }
public void Should_sum_two_subsequent_rolls_if_strike(int[] rolls, int total) { // Arrange var scorer = new Scorer(); // Act foreach (int pins in rolls) { scorer.Roll(pins); } var score = scorer.CalculateScore(); // Assert score.Should().Be(total); }
private string ActualPoints(NFLPlayer p) { var nScore = Scorer.RatePlayer(p, NflWeek); return(nScore.ToString()); }
public virtual void SetScorer(Scorer scorer) { this.scorer = scorer; }
public void Should_Score_Category_Eights() { var scorer = new Scorer(); Assert.AreEqual(24, scorer.Score("Eights", new[] { 7, 7, 8, 8, 8 })); }
public void Should_allow_only_19_rolls_if_strike_is_not_in_the_last_frame() { // Arrange var scorer = new Scorer(); // Act scorer.Roll(10); for (int i = 0; i < 18; i++) { scorer.Roll(2); } // Assert scorer.Invoking(r => r.Roll(1)).ShouldThrow<MaxNumberOfRollsExceededException>(); }
public override void SetScorer(Scorer scorer) { _scorer = scorer; }