You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Shay Hummel <sh...@gmail.com> on 2015/06/15 08:12:14 UTC
Tf and Df in lucene
Hi
I was wondering, what is the easiest way to get the term frequency of a
term t in document d, namely tf(t,d) ?
In the same spirit - what is the easieast way the get the document
frequency of a term in the collection, i.e. how many contain the term t,
namely df(t) ?
Regards,
Shay
Re: Tf and Df in lucene
Posted by Shay Hummel <sh...@gmail.com>.
Erick and Ahmet - thank you
Shay
On Mon, Jun 15, 2015 at 6:19 PM Ahmet Arslan <io...@yahoo.com.invalid>
wrote:
> Hi,
>
> If you are interested in summed up tf values of multiple terms,
> I suggest to extend SimilarityBase class to return raw freq as score.
>
> float score(BasicStats stats, float freq, float docLen){
> return freq;
> }
>
> When you use this similarity, search for three term query, scores will
> summed tf values. Also you can extract additional info from explain feature.
>
> Ahmet
>
>
>
>
> On Monday, June 15, 2015 5:50 PM, Shay Hummel <sh...@gmail.com>
> wrote:
> Hi Ahmet
>
> Thank you for the reply.
> Can the term reflect a multi word expression?
> For example:
> I want to find the term frequency \ document frequency of "united states"
> (two terms) or "free speech zones" (three terms).
>
> Shay
>
>
> On Mon, Jun 15, 2015 at 4:55 PM Ahmet Arslan <io...@yahoo.com.invalid>
> wrote:
>
> > Hi Hummel,
> >
> > regarding df,
> >
> > Term term = new Term(field, word);
> > TermStatistics termStatistics = searcher.termStatistics(term,
> > TermContext.build(reader.getContext(), term));
> > System.out.println(query + "\t totalTermFreq \t " +
> > termStatistics.totalTermFreq());
> > System.out.println(query + "\t docFreq \t " + termStatistics.docFreq());
> >
> > regarding tf,
> >
> > Term term = new Term(field, word);
> > Bits bits = MultiFields.getLiveDocs(reader);
> > PostingsEnum postingsEnum = MultiFields.getTermDocsEnum(reader, bits,
> > field, term.bytes());
> >
> > if (postingsEnum == null) return;
> >
> > int max = 0;
> > while (postingsEnum.nextDoc() != PostingsEnum.NO_MORE_DOCS) {
> > final int freq = postingsEnum.freq();
> > int docID = postingsEnum.docID();}
> >
> >
> > Ahmet
> >
> >
> >
> >
> > On Monday, June 15, 2015 9:12 AM, Shay Hummel <sh...@gmail.com>
> > wrote:
> > Hi
> >
> > I was wondering, what is the easiest way to get the term frequency of a
> > term t in document d, namely tf(t,d) ?
> > In the same spirit - what is the easieast way the get the document
> > frequency of a term in the collection, i.e. how many contain the term t,
> > namely df(t) ?
> >
> > Regards,
> > Shay
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: Tf and Df in lucene
Posted by Ahmet Arslan <io...@yahoo.com.INVALID>.
Hi,
If you are interested in summed up tf values of multiple terms,
I suggest to extend SimilarityBase class to return raw freq as score.
float score(BasicStats stats, float freq, float docLen){
return freq;
}
When you use this similarity, search for three term query, scores will summed tf values. Also you can extract additional info from explain feature.
Ahmet
On Monday, June 15, 2015 5:50 PM, Shay Hummel <sh...@gmail.com> wrote:
Hi Ahmet
Thank you for the reply.
Can the term reflect a multi word expression?
For example:
I want to find the term frequency \ document frequency of "united states"
(two terms) or "free speech zones" (three terms).
Shay
On Mon, Jun 15, 2015 at 4:55 PM Ahmet Arslan <io...@yahoo.com.invalid>
wrote:
> Hi Hummel,
>
> regarding df,
>
> Term term = new Term(field, word);
> TermStatistics termStatistics = searcher.termStatistics(term,
> TermContext.build(reader.getContext(), term));
> System.out.println(query + "\t totalTermFreq \t " +
> termStatistics.totalTermFreq());
> System.out.println(query + "\t docFreq \t " + termStatistics.docFreq());
>
> regarding tf,
>
> Term term = new Term(field, word);
> Bits bits = MultiFields.getLiveDocs(reader);
> PostingsEnum postingsEnum = MultiFields.getTermDocsEnum(reader, bits,
> field, term.bytes());
>
> if (postingsEnum == null) return;
>
> int max = 0;
> while (postingsEnum.nextDoc() != PostingsEnum.NO_MORE_DOCS) {
> final int freq = postingsEnum.freq();
> int docID = postingsEnum.docID();}
>
>
> Ahmet
>
>
>
>
> On Monday, June 15, 2015 9:12 AM, Shay Hummel <sh...@gmail.com>
> wrote:
> Hi
>
> I was wondering, what is the easiest way to get the term frequency of a
> term t in document d, namely tf(t,d) ?
> In the same spirit - what is the easieast way the get the document
> frequency of a term in the collection, i.e. how many contain the term t,
> namely df(t) ?
>
> Regards,
> Shay
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Tf and Df in lucene
Posted by Erick Erickson <er...@gmail.com>.
In a word, no. Terms are, by definition, whatever a "token" is.
Tokens are delimited by, say, the WhitespaceTokenizer
so a-priori can't do what you want.
Unless... you do "something special". In this case, "something special"
would be put shingles (See ShingleFilter in Lucene or
ShingleFilterFactory in Solr). That will make your index bigger,
but will put things like free_speech_zones in your index as a
single token which you could then allow you to get what you're asking
for.
Best,
Erick
On Mon, Jun 15, 2015 at 7:49 AM, Shay Hummel <sh...@gmail.com> wrote:
> Hi Ahmet
>
> Thank you for the reply.
> Can the term reflect a multi word expression?
> For example:
> I want to find the term frequency \ document frequency of "united states"
> (two terms) or "free speech zones" (three terms).
>
> Shay
>
> On Mon, Jun 15, 2015 at 4:55 PM Ahmet Arslan <io...@yahoo.com.invalid>
> wrote:
>
>> Hi Hummel,
>>
>> regarding df,
>>
>> Term term = new Term(field, word);
>> TermStatistics termStatistics = searcher.termStatistics(term,
>> TermContext.build(reader.getContext(), term));
>> System.out.println(query + "\t totalTermFreq \t " +
>> termStatistics.totalTermFreq());
>> System.out.println(query + "\t docFreq \t " + termStatistics.docFreq());
>>
>> regarding tf,
>>
>> Term term = new Term(field, word);
>> Bits bits = MultiFields.getLiveDocs(reader);
>> PostingsEnum postingsEnum = MultiFields.getTermDocsEnum(reader, bits,
>> field, term.bytes());
>>
>> if (postingsEnum == null) return;
>>
>> int max = 0;
>> while (postingsEnum.nextDoc() != PostingsEnum.NO_MORE_DOCS) {
>> final int freq = postingsEnum.freq();
>> int docID = postingsEnum.docID();}
>>
>>
>> Ahmet
>>
>>
>>
>>
>> On Monday, June 15, 2015 9:12 AM, Shay Hummel <sh...@gmail.com>
>> wrote:
>> Hi
>>
>> I was wondering, what is the easiest way to get the term frequency of a
>> term t in document d, namely tf(t,d) ?
>> In the same spirit - what is the easieast way the get the document
>> frequency of a term in the collection, i.e. how many contain the term t,
>> namely df(t) ?
>>
>> Regards,
>> Shay
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Tf and Df in lucene
Posted by Shay Hummel <sh...@gmail.com>.
Hi Ahmet
Thank you for the reply.
Can the term reflect a multi word expression?
For example:
I want to find the term frequency \ document frequency of "united states"
(two terms) or "free speech zones" (three terms).
Shay
On Mon, Jun 15, 2015 at 4:55 PM Ahmet Arslan <io...@yahoo.com.invalid>
wrote:
> Hi Hummel,
>
> regarding df,
>
> Term term = new Term(field, word);
> TermStatistics termStatistics = searcher.termStatistics(term,
> TermContext.build(reader.getContext(), term));
> System.out.println(query + "\t totalTermFreq \t " +
> termStatistics.totalTermFreq());
> System.out.println(query + "\t docFreq \t " + termStatistics.docFreq());
>
> regarding tf,
>
> Term term = new Term(field, word);
> Bits bits = MultiFields.getLiveDocs(reader);
> PostingsEnum postingsEnum = MultiFields.getTermDocsEnum(reader, bits,
> field, term.bytes());
>
> if (postingsEnum == null) return;
>
> int max = 0;
> while (postingsEnum.nextDoc() != PostingsEnum.NO_MORE_DOCS) {
> final int freq = postingsEnum.freq();
> int docID = postingsEnum.docID();}
>
>
> Ahmet
>
>
>
>
> On Monday, June 15, 2015 9:12 AM, Shay Hummel <sh...@gmail.com>
> wrote:
> Hi
>
> I was wondering, what is the easiest way to get the term frequency of a
> term t in document d, namely tf(t,d) ?
> In the same spirit - what is the easieast way the get the document
> frequency of a term in the collection, i.e. how many contain the term t,
> namely df(t) ?
>
> Regards,
> Shay
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: Tf and Df in lucene
Posted by Ahmet Arslan <io...@yahoo.com.INVALID>.
Hi Hummel,
regarding df,
Term term = new Term(field, word);
TermStatistics termStatistics = searcher.termStatistics(term, TermContext.build(reader.getContext(), term));
System.out.println(query + "\t totalTermFreq \t " + termStatistics.totalTermFreq());
System.out.println(query + "\t docFreq \t " + termStatistics.docFreq());
regarding tf,
Term term = new Term(field, word);
Bits bits = MultiFields.getLiveDocs(reader);
PostingsEnum postingsEnum = MultiFields.getTermDocsEnum(reader, bits, field, term.bytes());
if (postingsEnum == null) return;
int max = 0;
while (postingsEnum.nextDoc() != PostingsEnum.NO_MORE_DOCS) {
final int freq = postingsEnum.freq();
int docID = postingsEnum.docID();}
Ahmet
On Monday, June 15, 2015 9:12 AM, Shay Hummel <sh...@gmail.com> wrote:
Hi
I was wondering, what is the easiest way to get the term frequency of a
term t in document d, namely tf(t,d) ?
In the same spirit - what is the easieast way the get the document
frequency of a term in the collection, i.e. how many contain the term t,
namely df(t) ?
Regards,
Shay
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org