def test_convert_simple_value_boolean_query_to_and_boolean_queries(): parse_tree = \ parser.SimpleQuery( parser.SpiresKeywordQuery( parser.InspireKeyword('author'), parser.Value( parser.SimpleValueBooleanQuery( parser.SimpleValue('foo'), parser.And(), parser.SimpleValueBooleanQuery( parser.SimpleValue('bar'), parser.Or(), parser.SimpleValueNegation(parser.SimpleValue('foobar')) ) ) ) ) ) expected_parse_tree = \ AndOp( KeywordOp(Keyword('author'), Value('foo')), OrOp( KeywordOp(Keyword('author'), Value('bar')), NotOp(KeywordOp(Keyword('author'), Value('foobar'))) ) ) restructuring_visitor = RestructuringVisitor() parse_tree = parse_tree.accept(restructuring_visitor) assert parse_tree == expected_parse_tree
def test_foo_bar(): query_str = 'find j Nucl.Phys. and not vol A531 and a ellis' print("Parsing: " + query_str) stateful_parser = StatefulParser() restructuring_visitor = RestructuringVisitor() _, parse_tree = stateful_parser.parse(query_str, parser.Query) parse_tree = parse_tree.accept(restructuring_visitor) expected_parse_tree = AndOp( KeywordOp(Keyword('journal'), Value('Nucl.Phys.')), KeywordOp(Keyword('author'), Value('ellis'))) assert parse_tree == expected_parse_tree
def test_visit_complex_value_with_new_complex_value_category(): node = parser.ComplexValue('$foo$') restructuring_visitor = RestructuringVisitor() parse_tree = node.accept(restructuring_visitor) assert parse_tree == Value(node.value)
NestedKeywordOp, NotOp, OrOp, PartialMatchValue, QueryWithMalformedPart, RangeOp, RegexValue, Value, ValueOp) from inspire_query_parser.stateful_pypeg_parser import StatefulParser from inspire_query_parser.visitors.restructuring_visitor import \ RestructuringVisitor @pytest.mark.parametrize( ['query_str', 'expected_parse_tree'], [ # Find keyword combined with other production rules ('FIN author:\'ellis\'', KeywordOp(Keyword('author'), PartialMatchValue('ellis'))), ('Find author "ellis"', KeywordOp(Keyword('author'), ExactMatchValue('ellis'))), ('f author ellis', KeywordOp(Keyword('author'), Value('ellis'))), # Invenio like search ('author:ellis and title:boson', AndOp(KeywordOp(Keyword('author'), Value('ellis')), KeywordOp(Keyword('title'), Value('boson')))), ('unknown_keyword:\'bar\'', KeywordOp(Keyword('unknown_keyword'), PartialMatchValue('bar'))), ('dotted.keyword:\'bar\'', KeywordOp(Keyword('dotted.keyword'), PartialMatchValue('bar'))), # Boolean operator testing (And/Or) ('author ellis and title \'boson\'', AndOp(KeywordOp(Keyword('author'), Value('ellis')), KeywordOp(Keyword('title'), PartialMatchValue('boson')))), ('f a appelquist and date 1983',