| author | berghofe | 
| Tue, 01 Jun 2010 11:13:09 +0200 | |
| changeset 37233 | b78f31ca4675 | 
| parent 36377 | b3dce4c715d0 | 
| child 38037 | f6059e262004 | 
| permissions | -rwxr-xr-x | 
| 28573 | 1 | #!/usr/bin/env perl | 
| 2 | # | |
| 3 | # Wrapper for custom remote provers on SystemOnTPTP | |
| 4 | # Author: Fabian Immler, TU Muenchen | |
| 5 | # | |
| 6 | ||
| 7 | use warnings; | |
| 8 | use strict; | |
| 9 | use Getopt::Std; | |
| 10 | use HTTP::Request::Common; | |
| 29590 | 11 | use LWP; | 
| 28573 | 12 | |
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 13 | my $SystemOnTPTPFormReplyURL = | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 14 | "http://www.cs.miami.edu/~tptp/cgi-bin/SystemOnTPTPFormReply"; | 
| 28573 | 15 | |
| 29590 | 16 | # default parameters | 
| 28573 | 17 | my %URLParameters = ( | 
| 18 | "NoHTML" => 1, | |
| 19 | "QuietFlag" => "-q01", | |
| 20 | "SubmitButton" => "RunSelectedSystems", | |
| 21 | "ProblemSource" => "UPLOAD", | |
| 32435 
711d680eab26
New option ForceSystem that makes sure we *really* get the system we ask for
 nipkow parents: 
32327diff
changeset | 22 | "ForceSystem" => "-force", | 
| 29590 | 23 | ); | 
| 24 | ||
| 25 | #----Get format and transform options if specified | |
| 26 | my %Options; | |
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 27 | getopts("hwxs:t:c:",\%Options);
 | 
| 29590 | 28 | |
| 29 | #----Usage | |
| 30874 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 30 | sub usage() {
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 31 |   print("Usage: remote [<options>] <File name>\n");
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 32 |   print("    <options> are ...\n");
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 33 |   print("    -h            - print this help\n");
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 34 |   print("    -w            - list available ATP systems\n");
 | 
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 35 |   print("    -x            - use X2TPTP to convert output of prover\n");
 | 
| 30874 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 36 |   print("    -s<system>    - specified system to use\n");
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 37 |   print("    -t<timelimit> - CPU time limit for system\n");
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 38 |   print("    -c<command>   - custom command for system\n");
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 39 |   print("    <File name>   - TPTP problem file\n");
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 40 | exit(0); | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 41 | } | 
| 29590 | 42 | if (exists($Options{'h'})) {
 | 
| 30874 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 43 | usage(); | 
| 29590 | 44 | } | 
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 45 | |
| 29590 | 46 | #----What systems flag | 
| 47 | if (exists($Options{'w'})) {
 | |
| 48 |     $URLParameters{"SubmitButton"} = "ListSystems";
 | |
| 49 |     delete($URLParameters{"ProblemSource"});
 | |
| 50 | } | |
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 51 | |
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 52 | #----X2TPTP | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 53 | if (exists($Options{'x'})) {
 | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 54 |     $URLParameters{"X2TPTP"} = "-S";
 | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 55 | } | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 56 | |
| 29590 | 57 | #----Selected system | 
| 58 | my $System; | |
| 59 | if (exists($Options{'s'})) {
 | |
| 60 |     $System = $Options{'s'};
 | |
| 61 | } else {
 | |
| 62 | # use Vampire as default | |
| 63 | $System = "Vampire---9.0"; | |
| 64 | } | |
| 65 | $URLParameters{"System___$System"} = $System;
 | |
| 66 | ||
| 67 | #----Time limit | |
| 68 | if (exists($Options{'t'})) {
 | |
| 69 |     $URLParameters{"TimeLimit___$System"} = $Options{'t'};
 | |
| 70 | } | |
| 71 | #----Custom command | |
| 72 | if (exists($Options{'c'})) {
 | |
| 73 |     $URLParameters{"Command___$System"} = $Options{'c'};
 | |
| 74 | } | |
| 75 | ||
| 76 | #----Get single file name | |
| 77 | if (exists($URLParameters{"ProblemSource"})) {
 | |
| 78 |     if (scalar(@ARGV) >= 1) {
 | |
| 79 |         $URLParameters{"UPLOADProblem"} = [shift(@ARGV)];
 | |
| 80 |     } else {
 | |
| 30874 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 81 |       print("Missing problem file\n");
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 82 | usage(); | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 83 | die; | 
| 29590 | 84 | } | 
| 85 | } | |
| 28573 | 86 | |
| 87 | # Query Server | |
| 88 | my $Agent = LWP::UserAgent->new; | |
| 29590 | 89 | if (exists($Options{'t'})) {
 | 
| 90 | # give server more time to respond | |
| 30534 | 91 |   $Agent->timeout($Options{'t'} + 10);
 | 
| 29590 | 92 | } | 
| 28573 | 93 | my $Request = POST($SystemOnTPTPFormReplyURL, | 
| 94 | Content_Type => 'form-data',Content => \%URLParameters); | |
| 95 | my $Response = $Agent->request($Request); | |
| 29590 | 96 | |
| 97 | #catch errors / failure | |
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 98 | if(!$Response->is_success) {
 | 
| 30535 | 99 | print "HTTP-Error: " . $Response->message . "\n"; | 
| 100 | exit(-1); | |
| 29590 | 101 | } elsif (exists($Options{'w'})) {
 | 
| 102 | print $Response->content; | |
| 103 | exit (0); | |
| 104 | } elsif ($Response->content =~ /WARNING: (\S*) does not exist/) {
 | |
| 105 | print "Specified System $1 does not exist\n"; | |
| 106 | exit(-1); | |
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 107 | } elsif (exists($Options{'x'}) &&
 | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 108 | $Response->content =~ | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 109 | /%\s*Result\s*:\s*Unsatisfiable.*\n%\s*Output\s*:\s*(CNF)?Refutation.*\n%/ && | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 110 | $Response->content !~ /ERROR: Could not form TPTP format derivation/ ) | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 111 | {
 | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 112 | # converted output: extract proof | 
| 30874 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 113 | my @lines = split( /\n/, $Response->content); | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 114 | my $extract = ""; | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 115 |   foreach my $line (@lines){
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 116 | #ignore comments | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 117 |       if ($line !~ /^%/ && !($line eq "")) {
 | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 118 | $extract .= "$line"; | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 119 | } | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 120 | } | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 121 | # insert newlines after ').' | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 122 | $extract =~ s/\s//g; | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 123 | $extract =~ s/\)\.cnf/\)\.\ncnf/g; | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 124 | |
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 125 | print "========== ~~/lib/scripts/SystemOnTPTP extracted proof: ==========\n"; | 
| 36287 
96f45c5ffb36
if Isar proof reconstruction is not supported, tell the user so they don't wonder why their "isar_proof" option did nothing
 blanchet parents: 
32435diff
changeset | 126 | # orientation for "sledgehammer_proof_reconstruct.ML" | 
| 30874 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 127 | print "# SZS output start CNFRefutation.\n"; | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 128 | print "$extract\n"; | 
| 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 129 | print "# SZS output end CNFRefutation.\n"; | 
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 130 | # can be useful for debugging; Isabelle ignores this | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 131 | print "============== original response from SystemOnTPTP: ==============\n"; | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 132 | print $Response->content; | 
| 30874 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 133 | exit(0); | 
| 31833 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 134 | } elsif (!exists($Options{'x'})) {
 | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 135 | # pass output directly to Isabelle | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 136 | print $Response->content; | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 137 | exit(0); | 
| 
9ab1326ed98d
use X2TPTP optionally and only for remote_spass;
 immler@in.tum.de parents: 
30979diff
changeset | 138 | }else {
 | 
| 36377 
b3dce4c715d0
now rename the file "atp_wrapper.ML" to "atp_systems.ML" + fix typo in "SystemOnTPTP" script
 blanchet parents: 
36287diff
changeset | 139 | print "Remote script could not extract proof:\n".$Response->content; | 
| 30874 
34927a1e0ae8
reverted to explicitly check the presence of a refutation
 immler@in.tum.de parents: 
30535diff
changeset | 140 | exit(-1); | 
| 28573 | 141 | } | 
| 142 |