Class SimpleParser
- java.lang.Object
-
- it.unimi.di.big.mg4j.query.parser.SimpleParser
-
- All Implemented Interfaces:
QueryParser,SimpleParserConstants,FlyweightPrototype<QueryParser>
public class SimpleParser extends Object implements QueryParser, SimpleParserConstants
A simple parser that transform a query string into a query.The parser supports multiple indices. You must provide a set of index aliases that the user will use to select indices, and the name of the default index alias to be used. After that, you parse a query by using the
parse(String)method.The parser generated by JavaCC for this class will break terms using operators and nonspace-to-space transitions. Operators can be included in terms, if needed, using the backslash, which acts as an escape character, and makes the next character (usually an operator) a standard character. The syntax of the parser can be seen in action in the documentation of the package
it.unimi.di.big.mg4j.search.The parser returns a
Query—an abstract representation of the query string that can be turned later into aDocumentIterator.If a
TermProcessoris specified, it will be applied to the terms found in the query string. This can lead to transformations (e.g., downcasing) or generate an exception if the query string contains terms filtered by the term processor.- Since:
- 1.0.1
- Author:
- Sebastiano Vigna, Paolo Boldi
-
-
Field Summary
Fields Modifier and Type Field Description StringdefaultIndexThe default index alias.Set<String>indicesThe set of index aliases.Tokenjj_ntNext token.Map<String,? extends TermProcessor>termProcessorsThe term processor for each index.TokentokenCurrent token.SimpleParserTokenManagertoken_sourceGenerated Token Manager.-
Fields inherited from interface it.unimi.di.big.mg4j.query.parser.SimpleParserConstants
ALIGN, AND, ANNO, CLOSE_ENLARGE, CLOSE_PAREN, CLOSE_RANGE, CLOSE_REMAP, CLOSE_WEIGHT, COLON, DEFAULT, EOF, FALSE, HOLE, INTERVAL_SEPARATOR, LEFTARROW, MINUS, NOT, OAND, OPEN_ENLARGE, OPEN_PAREN, OPEN_RANGE, OPEN_REMAP, OPEN_WEIGHT, OR, PLUS, PREFIX, QUOTE, RIGHTARROW, SEMICOLON, SHARP, TILDA, tokenImage, TRUE, WORD
-
-
Constructor Summary
Constructors Constructor Description SimpleParser()Creates a parser for a single nameless index with no term processing.SimpleParser(TermProcessor termProcessor)Creates a parser for a single nameless index with a given term processor.SimpleParser(SimpleParserTokenManager tm)Constructor with generated Token Manager.SimpleParser(InputStream stream)Constructor with InputStream.SimpleParser(InputStream stream, String encoding)Constructor with InputStream and supplied encodingSimpleParser(Reader stream)Constructor.SimpleParser(Set<String> indices, String defaultIndex)Creates a parser with no term processing.SimpleParser(Set<String> indices, String defaultIndex, Map<String,? extends TermProcessor> termProcessors)Creates a parser.
-
Method Summary
Modifier and Type Method Description QueryalignQuery(String indexAlias)Starting rule for an alignment query.QueryandQuery(String indexAlias)Starting rule for an AND-query (the AND token is optional).QueryatomicQuery(String indexAlias)Starting rule for an atomic query.QueryatomicSimpleQuery(String indexAlias)Starting rule for an atomic simple query.SimpleParsercopy()QuerydifferenceQuery(String indexAlias)Starting rule for a difference query.voiddisable_tracing()Disable tracing.voidenable_tracing()Enable tracing.MutableStringescape(MutableString token)Escapes the provided mutable string, making it into a text token.Stringescape(String token)Escapes the provided string, making it into a text token.ParseExceptiongenerateParseException()Generate ParseException.TokengetNextToken()Get the next Token.TokengetToken(int index)Get the specific Token.QueryinclusionContainmentQuery(String indexAlias)Starting rule for an inclusion/containment query.QuerymultiTermQuery(String indexAlias)Starting rule for a multiterm query.QueryorderedAndQuery(String indexAlias)Starting rule for an AND<-query.QueryorQuery(String indexAlias)Starting rule for a OR-query.Queryparse(MutableString text)Turns the given query mutable string into a compositeQueryobject.Queryparse(String text)Turns the given query string into a compositeQueryobject.Queryquery(String indexAlias)Parser.QueryquotedQuery(String indexAlias)Starting rule for a quoted query.voidReInit(SimpleParserTokenManager tm)Reinitialise.voidReInit(InputStream stream)Reinitialise.voidReInit(InputStream stream, String encoding)Reinitialise.voidReInit(Reader stream)Reinitialise.QueryremappedQuery(String indexAlias)Starting rule for a remapped query.booleantrace_enabled()Trace enabled.
-
-
-
Field Detail
-
defaultIndex
public String defaultIndex
The default index alias.
-
termProcessors
public Map<String,? extends TermProcessor> termProcessors
The term processor for each index.
-
token_source
public SimpleParserTokenManager token_source
Generated Token Manager.
-
token
public Token token
Current token.
-
jj_nt
public Token jj_nt
Next token.
-
-
Constructor Detail
-
SimpleParser
public SimpleParser(Set<String> indices, String defaultIndex, Map<String,? extends TermProcessor> termProcessors)
Creates a parser.- Parameters:
indices- the set of index aliases.defaultIndex- the default index alias to be used when parsing the query.termProcessors- a map from index aliases to the corresponding term processor, ornullfor no term processing.
-
SimpleParser
public SimpleParser(Set<String> indices, String defaultIndex)
Creates a parser with no term processing.- Parameters:
indices- the set of index aliases.defaultIndex- the default index alias to be used when parsing the query.
-
SimpleParser
public SimpleParser()
Creates a parser for a single nameless index with no term processing.Parsers created by this constructor allow only nameless access, both in the query and in the interval-iterator methods.
-
SimpleParser
public SimpleParser(TermProcessor termProcessor)
Creates a parser for a single nameless index with a given term processor.Parsers created by this constructor allow only nameless access, both in the query and in the interval-iterator methods.
-
SimpleParser
public SimpleParser(InputStream stream)
Constructor with InputStream.
-
SimpleParser
public SimpleParser(InputStream stream, String encoding)
Constructor with InputStream and supplied encoding
-
SimpleParser
public SimpleParser(Reader stream)
Constructor.
-
SimpleParser
public SimpleParser(SimpleParserTokenManager tm)
Constructor with generated Token Manager.
-
-
Method Detail
-
copy
public SimpleParser copy()
- Specified by:
copyin interfaceFlyweightPrototype<QueryParser>
-
escape
public String escape(String token)
Description copied from interface:QueryParserEscapes the provided string, making it into a text token.- Specified by:
escapein interfaceQueryParser- Parameters:
token- a wannabe text token (maybe containing special characters, but no character below code 32).- Returns:
- an escaped representation of
tokenthat will be interpreted as a text token by this parser.
-
escape
public MutableString escape(MutableString token)
Description copied from interface:QueryParserEscapes the provided mutable string, making it into a text token.- Specified by:
escapein interfaceQueryParser- Parameters:
token- a wannabe text token (maybe containing special characters, but no character below code 32).- Returns:
token, escaped so that it will be interpreted as a text token by this parser.
-
parse
public Query parse(String text) throws QueryParserException
Description copied from interface:QueryParserTurns the given query string into a compositeQueryobject.- Specified by:
parsein interfaceQueryParser- Parameters:
text- a string representing a query.- Returns:
- the corresponding composite object.
- Throws:
QueryParserException
-
parse
public Query parse(MutableString text) throws QueryParserException
Description copied from interface:QueryParserTurns the given query mutable string into a compositeQueryobject.- Specified by:
parsein interfaceQueryParser- Parameters:
text- a mutable string representing a query.- Returns:
- the corresponding composite object.
- Throws:
QueryParserException
-
query
public final Query query(String indexAlias) throws ParseException
Parser.- Throws:
ParseException
-
remappedQuery
public final Query remappedQuery(String indexAlias) throws ParseException
Starting rule for a remapped query.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
inclusionContainmentQuery
public final Query inclusionContainmentQuery(String indexAlias) throws ParseException
Starting rule for an inclusion/containment query.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
differenceQuery
public final Query differenceQuery(String indexAlias) throws ParseException
Starting rule for a difference query.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
orQuery
public final Query orQuery(String indexAlias) throws ParseException
Starting rule for a OR-query.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
andQuery
public final Query andQuery(String indexAlias) throws ParseException
Starting rule for an AND-query (the AND token is optional).- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
orderedAndQuery
public final Query orderedAndQuery(String indexAlias) throws ParseException
Starting rule for an AND<-query.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
alignQuery
public final Query alignQuery(String indexAlias) throws ParseException
Starting rule for an alignment query.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
multiTermQuery
public final Query multiTermQuery(String indexAlias) throws ParseException
Starting rule for a multiterm query.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
quotedQuery
public final Query quotedQuery(String indexAlias) throws ParseException
Starting rule for a quoted query. Subqueries cannot change index.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
atomicQuery
public final Query atomicQuery(String indexAlias) throws ParseException
Starting rule for an atomic query. May be either an atomic simple query or a quoted query. It can optionally contain an index selector and a low-pass limit.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
atomicSimpleQuery
public final Query atomicSimpleQuery(String indexAlias) throws ParseException
Starting rule for an atomic simple query. May be either a word or a query enclosed within parentheses.- Parameters:
indexAlias- the index alias for the default index to be used for the query that is going to be parsed.- Returns:
- the result of the query.
- Throws:
ParseException
-
ReInit
public void ReInit(InputStream stream)
Reinitialise.
-
ReInit
public void ReInit(InputStream stream, String encoding)
Reinitialise.
-
ReInit
public void ReInit(Reader stream)
Reinitialise.
-
ReInit
public void ReInit(SimpleParserTokenManager tm)
Reinitialise.
-
getNextToken
public final Token getNextToken()
Get the next Token.
-
getToken
public final Token getToken(int index)
Get the specific Token.
-
generateParseException
public ParseException generateParseException()
Generate ParseException.
-
trace_enabled
public final boolean trace_enabled()
Trace enabled.
-
enable_tracing
public final void enable_tracing()
Enable tracing.
-
disable_tracing
public final void disable_tracing()
Disable tracing.
-
-