private void MyInit() { ISimilarity editdistance=new Leven() ; getSimilarity=new Similarity(editdistance.GetSimilarity) ; //ISimilarity lexical=new LexicalSimilarity() ; //getSimilarity=new Similarity(lexical.GetSimilarity) ; Tokeniser tokeniser=new Tokeniser() ; _leftTokens=tokeniser.Partition(_lString); _rightTokens=tokeniser.Partition(_rString); if (_leftTokens.Length > _rightTokens.Length) { string[] tmp=_leftTokens; _leftTokens=_rightTokens; _rightTokens=tmp; string s=_lString; _lString=_rString; _rString=s; } leftLen=_leftTokens.Length - 1 ; rightLen=_rightTokens.Length - 1; Initialize(); }
/// <summary> /// Creates a new entity based on the specified mention and its specified gender and number properties. /// </summary> /// <param name="mention"> /// The first mention of this entity. /// </param> /// <param name="gender"> /// The gender of this entity. /// </param> /// <param name="genderProbability"> /// The probability that the specified gender is correct. /// </param> /// <param name="number"> /// The number for this entity. /// </param> /// <param name="numberProbability"> /// The probability that the specified number is correct. /// </param> public DiscourseEntity(Mention.MentionContext mention, Similarity.GenderEnum gender, double genderProbability, Similarity.NumberEnum number, double numberProbability) : base(mention) { mGender = gender; mGenderProbability = genderProbability; mNumber = number; mNumberProbability = numberProbability; }
public SpanWeight(SpanQuery query, Searcher searcher) { this.similarity = query.GetSimilarity(searcher); this.internalQuery = query; terms = Lucene.Net.Support.Compatibility.SetFactory.CreateHashSet<Term>(); query.ExtractTerms(terms); idfExp = similarity.IdfExplain(terms, searcher); idf = idfExp.Idf; }
/// <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(); }
/// <summary> /// Copies the specified <see cref="ConnectedImage"/> into the new instance /// </summary> public ConnectedImage(ConnectedImage image) : base(image) { labelData = image.labelData; foreach (Similarity similarity in image.labels) { Similarity sim = new Similarity(); sim.ID = similarity.ID; sim.SameAs = similarity.SameAs; sim.Tag = similarity.Tag; labels.Add(sim); } }
// tries extra hard to cast the sim to TFIDFSimilarity internal static TFIDFSimilarity AsTFIDF(Similarity sim, string field) { while (sim is PerFieldSimilarityWrapper) { sim = ((PerFieldSimilarityWrapper)sim).Get(field); } if (sim is TFIDFSimilarity) { return (TFIDFSimilarity)sim; } else { return null; } }
protected internal SpanScorer(Spans spans, Weight weight, Similarity similarity, byte[] norms):base(similarity) { this.spans = spans; this.norms = norms; this.weight = weight; this.value_Renamed = weight.Value; if (this.spans.Next()) { doc = - 1; } else { doc = NO_MORE_DOCS; more = false; } }
protected internal virtual void ProcessPayload(Similarity similarity) { if (TermSpans.PayloadAvailable) { DocsAndPositionsEnum postings = TermSpans.Postings; Payload = postings.Payload; if (Payload != null) { PayloadScore_Renamed = OuterInstance.OuterInstance.Function.CurrentScore(Doc, OuterInstance.OuterInstance.Term.Field, Spans.Start(), Spans.End(), PayloadsSeen, PayloadScore_Renamed, DocScorer.ComputePayloadFactor(Doc, Spans.Start(), Spans.End(), Payload)); } else { PayloadScore_Renamed = OuterInstance.OuterInstance.Function.CurrentScore(Doc, OuterInstance.OuterInstance.Term.Field, Spans.Start(), Spans.End(), PayloadsSeen, PayloadScore_Renamed, 1F); } PayloadsSeen++; } else { // zero out the payload? } }
public TestRuleSetupAndRestoreClassEnv() { /*// if verbose: print some debugging stuff about which codecs are loaded. if (LuceneTestCase.VERBOSE) { ISet<string> codecs = Codec.AvailableCodecs(); foreach (string codec in codecs) { Console.WriteLine("Loaded codec: '" + codec + "': " + Codec.ForName(codec).GetType().Name); } ISet<string> postingsFormats = PostingsFormat.AvailablePostingsFormats(); foreach (string postingsFormat in postingsFormats) { Console.WriteLine("Loaded postingsFormat: '" + postingsFormat + "': " + PostingsFormat.ForName(postingsFormat).GetType().Name); } } SavedInfoStream = InfoStream.Default; Random random = RandomizedContext.Current.Random; bool v = random.NextBoolean(); if (LuceneTestCase.INFOSTREAM) { InfoStream.Default = new ThreadNameFixingPrintStreamInfoStream(Console.Out); } else if (v) { InfoStream.Default = new NullInfoStream(); } Type targetClass = RandomizedContext.Current.GetTargetType; AvoidCodecs = new HashSet<string>(); // set back to default LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false; SavedCodec = Codec.Default; int randomVal = random.Next(10); if ("Lucene3x".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) && randomVal == 3 && !ShouldAvoidCodec("Lucene3x"))) // preflex-only setup { Codec = Codec.ForName("Lucene3x"); Debug.Assert((Codec is PreFlexRWCodec), "fix your classpath to have tests-framework.jar before lucene-core.jar"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; } else if ("Lucene40".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && randomVal == 0 && !ShouldAvoidCodec("Lucene40"))) // 4.0 setup { Codec = Codec.ForName("Lucene40"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; Debug.Assert(Codec is Lucene40RWCodec, "fix your classpath to have tests-framework.jar before lucene-core.jar"); Debug.Assert((PostingsFormat.ForName("Lucene40") is Lucene40RWPostingsFormat), "fix your classpath to have tests-framework.jar before lucene-core.jar"); } else if ("Lucene41".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) && randomVal == 1 && !ShouldAvoidCodec("Lucene41"))) { Codec = Codec.ForName("Lucene41"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; Debug.Assert(Codec is Lucene41RWCodec, "fix your classpath to have tests-framework.jar before lucene-core.jar"); } else if ("Lucene42".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) && randomVal == 2 && !ShouldAvoidCodec("Lucene42"))) { Codec = Codec.ForName("Lucene42"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; Debug.Assert(Codec is Lucene42RWCodec, "fix your classpath to have tests-framework.jar before lucene-core.jar"); } else if ("Lucene45".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) && randomVal == 5 && !ShouldAvoidCodec("Lucene45"))) { Codec = Codec.ForName("Lucene45"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; Debug.Assert(Codec is Lucene45RWCodec, "fix your classpath to have tests-framework.jar before lucene-core.jar"); } else if (("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) == false) || ("random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) == false)) { // the user wired postings or DV: this is messy // refactor into RandomCodec.... PostingsFormat format; if ("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT)) { format = PostingsFormat.ForName("Lucene41"); } else { format = PostingsFormat.ForName(LuceneTestCase.TEST_POSTINGSFORMAT); } DocValuesFormat dvFormat; if ("random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT)) { dvFormat = DocValuesFormat.ForName("Lucene45"); } else { dvFormat = DocValuesFormat.ForName(LuceneTestCase.TEST_DOCVALUESFORMAT); } Codec = new Lucene46CodecAnonymousInnerClassHelper(this, format, dvFormat); } else if ("Asserting".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && randomVal == 6 && !ShouldAvoidCodec("Asserting"))) { Codec = new AssertingCodec(); } else if ("Compressing".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && randomVal == 5 && !ShouldAvoidCodec("Compressing"))) { Codec = CompressingCodec.RandomInstance(random); } else if (!"random".Equals(LuceneTestCase.TEST_CODEC)) { Codec = Codec.ForName(LuceneTestCase.TEST_CODEC); } else if ("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT)) { Codec = new RandomCodec(random, AvoidCodecs); } else { Debug.Assert(false); } Codec.Default = Codec; */ Random random = new Random(); Similarity = random.NextBoolean() ? (Similarity)new DefaultSimilarity() : new RandomSimilarityProvider(new Random()); /* // Check codec restrictions once at class level. try { CheckCodecRestrictions(Codec); } catch (Exception e) { Console.Error.WriteLine("NOTE: " + e.Message + " Suppressed codecs: " + Arrays.ToString(AvoidCodecs.ToArray())); throw e; }*/ }
private float[] vScores; // reused in score() to avoid allocating this array for each doc // constructor internal CustomScorer(CustomScoreQuery enclosingInstance, Similarity similarity, IndexReader reader, CustomWeight w, Scorer subQueryScorer, Scorer[] valSrcScorers):base(similarity) { InitBlock(enclosingInstance); this.qWeight = w.Value; this.subQueryScorer = subQueryScorer; this.valSrcScorers = valSrcScorers; this.reader = reader; this.vScores = new float[valSrcScorers.Length]; this.provider = this.Enclosing_Instance.GetCustomScoreProvider(reader); }
public NormsSimilarity(Similarity @in) { this.@in = @in; }
/// <summary> /// Builder method for <see cref="IndexWriterConfig.Similarity"/>. /// </summary> /// <param name="config">this <see cref="IndexWriterConfig"/> instance</param> /// <param name="similarity"></param> /// <returns>this <see cref="IndexWriterConfig"/> instance</returns> public static IndexWriterConfig SetSimilarity(this IndexWriterConfig config, Similarity similarity) { config.Similarity = similarity; return(config); }
public ValueSourceWeight(ValueSourceQuery enclosingInstance, Searcher searcher) { InitBlock(enclosingInstance); this.similarity = Enclosing_Instance.GetSimilarity(searcher); }
public override Explanation Explain(IndexReader reader, int doc) { ComplexExplanation result = new ComplexExplanation(); result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:"); System.String field = ((SpanQuery)GetQuery()).GetField(); Explanation idfExpl = new Explanation(idf, "idf(" + field + ": " + idfExp.Explain() + ")"); // explain query weight Explanation queryExpl = new Explanation(); queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:"); Explanation boostExpl = new Explanation(GetQuery().GetBoost(), "boost"); if (GetQuery().GetBoost() != 1.0f) { queryExpl.AddDetail(boostExpl); } queryExpl.AddDetail(idfExpl); Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm"); queryExpl.AddDetail(queryNormExpl); queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue()); result.AddDetail(queryExpl); // explain field weight ComplexExplanation fieldExpl = new ComplexExplanation(); fieldExpl.SetDescription("fieldWeight(" + field + ":" + query.ToString(field) + " in " + doc + "), product of:"); Explanation tfExpl = Scorer(reader, true, false).Explain(doc); fieldExpl.AddDetail(tfExpl); fieldExpl.AddDetail(idfExpl); Explanation fieldNormExpl = new Explanation(); byte[] fieldNorms = reader.Norms(field); float fieldNorm = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]) : 1.0f; fieldNormExpl.SetValue(fieldNorm); fieldNormExpl.SetDescription("fieldNorm(field=" + field + ", doc=" + doc + ")"); fieldExpl.AddDetail(fieldNormExpl); fieldExpl.SetMatch(tfExpl.IsMatch()); fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue()); result.AddDetail(fieldExpl); System.Boolean?tempAux = fieldExpl.GetMatch(); result.SetMatch(tempAux); // combine them result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue()); if (queryExpl.GetValue() == 1.0f) { return(fieldExpl); } return(result); }
public PayloadTermSpanScorer(PayloadTermWeight enclosingInstance, TermSpans spans, Weight weight, Similarity similarity, byte[] norms) : base(spans, weight, similarity, norms) { InitBlock(enclosingInstance); positions = spans.Positions; }
/// <summary> /// Writes the document to the directory using the analyzer /// and the similarity score; returns the SegmentInfo /// describing the new segment /// </summary> public static SegmentCommitInfo WriteDoc(Random random, Directory dir, Analyzer analyzer, Similarity similarity, Document doc) { IndexWriter writer = new IndexWriter(dir, (new IndexWriterConfig(Util.LuceneTestCase.TEST_VERSION_CURRENT, analyzer)).SetSimilarity(similarity ?? IndexSearcher.DefaultSimilarity)); // LuceneTestCase.newIndexWriterConfig(random, //writer.SetNoCFSRatio(0.0); writer.AddDocument(doc); writer.Commit(); SegmentCommitInfo info = writer.NewestSegment(); writer.Dispose(); return(info); }
public SectionSearchWeight(SectionSearchQuery parent, Searcher searcher) { _parent = parent; _similarity = _parent.GetSimilarity(searcher); }
public MatchNoDocsWeight(MatchNoDocsQuery enclosingInstance, Searcher searcher) { this.InitBlock(enclosingInstance); this.similarity = searcher.Similarity; }
internal MatchNoDocsScorer(MatchNoDocsQuery enclosingInstance, IndexReader reader, Similarity similarity, Weight w, byte[] norms) : base(similarity) { this.InitBlock(enclosingInstance); this.termDocs = reader.TermDocs((Term)null); this.score = w.Value; this.norms = norms; }
protected internal PayloadNearSpanScorer(PayloadNearQuery outerInstance, Spans spans, Weight weight, Similarity similarity, Similarity.SimScorer docScorer) : base(spans, weight, docScorer) { this.outerInstance = outerInstance; this.spans = spans; }
public override void Before(LuceneTestCase testInstance) { // LUCENENET specific - SOLR setup code removed // if verbose: print some debugging stuff about which codecs are loaded. if (LuceneTestCase.VERBOSE) { ICollection <string> codecs = Codec.AvailableCodecs(); foreach (string codec in codecs) { Console.WriteLine("Loaded codec: '" + codec + "': " + Codec.ForName(codec).GetType().Name); } ICollection <string> postingsFormats = PostingsFormat.AvailablePostingsFormats(); foreach (string postingsFormat in postingsFormats) { Console.WriteLine("Loaded postingsFormat: '" + postingsFormat + "': " + PostingsFormat.ForName(postingsFormat).GetType().Name); } } savedInfoStream = InfoStream.Default; Random random = LuceneTestCase.Random; bool v = random.NextBoolean(); if (LuceneTestCase.INFOSTREAM) { InfoStream.Default = new ThreadNameFixingPrintStreamInfoStream(Console.Out); } else if (v) { InfoStream.Default = new NullInfoStream(); } Type targetClass = testInstance.GetType(); avoidCodecs = new HashSet <string>(); var suppressCodecsAttribute = targetClass.GetTypeInfo().GetCustomAttribute <LuceneTestCase.SuppressCodecsAttribute>(); if (suppressCodecsAttribute != null) { avoidCodecs.AddAll(suppressCodecsAttribute.Value); } // set back to default LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false; savedCodec = Codec.Default; int randomVal = random.Next(10); if ("Lucene3x".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) && randomVal == 3 && !ShouldAvoidCodec("Lucene3x"))) // preflex-only setup { codec = Codec.ForName("Lucene3x"); Debug.Assert((codec is PreFlexRWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; } else if ("Lucene40".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) && randomVal == 0 && !ShouldAvoidCodec("Lucene40"))) // 4.0 setup { codec = Codec.ForName("Lucene40"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; Debug.Assert((codec is Lucene40RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework"); Debug.Assert((PostingsFormat.ForName("Lucene40") is Lucene40RWPostingsFormat), "fix your IPostingsFormatFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework"); } else if ("Lucene41".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) && randomVal == 1 && !ShouldAvoidCodec("Lucene41"))) { codec = Codec.ForName("Lucene41"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; Debug.Assert((codec is Lucene41RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework"); } else if ("Lucene42".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) && randomVal == 2 && !ShouldAvoidCodec("Lucene42"))) { codec = Codec.ForName("Lucene42"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; Debug.Assert((codec is Lucene42RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework"); } else if ("Lucene45".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) && randomVal == 5 && !ShouldAvoidCodec("Lucene45"))) { codec = Codec.ForName("Lucene45"); LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; Debug.Assert((codec is Lucene45RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework"); } else if (("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) == false) || ("random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) == false)) { // the user wired postings or DV: this is messy // refactor into RandomCodec.... PostingsFormat format; if ("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal)) { format = PostingsFormat.ForName("Lucene41"); } else if ("MockRandom".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal)) { format = new MockRandomPostingsFormat(new Random(random.Next())); } else { format = PostingsFormat.ForName(LuceneTestCase.TEST_POSTINGSFORMAT); } DocValuesFormat dvFormat; if ("random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal)) { dvFormat = DocValuesFormat.ForName("Lucene45"); } else { dvFormat = DocValuesFormat.ForName(LuceneTestCase.TEST_DOCVALUESFORMAT); } codec = new Lucene46CodecAnonymousInnerClassHelper(this, format, dvFormat); } else if ("SimpleText".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && randomVal == 9 && LuceneTestCase.Rarely(random) && !ShouldAvoidCodec("SimpleText"))) { codec = new SimpleTextCodec(); } else if ("CheapBastard".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && randomVal == 8 && !ShouldAvoidCodec("CheapBastard") && !ShouldAvoidCodec("Lucene41"))) { // we also avoid this codec if Lucene41 is avoided, since thats the postings format it uses. codec = new CheapBastardCodec(); } else if ("Asserting".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && randomVal == 6 && !ShouldAvoidCodec("Asserting"))) { codec = new AssertingCodec(); } else if ("Compressing".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && randomVal == 5 && !ShouldAvoidCodec("Compressing"))) { codec = CompressingCodec.RandomInstance(random); } else if (!"random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal)) { codec = Codec.ForName(LuceneTestCase.TEST_CODEC); } else if ("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal)) { codec = new RandomCodec(random, avoidCodecs); } else { Debug.Assert(false); } Codec.Default = codec; // Initialize locale/ timezone. string testLocale = SystemProperties.GetProperty("tests.locale", "random"); string testTimeZone = SystemProperties.GetProperty("tests.timezone", "random"); // Always pick a random one for consistency (whether tests.locale was specified or not). savedLocale = CultureInfo.CurrentCulture; CultureInfo randomLocale = LuceneTestCase.RandomCulture(random); locale = testLocale.Equals("random", StringComparison.Ordinal) ? randomLocale : LuceneTestCase.CultureForName(testLocale); #if NETSTANDARD CultureInfo.CurrentCulture = locale; #else Thread.CurrentThread.CurrentCulture = locale; #endif // TimeZone.getDefault will set user.timezone to the default timezone of the user's locale. // So store the original property value and restore it at end. restoreProperties["user.timezone"] = SystemProperties.GetProperty("user.timezone"); savedTimeZone = testInstance.TimeZone; TimeZoneInfo randomTimeZone = LuceneTestCase.RandomTimeZone(random); timeZone = testTimeZone.Equals("random", StringComparison.Ordinal) ? randomTimeZone : TimeZoneInfo.FindSystemTimeZoneById(testTimeZone); //TimeZone.Default = TimeZone; // LUCENENET NOTE: There doesn't seem to be an equivalent to this, but I don't think we need it. similarity = random.NextBoolean() ? (Similarity) new DefaultSimilarity() : new RandomSimilarityProvider(random); // Check codec restrictions once at class level. try { CheckCodecRestrictions(codec); } catch (Exception e) { Console.Error.WriteLine("NOTE: " + e.Message + " Suppressed codecs: " + Arrays.ToString(avoidCodecs.ToArray())); throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) } }
static BooleanScorer2() { defaultSimilarity = Search.Similarity.Default; }
/// <summary> /// Creates a new config that that handles the live <seealso cref="IndexWriter"/> /// settings. /// </summary> internal LiveIndexWriterConfig(IndexWriterConfig config) { maxBufferedDeleteTerms = config.MaxBufferedDeleteTerms; maxBufferedDocs = config.MaxBufferedDocs; mergedSegmentWarmer = config.MergedSegmentWarmer; RamBufferSizeMB = config.RAMBufferSizeMB; readerTermsIndexDivisor = config.ReaderTermsIndexDivisor; termIndexInterval = config.TermIndexInterval; MatchVersion = config.MatchVersion; analyzer = config.Analyzer; delPolicy = config.DelPolicy; Commit = config.IndexCommit; openMode = config.OpenMode; similarity = config.Similarity; mergeScheduler = config.MergeScheduler; writeLockTimeout = config.WriteLockTimeout; indexingChain = config.IndexingChain; codec = config.Codec; infoStream = config.InfoStream; mergePolicy = config.MergePolicy; indexerThreadPool = config.IndexerThreadPool; readerPooling = config.ReaderPooling; flushPolicy = config.FlushPolicy; PerThreadHardLimitMB = config.RAMPerThreadHardLimitMB; useCompoundFile = config.UseCompoundFile; checkIntegrityAtMerge = config.CheckIntegrityAtMerge; }
/// <summary> /// Assigns the specified number with the specified probability to this mention. /// </summary> /// <param name="number"> /// The number to be given to this mention. /// </param> /// <param name="probability"> /// The probability assosicated with the number assignment. /// </param> public virtual void SetNumber(Similarity.NumberEnum number, double probability) { mNumber = number; mNumberProbability = probability; }
protected internal PayloadNearSpanScorer(PayloadNearQuery outerInstance, Spans spans, Weight weight, Similarity similarity, Similarity.SimScorer docScorer) : base(spans, weight, docScorer) { this.OuterInstance = outerInstance; this.Spans = spans; }
protected internal PayloadNearSpanScorer(PayloadNearQuery enclosingInstance, Lucene.Net.Search.Spans.Spans spans, Weight weight, Similarity similarity, byte[] norms):base(spans, weight, similarity, norms) { InitBlock(enclosingInstance); this.spans = spans; }
public BoostingSpanScorer(BoostingTermWeight enclosingInstance, TermSpans spans, Weight weight, Similarity similarity, byte[] norms) : base(spans, weight, similarity, norms) { InitBlock(enclosingInstance); positions = spans.GetPositions(); }
public CustomWeight(CustomScoreQuery enclosingInstance, Searcher searcher) { InitBlock(enclosingInstance); this.similarity = Enclosing_Instance.GetSimilarity(searcher); this.subQueryWeight = Enclosing_Instance.subQuery.Weight(searcher); this.valSrcWeights = new Weight[Enclosing_Instance.valSrcQueries.Length]; for (int i = 0; i < Enclosing_Instance.valSrcQueries.Length; i++) { this.valSrcWeights[i] = Enclosing_Instance.valSrcQueries[i].CreateWeight(searcher); } this.qStrict = Enclosing_Instance.strict; }
public PayloadTermSpanScorer(PayloadTermWeight enclosingInstance, TermSpans spans, Weight weight, Similarity similarity, byte[] norms):base(spans, weight, similarity, norms) { InitBlock(enclosingInstance); positions = spans.Positions; }
// used by IndexWriterConfig internal LiveIndexWriterConfig(Analyzer analyzer, Version matchVersion) { this.analyzer = analyzer; this.MatchVersion = matchVersion; RamBufferSizeMB = IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB; maxBufferedDocs = IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS; maxBufferedDeleteTerms = IndexWriterConfig.DEFAULT_MAX_BUFFERED_DELETE_TERMS; readerTermsIndexDivisor = IndexWriterConfig.DEFAULT_READER_TERMS_INDEX_DIVISOR; mergedSegmentWarmer = null; termIndexInterval = IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL; // TODO: this should be private to the codec, not settable here delPolicy = new KeepOnlyLastCommitDeletionPolicy(); Commit = null; useCompoundFile = IndexWriterConfig.DEFAULT_USE_COMPOUND_FILE_SYSTEM; openMode = OpenMode_e.CREATE_OR_APPEND; similarity = IndexSearcher.DefaultSimilarity; mergeScheduler = new ConcurrentMergeScheduler(); writeLockTimeout = IndexWriterConfig.WRITE_LOCK_TIMEOUT; indexingChain = DocumentsWriterPerThread.defaultIndexingChain; codec = Codec.Default; if (codec == null) { throw new System.NullReferenceException(); } infoStream = Util.InfoStream.Default; mergePolicy = new TieredMergePolicy(); flushPolicy = new FlushByRamOrCountsPolicy(); readerPooling = IndexWriterConfig.DEFAULT_READER_POOLING; indexerThreadPool = new ThreadAffinityDocumentsWriterThreadPool(IndexWriterConfig.DEFAULT_MAX_THREAD_STATES); PerThreadHardLimitMB = IndexWriterConfig.DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB; }
public int CompareTo(Edge obj) { return(Similarity.CompareTo(obj.Similarity)); }
internal JustCompileSpanScorer(Spans spans, Weight weight, Similarity.SimScorer docScorer) : base(spans, weight, docScorer) { }
/// <summary>Constructs a Scorer.</summary> /// <param name="similarity">The <c>Similarity</c> implementation used by this scorer. /// </param> protected internal Scorer(Similarity similarity) { this.similarity = similarity; }
public PerFieldSimilarityWrapperHelper(Similarity ssBar, Similarity ssYak, Similarity ssA, Similarity ssB, Similarity ss) { this.ssBar = ssBar; this.ssYak = ssYak; this.ssA = ssA; this.ssB = ssB; this.ss = ss; }
/// <summary> /// Writes the document to the directory using the analyzer /// and the similarity score; returns the SegmentInfo /// describing the new segment /// </summary> public static SegmentCommitInfo WriteDoc(Random random, Directory dir, Analyzer analyzer, Similarity similarity, Document doc) { IndexWriter writer = new IndexWriter(dir, (new IndexWriterConfig(Util.LuceneTestCase.TEST_VERSION_CURRENT, analyzer)).SetSimilarity(similarity ?? IndexSearcher.DefaultSimilarity)); // LuceneTestCase.newIndexWriterConfig(random, //writer.SetNoCFSRatio(0.0); writer.AddDocument(doc); writer.Commit(); SegmentCommitInfo info = writer.NewestSegment(); writer.Dispose(); return info; }
public static float ComputeAndDecodeNorm(SweetSpotSimilarity decode, Similarity encode, FieldInvertState state) { return(decode.DecodeNormValue(ComputeAndGetNorm(encode, state))); }
protected internal virtual void ProcessPayload(Similarity similarity) { if (positions.IsPayloadAvailable) { payload = positions.GetPayload(payload, 0); payloadScore = Enclosing_Instance.Enclosing_Instance.function.CurrentScore(doc, Enclosing_Instance.Enclosing_Instance.internalTerm.Field, spans.Start(), spans.End(), payloadsSeen, payloadScore, similarity.ScorePayload(doc, Enclosing_Instance.Enclosing_Instance.internalTerm.Field, spans.Start(), spans.End(), payload, 0, positions.PayloadLength)); payloadsSeen++; } else { // zero out the payload? } }
public static byte ComputeAndGetNorm(Similarity s, FieldInvertState state) { return((byte)s.ComputeNorm(state)); }
public void TestSweetSpotComputeNorm() { SweetSpotSimilarity ss = new SweetSpotSimilarity(); ss.SetLengthNormFactors(1, 1, 0.5f, true); Similarity d = new DefaultSimilarity(); Similarity s = ss; // base case, should degrade FieldInvertState invertState = new FieldInvertState("bogus"); invertState.Boost = 1.0f; for (int i = 1; i < 1000; i++) { invertState.Length = i; assertEquals("base case: i=" + i, ComputeAndGetNorm(d, invertState), ComputeAndGetNorm(s, invertState), 0.0f); } // make a sweet spot ss.SetLengthNormFactors(3, 10, 0.5f, true); for (int i = 3; i <= 10; i++) { invertState.Length = i; assertEquals("3,10: spot i=" + i, 1.0f, ComputeAndDecodeNorm(ss, ss, invertState), 0.0f); } for (int i = 10; i < 1000; i++) { invertState.Length = (i - 9); byte normD = ComputeAndGetNorm(d, invertState); invertState.Length = i; byte normS = ComputeAndGetNorm(s, invertState); assertEquals("3,10: 10<x : i=" + i, normD, normS, 0.0f); } // separate sweet spot for certain fields SweetSpotSimilarity ssBar = new SweetSpotSimilarity(); ssBar.SetLengthNormFactors(8, 13, 0.5f, false); SweetSpotSimilarity ssYak = new SweetSpotSimilarity(); ssYak.SetLengthNormFactors(6, 9, 0.5f, false); SweetSpotSimilarity ssA = new SweetSpotSimilarity(); ssA.SetLengthNormFactors(5, 8, 0.5f, false); SweetSpotSimilarity ssB = new SweetSpotSimilarity(); ssB.SetLengthNormFactors(5, 8, 0.1f, false); Similarity sp = new PerFieldSimilarityWrapperHelper(ssBar, ssYak, ssA, ssB, ss); invertState = new FieldInvertState("foo"); invertState.Boost = 1.0f; for (int i = 3; i <= 10; i++) { invertState.Length = i; assertEquals("f: 3,10: spot i=" + i, 1.0f, ComputeAndDecodeNorm(ss, sp, invertState), 0.0f); } for (int i = 10; i < 1000; i++) { invertState.Length = (i - 9); byte normD = ComputeAndGetNorm(d, invertState); invertState.Length = (i); byte normS = ComputeAndGetNorm(sp, invertState); assertEquals("f: 3,10: 10<x : i=" + i, normD, normS, 0.0f); } invertState = new FieldInvertState("bar"); invertState.Boost = (1.0f); for (int i = 8; i <= 13; i++) { invertState.Length = (i); assertEquals("f: 8,13: spot i=" + i, 1.0f, ComputeAndDecodeNorm(ss, sp, invertState), 0.0f); } invertState = new FieldInvertState("yak"); invertState.Boost = (1.0f); for (int i = 6; i <= 9; i++) { invertState.Length = (i); assertEquals("f: 6,9: spot i=" + i, 1.0f, ComputeAndDecodeNorm(ss, sp, invertState), 0.0f); } invertState = new FieldInvertState("bar"); invertState.Boost = (1.0f); for (int i = 13; i < 1000; i++) { invertState.Length = (i - 12); byte normD = ComputeAndGetNorm(d, invertState); invertState.Length = (i); byte normS = ComputeAndGetNorm(sp, invertState); assertEquals("f: 8,13: 13<x : i=" + i, normD, normS, 0.0f); } invertState = new FieldInvertState("yak"); invertState.Boost = (1.0f); for (int i = 9; i < 1000; i++) { invertState.Length = (i - 8); byte normD = ComputeAndGetNorm(d, invertState); invertState.Length = (i); byte normS = ComputeAndGetNorm(sp, invertState); assertEquals("f: 6,9: 9<x : i=" + i, normD, normS, 0.0f); } // steepness for (int i = 9; i < 1000; i++) { invertState = new FieldInvertState("a"); invertState.Boost = (1.0f); invertState.Length = (i); byte normSS = ComputeAndGetNorm(sp, invertState); invertState = new FieldInvertState("b"); invertState.Boost = (1.0f); invertState.Length = (i); byte normS = ComputeAndGetNorm(sp, invertState); assertTrue("s: i=" + i + " : a=" + normSS + " < b=" + normS, normSS < normS); } }
private void Proceed(string folderLocation, int nGramValue, string outputLocation, float threshold) { var pdfParser = new PdfParser(); var tfIdf = new DocumentTermFrequency(); var nGram = new Ngram(); var reports = new Dictionary <string, List <string> >(); foreach (var file in Directory.EnumerateFiles(folderLocation, "*.pdf")) { var fileName = Path.GetFileNameWithoutExtension(file); var contents = pdfParser.GetText(file); reports[fileName] = nGram.Create(contents, nGramValue); } var tfIdfMatrix = tfIdf.Create(reports); var sw = new Stopwatch(); sw.Start(); Debug.WriteLine($"Create rowwise start."); var sim = new Similarity().CreateRowWise(tfIdfMatrix); Debug.WriteLine($"Create rowwise end ({sw.ElapsedMilliseconds} ms)."); // all report. var strBuilder = new StringBuilder(); strBuilder.AppendLine("Roll,Similarity"); for (var r = 0; r < sim.GetLength(0); r++) { var line = ""; for (var c = 0; c < sim.GetLength(1); c++) { if (sim[r, c] > threshold) { line += $"{reports.Keys.ElementAt(c)}={Math.Round(sim[r, c] * 100, 2)}%,"; } } if (!string.IsNullOrEmpty(line)) { var idx = line.LastIndexOf(','); if (idx >= 0) { line = line.Substring(0, line.Length - 1); } } strBuilder.AppendLine($"\"{reports.Keys.ElementAt(r)}\",\"{line}\""); } var output = $"{outputLocation}/Plagiarism_Output{DateTime.Now:yyyy-dd-M--HH-mm-ss}.csv"; File.WriteAllBytes(output, Encoding.UTF8.GetBytes(strBuilder.ToString())); Process.Start(output); }
public PayloadTermSpanScorer(PayloadTermQuery.PayloadTermWeight outerInstance, TermSpans spans, Weight weight, Similarity.SimScorer docScorer) : base(spans, weight, docScorer) { this.OuterInstance = outerInstance; TermSpans = spans; }
public static string SetSimilarity(Similarity sim) { UseOBM25 = sim.Equals(Similarity.OkapiBM25); return(Initialize()); }
/// <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(); }
/// <summary> /// Creates a RandomIndexWriter with a random config /// /// LUCENENET specific /// Similarity and TimeZone parameters allow a RandomIndexWriter to be /// created without adding a dependency on /// <see cref="LuceneTestCase.ClassEnv.Similarity"/> and /// <see cref="LuceneTestCase.ClassEnv.TimeZone"/> /// </summary> public RandomIndexWriter(Random r, Directory dir, LuceneVersion v, Analyzer a, Similarity similarity, TimeZone timezone) : this(r, dir, LuceneTestCase.NewIndexWriterConfig(r, v, a, similarity, timezone)) { }
// constructor internal ValueSourceScorer(ValueSourceQuery enclosingInstance, Similarity similarity, IndexReader reader, ValueSourceWeight w) : base(similarity) { InitBlock(enclosingInstance); this.weight = w; this.qWeight = w.Value; // this is when/where the values are first created. vals = Enclosing_Instance.valSrc.GetValues(reader); termDocs = reader.TermDocs(null); }
/* private static String[] getLemmas(MentionContext xec) { //TODO: Try multi-word lemmas first. String word = xec.getHeadTokenText(); return DictionaryFactory.getDictionary().getLemmas(word,"NN"); } private static Set getSynsetSet(MentionContext xec) { //System.err.println("getting synsets for mention:"+xec.toText()); Set synsetSet = new HashSet(); String[] lemmas = getLemmas(xec); for (int li = 0; li < lemmas.length; li++) { String[] synsets = DictionaryFactory.getDictionary().getParentSenseKeys(lemmas[li],"NN",0); for (int si=0,sn=synsets.length;si<sn;si++) { synsetSet.add(synsets[si]); } } return (synsetSet); } */ /// <summary> /// Assigns the specified gender with the specified probability to this mention. /// </summary> /// <param name="gender"> /// The gender to be given to this mention. /// </param> /// <param name="probability"> /// The probability assosicated with the gender assignment. /// </param> public virtual void SetGender(Similarity.GenderEnum gender, double probability) { mGender = gender; mGenderProbability = probability; }
/// <summary> /// create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT /// /// LUCENENET specific /// Similarity and TimeZone parameters allow a RandomIndexWriter to be /// created without adding a dependency on /// <see cref="LuceneTestCase.ClassEnv.Similarity"/> and /// <see cref="LuceneTestCase.ClassEnv.TimeZone"/> /// </summary> public RandomIndexWriter(Random r, Directory dir, Analyzer a, Similarity similarity, TimeZoneInfo timezone) : this(r, dir, LuceneTestCase.NewIndexWriterConfig(r, LuceneTestCase.TEST_VERSION_CURRENT, a, similarity, timezone)) { }
/// <summary> /// Expert: set the <seealso cref="Similarity"/> implementation used by this IndexWriter. /// <p> /// <b>NOTE:</b> the similarity cannot be null. /// /// <p>Only takes effect when IndexWriter is first created. /// </summary> public IndexWriterConfig SetSimilarity(Similarity similarity) { if (similarity == null) { throw new System.ArgumentException("similarity must not be null"); } this.similarity = similarity; return this; }
public TestRuleSetupAndRestoreClassEnv() { /*// if verbose: print some debugging stuff about which codecs are loaded. * if (LuceneTestCase.VERBOSE) * { * ISet<string> codecs = Codec.AvailableCodecs(); * foreach (string codec in codecs) * { * Console.WriteLine("Loaded codec: '" + codec + "': " + Codec.ForName(codec).GetType().Name); * } * * ISet<string> postingsFormats = PostingsFormat.AvailablePostingsFormats(); * foreach (string postingsFormat in postingsFormats) * { * Console.WriteLine("Loaded postingsFormat: '" + postingsFormat + "': " + PostingsFormat.ForName(postingsFormat).GetType().Name); * } * } * * SavedInfoStream = InfoStream.Default; * Random random = RandomizedContext.Current.Random; * bool v = random.NextBoolean(); * if (LuceneTestCase.INFOSTREAM) * { * InfoStream.Default = new ThreadNameFixingPrintStreamInfoStream(Console.Out); * } * else if (v) * { * InfoStream.Default = new NullInfoStream(); * } * * Type targetClass = RandomizedContext.Current.GetTargetType; * AvoidCodecs = new HashSet<string>(); * * // set back to default * LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false; * * SavedCodec = Codec.Default; * int randomVal = random.Next(10); * if ("Lucene3x".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) && randomVal == 3 && !ShouldAvoidCodec("Lucene3x"))) // preflex-only setup * { * Codec = Codec.ForName("Lucene3x"); * Debug.Assert((Codec is PreFlexRWCodec), "fix your classpath to have tests-framework.jar before lucene-core.jar"); * LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; * } * else if ("Lucene40".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && randomVal == 0 && !ShouldAvoidCodec("Lucene40"))) // 4.0 setup * { * Codec = Codec.ForName("Lucene40"); * LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; * Debug.Assert(Codec is Lucene40RWCodec, "fix your classpath to have tests-framework.jar before lucene-core.jar"); * Debug.Assert((PostingsFormat.ForName("Lucene40") is Lucene40RWPostingsFormat), "fix your classpath to have tests-framework.jar before lucene-core.jar"); * } * else if ("Lucene41".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) && randomVal == 1 && !ShouldAvoidCodec("Lucene41"))) * { * Codec = Codec.ForName("Lucene41"); * LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; * Debug.Assert(Codec is Lucene41RWCodec, "fix your classpath to have tests-framework.jar before lucene-core.jar"); * } * else if ("Lucene42".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) && randomVal == 2 && !ShouldAvoidCodec("Lucene42"))) * { * Codec = Codec.ForName("Lucene42"); * LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; * Debug.Assert(Codec is Lucene42RWCodec, "fix your classpath to have tests-framework.jar before lucene-core.jar"); * } * else if ("Lucene45".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) && "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) && randomVal == 5 && !ShouldAvoidCodec("Lucene45"))) * { * Codec = Codec.ForName("Lucene45"); * LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; * Debug.Assert(Codec is Lucene45RWCodec, "fix your classpath to have tests-framework.jar before lucene-core.jar"); * } * else if (("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT) == false) || ("random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT) == false)) * { * // the user wired postings or DV: this is messy * // refactor into RandomCodec.... * * PostingsFormat format; * if ("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT)) * { * format = PostingsFormat.ForName("Lucene41"); * } * else * { * format = PostingsFormat.ForName(LuceneTestCase.TEST_POSTINGSFORMAT); * } * * DocValuesFormat dvFormat; * if ("random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT)) * { * dvFormat = DocValuesFormat.ForName("Lucene45"); * } * else * { * dvFormat = DocValuesFormat.ForName(LuceneTestCase.TEST_DOCVALUESFORMAT); * } * * Codec = new Lucene46CodecAnonymousInnerClassHelper(this, format, dvFormat); * } * else if ("Asserting".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && randomVal == 6 && !ShouldAvoidCodec("Asserting"))) * { * Codec = new AssertingCodec(); * } * else if ("Compressing".Equals(LuceneTestCase.TEST_CODEC) || ("random".Equals(LuceneTestCase.TEST_CODEC) && randomVal == 5 && !ShouldAvoidCodec("Compressing"))) * { * Codec = CompressingCodec.RandomInstance(random); * } * else if (!"random".Equals(LuceneTestCase.TEST_CODEC)) * { * Codec = Codec.ForName(LuceneTestCase.TEST_CODEC); * } * else if ("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT)) * { * Codec = new RandomCodec(random, AvoidCodecs); * } * else * { * Debug.Assert(false); * } * Codec.Default = Codec; */ Random random = new Random(1); Similarity = random.NextBoolean() ? (Similarity) new DefaultSimilarity() : new RandomSimilarityProvider(new Random(1)); /* * // Check codec restrictions once at class level. * try * { * CheckCodecRestrictions(Codec); * } * catch (Exception e) * { * Console.Error.WriteLine("NOTE: " + e.Message + " Suppressed codecs: " + Arrays.ToString(AvoidCodecs.ToArray())); * throw e; * }*/ }