Package org.terrier.matching
Class MatchingQueryTerms
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<MatchingQueryTerms.MatchingTerm>
-
- org.terrier.matching.MatchingQueryTerms
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<MatchingQueryTerms.MatchingTerm>
,java.util.Collection<MatchingQueryTerms.MatchingTerm>
,java.util.List<MatchingQueryTerms.MatchingTerm>
,java.util.RandomAccess
public class MatchingQueryTerms extends java.util.ArrayList<MatchingQueryTerms.MatchingTerm> implements java.io.Serializable, java.lang.Cloneable
Models a query used for matching documents. It is created by creating an instance of this class, and then passing it as an argument to the method obtainQueryTerms of a Query. It contains the query terms, their weights, optionally the corresponding term identifiers and the associated term score modifiers. It also stores the document score modifiers for the query.- Author:
- Vassilis Plachouras, Craig Macdonald.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MatchingQueryTerms.MatchingTerm
static class
MatchingQueryTerms.QueryTermProperties
The weight and the modifiers associated with a query term.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<java.lang.String>
defaultTags
protected WeightingModel
defaultWeightingModel
default weighting model for all termsprotected java.util.ArrayList<DocumentScoreModifier>
docScoreModifiers
The document score modifiers associated with the query terms.protected int
numDocsRequest
number of documents to request matching provides.protected Query
query
The original query as it came from the parser, in case any TSMs or DSMs wish to refer to itprotected java.lang.String
queryId
The query ID, if providedprotected Request
rq
-
Constructor Summary
Constructors Constructor Description MatchingQueryTerms()
Generate a MatchingQueryTerms object.MatchingQueryTerms(java.lang.String qid)
Generate a MatchingQueryTerms object, with the specified query id.MatchingQueryTerms(java.lang.String qid, Request _rq)
Generate a MatchingQueryTerms object, with the specified query id, and requestMatchingQueryTerms(java.util.Collection<MatchingQueryTerms.MatchingTerm> coll)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
add(MatchingQueryTerms.MatchingTerm e)
void
addDocumentScoreModifier(DocumentScoreModifier dsm)
Adds a document score modifier for the query.void
addTermPropertyWeight(java.lang.String term, double d)
MatchingQueryTerms
clone()
Performs a deep clone of this object, and all objects it contains.protected MatchingQueryTerms.QueryTermProperties
combine(MatchingQueryTerms.QueryTermProperties existingProps, MatchingQueryTerms.QueryTermProperties newProps)
java.util.Map.Entry<Operator,MatchingQueryTerms.QueryTermProperties>
get(java.lang.String singleTerm)
MatchingQueryTerms.QueryTermProperties
get(Operator term)
DocumentScoreModifier[]
getDocumentScoreModifiers()
Returns the document score modifiers used for the query.int
getMatchingRequestSize()
Operator[]
getMatchingTerms()
Returns the query terms, as they were added to this object.java.util.List<MatchingQueryTerms.MatchingTerm>
getMatchingTerms(java.lang.String tag)
Query
getQuery()
Returns guess what?java.lang.String
getQueryId()
Returns the query id specified when constructing this object.Request
getRequest()
Returns the request.EntryStatistics
getStatistics(java.lang.String term)
EntryStatistics
getStatistics(Operator term)
Returns the assocciated code of the given query term.java.lang.String[]
getTerms()
Returns the query terms, as they were added to this object.double
getTermWeight(java.lang.String term)
double
getTermWeight(Operator term)
Returns the associated weight of the given query term.double[]
getTermWeights()
Returns the associated weights of the given query terms.int
length()
Deprecated.void
normaliseTermWeights()
This method normalises the term weights by dividing each term weight by the maximum of the terms.boolean
removeTerm(Operator term)
Remove a term from the list of terms to be matchedvoid
resetTermProperties()
This method resets query term statistics to allow for a single instance of MatchingQueryTerms to be reused for matching against different indices.void
setDefaultTermWeightingModel(WeightingModel weightingModel)
Set the default weighting model to be used for terms that do NOT have an explicit WeightingModel set.void
setMatchingRequestSize(int numDocs)
void
setQuery(Query q)
Allows the manager to set the query that was used to query the system.void
setQueryId(java.lang.String newId)
Sets the query idvoid
setRequest(Request r)
Sets the request.void
setTermProperty(java.lang.String term, double weight)
void
setTermProperty(java.lang.String term, EntryStatistics e)
Sets a term's statistics for the given query term.void
setTermProperty(Operator term, double weight)
Adds a term to the query with a given weight.void
setTermProperty(Operator term, double weight, WeightingModel tsm)
Sets the weight and a term score modifier for the given query term.void
setTermProperty(Operator term, WeightingModel tsm)
Sets a term score modifier for the given query term.void
setTermProperty(Operator term, EntryStatistics e)
java.lang.String
toString()
-
Methods inherited from class java.util.ArrayList
add, addAll, addAll, clear, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
-
-
-
Field Detail
-
queryId
protected java.lang.String queryId
The query ID, if provided
-
rq
protected Request rq
-
numDocsRequest
protected int numDocsRequest
number of documents to request matching provides. -1 means default.
-
defaultTags
protected java.util.Set<java.lang.String> defaultTags
-
defaultWeightingModel
protected WeightingModel defaultWeightingModel
default weighting model for all terms
-
docScoreModifiers
protected java.util.ArrayList<DocumentScoreModifier> docScoreModifiers
The document score modifiers associated with the query terms. It should contain the phrase score modifiers for example.
-
query
protected Query query
The original query as it came from the parser, in case any TSMs or DSMs wish to refer to it
-
-
Constructor Detail
-
MatchingQueryTerms
public MatchingQueryTerms(java.util.Collection<MatchingQueryTerms.MatchingTerm> coll)
-
MatchingQueryTerms
public MatchingQueryTerms()
Generate a MatchingQueryTerms object. Query id will be null.
-
MatchingQueryTerms
public MatchingQueryTerms(java.lang.String qid)
Generate a MatchingQueryTerms object, with the specified query id.- Parameters:
qid
- A string representation of the query id
-
MatchingQueryTerms
public MatchingQueryTerms(java.lang.String qid, Request _rq)
Generate a MatchingQueryTerms object, with the specified query id, and request- Parameters:
qid
- A string representation of the query id_rq
- A request for matching
-
-
Method Detail
-
getRequest
public Request getRequest()
Returns the request.- Returns:
- Request
-
setRequest
public void setRequest(Request r)
Sets the request.
-
getMatchingRequestSize
public int getMatchingRequestSize()
-
setMatchingRequestSize
public void setMatchingRequestSize(int numDocs)
-
addDocumentScoreModifier
public void addDocumentScoreModifier(DocumentScoreModifier dsm)
Adds a document score modifier for the query.- Parameters:
dsm
- DocumentScoreModifier a document score modifier for the query.
-
getDocumentScoreModifiers
public DocumentScoreModifier[] getDocumentScoreModifiers()
Returns the document score modifiers used for the query.- Returns:
- DocumentScoreModifiers[] an array of the registered document score modifiers for the query. If there are no document score modifiers, then it returns null.
-
setQuery
public void setQuery(Query q)
Allows the manager to set the query that was used to query the system.- Parameters:
q
- The Query, duh
-
getQuery
public Query getQuery()
Returns guess what?- Returns:
- the query
-
getQueryId
public java.lang.String getQueryId()
Returns the query id specified when constructing this object.- Returns:
- String query id, or null if none was specified.
-
setQueryId
public void setQueryId(java.lang.String newId)
Sets the query id
-
normaliseTermWeights
public void normaliseTermWeights()
This method normalises the term weights by dividing each term weight by the maximum of the terms.
-
resetTermProperties
public void resetTermProperties()
This method resets query term statistics to allow for a single instance of MatchingQueryTerms to be reused for matching against different indices.
-
setTermProperty
public void setTermProperty(Operator term, EntryStatistics e)
-
setTermProperty
public void setTermProperty(java.lang.String term, EntryStatistics e)
Sets a term's statistics for the given query term.- Parameters:
term
- String the term for which to override the statiticse
- EntryStatistics the term score modifier to apply for the given term.
-
setTermProperty
public void setTermProperty(Operator term, WeightingModel tsm)
Sets a term score modifier for the given query term.- Parameters:
term
- String the term for which to add a term score modifier.tsm
- TermScoreModifier the term score modifier to apply for the given term.
-
setTermProperty
public void setTermProperty(Operator term, double weight, WeightingModel tsm)
Sets the weight and a term score modifier for the given query term.- Parameters:
term
- String the term for which we set the properties.weight
- int the weight of the query term.tsm
- TermScoreModifier the term score modifier applied for the query term.
-
combine
protected MatchingQueryTerms.QueryTermProperties combine(MatchingQueryTerms.QueryTermProperties existingProps, MatchingQueryTerms.QueryTermProperties newProps)
-
add
public boolean add(MatchingQueryTerms.MatchingTerm e)
- Specified by:
add
in interfacejava.util.Collection<MatchingQueryTerms.MatchingTerm>
- Specified by:
add
in interfacejava.util.List<MatchingQueryTerms.MatchingTerm>
- Overrides:
add
in classjava.util.ArrayList<MatchingQueryTerms.MatchingTerm>
-
getTermWeight
public double getTermWeight(Operator term)
Returns the associated weight of the given query term.- Parameters:
term
- String the query term for which the weight is returned.- Returns:
- double the weight of the given query term. If the term is not part of the query, then it returns 0.
-
getTermWeight
public double getTermWeight(java.lang.String term)
-
getTermWeights
public double[] getTermWeights()
Returns the associated weights of the given query terms.- Returns:
- double The weights of the given terms in a double array.
-
getStatistics
public EntryStatistics getStatistics(Operator term)
Returns the assocciated code of the given query term.- Parameters:
term
- String the query term for which the weight is returned.- Returns:
- EntryStatistics the statistics of the term, or null if the term does not appear in the query.
-
getStatistics
public EntryStatistics getStatistics(java.lang.String term)
-
get
public MatchingQueryTerms.QueryTermProperties get(Operator term)
-
get
public java.util.Map.Entry<Operator,MatchingQueryTerms.QueryTermProperties> get(java.lang.String singleTerm)
-
setTermProperty
public void setTermProperty(java.lang.String term, double weight)
-
getMatchingTerms
public Operator[] getMatchingTerms()
Returns the query terms, as they were added to this object.- Returns:
- Query terms in order that they were added to the query. Empty array if object has no query terms added.
-
getTerms
public java.lang.String[] getTerms()
Returns the query terms, as they were added to this object.- Returns:
- Query terms in order that they were added to the query. Empty array if object has no query terms added.
-
getMatchingTerms
public java.util.List<MatchingQueryTerms.MatchingTerm> getMatchingTerms(java.lang.String tag)
-
setTermProperty
public void setTermProperty(Operator term, double weight)
Adds a term to the query with a given weight. If the term already exists, the existing weight is overwritten.- Parameters:
term
- String the term to add.weight
- double the weight of the added term.
-
length
@Deprecated public int length()
Deprecated.Returns the number of unique terms in the query.- Returns:
- int the number of unique terms in the query.
-
clone
public MatchingQueryTerms clone()
Performs a deep clone of this object, and all objects it contains. This allows a MQT to be copied, and changed without affecting the original object.- Overrides:
clone
in classjava.util.ArrayList<MatchingQueryTerms.MatchingTerm>
-
removeTerm
public boolean removeTerm(Operator term)
Remove a term from the list of terms to be matched- Since:
- 3.6
-
setDefaultTermWeightingModel
public void setDefaultTermWeightingModel(WeightingModel weightingModel)
Set the default weighting model to be used for terms that do NOT have an explicit WeightingModel set.
-
addTermPropertyWeight
public void addTermPropertyWeight(java.lang.String term, double d)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractCollection<MatchingQueryTerms.MatchingTerm>
-
-