Invenio-Query-Parser¶
Search query parser supporting Invenio and SPIRES search syntax.
Contents¶
Installation¶
Invenio-Query-Parser is on PyPI so all you need is:
$ pip install invenio-query-parser
Usage¶
The easiest way is to use pypeg2 directly with
Main
.
import pypeg2
from invenio_query_parser.parser import Main
pypeg2.parse('author:"Ellis"', Main)
API¶
API for Invenio-Query-Parser.
Define abstract classes.
-
class
invenio_query_parser.ast.
AndOp
(left, right)¶
-
class
invenio_query_parser.ast.
DoubleQuotedValue
(value)¶
-
class
invenio_query_parser.ast.
EmptyQuery
(value)¶
-
class
invenio_query_parser.ast.
GreaterEqualOp
(op)¶
-
class
invenio_query_parser.ast.
GreaterOp
(op)¶
-
class
invenio_query_parser.ast.
Keyword
(value)¶
-
class
invenio_query_parser.ast.
KeywordOp
(left, right)¶
-
class
invenio_query_parser.ast.
LowerEqualOp
(op)¶
-
class
invenio_query_parser.ast.
LowerOp
(op)¶
-
class
invenio_query_parser.ast.
OrOp
(left, right)¶
-
class
invenio_query_parser.ast.
RangeOp
(left, right)¶
-
class
invenio_query_parser.ast.
RegexValue
(value)¶
-
class
invenio_query_parser.ast.
SingleQuotedValue
(value)¶
-
class
invenio_query_parser.ast.
Value
(value)¶
-
class
invenio_query_parser.ast.
ValueQuery
(op)¶
Define parsers.
-
class
invenio_query_parser.parser.
And
¶ -
grammar
= (-6, [<_sre.SRE_Pattern object at 0x7f2c348319c0>, Literal('+')])¶
-
-
class
invenio_query_parser.parser.
AndQuery
¶ -
grammar
= [((-6, <class 'invenio_query_parser.parser.And'>), [((-6, <class 'invenio_query_parser.parser.Whitespace'>), Attribute(name='op', thing=<class 'invenio_query_parser.parser.SimpleQuery'>, subtype=None)), ((-6, (0, <class 'invenio_query_parser.parser.Whitespace'>)), Attribute(name='op', thing=<class 'invenio_query_parser.parser.ParenthesizedQuery'>, subtype=None))]), ((-6, Literal('+')), Attribute(name='op', thing=<class 'invenio_query_parser.parser.SimpleQuery'>, subtype=None))]¶
-
-
class
invenio_query_parser.parser.
BinaryRule
¶
-
class
invenio_query_parser.parser.
DoubleQuotedString
¶ -
grammar
= (Literal('"'), Attribute(name='value', thing=<_sre.SRE_Pattern object at 0x7f2c348dae90>, subtype=None), Literal('"'))¶
-
-
class
invenio_query_parser.parser.
EmptyQueryRule
¶ -
grammar
= Attribute(name='value', thing=<_sre.SRE_Pattern object at 0x7f2c34831b58>, subtype=None)¶
-
-
class
invenio_query_parser.parser.
ImplicitAndQuery
¶ -
grammar
= [Attribute(name='op', thing=<class 'invenio_query_parser.parser.ParenthesizedQuery'>, subtype=None), Attribute(name='op', thing=<class 'invenio_query_parser.parser.SimpleQuery'>, subtype=None)]¶
-
-
class
invenio_query_parser.parser.
KeywordQuery
¶ -
grammar
= [(Attribute(name='left', thing=<class 'invenio_query_parser.parser.KeywordRule'>, subtype=None), (-6, ((0, <class 'invenio_query_parser.parser.Whitespace'>), Literal(':'), (0, <class 'invenio_query_parser.parser.Whitespace'>))), Attribute(name='right', thing=<class 'invenio_query_parser.parser.KeywordQuery'>, subtype=None)), (Attribute(name='left', thing=<class 'invenio_query_parser.parser.KeywordRule'>, subtype=None), (-6, ((0, <class 'invenio_query_parser.parser.Whitespace'>), Literal(':'), (0, <class 'invenio_query_parser.parser.Whitespace'>))), Attribute(name='right', thing=<class 'invenio_query_parser.parser.Value'>, subtype=None)), (Attribute(name='left', thing=<class 'invenio_query_parser.parser.KeywordRule'>, subtype=None), (-6, ((0, <class 'invenio_query_parser.parser.Whitespace'>), Literal(':'), (0, <class 'invenio_query_parser.parser.Whitespace'>))), Attribute(name='right', thing=<class 'invenio_query_parser.parser.Query'>, subtype=None))]¶
-
-
class
invenio_query_parser.parser.
KeywordRule
¶ -
grammar
= Attribute(name='value', thing=<_sre.SRE_Pattern object at 0x7f2c348e6a30>, subtype=None)¶
-
-
class
invenio_query_parser.parser.
LeafRule
¶
-
class
invenio_query_parser.parser.
ListRule
¶
-
class
invenio_query_parser.parser.
Main
¶ -
grammar
= [((-6, (0, <class 'invenio_query_parser.parser.Whitespace'>)), Attribute(name='op', thing=<class 'invenio_query_parser.parser.Query'>, subtype=None), (-6, (0, <class 'invenio_query_parser.parser.Whitespace'>))), Attribute(name='op', thing=<class 'invenio_query_parser.parser.EmptyQueryRule'>, subtype=None)]¶
-
-
class
invenio_query_parser.parser.
NestableKeyword
¶ -
grammar
= Attribute(name='value', thing=[<_sre.SRE_Pattern object at 0x7f2c3484bc90>, <_sre.SRE_Pattern object at 0x7f2c347ae2d0>], subtype=None)¶
-
-
class
invenio_query_parser.parser.
Not
¶ -
grammar
= (-6, [(-6, <_sre.SRE_Pattern object at 0x7f2c348c6f08>), <_sre.SRE_Pattern object at 0x7f2c348e5f10>, Literal('-')])¶
-
-
class
invenio_query_parser.parser.
NotQuery
¶ -
grammar
= [((-6, <class 'invenio_query_parser.parser.Not'>), [((-6, <class 'invenio_query_parser.parser.Whitespace'>), Attribute(name='op', thing=<class 'invenio_query_parser.parser.SimpleQuery'>, subtype=None)), ((-6, (0, <class 'invenio_query_parser.parser.Whitespace'>)), Attribute(name='op', thing=<class 'invenio_query_parser.parser.ParenthesizedQuery'>, subtype=None))]), ((-6, Literal('-')), Attribute(name='op', thing=<class 'invenio_query_parser.parser.SimpleQuery'>, subtype=None))]¶
-
-
class
invenio_query_parser.parser.
Number
¶ -
grammar
= Attribute(name='value', thing=<_sre.SRE_Pattern object at 0x7f2c34855f08>, subtype=None)¶
-
-
class
invenio_query_parser.parser.
Or
¶ -
grammar
= (-6, [<_sre.SRE_Pattern object at 0x7f2c347c7eb0>, Literal('|')])¶
-
-
class
invenio_query_parser.parser.
OrQuery
¶ -
grammar
= [((-6, <class 'invenio_query_parser.parser.Or'>), [((-6, <class 'invenio_query_parser.parser.Whitespace'>), Attribute(name='op', thing=<class 'invenio_query_parser.parser.SimpleQuery'>, subtype=None)), ((-6, (0, <class 'invenio_query_parser.parser.Whitespace'>)), Attribute(name='op', thing=<class 'invenio_query_parser.parser.ParenthesizedQuery'>, subtype=None))]), ((-6, Literal('|')), Attribute(name='op', thing=<class 'invenio_query_parser.parser.SimpleQuery'>, subtype=None))]¶
-
-
class
invenio_query_parser.parser.
ParenthesizedQuery
¶ -
grammar
= ((-6, (Literal('('), (0, <class 'invenio_query_parser.parser.Whitespace'>))), Attribute(name='op', thing=<class 'invenio_query_parser.parser.Query'>, subtype=None), (-6, ((0, <class 'invenio_query_parser.parser.Whitespace'>), Literal(')'))))¶
-
-
class
invenio_query_parser.parser.
Query
¶ -
grammar
= Attribute(name='children', thing=([<class 'invenio_query_parser.parser.ParenthesizedQuery'>, <class 'invenio_query_parser.parser.SimpleQuery'>], (-1, ((-6, (0, <class 'invenio_query_parser.parser.Whitespace'>)), [<class 'invenio_query_parser.parser.NotQuery'>, <class 'invenio_query_parser.parser.AndQuery'>, <class 'invenio_query_parser.parser.OrQuery'>, <class 'invenio_query_parser.parser.ImplicitAndQuery'>]))), subtype=None)¶
-
-
class
invenio_query_parser.parser.
RangeOp
¶ -
grammar
= (Attribute(name='left', thing=<class 'invenio_query_parser.parser.RangeValue'>, subtype=None), Literal('->'), Attribute(name='right', thing=<class 'invenio_query_parser.parser.RangeValue'>, subtype=None))¶
-
-
class
invenio_query_parser.parser.
RangeValue
¶ -
grammar
= Attribute(name='op', thing=[<class 'invenio_query_parser.parser.DoubleQuotedString'>, <class 'invenio_query_parser.parser.SimpleRangeValue'>], subtype=None)¶
-
-
class
invenio_query_parser.parser.
SimpleQuery
¶ -
grammar
= Attribute(name='op', thing=[<class 'invenio_query_parser.parser.KeywordQuery'>, <class 'invenio_query_parser.parser.ValueQuery'>], subtype=None)¶
-
-
class
invenio_query_parser.parser.
SimpleRangeValue
¶ -
grammar
= Attribute(name='value', thing=<_sre.SRE_Pattern object at 0x7f2c3495a290>, subtype=None)¶
-
-
class
invenio_query_parser.parser.
SimpleValue
(values)¶ -
grammar
= (-2, <class 'invenio_query_parser.parser.SimpleValueUnit'>)¶
-
-
class
invenio_query_parser.parser.
SimpleValueUnit
(args)¶ -
grammar
= [<_sre.SRE_Pattern object at 0x7f2c34782030>, (<_sre.SRE_Pattern object at 0x7f2c34831a48>, <class 'invenio_query_parser.parser.SimpleValue'>, <_sre.SRE_Pattern object at 0x7f2c34831ad0>)]¶
-
-
class
invenio_query_parser.parser.
SingleQuotedString
¶ -
grammar
= (Literal("'"), Attribute(name='value', thing=<_sre.SRE_Pattern object at 0x7f2c348dadd8>, subtype=None), Literal("'"))¶
-
-
class
invenio_query_parser.parser.
SlashQuotedString
¶ -
grammar
= (Literal('/'), Attribute(name='value', thing=<_sre.SRE_Pattern object at 0x7f2c348daf48>, subtype=None), Literal('/'))¶
-
-
class
invenio_query_parser.parser.
UnaryRule
¶
-
class
invenio_query_parser.parser.
Value
¶ -
grammar
= Attribute(name='op', thing=[<class 'invenio_query_parser.parser.RangeOp'>, <class 'invenio_query_parser.parser.SingleQuotedString'>, <class 'invenio_query_parser.parser.DoubleQuotedString'>, <class 'invenio_query_parser.parser.SlashQuotedString'>, <class 'invenio_query_parser.parser.SimpleValue'>], subtype=None)¶
-
-
class
invenio_query_parser.parser.
ValueQuery
¶ -
grammar
= Attribute(name='op', thing=<class 'invenio_query_parser.parser.Value'>, subtype=None)¶
-
-
class
invenio_query_parser.parser.
Whitespace
¶ -
grammar
= Attribute(name='value', thing=<_sre.SRE_Pattern object at 0x7f2c34855e70>, subtype=None)¶
-
Store the actual visitor methods.
-
class
invenio_query_parser.visitor.
make_visitor
(methods=None)¶ Make a visitor decorator.
Changes¶
Version 0.3.0 (released 2015-07-29):
- Allows search keywords to contain dots to point to subfield content, i.e. author.name: Ellis.
Version 0.2.0 (released 2014-12-10):
- Initial public release.
- Adds Python2/Python3 compatibility layer. (#2)
- Adds new Sphinx documentation page. (#3)
- Adds simple inheritance for visitor pattern and separates SPIRES syntax parser to contrib module. (#7)
Version 0.1.0 (release 2014-10-13):
- Initial private release. Includes code developed by Alessio Deiana and Federico Poli.
Contributing¶
Bug reports, feature requests, and other contributions are welcome. If you find a demonstrable problem that is caused by the code of this library, please:
- Search for already reported problems.
- Check if the issue has been fixed or is still reproducible on the latest master branch.
- Create an issue with a test case.
If you create a feature branch, you can run the tests to ensure everything is operating correctly:
$ python setup.py test
...
======= 146 passed in 1.90 seconds ======
Authors¶
Invenio-Query-Parser is developed for the Invenio digital library software.
Contact us at info@invenio-software.org.
- Alessio Deiana <https://github.com/osso>
- Federico Poli <https://github.com/fpoli>
- Jiri Kuncar <https://github.com/jirikuncar>
- Tibor Simko <https://github.com/tiborsimko>