Documentation ¶
Overview ¶
Package parser parses the query strings inside a search strategy. This package represents the intermediate step between the lexer and ir.
Index ¶
- Variables
- func ReversePreservingCombiningCharacters(s string) string
- type CQRTransformer
- type CochraneLibParser
- type MedlineTransformer
- func (p MedlineTransformer) ConvertInfixToPrefix(infix []string) []string
- func (p MedlineTransformer) IsOperator(s string) bool
- func (p MedlineTransformer) ParseInfixKeywords(line string, fields []string, mapping map[string][]string) ir.BooleanQuery
- func (p MedlineTransformer) TransformFields(fields string, mapping map[string][]string) []string
- func (p MedlineTransformer) TransformNested(query string, mapping map[string][]string) ir.BooleanQuery
- func (p MedlineTransformer) TransformPrefixGroupToQueryGroup(prefix []string, queryGroup ir.BooleanQuery, fields []string, ...) ([]string, ir.BooleanQuery)
- func (p MedlineTransformer) TransformSingle(query string, mapping map[string][]string) ir.Keyword
- type PubMedTransformer
- func (t PubMedTransformer) ConvertInfixToPrefix(infix []string) []string
- func (t PubMedTransformer) IsOperator(s string) bool
- func (t PubMedTransformer) ParseInfixKeywords(line string, mapping map[string][]string) ir.BooleanQuery
- func (t PubMedTransformer) RemoveParenthesis(expr []string) []string
- func (t PubMedTransformer) TransformNested(query string, mapping map[string][]string) ir.BooleanQuery
- func (t PubMedTransformer) TransformPrefixGroupToQueryGroup(prefix []string, queryGroup ir.BooleanQuery, mapping map[string][]string) ([]string, ir.BooleanQuery)
- func (t PubMedTransformer) TransformSingle(query string, mapping map[string][]string) ir.Keyword
- type QueryParser
- type QueryTransformer
Constants ¶
This section is empty.
Variables ¶
var MedlineFieldMapping = map[string][]string{ "ab": {fields.Abstract}, "af": {fields.AllFields}, "ai": {fields.AuthorFull}, "as": {fields.PublicationDate}, "au": {fields.Authors}, "ax": {fields.AuthorLast}, "ba": {fields.Authors}, "bd": {fields.PublicationDate}, "be": {fields.Editor}, "bf": {fields.Authors}, "bk": {fields.AllFields}, "em": {fields.PublicationDate}, "ed": {fields.PublicationDate}, "fa": {fields.AuthorFull}, "fe": {fields.Editor}, "fs": {fields.FloatingMeshHeadings}, "fx": {fields.FloatingMeshHeadings}, "kf": {fields.AllFields}, "ot": {fields.Title}, "mp": {fields.AllFields}, "mh": {fields.MeshHeadings}, "nm": {fields.AllFields}, "px": {fields.MeshHeadings}, "pt": {fields.PublicationType}, "rs": {fields.AllFields}, "rn": {fields.AllFields}, "sb": {fields.PublicationType}, "sh": {fields.MeSHSubheading}, "tw": {fields.TextWord}, "ti": {fields.Title}, "ja": {fields.Journal}, "jn": {fields.Journal}, "jw": {fields.Journal}, "pmid": {fields.PMID}, "ti,ab": {fields.TitleAbstract}, "ti,ab,sh": {fields.AllFields}, "default": {fields.AllFields}, }
var PubMedFieldMapping = map[string][]string{}/* 118 elements not displayed */
Functions ¶
func ReversePreservingCombiningCharacters ¶
ReversePreservingCombiningCharacters interprets its argument as UTF-8 and ignores bytes that do not form valid UTF-8. return value is UTF-8. https://rosettacode.org/wiki/Reverse_a_string#Go
Types ¶
type CQRTransformer ¶
type CQRTransformer struct{}
CQRTransformer is an implementation of a query transformer for CQR queries.
func (CQRTransformer) TransformNested ¶
func (c CQRTransformer) TransformNested(query string, mapping map[string][]string) ir.BooleanQuery
TransformNested takes a JSON string a parses a CQR object into the ir.
func (CQRTransformer) TransformSingle ¶
TransformSingle is unused for this parser.
type CochraneLibParser ¶
type CochraneLibParser struct { }
func (CochraneLibParser) TransformNested ¶
func (CochraneLibParser) TransformNested(query string, mapping map[string][]string) ir.BooleanQuery
func (CochraneLibParser) TransformSingle ¶
type MedlineTransformer ¶
type MedlineTransformer struct{}
MedlineTransformer is an implementation of a QueryTransformer in the parser package.
func (MedlineTransformer) ConvertInfixToPrefix ¶
func (p MedlineTransformer) ConvertInfixToPrefix(infix []string) []string
ConvertInfixToPrefix translates an infix grouping expression into a prefix expression. The way this is done is the Shunting-yard algorithm (https://en.wikipedia.org/wiki/Shunting-yard_algorithm).
func (MedlineTransformer) IsOperator ¶
func (p MedlineTransformer) IsOperator(s string) bool
IsOperator tests to see if a string is a valid PubMed/Medline operator.
func (MedlineTransformer) ParseInfixKeywords ¶
func (p MedlineTransformer) ParseInfixKeywords(line string, fields []string, mapping map[string][]string) ir.BooleanQuery
ParseInfixKeywords parses an infix expression containing keywords separated by operators into an infix expression, and then into the immediate representation.
func (MedlineTransformer) TransformFields ¶
func (p MedlineTransformer) TransformFields(fields string, mapping map[string][]string) []string
TransformFields maps a string of fields into a slice of mapped fields.
func (MedlineTransformer) TransformNested ¶
func (p MedlineTransformer) TransformNested(query string, mapping map[string][]string) ir.BooleanQuery
TransformNested implements the transformation of a nested query.
func (MedlineTransformer) TransformPrefixGroupToQueryGroup ¶
func (p MedlineTransformer) TransformPrefixGroupToQueryGroup(prefix []string, queryGroup ir.BooleanQuery, fields []string, mapping map[string][]string) ([]string, ir.BooleanQuery)
transformPrefixGroupToQueryGroup transforms a prefix syntax tree into a query group. The new QueryGroup is built by recursively navigating the syntax tree.
func (MedlineTransformer) TransformSingle ¶
TransformSingle implements the transformation of a single, stand-alone query. This is called from TransformNested to transform the inner queries.
type PubMedTransformer ¶
type PubMedTransformer struct{}
func (PubMedTransformer) ConvertInfixToPrefix ¶
func (t PubMedTransformer) ConvertInfixToPrefix(infix []string) []string
ConvertInfixToPrefix translates an infix grouping expression into a prefix expression. The way this is done is the Shunting-yard algorithm (https://en.wikipedia.org/wiki/Shunting-yard_algorithm).
func (PubMedTransformer) IsOperator ¶
func (t PubMedTransformer) IsOperator(s string) bool
IsOperator tests to see if a string is a valid PubMed/Medline operator.
func (PubMedTransformer) ParseInfixKeywords ¶
func (t PubMedTransformer) ParseInfixKeywords(line string, mapping map[string][]string) ir.BooleanQuery
ParseInfixKeywords parses an infix expression containing keywords separated by operators into an infix expression, and then into the immediate representation.
func (PubMedTransformer) RemoveParenthesis ¶
func (t PubMedTransformer) RemoveParenthesis(expr []string) []string
func (PubMedTransformer) TransformNested ¶
func (t PubMedTransformer) TransformNested(query string, mapping map[string][]string) ir.BooleanQuery
func (PubMedTransformer) TransformPrefixGroupToQueryGroup ¶
func (t PubMedTransformer) TransformPrefixGroupToQueryGroup(prefix []string, queryGroup ir.BooleanQuery, mapping map[string][]string) ([]string, ir.BooleanQuery)
transformPrefixGroupToQueryGroup transforms a prefix syntax tree into a query group. The new QueryGroup is built by recursively navigating the syntax tree.
func (PubMedTransformer) TransformSingle ¶
type QueryParser ¶
type QueryParser struct { // FieldMapping determines how fields are mapped for a query. FieldMapping map[string][]string // Parser is an implemented QueryTransformer. Parser QueryTransformer }
QueryParser represents the full implementation of a query parser.
func NewCQRParser ¶
func NewCQRParser() QueryParser
NewCQRParser creates a new parser for CQR queries. This parser makes a lot of assumptions as it assumes the structure of this query is perfect.
func NewMedlineParser ¶
func NewMedlineParser() QueryParser
func NewPubMedParser ¶
func NewPubMedParser() QueryParser
func (QueryParser) Parse ¶
func (q QueryParser) Parse(ast lexer.Node) ir.BooleanQuery
Parse takes an AST created from lexing a query and parses each node in it. It uses the TransformNested and TransformSingle functions defined by the Parser and the Field mapping to create an immediate representation tree.
type QueryTransformer ¶
type QueryTransformer interface { // TransformSingle transforms a single query string. TransformSingle(query string, mapping map[string][]string) ir.Keyword // TransformNested transforms a nested query - queries that start with a `(`. TransformNested(query string, mapping map[string][]string) ir.BooleanQuery }
QueryTransformer must be implemented to parse queries.