You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2016/10/02 14:35:23 UTC
[05/50] [abbrv] lucenenet git commit: Finished porting
TestFreeTextSuggester (NOTE: missing test data file so the test can't be run,
but the test was ignored anyway).
Finished porting TestFreeTextSuggester (NOTE: missing test data file so the test can't be run, but the test was ignored anyway).
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/48984505
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/48984505
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/48984505
Branch: refs/heads/master
Commit: 489845058723adf6d96de5f22a428f8fac02a062
Parents: 98458d6
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Thu Sep 15 01:05:35 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Sun Oct 2 17:44:02 2016 +0700
----------------------------------------------------------------------
.../Suggest/Analyzing/TestFreeTextSuggester.cs | 185 +++++++++++--------
1 file changed, 104 insertions(+), 81 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/48984505/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs
index 5d9ec3c..2d4f61f 100644
--- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs
+++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs
@@ -1,6 +1,7 @@
\ufeffusing Lucene.Net.Analysis;
using Lucene.Net.Analysis.Core;
using Lucene.Net.Analysis.Util;
+using Lucene.Net.Documents;
using Lucene.Net.Support;
using Lucene.Net.Util;
using NUnit.Framework;
@@ -125,87 +126,109 @@ namespace Lucene.Net.Search.Suggest.Analyzing
}
}
- // [Ignore]
- // public void TestWiki()
- //{
- // final LineFileDocs lfd = new LineFileDocs(null, "/lucenedata/enwiki/enwiki-20120502-lines-1k.txt", false);
- //// Skip header:
- //lfd.nextDoc();
- // FreeTextSuggester sug = new FreeTextSuggester(new MockAnalyzer(Random()));
- //sug.Build(new IInputIterator()
- //{
-
- // private int count;
-
- //@Override
- // public long weight()
- //{
- // return 1;
- //}
-
- //@Override
- // public Comparator<BytesRef> getComparator()
- //{
- // return null;
- //}
-
- //@Override
- // public BytesRef next()
- //{
- // Document doc;
- // try
- // {
- // doc = lfd.nextDoc();
- // }
- // catch (IOException ioe)
- // {
- // throw new RuntimeException(ioe);
- // }
- // if (doc == null)
- // {
- // return null;
- // }
- // if (count++ == 10000)
- // {
- // return null;
- // }
- // return new BytesRef(doc.get("body"));
- //}
-
- //@Override
- // public BytesRef payload()
- //{
- // return null;
- //}
-
- //@Override
- // public boolean hasPayloads()
- //{
- // return false;
- //}
-
- //@Override
- // public Set<BytesRef> contexts()
- //{
- // return null;
- //}
-
- //@Override
- // public boolean hasContexts()
- //{
- // return false;
- //}
- // });
- // if (VERBOSE) {
- // System.out.println(sug.sizeInBytes() + " bytes");
-
- // List<LookupResult> results = sug.DoLookup("general r", 10);
- //System.out.println("results:");
- // for(LookupResult result : results) {
- // System.out.println(" " + result);
- // }
- // }
- // }
+ internal class TestWikiInputIterator : IInputIterator
+ {
+ private readonly LineFileDocs lfd;
+ private readonly TestFreeTextSuggester outerInstance;
+ private int count;
+
+ public TestWikiInputIterator(TestFreeTextSuggester outerInstance, LineFileDocs lfd)
+ {
+ this.outerInstance = outerInstance;
+ this.lfd = lfd;
+ }
+
+ public long Weight
+ {
+ get
+ {
+ return 1;
+ }
+ }
+
+ public IComparer<BytesRef> Comparator
+ {
+ get
+ {
+ return null;
+ }
+ }
+
+ public BytesRef Next()
+ {
+ Document doc;
+ try
+ {
+ doc = lfd.NextDoc();
+ }
+ catch (IOException ioe)
+ {
+ throw new Exception(ioe.Message, ioe);
+ }
+ if (doc == null)
+ {
+ return null;
+ }
+ if (count++ == 10000)
+ {
+ return null;
+ }
+ return new BytesRef(doc.Get("body"));
+ }
+
+ public BytesRef Payload
+ {
+ get
+ {
+ return null;
+ }
+ }
+
+ public bool HasPayloads
+ {
+ get
+ {
+ return false;
+ }
+ }
+
+ public IEnumerable<BytesRef> Contexts
+ {
+ get
+ {
+ return null;
+ }
+ }
+
+ public bool HasContexts
+ {
+ get
+ {
+ return false;
+ }
+ }
+ }
+
+ [Ignore]
+ public void TestWiki()
+ {
+ LineFileDocs lfd = new LineFileDocs(null, "/lucenedata/enwiki/enwiki-20120502-lines-1k.txt", false);
+ // Skip header:
+ lfd.NextDoc();
+ FreeTextSuggester sug = new FreeTextSuggester(new MockAnalyzer(Random()));
+ sug.Build(new TestWikiInputIterator(this, lfd));
+ if (VERBOSE)
+ {
+ Console.WriteLine(sug.SizeInBytes() + " bytes");
+
+ IList<Lookup.LookupResult> results = sug.DoLookup("general r", 10);
+ Console.WriteLine("results:");
+ foreach (Lookup.LookupResult result in results)
+ {
+ Console.WriteLine(" " + result);
+ }
+ }
+ }
// Make sure you can suggest based only on unigram model:
[Test]