All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.terrier.querying.ExpansionTerms 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 ExpansionTerms.java.
 *
 * The Original Code is Copyright (C) 2004-2020 the University of Glasgow.
 * All Rights Reserved.
 *
 * Contributor(s):
 *   Gianni Amati  (original author)
 *   Ben He  
 *   Vassilis Plachouras 
 *   Craig Macdonald 
 */

package org.terrier.querying;

import gnu.trove.TIntDoubleHashMap;
import gnu.trove.TIntObjectHashMap;

import java.io.IOException;
import java.util.Comparator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terrier.matching.MatchingQueryTerms;
import org.terrier.matching.models.queryexpansion.QueryExpansionModel;
import org.terrier.querying.parser.SingleTermQuery;
import org.terrier.structures.EntryStatistics;
/** Base class for weighting term occurrences in feedback documents. 
 * @since 3.0
 * @author Craig Macdonald
 */
public abstract class ExpansionTerms
{
	protected static final Logger logger = LoggerFactory.getLogger(ExpansionTerms.class);
	
	protected static final Comparator EXPANSIONTERM_DESC_SCORE_SORTER = new Comparator()
	{
		public int compare(ExpansionTerm t1, ExpansionTerm t2)
		{
			final double res = t1.getWeightExpansion() - t2.getWeightExpansion();
			return res>0.0d ? -1 : (res< 0.0d ? 1 : 0);
		}
	};

	protected ExpansionTerms(){}	

	/** The original query terms. Used only for Conservative Query Expansion,
	 * where no terms are added to the query, only the existing ones are 
	 * reweighted. */
	protected TIntObjectHashMap originalTermids = new TIntObjectHashMap();
	/**
	 * The frequency of each query term in the original query. Currently used by RM3 only.
	 */
	protected TIntDoubleHashMap originalTermFreqs = new TIntDoubleHashMap();
	protected QueryExpansionModel model;

	/**
	 * Set the original query terms.
	 * @param query The original query.
	 */
	public void setOriginalQueryTerms(MatchingQueryTerms query){
		String[] terms = query.getTerms();
		this.originalTermids.clear();
		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy