Permalink
Browse files

[VRG]

- added "install" target to Makefile
- added "-d", "-trim", and "-c" options to
  script/xclips.pl


git-svn-id: http://svn.berlios.de/svnroot/repos/unisimu/VRG@861 625e195c-0704-0410-94f2-f261ee9f2fe7
  • Loading branch information...
agent
agent committed Nov 13, 2006
1 parent d82bd21 commit 551ab451241292ee4d53910169fa96360e95f872
Showing with 76 additions and 28 deletions.
  1. +12 −1 Makefile
  2. +1 −0 lib/Clips/GraphViz.pm
  3. +62 −26 script/xclips.pl
  4. +1 −1 t/VRG.pm
View
@@ -1,14 +1,17 @@
SHELL := cmd
+PERL_BIN := E:/perl/bin
+PERL_LIB := E:/perl/site/lib
sample_vrg_files := $(wildcard sample/*.vrg)
sample_png_files := $(patsubst %.vrg,%.png,$(sample_vrg_files))
xpro := perl xprolog/xpro.pl
-xclp := perl -Ilib script/xclips.pl -I knowledge
+xclp := perl -Ilib script/xclips.pl -I knowledge -c
vrg_run := perl -Ilib script/vrg-run.pl
rm_f = perl -MExtUtils::Command -e rm_f
mv_f = perl -MExtUtils::Command -e mv
+cp_f = perl -MExtUtils::Command -e cp
xpro_files := $(wildcard xprolog/*.xpro)
pro_files := $(patsubst %.xpro,%.pro, $(xpro_files))
@@ -65,3 +68,11 @@ sample: $(sample_png_files)
sample/%.png: sample/%.vrg clips_all
$(vrg_run) $<
+
+install:
+ pl2bat script/xclips.pl
+ $(cp_f) script/xclips.bat $(PERL_BIN)
+ $(cp_f) lib/Clips/Batch.pm $(PERL_LIB)/Clips
+ $(cp_f) lib/Clips/GraphViz.pm $(PERL_LIB)/Clips
+ $(cp_f) lib/XClips/Compiler.pm $(PERL_LIB)/XClips
+ $(cp_f) lib/XClips/Compiler/Base.pm $(PERL_LIB)/XClips/Compiler
View
@@ -2,6 +2,7 @@ package Clips::GraphViz;
use strict;
use warnings;
+no warnings 'redefine';
use List::MoreUtils qw(any first_index);
use GraphViz;
View
@@ -3,14 +3,16 @@
use Getopt::Long;
use FindBin;
-use lib "$FindBin::Bin/../lib";
use XClips::Compiler;
use List::MoreUtils 'uniq';
use File::Slurp;
use Data::Dump::Streamer;
GetOptions(
- 'I=s' => \@::Include,
+ 'I=s' => \@::Include,
+ 'c' => \my $compile_only,
+ 'trim' => \my $trim,
+ 'debug' => \my $debug,
) or help();
our $infile = shift or help();
@@ -19,34 +21,68 @@ sub help {
die "usage: $0 [-I dir] infile\n";
}
-(my $outfile = $infile) =~ s/\.xclp$/.clp/i;
-$outfile .= '.clp' if $outfile !~ /\.clp$/i;
+my $outfile;
-our ($base) = ($outfile =~ /([\w-]+)\.\w+$/);
-$base = "f$base" if $base !~ /^[A-Za-z_]/;
+if ($infile !~ /\.clp$/i) {
+ ($outfile = $infile) =~ s/\.xclp$/.clp/i;
+ $outfile .= '.clp' if $outfile !~ /\.clp$/i;
-my $source = read_file($infile);
+ our ($base) = ($outfile =~ /([\w-]+)\.\w+$/);
+ $base = "f$base" if $base !~ /^[A-Za-z_]/;
-$::RD_HINT = 1;
-#$::RD_TRACE = 1;
-our $parser = XClips::Compiler->new;
-my $data = $parser->program($source);
-if (!defined $data) {
- die "abort.\n";
-}
-$data .= "\n" if $data and $data !~ /\n$/s;
-if (@::facts) {
- $data .= "(deffacts $base\n " . join("\n ", uniq @::facts). ")\n";
-}
-$data .= "\n" if $data and $data !~ /\n$/s;
+ my $source = read_file($infile);
+
+ $::RD_HINT = 1;
+ #$::RD_TRACE = 1;
+ our $parser = XClips::Compiler->new;
+ my $data = $parser->program($source);
+ if (!defined $data) {
+ die "abort.\n";
+ }
+ $data .= "\n" if $data and $data !~ /\n$/s;
+ if (@::facts) {
+ $data .= "(deffacts $base\n " . join("\n ", uniq @::facts). ")\n";
+ }
+ $data .= "\n" if $data and $data !~ /\n$/s;
-#my @elems = %infix_circumfix;
-#warn "\%infix_circumfix: @elems\n";
+ #my @elems = %infix_circumfix;
+ #warn "\%infix_circumfix: @elems\n";
-#@elems = %infix_circum_close;
-#warn "\%infix_circum_close: @elems\n";
+ #@elems = %infix_circum_close;
+ #warn "\%infix_circum_close: @elems\n";
+
+ if ($data) {
+ write_file($outfile, $data);
+ #print $data;
+ }
+} else {
+ $outfile = $infile;
+}
-if ($data) {
- write_file($outfile, $data);
- #print $data;
+if (!$compile_only) {
+ if ($debug) {
+ require Clips::Batch;
+ require Clips::GraphViz;
+ my $clips = Clips->new($outfile);
+ $clips->watch('facts');
+ $clips->watch('rules');
+ $clips->reset;
+ $clips->facts('*', \my $init_facts);
+ $clips->rules('*', \my $rules);
+ $clips->run(\my $run_log);
+ $clips->eof;
+ my $painter = Clips::GraphViz->new($init_facts, $run_log);
+ $outfile =~ s/\.clp$/\.png/i;
+ $painter->draw(
+ outfile => $outfile,
+ trim => $trim,
+ );
+ warn "generating $outfile...\n";
+ } else {
+ require Clips::Batch;
+ my $clips = Clips->new($outfile);
+ $clips->reset;
+ $clips->run(sub { print $_[0] } );
+ $clips->eof;
+ }
}
View
@@ -8,7 +8,7 @@ our @EXPORT = qw(run_tests);
my $count = 0;
-my $xclips = "$^X script/xclips.pl -I knowledge ";
+my $xclips = "$^X -Ilib script/xclips.pl -c -I knowledge";
#no_diff;

0 comments on commit 551ab45

Please sign in to comment.