Documentation ¶
Overview ¶
Package rewrite uses query chains to rewrite queries.
Index ¶
- Constants
- Variables
- func DriftStoppingCondition(depth int, candidates []CandidateQuery) bool
- func NearestNeighbourDepth(depth int) func(c *NearestNeighbourQueryCandidateSelector)
- func NearestNeighbourLoadModel(file string) func(c *NearestNeighbourQueryCandidateSelector)
- func NearestNeighbourModelName(file string) func(c *NearestNeighbourQueryCandidateSelector)
- func NearestNeighbourStatisticsSource(s stats.StatisticsSource) func(c *NearestNeighbourQueryCandidateSelector)
- func QuickRankCandidateSelectorMaxDepth(d int) func(c *QuickRankQueryCandidateSelector)
- func QuickRankCandidateSelectorStatisticsSource(s stats.StatisticsSource) func(c *QuickRankQueryCandidateSelector)
- type BooleanTransformer
- type BreadthFirstExplorer
- type BreadthFirstStoppingCondition
- type CandidateQuery
- func BalancedScoredStrategy(candidates []ScoredCandidateQuery, _ map[string]map[string]float64, N int, ...) []CandidateQuery
- func BalancedTransformationStrategy(candidates []CandidateQuery, N int) []CandidateQuery
- func NegativeBiasScoredStrategy(candidates []ScoredCandidateQuery, scores map[string]map[string]float64, N int, ...) []CandidateQuery
- func NewCandidateQuery(query cqr.CommonQueryRepresentation, topic string, ff Features) CandidateQuery
- func PositiveBiasScoredStrategy(candidates []ScoredCandidateQuery, scores map[string]map[string]float64, N int, ...) []CandidateQuery
- func RankedGreedyStrategy(candidates []GreedyCandidateQuery, N int) []CandidateQuery
- func StratifiedScoredStrategy(candidates []ScoredCandidateQuery, scores map[string]map[string]float64, N int, ...) []CandidateQuery
- func StratifiedTransformationStrategy(candidates []CandidateQuery, N int) []CandidateQuery
- func Variations(query CandidateQuery, ss stats.StatisticsSource, ...) ([]CandidateQuery, error)
- type ClusterSampler
- type DepthFirstExplorer
- type DepthFirstSamplingCriteria
- func BalancedEvaluationSamplingCriteria(measure eval.Evaluator, scores map[string]map[string]float64, ...) DepthFirstSamplingCriteria
- func BalancedTransformationSamplingCriteria(numTransformations int) DepthFirstSamplingCriteria
- func BiasedTransformationSamplingCriteria() DepthFirstSamplingCriteria
- func NegativeBiasedEvaluationSamplingCriteria(measure eval.Evaluator, scores map[string]map[string]float64, ...) DepthFirstSamplingCriteria
- func PositiveBiasedEvaluationSamplingCriteria(measure eval.Evaluator, scores map[string]map[string]float64, ...) DepthFirstSamplingCriteria
- func ProbabilisticSamplingCriteria(likelihood float64) DepthFirstSamplingCriteria
- type EvaluationSampler
- type Feature
- type FeatureGenerator
- type Features
- type GenerationResult
- type GreedyCandidateQuery
- type GreedySampler
- type GreedyStrategy
- type LearntCandidateQuery
- type LearntFeature
- type Model
- type NearestNeighbourQueryCandidateSelector
- func (u NearestNeighbourQueryCandidateSelector) Output(lf LearntFeature, w io.Writer) error
- func (u NearestNeighbourQueryCandidateSelector) Predict(lf LearntFeature) float64
- func (u NearestNeighbourQueryCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
- func (u NearestNeighbourQueryCandidateSelector) StoppingCriteria() bool
- func (u NearestNeighbourQueryCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
- type OracleQueryChainCandidateSelector
- func (oc OracleQueryChainCandidateSelector) Output(lf LearntFeature, w io.Writer) error
- func (oc OracleQueryChainCandidateSelector) Select(query CandidateQuery, candidates []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
- func (oc OracleQueryChainCandidateSelector) StoppingCriteria() bool
- func (oc OracleQueryChainCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
- type QueryChain
- func NewNearestNeighbourQueryChain(options ...func(c *NearestNeighbourQueryCandidateSelector)) *QueryChain
- func NewQueryChain(selector QueryChainCandidateSelector, ss stats.StatisticsSource, ...) *QueryChain
- func NewQuickRankQueryChain(binary string, arguments map[string]interface{}, ...) *QueryChain
- func NewRankOracleCandidateSelector(ss stats.StatisticsSource, qrels trecresults.QrelsFile, measure eval.Evaluator, ...) *QueryChain
- func NewReinforcementQueryChain() *QueryChain
- type QueryChainCandidateSelector
- type QueryChainGenerationExplorer
- type QuickRankQueryCandidateSelector
- func (QuickRankQueryCandidateSelector) Output(lf LearntFeature, w io.Writer) error
- func (qr QuickRankQueryCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
- func (qr QuickRankQueryCandidateSelector) StoppingCriteria() bool
- func (qr QuickRankQueryCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
- type RandomCandidateSelector
- func (c RandomCandidateSelector) Output(lf LearntFeature, w io.Writer) error
- func (c RandomCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
- func (c RandomCandidateSelector) StoppingCriteria() bool
- func (c RandomCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
- type RandomSampler
- type RankOracleCandidateSelector
- func (RankOracleCandidateSelector) Output(lf LearntFeature, w io.Writer) error
- func (r RankOracleCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
- func (r RankOracleCandidateSelector) StoppingCriteria() bool
- func (RankOracleCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
- type ReinforcementQueryCandidateSelector
- func (ReinforcementQueryCandidateSelector) Output(lf LearntFeature, w io.Writer) error
- func (ReinforcementQueryCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
- func (sel ReinforcementQueryCandidateSelector) StoppingCriteria() bool
- func (ReinforcementQueryCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
- type Sampler
- type ScoredCandidateQuery
- type ScoredStrategy
- type Transformation
- func NewAdjacencyRangeTransformer() Transformation
- func NewAdjacencyReplacementTransformer() Transformation
- func NewClauseRemovalTransformer() Transformation
- func NewFieldRestrictionsTransformer() Transformation
- func NewLogicalOperatorTransformer() Transformation
- func NewMeSHExplosionTransformer() Transformation
- func NewMeshParentTransformer() Transformation
- func Newcui2vecExpansionTransformer(vector cui2vec.Embeddings, mapping cui2vec.Mapping, cache quickumlsrest.Cache, ...) Transformation
- type TransformationContext
- type TransformationSampler
- type TransformationStrategy
- type Transformer
Constants ¶
const ( DepthFeature ClauseTypeFeature // This isn't the operator type, it's the type of the clause (keyword query/Boolean query). ChildrenCountFeature // Transformation-based Features. TransformationTypeFeature LogicalReplacementTypeFeature AdjacencyReplacementFeature AdjacencyDistanceFeature MeshDepthFeature MeshParentFeature RestrictionTypeFeature ClauseRemovalFeature Cui2vecExpansionFeature Cui2vecNumExpansionsFeature // Keyword specific Features. IsExplodedFeature IsTruncatedFeature NumFieldsFeature // Boolean specific Features. OperatorTypeFeature // Protocol Query Type (when generated automatically from a protocol). ProtocolQueryTypeFeature )
const ( LogicalOperatorTransformation = iota AdjacencyRangeTransformation MeshExplosionTransformation FieldRestrictionsTransformation AdjacencyReplacementTransformation ClauseRemovalTransformation Cui2vecExpansionTransformation MeshParentTransformation )
Variables ¶
var ChainFeatures = chainFeatures + len(MeasurementFeatureKeys)*2
Chain of transformations !!THIS MUST BE THE LAST FEATURE IN THE LIST!!
var ComputeFeatures = true
var MeasurementFeatureKeys = map[string]int{ analysis.BooleanFields.Name(): measurementFeatures, analysis.BooleanClauses.Name(): measurementFeatures + 1, analysis.BooleanKeywords.Name(): measurementFeatures + 2, analysis.BooleanTruncated.Name(): measurementFeatures + 3, preqpp.RetrievalSize.Name(): measurementFeatures + 4, preqpp.QueryScope.Name(): measurementFeatures + 5, analysis.MeshKeywordCount.Name(): measurementFeatures + 6, analysis.MeshExplodedCount.Name(): measurementFeatures + 7, analysis.MeshNonExplodedCount.Name(): measurementFeatures + 8, analysis.MeshAvgDepth.Name(): measurementFeatures + 9, analysis.MeshMaxDepth.Name(): measurementFeatures + 10, analysis.BooleanNonAtomicClauses.Name(): measurementFeatures + 11, analysis.BooleanAndCount.Name(): measurementFeatures + 12, analysis.BooleanOrCount.Name(): measurementFeatures + 13, analysis.BooleanNotCount.Name(): measurementFeatures + 14, analysis.BooleanFieldsTitle.Name(): measurementFeatures + 15, analysis.BooleanFieldsAbstract.Name(): measurementFeatures + 16, analysis.BooleanFieldsMeSH.Name(): measurementFeatures + 17, analysis.BooleanFieldsOther.Name(): measurementFeatures + 18, analysis.TermCount.Name(): measurementFeatures + 19, }
MeasurementFeatureKeys contains a mapping of applicable measurement to a feature.
var (
NNFeaturesN = ChainFeatures
)
Functions ¶
func DriftStoppingCondition ¶
func DriftStoppingCondition(depth int, candidates []CandidateQuery) bool
DriftStoppingCondition TODO
func NearestNeighbourDepth ¶
func NearestNeighbourDepth(depth int) func(c *NearestNeighbourQueryCandidateSelector)
func NearestNeighbourLoadModel ¶
func NearestNeighbourLoadModel(file string) func(c *NearestNeighbourQueryCandidateSelector)
func NearestNeighbourModelName ¶
func NearestNeighbourModelName(file string) func(c *NearestNeighbourQueryCandidateSelector)
func NearestNeighbourStatisticsSource ¶
func NearestNeighbourStatisticsSource(s stats.StatisticsSource) func(c *NearestNeighbourQueryCandidateSelector)
func QuickRankCandidateSelectorMaxDepth ¶
func QuickRankCandidateSelectorMaxDepth(d int) func(c *QuickRankQueryCandidateSelector)
func QuickRankCandidateSelectorStatisticsSource ¶
func QuickRankCandidateSelectorStatisticsSource(s stats.StatisticsSource) func(c *QuickRankQueryCandidateSelector)
Types ¶
type BooleanTransformer ¶
type BooleanTransformer interface {
BooleanFeatures(query cqr.CommonQueryRepresentation, context TransformationContext) []Features
}
type BreadthFirstExplorer ¶
type BreadthFirstExplorer struct { Sampler BreadthFirstStoppingCondition // contains filtered or unexported fields }
BreadthFirstExplorer explores the space of candidates breadth-first. It generates a set of variations for each candidate query, and pools these together to be sampled.
func NewBreadthFirstExplorer ¶
func NewBreadthFirstExplorer(chain *QueryChain, sampler Sampler, condition BreadthFirstStoppingCondition) BreadthFirstExplorer
func (BreadthFirstExplorer) Traverse ¶
func (e BreadthFirstExplorer) Traverse(candidate CandidateQuery, c chan GenerationResult)
type BreadthFirstStoppingCondition ¶
type BreadthFirstStoppingCondition func(depth int, candidates []CandidateQuery) bool
BreadthFirstStoppingCondition controls at what depth in the chain the breadth-first explorer should stop.
func DepthStoppingCondition ¶
func DepthStoppingCondition(d int) BreadthFirstStoppingCondition
DepthStoppingCondition uses the depth of the chain to determine when to stop.
type CandidateQuery ¶
type CandidateQuery struct { TransformationID int Topic string Query cqr.CommonQueryRepresentation Chain []CandidateQuery Features }
CandidateQuery is a possible transformation a query can take.
func BalancedScoredStrategy ¶
func BalancedScoredStrategy(candidates []ScoredCandidateQuery, _ map[string]map[string]float64, N int, _ eval.Evaluator) []CandidateQuery
func BalancedTransformationStrategy ¶
func BalancedTransformationStrategy(candidates []CandidateQuery, N int) []CandidateQuery
func NegativeBiasScoredStrategy ¶
func NegativeBiasScoredStrategy(candidates []ScoredCandidateQuery, scores map[string]map[string]float64, N int, measurement eval.Evaluator) []CandidateQuery
NegativeBiasScoredStrategy samples up to N candidates that are worse than the comparison score in `scores`.
func NewCandidateQuery ¶
func NewCandidateQuery(query cqr.CommonQueryRepresentation, topic string, ff Features) CandidateQuery
NewCandidateQuery creates a new candidate query.
func PositiveBiasScoredStrategy ¶
func PositiveBiasScoredStrategy(candidates []ScoredCandidateQuery, scores map[string]map[string]float64, N int, measurement eval.Evaluator) []CandidateQuery
PositiveBiasScoredStrategy samples up to N candidates that improve over the comparison score in `scores`.
func RankedGreedyStrategy ¶
func RankedGreedyStrategy(candidates []GreedyCandidateQuery, N int) []CandidateQuery
func StratifiedScoredStrategy ¶
func StratifiedScoredStrategy(candidates []ScoredCandidateQuery, scores map[string]map[string]float64, N int, measurement eval.Evaluator) []CandidateQuery
func StratifiedTransformationStrategy ¶
func StratifiedTransformationStrategy(candidates []CandidateQuery, N int) []CandidateQuery
func Variations ¶
func Variations(query CandidateQuery, ss stats.StatisticsSource, me analysis.MeasurementExecutor, measurements []analysis.Measurement, transformations ...Transformation) ([]CandidateQuery, error)
Variations creates query variations of the input query using the specified transformations. Permute will only generate query variations that modify the query in one single place. This means that no transformation is applied twice to an already modified query.
func (CandidateQuery) Append ¶
func (c CandidateQuery) Append(query CandidateQuery) CandidateQuery
Append adds the previous query to the chain of transformations so far so we can keep track of which transformations have been applied up until this point, and for Features about the query.
func (CandidateQuery) SetTransformationID ¶
func (c CandidateQuery) SetTransformationID(id int) CandidateQuery
SetTransformationID sets the transformation id to the candidate query.
type ClusterSampler ¶
type ClusterSampler struct {
// contains filtered or unexported fields
}
func NewClusterSampler ¶
func NewClusterSampler(n int, delta float64, k int) ClusterSampler
func (ClusterSampler) Sample ¶
func (s ClusterSampler) Sample(candidates []CandidateQuery) ([]CandidateQuery, error)
type DepthFirstExplorer ¶
type DepthFirstExplorer struct { DepthFirstSamplingCriteria // contains filtered or unexported fields }
DepthFirstExplorer explores the query space depth-first. It traverses one query at a time, backtracking further if necessary. The breadth-first approach uses two conditions to control (1) when the explorer should stop and backtrack, and (2) when a query should be sampled.
func NewDepthFirstExplorer ¶
func NewDepthFirstExplorer(chain *QueryChain, sampling DepthFirstSamplingCriteria, budget int) DepthFirstExplorer
func (DepthFirstExplorer) Traverse ¶
func (e DepthFirstExplorer) Traverse(query CandidateQuery, c chan GenerationResult)
type DepthFirstSamplingCriteria ¶
type DepthFirstSamplingCriteria func(query CandidateQuery) bool
ExplorationSamplingCriteria controls when the explorer should sample a query.
func BalancedEvaluationSamplingCriteria ¶
func BalancedEvaluationSamplingCriteria(measure eval.Evaluator, scores map[string]map[string]float64, chain *QueryChain) DepthFirstSamplingCriteria
PositiveBiasedEvaluationSamplingCriteria samples using an evaluation measure to determine if the candidate query improves over the seed query for that measure.
func BalancedTransformationSamplingCriteria ¶
func BalancedTransformationSamplingCriteria(numTransformations int) DepthFirstSamplingCriteria
BalancedTransformationSamplingCriteria ensures the candidate query potentially being sampled has approximately equal transformations applied to it.
func BiasedTransformationSamplingCriteria ¶
func BiasedTransformationSamplingCriteria() DepthFirstSamplingCriteria
BiasedTransformationSamplingCriteria samples candidate queries when all of the transformations applied to a query are the same.
func NegativeBiasedEvaluationSamplingCriteria ¶
func NegativeBiasedEvaluationSamplingCriteria(measure eval.Evaluator, scores map[string]map[string]float64, chain *QueryChain) DepthFirstSamplingCriteria
NegativeBiasedEvaluationSamplingCriteria samples using an evaluation measure to determine if the candidate query is worse than the seed query for that measure.
func PositiveBiasedEvaluationSamplingCriteria ¶
func PositiveBiasedEvaluationSamplingCriteria(measure eval.Evaluator, scores map[string]map[string]float64, chain *QueryChain) DepthFirstSamplingCriteria
PositiveBiasedEvaluationSamplingCriteria samples using an evaluation measure to determine if the candidate query improves over the seed query for that measure.
func ProbabilisticSamplingCriteria ¶
func ProbabilisticSamplingCriteria(likelihood float64) DepthFirstSamplingCriteria
ProbabilisticSamplingCriteria samples queries using a likelihood.
type EvaluationSampler ¶
type EvaluationSampler struct { ScoredStrategy // contains filtered or unexported fields }
EvaluationSampler samples candidate queries based on some evaluation measure. It uses stratified sampling by ensuring a minimum of n candidates are sampled, plus an additional delta-%.
func NewEvaluationSampler ¶
func NewEvaluationSampler(n int, delta float64, measure eval.Evaluator, chain *QueryChain, scores map[string]map[string]float64, strategy ScoredStrategy) EvaluationSampler
func (EvaluationSampler) Sample ¶
func (s EvaluationSampler) Sample(candidates []CandidateQuery) ([]CandidateQuery, error)
type Feature ¶
Feature is some value that is applicable to a query transformation.
func NewFeature ¶
NewFeature creates a new feature with the specified ID and `Score`.
type FeatureGenerator ¶
type FeatureGenerator interface {
Generate() error
}
FeatureGenerator models a way for Features to be generated for a machine learning task that may be used by a Model.
type Features ¶
type Features []Feature
Features is the group of Features used to learn or predict a Score.
func (Features) AverageScore ¶
AverageScore compute the average Feature Score for a group of Features.
type GenerationResult ¶
type GenerationResult struct { CandidateQuery // contains filtered or unexported fields }
type GreedyCandidateQuery ¶
type GreedyCandidateQuery struct { CandidateQuery // contains filtered or unexported fields }
ScoredCandidateQuery contains a candidate query and some Score.
type GreedySampler ¶
type GreedySampler struct { GreedyStrategy // contains filtered or unexported fields }
GreedySampler samples candidate queries based on both the number of retrieved documents and some evaluation measure. It uses stratified sampling by ensuring a minimum of n candidates are sampled, plus an additional delta-%.
func NewGreedySampler ¶
func NewGreedySampler(n int, delta float64, measure eval.Evaluator, chain *QueryChain, strategy GreedyStrategy) GreedySampler
func (GreedySampler) Sample ¶
func (s GreedySampler) Sample(candidates []CandidateQuery) ([]CandidateQuery, error)
type GreedyStrategy ¶
type GreedyStrategy func(candidates []GreedyCandidateQuery, N int) []CandidateQuery
type LearntCandidateQuery ¶
type LearntCandidateQuery struct { Topic int64 `json:"topic"` Depth int64 `json:"Depth"` Candidate CandidateQuery `json:"candidate"` Eval map[string]float64 `json:"eval"` }
LearntCandidateQuery is the serialised struct written from the oracle query chain candidate selector.
type LearntFeature ¶
LearntFeature contains the Features that were used to produce a particular Score.
func LoadFeatures ¶
func LoadFeatures(reader io.Reader) ([]LearntFeature, error)
func LoadReinforcementFeatures ¶
func LoadReinforcementFeatures(reader io.Reader) ([]LearntFeature, error)
func NewLearntFeature ¶
func NewLearntFeature(features Features) LearntFeature
NewLearntFeature creates a new learnt feature with a Score and a set of Features.
func (LearntFeature) WriteLibSVM ¶
func (lf LearntFeature) WriteLibSVM(writer io.Writer, comment ...interface{}) (int, error)
WriteLibSVM writes a LIBSVM compatible line to a writer.
func (LearntFeature) WriteLibSVMRank ¶
func (lf LearntFeature) WriteLibSVMRank(writer io.Writer) (int, error)
WriteLibSVMRank writes a LIBSVM^rank compatible line to a writer.
type Model ¶
type Model interface { // Train must train a model. Train() error // Validate must (optionally) validate the model. Validate() error // Test must test the model to produce some output. Test() error // Generate Features for learning. Generate() error }
Model is an abstract representation of a machine learning model that can perform a training and a testing task. Optionally, the model may also have a validation task. Additionally, a model must implement how Features for training are generated.
type NearestNeighbourQueryCandidateSelector ¶
type NearestNeighbourQueryCandidateSelector struct {
// contains filtered or unexported fields
}
func NewNearestNeighbourCandidateSelector ¶
func NewNearestNeighbourCandidateSelector(options ...func(c *NearestNeighbourQueryCandidateSelector)) NearestNeighbourQueryCandidateSelector
func (NearestNeighbourQueryCandidateSelector) Output ¶
func (u NearestNeighbourQueryCandidateSelector) Output(lf LearntFeature, w io.Writer) error
func (NearestNeighbourQueryCandidateSelector) Predict ¶
func (u NearestNeighbourQueryCandidateSelector) Predict(lf LearntFeature) float64
func (NearestNeighbourQueryCandidateSelector) Select ¶
func (u NearestNeighbourQueryCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
func (NearestNeighbourQueryCandidateSelector) StoppingCriteria ¶
func (u NearestNeighbourQueryCandidateSelector) StoppingCriteria() bool
func (NearestNeighbourQueryCandidateSelector) Train ¶
func (u NearestNeighbourQueryCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
type OracleQueryChainCandidateSelector ¶
type OracleQueryChainCandidateSelector struct {
// contains filtered or unexported fields
}
OracleQueryChainCandidateSelector finds the best possible combination of query rewrites.
func NewOracleQueryChainCandidateSelector ¶
func NewOracleQueryChainCandidateSelector(source stats.StatisticsSource, file trecresults.QrelsFile, cache combinator.QueryCacher) OracleQueryChainCandidateSelector
NewOracleQueryChainCandidateSelector creates a new oracle query chain candidate selector.
func (OracleQueryChainCandidateSelector) Output ¶
func (oc OracleQueryChainCandidateSelector) Output(lf LearntFeature, w io.Writer) error
func (OracleQueryChainCandidateSelector) Select ¶
func (oc OracleQueryChainCandidateSelector) Select(query CandidateQuery, candidates []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
Select is a grid search for the best possible query transformation chain.
func (OracleQueryChainCandidateSelector) StoppingCriteria ¶
func (oc OracleQueryChainCandidateSelector) StoppingCriteria() bool
StoppingCriteria defines stopping criteria.
func (OracleQueryChainCandidateSelector) Train ¶
func (oc OracleQueryChainCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
type QueryChain ¶
type QueryChain struct { Transformations []Transformation Measurements []analysis.Measurement CandidateSelector QueryChainCandidateSelector StatisticsSource stats.StatisticsSource MeasurementExecutor analysis.MeasurementExecutor Queries []pipeline.Query TransformedOutput string LearntFeatures []LearntFeature GenerationFile string Evaluators []eval.Evaluator QueryCacher combinator.QueryCacher QrelsFile trecresults.QrelsFile GenerationExplorer QueryChainGenerationExplorer ComputeFeatures bool }
QueryChain contains implementations for transformations to apply to a query and the selector to pick a candidate.
func NewNearestNeighbourQueryChain ¶
func NewNearestNeighbourQueryChain(options ...func(c *NearestNeighbourQueryCandidateSelector)) *QueryChain
func NewQueryChain ¶
func NewQueryChain(selector QueryChainCandidateSelector, ss stats.StatisticsSource, me analysis.MeasurementExecutor, measurements []analysis.Measurement, transformations ...Transformation) *QueryChain
NewQueryChain creates a new query chain with implementations for a selector and transformations.
func NewQuickRankQueryChain ¶
func NewQuickRankQueryChain(binary string, arguments map[string]interface{}, options ...func(c *QuickRankQueryCandidateSelector)) *QueryChain
func NewRankOracleCandidateSelector ¶
func NewRankOracleCandidateSelector(ss stats.StatisticsSource, qrels trecresults.QrelsFile, measure eval.Evaluator, maxDepth int) *QueryChain
func NewReinforcementQueryChain ¶
func NewReinforcementQueryChain() *QueryChain
func (*QueryChain) Execute ¶
func (qc *QueryChain) Execute(q pipeline.Query) (CandidateQuery, error)
Execute executes a query chain in full. At each "transition point" in the chain, the candidate selector is queried in order to see if the chain should continue or not. At the end of the chain, the selector is cleaned using the finalise method.
func (*QueryChain) Generate ¶
func (qc *QueryChain) Generate() error
Generate will create test data sampling using random stratified sampling.
func (*QueryChain) Test ¶
func (qc *QueryChain) Test() error
func (*QueryChain) Train ¶
func (qc *QueryChain) Train() error
Train hands off the training to the candidate selector.
func (*QueryChain) Validate ¶
func (qc *QueryChain) Validate() error
type QueryChainCandidateSelector ¶
type QueryChainCandidateSelector interface { Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error) Train(lfs []LearntFeature) ([]byte, error) Output(lf LearntFeature, w io.Writer) error StoppingCriteria() bool }
QueryChainCandidateSelector describes how transformed queries are chosen from the set of transformations.
type QueryChainGenerationExplorer ¶
type QueryChainGenerationExplorer interface {
Traverse(seed CandidateQuery, c chan GenerationResult)
}
QueryChainGenerationExplorer explores the space of candidate queries from an initial "seed" query, sending results through the supplied channel as it explores the possible space of queries. Note that the implementations of an explorer must provide the facility for sampling, as the method of sampling may apply to different methods of traversal.
type QuickRankQueryCandidateSelector ¶
type QuickRankQueryCandidateSelector struct {
// contains filtered or unexported fields
}
func NewQuickRankQueryCandidateSelector ¶
func NewQuickRankQueryCandidateSelector(binary string, arguments map[string]interface{}, args ...func(c *QuickRankQueryCandidateSelector)) QuickRankQueryCandidateSelector
func (QuickRankQueryCandidateSelector) Output ¶
func (QuickRankQueryCandidateSelector) Output(lf LearntFeature, w io.Writer) error
func (QuickRankQueryCandidateSelector) Select ¶
func (qr QuickRankQueryCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
func (QuickRankQueryCandidateSelector) StoppingCriteria ¶
func (qr QuickRankQueryCandidateSelector) StoppingCriteria() bool
func (QuickRankQueryCandidateSelector) Train ¶
func (qr QuickRankQueryCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
type RandomCandidateSelector ¶
type RandomCandidateSelector struct {
// contains filtered or unexported fields
}
func NewRandomCandidateSelector ¶
func NewRandomCandidateSelector() RandomCandidateSelector
func (RandomCandidateSelector) Output ¶
func (c RandomCandidateSelector) Output(lf LearntFeature, w io.Writer) error
func (RandomCandidateSelector) Select ¶
func (c RandomCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
func (RandomCandidateSelector) StoppingCriteria ¶
func (c RandomCandidateSelector) StoppingCriteria() bool
func (RandomCandidateSelector) Train ¶
func (c RandomCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
type RandomSampler ¶
type RandomSampler struct {
// contains filtered or unexported fields
}
RandomSampler samples candidates randomly. It will reduce the candidates to delta-% and sample at least n candidates (if there are at least n to sample from).
func NewRandomSampler ¶
func NewRandomSampler(n int, delta float64) RandomSampler
func (RandomSampler) Sample ¶
func (s RandomSampler) Sample(candidates []CandidateQuery) ([]CandidateQuery, error)
type RankOracleCandidateSelector ¶
type RankOracleCandidateSelector struct {
// contains filtered or unexported fields
}
func (RankOracleCandidateSelector) Output ¶
func (RankOracleCandidateSelector) Output(lf LearntFeature, w io.Writer) error
func (RankOracleCandidateSelector) Select ¶
func (r RankOracleCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
func (RankOracleCandidateSelector) StoppingCriteria ¶
func (r RankOracleCandidateSelector) StoppingCriteria() bool
func (RankOracleCandidateSelector) Train ¶
func (RankOracleCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
type ReinforcementQueryCandidateSelector ¶
type ReinforcementQueryCandidateSelector struct { Depth int // contains filtered or unexported fields }
func (ReinforcementQueryCandidateSelector) Output ¶
func (ReinforcementQueryCandidateSelector) Output(lf LearntFeature, w io.Writer) error
func (ReinforcementQueryCandidateSelector) Select ¶
func (ReinforcementQueryCandidateSelector) Select(query CandidateQuery, transformations []CandidateQuery) (CandidateQuery, QueryChainCandidateSelector, error)
func (ReinforcementQueryCandidateSelector) StoppingCriteria ¶
func (sel ReinforcementQueryCandidateSelector) StoppingCriteria() bool
func (ReinforcementQueryCandidateSelector) Train ¶
func (ReinforcementQueryCandidateSelector) Train(lfs []LearntFeature) ([]byte, error)
type Sampler ¶
type Sampler interface {
Sample(candidates []CandidateQuery) ([]CandidateQuery, error)
}
type ScoredCandidateQuery ¶
type ScoredCandidateQuery struct { CandidateQuery Score float64 }
ScoredCandidateQuery contains a candidate query and some Score.
type ScoredStrategy ¶
type ScoredStrategy func(candidates []ScoredCandidateQuery, scores map[string]map[string]float64, N int, measurement eval.Evaluator) []CandidateQuery
ScoredStrategy samples scored candidates.
func MaximalMarginalRelevanceScoredStrategy ¶
func MaximalMarginalRelevanceScoredStrategy(lambda float64, similarity func(x, y []float64) (float64, error)) ScoredStrategy
MaximalMarginalRelevanceScoredStrategy samples candidates according to a diversity-based strategy. Diversity functions commonly employ a notion of sim(d,q) where d is a document and q is a query. In this case (diversifying queries), this is replaced with the evaluation score of a query (for a particular evaluation measure). The sim(q1,q2) - i.e., the similarity between two queries, remains the same. Queries are sampled according to Maximal Marginal Relevance (Carbonell '98).
type Transformation ¶
type Transformation struct { ID int Transformer BooleanTransformer }
Transformation is the implementation of a transformer.
func NewAdjacencyRangeTransformer ¶
func NewAdjacencyRangeTransformer() Transformation
NewAdjacencyRangeTransformer creates an adjacency range transformation.
func NewAdjacencyReplacementTransformer ¶
func NewAdjacencyReplacementTransformer() Transformation
NewAdjacencyReplacementTransformer creates an adjacency replacement transformer.
func NewClauseRemovalTransformer ¶
func NewClauseRemovalTransformer() Transformation
NewClauseRemovalTransformer creates a clause removal transformer.
func NewFieldRestrictionsTransformer ¶
func NewFieldRestrictionsTransformer() Transformation
NewFieldRestrictionsTransformer creates a field restrictions transformer.
func NewLogicalOperatorTransformer ¶
func NewLogicalOperatorTransformer() Transformation
NewLogicalOperatorTransformer creates a logical operator transformation.
func NewMeSHExplosionTransformer ¶
func NewMeSHExplosionTransformer() Transformation
NewMeSHExplosionTransformer creates a mesh explosion transformer.
func NewMeshParentTransformer ¶
func NewMeshParentTransformer() Transformation
func Newcui2vecExpansionTransformer ¶
func Newcui2vecExpansionTransformer(vector cui2vec.Embeddings, mapping cui2vec.Mapping, cache quickumlsrest.Cache, source ...stats.EntrezStatisticsSource) Transformation
NewClauseRemovalTransformer creates a clause removal transformer.
type TransformationContext ¶
TransformationContext is the context under a transformation is applied.
func (TransformationContext) AddDepth ¶
func (t TransformationContext) AddDepth(d float64) TransformationContext
AddDepth increases the depth of the transformation.
func (TransformationContext) SetChildrenCount ¶
func (t TransformationContext) SetChildrenCount(v float64) TransformationContext
SetChildrenCount sets the number of children a clause has.
func (TransformationContext) SetClauseType ¶
func (t TransformationContext) SetClauseType(v float64) TransformationContext
SetClauseType sets the type of clause (boolean/keyword).
type TransformationSampler ¶
type TransformationSampler struct { TransformationStrategy // contains filtered or unexported fields }
TransformationSampler samples candidate queries based on the transformation that was applied. It uses stratified sampling by ensuring a minimum of n candidates are sampled, plus an additional delta-%.
func NewTransformationSampler ¶
func NewTransformationSampler(n int, delta float64, strategy TransformationStrategy) TransformationSampler
func (TransformationSampler) Sample ¶
func (s TransformationSampler) Sample(candidates []CandidateQuery) ([]CandidateQuery, error)
type TransformationStrategy ¶
type TransformationStrategy func(candidates []CandidateQuery, N int) []CandidateQuery
TransformationStrategy samples candidates using a transformation strategy.
type Transformer ¶
type Transformer interface { Apply(query cqr.CommonQueryRepresentation) (queries []cqr.CommonQueryRepresentation, err error) BooleanApplicable() bool Features(query cqr.CommonQueryRepresentation, context TransformationContext) Features Name() string }
Transformer is applied to a query to generate a set of query candidates.