aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-02-16 23:11:38 +0000
committerBibiko <bibiko@eva.mpg.de>2010-02-16 23:11:38 +0000
commit72c4522db57b9699e1dc324f62dbeb036405f2c6 (patch)
treedb10818cac8e148a91137b1258241f34da6bf184
parent429e77d0512d3d36a4ca8e9aa994be48906c1445 (diff)
downloadsequelpro-72c4522db57b9699e1dc324f62dbeb036405f2c6.tar.gz
sequelpro-72c4522db57b9699e1dc324f62dbeb036405f2c6.tar.bz2
sequelpro-72c4522db57b9699e1dc324f62dbeb036405f2c6.zip
• csv field mapper
- added chance to align the csv field and table field names via 'matching names' which uses the Levenshtein distance [first approach] if csv file's first line is an header
-rw-r--r--Interfaces/English.lproj/DataMigrationDialog.xib71
-rw-r--r--Source/SPFieldMapperController.h10
-rw-r--r--Source/SPFieldMapperController.m48
3 files changed, 104 insertions, 25 deletions
diff --git a/Interfaces/English.lproj/DataMigrationDialog.xib b/Interfaces/English.lproj/DataMigrationDialog.xib
index f908ed52..d0afc212 100644
--- a/Interfaces/English.lproj/DataMigrationDialog.xib
+++ b/Interfaces/English.lproj/DataMigrationDialog.xib
@@ -12,7 +12,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="133"/>
+ <integer value="12"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -991,7 +991,7 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
<bytes key="NSRGB">MC45Mjk0MTE4Mjg1IDAuOTI5NDExODI4NSAwLjkyOTQxMTgyODUAA</bytes>
</object>
<object class="NSCursor" key="NSCursor">
- <string key="NSHotSpot">{4, 4}</string>
+ <string key="NSHotSpot">{1, -1}</string>
<int key="NSCursorType">0</int>
</object>
<int key="NScvFlags">6</int>
@@ -1043,9 +1043,10 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
<int key="NSPeriodicInterval">75</int>
- <object class="NSMenuItem" key="NSMenuItem" id="288483296">
+ <object class="NSMenuItem" key="NSMenuItem" id="863046035">
<reference key="NSMenu" ref="877368345"/>
- <string key="NSTitle">file order</string>
+ <bool key="NSIsDisabled">YES</bool>
+ <string key="NSTitle">matching names</string>
<string key="NSKeyEquiv"/>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
@@ -1053,6 +1054,7 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
<reference key="NSOnImage" ref="884724275"/>
<reference key="NSMixedImage" ref="1071040955"/>
<string key="NSAction">_popUpItemAction:</string>
+ <int key="NSTag">2</int>
<reference key="NSTarget" ref="940205369"/>
</object>
<bool key="NSMenuItemRespectAlignment">YES</bool>
@@ -1060,35 +1062,34 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
<string key="NSTitle">OtherViews</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="288483296"/>
- <object class="NSMenuItem" id="771511410">
+ <object class="NSMenuItem" id="288483296">
<reference key="NSMenu" ref="877368345"/>
- <string key="NSTitle">reversed file order</string>
+ <string key="NSTitle">file order</string>
<string key="NSKeyEquiv"/>
+ <int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="884724275"/>
<reference key="NSMixedImage" ref="1071040955"/>
<string key="NSAction">_popUpItemAction:</string>
- <int key="NSTag">1</int>
<reference key="NSTarget" ref="940205369"/>
</object>
- <object class="NSMenuItem" id="863046035">
+ <object class="NSMenuItem" id="771511410">
<reference key="NSMenu" ref="877368345"/>
- <bool key="NSIsDisabled">YES</bool>
- <string key="NSTitle">matching names</string>
+ <string key="NSTitle">reversed file order</string>
<string key="NSKeyEquiv"/>
- <int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="884724275"/>
<reference key="NSMixedImage" ref="1071040955"/>
<string key="NSAction">_popUpItemAction:</string>
- <int key="NSTag">2</int>
+ <int key="NSTag">1</int>
<reference key="NSTarget" ref="940205369"/>
</object>
+ <reference ref="863046035"/>
</object>
<bool key="NSNoAutoenable">YES</bool>
<reference key="NSMenuFont" ref="388072550"/>
</object>
+ <int key="NSSelectedIndex">2</int>
<int key="NSPreferredEdge">1</int>
<bool key="NSUsesItemFromMenu">YES</bool>
<bool key="NSAltersState">YES</bool>
@@ -1335,6 +1336,30 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
</object>
<int key="connectionID">152</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">matchingNameMenuItem</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="863046035"/>
+ </object>
+ <int key="connectionID">154</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeHasHeaderCheckbox:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="397227507"/>
+ </object>
+ <int key="connectionID">155</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">addGlobalSourceVariable:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="42651750"/>
+ </object>
+ <int key="connectionID">156</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1974,9 +1999,9 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{164, 144}, {465, 405}}</string>
+ <string>{{120, 351}, {465, 405}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{164, 144}, {465, 405}}</string>
+ <string>{{120, 351}, {465, 405}}</string>
<integer value="1"/>
<string>{{387, 725}, {432, 282}}</string>
<integer value="0"/>
@@ -1995,7 +2020,7 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{170, 196}, {161, 54}}</string>
+ <string>{{126, 403}, {161, 54}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2138,7 +2163,7 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">152</int>
+ <int key="maxID">156</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -2174,7 +2199,9 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <string>addGlobalSourceVariable:</string>
<string>changeFieldAlignment:</string>
+ <string>changeHasHeaderCheckbox:</string>
<string>changeImportMethod:</string>
<string>changeTableTarget:</string>
<string>closeSheet:</string>
@@ -2187,6 +2214,8 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
+ <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
@@ -2200,6 +2229,7 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
<string>importButton</string>
<string>importFieldNamesHeaderSwitch</string>
<string>importMethodPopup</string>
+ <string>matchingNameMenuItem</string>
<string>recordCountLabel</string>
<string>rowDownButton</string>
<string>rowUpButton</string>
@@ -2208,17 +2238,18 @@ cyAKCQluZXcgcm93cyBSRVBMQUNFIElOVE8g4oCmA</bytes>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
- <string>id</string>
+ <string>NSPopUpButton</string>
<string>NSTableView</string>
<string>id</string>
<string>NSPathControl</string>
<string>id</string>
<string>id</string>
+ <string>NSPopUpButton</string>
+ <string>NSMenuItem</string>
<string>id</string>
<string>id</string>
<string>id</string>
- <string>id</string>
- <string>id</string>
+ <string>NSPopUpButton</string>
<string>id</string>
</object>
</object>
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h
index 62139b7d..4b9a3178 100644
--- a/Source/SPFieldMapperController.h
+++ b/Source/SPFieldMapperController.h
@@ -37,10 +37,11 @@
IBOutlet id importFieldNamesHeaderSwitch;
IBOutlet id importButton;
IBOutlet NSPopUpButton *alignByPopup;
-
+ IBOutlet NSMenuItem *matchingNameMenuItem;
+
id theDelegate;
id fieldMappingImportArray;
-
+
NSInteger fieldMappingCurrentRow;
NSMutableArray *fieldMappingArray;
NSMutableArray *fieldMappingTableColumnNames;
@@ -49,7 +50,7 @@
NSMutableArray *fieldMappingButtonOptions;
NSMutableArray *fieldMappingOperatorOptions;
NSMutableArray *fieldMappingOperatorArray;
-
+
NSNumber *doImport;
NSNumber *doNotImport;
NSNumber *isEqual;
@@ -87,10 +88,13 @@
- (IBAction)changeTableTarget:(id)sender;
- (IBAction)changeImportMethod:(id)sender;
- (IBAction)changeFieldAlignment:(id)sender;
+- (IBAction)changeHasHeaderCheckbox:(id)sender;
- (IBAction)stepRow:(id)sender;
+- (IBAction)addGlobalSourceVariable:(id)sender;
- (IBAction)closeSheet:(id)sender;
// Others
+- (void)matchHeaderNames;
- (void)setupFieldMappingArray;
- (void)updateFieldMappingButtonCell;
- (void)updateFieldMappingOperatorOptions;
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index 84dfc4c8..42ac3b0d 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -27,6 +27,7 @@
#import "SPTableData.h"
#import "TablesList.h"
#import "SPArrayAdditions.h"
+#import "SPStringAdditions.h"
#import "SPConstants.h"
@implementation SPFieldMapperController
@@ -95,6 +96,7 @@
[importFieldNamesHeaderSwitch setState:importFieldNamesHeader];
+ [self changeHasHeaderCheckbox:self];
[self changeTableTarget:self];
[[self window] makeFirstResponder:fieldMapperTableView];
if([fieldMappingTableColumnNames count])
@@ -162,7 +164,7 @@
- (BOOL)importFieldNamesHeader
{
- return importFieldNamesHeader;
+ return ([importFieldNamesHeaderSwitch state] == NSOnState)?YES:NO;
}
#pragma mark -
@@ -279,7 +281,9 @@
for(i=possibleImports; i>=0; i--)
[fieldMappingArray replaceObjectAtIndex:possibleImports-i withObject:[NSNumber numberWithInteger:i]];
break;
-
+ case 2: // try to align header and table target field names via Levenshtein distance
+ [self matchHeaderNames];
+ break;
}
[fieldMapperTableView reloadData];
}
@@ -304,6 +308,46 @@
[rowUpButton setEnabled:(fieldMappingCurrentRow != ([fieldMappingImportArray count]-1))];
}
+- (IBAction)changeHasHeaderCheckbox:(id)sender
+{
+ [matchingNameMenuItem setEnabled:([importFieldNamesHeaderSwitch state] == NSOnState)?YES:NO];
+}
+
+- (IBAction)addGlobalSourceVariable:(id)sender
+{
+
+}
+
+#pragma mark -
+#pragma mark Others
+
+- (void)matchHeaderNames
+{
+ if(![fieldMappingImportArray count]) return;
+
+ NSMutableArray *fileHeaderNames = [NSMutableArray array];
+ [fileHeaderNames setArray:NSArrayObjectAtIndex(fieldMappingImportArray, 0)];
+ NSMutableArray *tableHeaderNames = [NSMutableArray array];
+ [tableHeaderNames setArray:fieldMappingTableColumnNames];
+
+ NSInteger i,j;
+ NSMutableArray *matchedHeaderNames = [NSMutableArray array];
+ for(i=0; i < [tableHeaderNames count]; i++) {
+ CGFloat minDist = 1e6;
+ NSInteger minIndex = 0;
+ for(j=0; j < [fileHeaderNames count]; j++) {
+ NSString *headerName = [NSArrayObjectAtIndex(fileHeaderNames,j) lowercaseString];
+ CGFloat dist = [[NSArrayObjectAtIndex(tableHeaderNames,i) lowercaseString] levenshteinDistanceWithWord:headerName];
+ if(dist < minDist && ![matchedHeaderNames containsObject:headerName]) {
+ minDist = dist;
+ minIndex = j;
+ }
+ if(dist == 0.0f) [matchedHeaderNames addObject:headerName];
+ }
+ [fieldMappingArray replaceObjectAtIndex:i withObject:[NSNumber numberWithInteger:minIndex]];
+ }
+}
+
/*
* Sets up the fieldMapping array to be shown in the tableView
*/