[rkward-cvs] SF.net SVN: rkward: [1275] trunk/rkward/rkward/plugins

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Feb 1 14:07:13 UTC 2007


Revision: 1275
          http://svn.sourceforge.net/rkward/?rev=1275&view=rev
Author:   tfry
Date:     2007-02-01 06:07:13 -0800 (Thu, 01 Feb 2007)

Log Message:
-----------
Import SPSS plugin can now deal with encodings

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/00saveload/import/import_spss.php
    trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml
    trunk/rkward/rkward/plugins/under_development.pluginmap

Modified: trunk/rkward/rkward/plugins/00saveload/import/import_spss.php
===================================================================
--- trunk/rkward/rkward/plugins/00saveload/import/import_spss.php	2007-02-01 13:04:56 UTC (rev 1274)
+++ trunk/rkward/rkward/plugins/00saveload/import/import_spss.php	2007-02-01 14:07:13 UTC (rev 1275)
@@ -1,8 +1,22 @@
 <?php
 function preprocess () { ?>
 require (foreign)
-<?
+<?	if (getRK_val ("do_locale_conversion")) { ?>
+
+# helper function to convert all strings to the current encoding
+rk.temp.convert <- function (x, from) {
+	attribs <- attributes (x);
+	if (is.character (x)) {
+		x <- iconv (x, from=from, to="", sub="")
+	} else if (is.list (x)) {
+		x <- lapply (x, function (sub) rk.temp.convert (sub, from))
+	}
+	# convert factor levels and all other attributes
+	attributes (x) <- lapply (attribs, function (sub) rk.temp.convert (sub, from))
+	x
 }
+<?	}
+}
 
 function calculate () {
 	if (getRK_val ("data_frame")) {
@@ -19,10 +33,17 @@
 	$object = getRK_val ("saveto");
 ?>
 <? echo ($object); ?> <- read.spss ("<? getRK ("file"); ?>"<? echo ($data_frame_opt); echo ($labels_opt); ?>)
+<?	if (getRK_val ("do_locale_conversion")) {
+		$from_locale = getRK_val ("encoding");
+		if ($from_locale == "other") {
+			$from_locale = getRK_val ("user_encoding");
+		} ?>
 
-<?	if ($data_frame) { 
-// actually, this should not only happen for a data.frame (the alternative is a list), but maybe according to an option (or always)
-?>
+# convert all strings to the current encoding
+<? echo ($object); ?> <- rk.temp.convert (<? echo ($object); ?>, from="<? echo ($from_locale); ?>")
+<?	}
+	if (getRK_val ("convert_var_labels")) { ?>
+
 # set variable labels for use in RKWard
 rk.temp.labels <- attr (<? echo ($object); ?>, "variable.labels");
 if (!is.null (rk.temp.labels)) {
@@ -36,10 +57,10 @@
 <?	} ?>
 <?
 }
-	
+
 function printout () {
 }
-	
+
 function cleanup () { ?>
 rm (list=grep ("^rk.temp", ls (), value=TRUE))
 <?

Modified: trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml
===================================================================
--- trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml	2007-02-01 13:04:56 UTC (rev 1274)
+++ trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml	2007-02-01 14:07:13 UTC (rev 1275)
@@ -7,17 +7,37 @@
 		
 		<connect governor="use_labels.state" client="labels_limit.enabled"/>
 		<connect governor="use_labels.state" client="trim_labels.enabled"/>
+		
+		<connect governor="do_locale_conversion.state" client="encoding.enabled" />
+		<convert id="other_encoding" mode="equals" standard="other" sources="encoding.string" />
+		<convert id="other_encoding2" mode="and" sources="other_encoding;do_locale_conversion.state" />
+		<connect governor="other_encoding2" client="user_encoding.enabled" />
+		<connect governor="other_encoding2" client="user_encoding.required" />
 	</logic>
 	<dialog label="Import SPSS file">
-		<browser size="small" id="file" label="File name" />
-		<stretch/>
-		<saveobject id="saveto" initial="my.spss.data" label="Object to save to"/>
-		<stretch/>
-		<checkbox id="data_frame" checked="true" label="Import as a data.frame" value="1" value_unchecked="0"/>
-		<frame label="Labels">
-			<checkbox id="use_labels" checked="true" label="Use value labels" value="1" value_unchecked="0"/>
-			<spinbox id="labels_limit" type="integer" initial="1000000" min="1" label="Maximum number of labels per object" />
-			<checkbox id="trim_labels" checked="false" label="Trim white space" value="1" value_unchecked="0"/>
-		</frame>
+		<tabbook>
+			<tab id="tab_general" label="General">
+				<browser size="small" id="file" label="File name" />
+				<stretch/>
+				<saveobject id="saveto" initial="my.spss.data" label="Object to save to"/>
+				<stretch/>
+				<checkbox id="data_frame" checked="true" label="Import as a data.frame" value="1" value_unchecked="0"/>
+				<frame label="Labels">
+					<checkbox id="convert_var_labels" checked="true" label="Convert Variable labels to RKWard format" value="1" value_unchecked="0"/>
+					<checkbox id="use_labels" checked="true" label="Use value labels" value="1" value_unchecked="0"/>
+					<spinbox id="labels_limit" type="integer" initial="1000000" min="1" label="Maximum number of labels per object" />
+					<checkbox id="trim_labels" checked="false" label="Trim white space" value="1" value_unchecked="0"/>
+				</frame>
+			</tab>
+			<tab id="tab_encoding" label="Encoding">
+				<checkbox id="do_locale_conversion" checked="false" label="Convert string encoding" value="1" value_unchecked="0"/>
+				<radio id="encoding" label="Convert from:">
+					<option value="latin1" label="Latin 1"/>
+					<option value="UTF-8" label="UTF-8"/>
+					<option value="other" label="Other (specify below)"/>
+				</radio>
+				<input id="user_encoding" label="Other encoding" />
+			</tab>
+		</tabbook>
 	</dialog>
 </document>

Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap	2007-02-01 13:04:56 UTC (rev 1274)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap	2007-02-01 14:07:13 UTC (rev 1275)
@@ -5,7 +5,7 @@
 		<component type="standard" id="export_x11_device" file="x11device/export.xml" label="Export..." />
 		<!-- The entry below is bogus for now, still testing some concepts with it -->
 		<component type="standard" id="import_spss" file="00saveload/import/import_spss.xml" label="Import SPSS">
-			<attribute id="format" value="*.sav" label="SPSS data files"/>
+			<attribute id="format" value="*.sav *.por" label="SPSS data files"/>
 		</component>
 		<component type="standard" id="import_csv" file="00saveload/import/import_spss.xml" label="Import SPSS">
 			<attribute id="format" value="*.txt *.csv" label="Comma Separate Values"/>


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list