This file is indexed.

/usr/share/doc/libparse-recdescent-perl/examples/demo_NL2SQL.pl is in libparse-recdescent-perl 1.967013+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl -ws

use Parse::RecDescent;


my $grammar = <<'EOGRAMMAR';

translate:	select
	 |	sum
	 |	identify
	 |			{ "Could you rephase that?\n" }

select:		ask_select qualifier(?) field /of/ qualifier(?) table
				{ "SELECT DISTINCT $item[3]\nFROM $item[6]\n" }
	      |	ask_select qualifier(?) table /'?/ qualifier(?) field
				{ "SELECT DISTINCT $item[6]\nFROM $item[3]\n" }
	      |	ask_select qualifier(?) table
				{ "SELECT *\nFROM $item[3]\n" }

sum:		ask_count table prep qualifier field prep(?) value
				{ "SELECT COUNT(*)\nFROM $item[2]\n" .
				  "WHERE $item[5] = $item[7]\n" }
   |		ask_count table
				{ "SELECT COUNT(*)\nFROM $item[2]\n" }

identify:	ask_select(?) /who supplies/ qualifier value
				{ "SELECT supplier\nFROM merchandise\n" .
				  "WHERE name = $item[4]\n" }

	|	whats qualifier field /of/ qualifier /suppliers? of/ value
				{ "SELECT suppliers.$item[3]\n" .
				  "FROM suppliers, products\n" .
				  "WHERE products.name = $item[-1]\n" .
				  "AND suppliers.name = products.supplier \n" }




field:		/(name)s?/			{ $1 }
     |		/(product)s?/			{ $1 }
     |		/(id)(entit(y|ies))?/		{ $1 }
     |		/(quantit(y|ies))/		{ $1 }
     |		/(received)s?/			{ $1 }
     |		/(supplier)s?/			{ $1 }
     |		/(cost)s?/			{ $1 }
     |		/(address)(es)?/		{ $1 }

table:		/suppliers?/			{ 'suppliers' }
     |		'merchandise'
     |		/orders?/			{ 'orders' }

qualifier:	/the|every|all( the)?|any|our/

ask_select:	reply to_me

ask_count:	ask_select(?) /how (many|much)/

reply:		/tell|show|list/

value:		/\w+/				{ qq{'$item[1]'} }

to_me:		/((to )?(me|us))?/

whats:		/what's|what (is|are)/

prep:		/for|of|with|by/

EOGRAMMAR

my $parser = Parse::RecDescent->new($grammar)
	or die "Bad grammar";

$| = 1;
while (<DATA>)
{
	print "> ";
	sleep 1;
	print; <>;
	my $SQL = $parser->translate($_);
	print $SQL, "\n";
}

__DATA__
how many orders for the product spam are there?
tell me how many suppliers by the name of Jones we have
what are the names of our suppliers of trinitrotoluene?
tell me our suppliers' names
list our merchandise
show us the suppliers of the mechanise
list all supplier names
how many orders are there?
how much merchandise do we carry?
who supplies our nitrocelluose?
tell me who supplies our ethylacetate?
what are the addresses of our suppliers of trinitrotoluene?