
org.terrier.matching.daat.FatCandidateResultSet Maven / Gradle / Ivy
The newest version!
/*
* Terrier - Terabyte Retriever
* Webpage: http://terrier.org
* Contact: terrier{a.}dcs.gla.ac.uk
* University of Glasgow - School of Computing Science
* http://www.gla.ac.uk/
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is FatCandidateResultSet.java.
*
* The Original Code is Copyright (C) 2004-2020 the University of Glasgow.
* All Rights Reserved.
*
* Contributor(s):
* Craig Macdonald
* Eric Sutherland
*/
package org.terrier.matching.daat;
import gnu.trove.TIntIntHashMap;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.hadoop.io.Writable;
import org.terrier.matching.FatQueryResultSet;
import org.terrier.matching.FatResultSet;
import org.terrier.matching.FatUtils;
import org.terrier.structures.CollectionStatistics;
import org.terrier.structures.EntryStatistics;
import org.terrier.structures.postings.WritablePosting;
import org.terrier.utility.StableSort;
@SuppressWarnings("serial")
/** A version of {@link CandidateResultSet} suitable for use within the Fat framework. This stores the postings
* for each retrieved document.
*
* @author Eric Sutherland, Craig Macdonald
* @since 4.0
*/
public class FatCandidateResultSet extends CandidateResultSet implements Writable, FatResultSet {
CollectionStatistics collStats;
protected WritablePosting[][] postings;
String[] queryTerms;
double[] keyFrequency;
Set[] tags;
EntryStatistics[] entryStats;
public FatCandidateResultSet(){
super();
}
@Deprecated
public FatCandidateResultSet(List resultList, CollectionStatistics cs, String[] queryTerms, EntryStatistics[] entryStats, double[] keyFrequency, Set[] tags) {
super(resultList);
this.queryTerms = queryTerms;
this.entryStats = entryStats;
this.keyFrequency = keyFrequency;
this.collStats = cs;
this.tags = tags;
int i=0;
postings = new WritablePosting[resultList.size()][];
for (CandidateResult cc: resultList)
{
postings[i] = ((FatCandidateResult) cc).getPostings();
assert verify(postings[i], cc.getDocId()) : "FatCandidateResult at position " + i + " had an id mismatch";
i++;
}
}
@Override
public WritablePosting[][] getPostings() {
return postings;
}
@Override
public double[] getKeyFrequencies() {
return keyFrequency;
}
@Override
public EntryStatistics[] getEntryStatistics() {
return entryStats;
}
@Override
public CollectionStatistics getCollectionStatistics()
{
return collStats;
}
@Override
public String[] getQueryTerms() {
return queryTerms;
}
@Override
public void readFields(DataInput in) throws IOException {
FatUtils.readFields(this, in);
}
@Override
public void write(DataOutput out) throws IOException {
FatUtils.write(this, out);
}
@Override
public FatResultSet getResultSet(int start, int length) {
length = length < docids.length ? length : docids.length;
FatQueryResultSet resultSet = new FatQueryResultSet(
length,
this.getCollectionStatistics(),
this.getQueryTerms(),
this.getEntryStatistics(),
this.getKeyFrequencies(),
this.getTags());
resultSet.setExactResultSize(this.exactResultSize);
System.arraycopy(docids, start, resultSet.getDocids(), 0, length);
System.arraycopy(scores, start, resultSet.getScores(), 0, length);
System.arraycopy(occurrences, start, resultSet.getOccurrences(), 0, length);
System.arraycopy(postings, start, resultSet.getPostings(), 0, length);
assert resultSet.verify() : "FatQueryResultSet verification failed after creation";
return resultSet;
}
@Override
public void sort(int topDocs) {
StableSort.sortDescending(getScores(), getDocids(), getOccurrences(), topDocs);
TIntIntHashMap sortedOrder = new TIntIntHashMap(postings.length);
for(int i=0;i[] getTags() {
return tags;
}
@Override
public void setTags(Set[] tags) {
this.tags = tags;
}
static final boolean verify(WritablePosting[] postings, int id) {
for (WritablePosting p : postings) {
if(p != null && p.getId() != id)
{
System.err.println("Posting mismatch - expected " + id + " found " + p.getId());
return false;
}
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy