Commits

Michael Granger committed 4e3d732

* Updated api experiment so that it actually runs by commenting out the leftover
Perl stuff.
* Added lprintf() experiment.

Comments (0)

Files changed (2)

experiments/api.rb

 #!/usr/bin/ruby
 # 
-# This is a little pseudo-program to work out how to best generalize the interface to the grammar tools.
+# This is a little pseudo-program to work out how to best generalize the
+# interface to the grammar tools.
 # 
 # == Authors
 # 
 # 
 # == Copyright
 #
-# Copyright (c) 2003 The FaerieMUD Consortium. All rights reserved.
+# Copyright (c) 2003, 2005 The FaerieMUD Consortium. All rights reserved.
 # 
 # This module is free software. You may use, modify, and/or redistribute this
 # software under the terms of the Perl Artistic License. (See
 "The plural of #{word} is PL(word)\n".inflect
 
 
-print inflect("The plural of $word is PL($word)\n");
-print inflect("I saw $cat_count PL("cat",$cat_count)\n");
-print inflect("PL(I,$N1) PL_V(saw,$N1) PL(a,$N2) PL_N(saw,$N2)");
-print inflect("NUM($N1,)PL(I) PL_V(saw) NUM($N2,)PL(a) PL_N(saw)");
-print inflect("I saw NUM($cat_count) PL("cat")\nNUM()");
-print inflect("There PL_V(was,$errors) NO(error,$errors)\n");
-print inflect("There NUM($errors,) PL_V(was) NO(error)\n";
-print inflect("Did you want A($thing) or AN($idea)\n");
-print inflect("It was ORD($position) from the left\n");
+# print inflect("The plural of $word is PL($word)\n")
+# print inflect("I saw $cat_count PL("cat",$cat_count)\n")
+# print inflect("PL(I,$N1) PL_V(saw,$N1) PL(a,$N2) PL_N(saw,$N2)")
+# print inflect("NUM($N1,)PL(I) PL_V(saw) NUM($N2,)PL(a) PL_N(saw)")
+# print inflect("I saw NUM($cat_count) PL("cat")\nNUM()")
+# print inflect("There PL_V(was,$errors) NO(error,$errors)\n")
+# print inflect("There NUM($errors,) PL_V(was) NO(error)\n"
+# print inflect("Did you want A($thing) or AN($idea)\n")
+# print inflect("It was ORD($position) from the left\n")
 
-# ADD USER-DEFINED INFLECTIONS (OVERRIDING INBUILT RULES):
+# # ADD USER-DEFINED INFLECTIONS (OVERRIDING INBUILT RULES):
 
-def_noun  "VAX"  => "VAXen";	# SINGULAR => PLURAL
+# def_noun  "VAX"  => "VAXen";	# SINGULAR => PLURAL
 
-def_verb  "will" => "shall",	# 1ST PERSON SINGULAR => PLURAL
-"will" => "will",	# 2ND PERSON SINGULAR => PLURAL
-"will" => "will",	# 3RD PERSON SINGULAR => PLURAL
+# def_verb  "will" => "shall",	# 1ST PERSON SINGULAR => PLURAL
+# "will" => "will",	# 2ND PERSON SINGULAR => PLURAL
+# "will" => "will",	# 3RD PERSON SINGULAR => PLURAL
 
-def_adj   "hir"  => "their",	# SINGULAR => PLURAL
+# def_adj   "hir"  => "their",	# SINGULAR => PLURAL
 
-def_a	"h"			# "AY HALWAYS SEZ 'HAITCH'!"
+# def_a	"h"			# "AY HALWAYS SEZ 'HAITCH'!"
 
-def_an	"horrendous.*"		# "AN HORRENDOUS AFFECTATION"
+# def_an	"horrendous.*"		# "AN HORRENDOUS AFFECTATION"
 

experiments/lprintf.rb

+#!/usr/bin/ruby
+#
+# Experiment to work out the implementation of sprintf-like formatting.
+#
+# Conclusion: re-opening the module doesn't work well, but I've added it to
+# en.rb, and it seems to work quite well for most cases. Still having trouble
+# with 'CONJUNCT'.
+# 
+# Time-stamp: <31-Oct-2005 06:11:43 ged>
+#
+
+BEGIN {
+	base = File::dirname( File::dirname(File::expand_path(__FILE__)) )
+	$LOAD_PATH.unshift "#{base}/lib"
+
+	require "#{base}/utils.rb"
+	include UtilityFunctions
+}
+
+require 'linguistics'
+
+Linguistics::use( :en, :classes => [String,Array] )
+
+module Linguistics::EN
+
+	module_function
+	def lprintf( fmt, *args )
+		fmt.to_s.gsub( /%([A-Z_]+)/ ) do |match|
+			op = $1
+			case op
+			when 'PL'
+				args.shift.en.plural
+			when 'A', 'AN'
+				args.shift.en.a
+			when 'NO'
+				args.shift.en.no
+			when 'CONJUNCT'
+				args.shift.en.conjunction
+			else
+				raise "no such formatter %p" % op
+			end
+		end
+	end
+
+end
+
+try( '"How many %PL do you want?".en.lprintf("monkey")' )
+
+