NSString - Unicode to ASCII equivalent - objective-c
I need to convert NSString in unicode to NSString in ASCII changing all local characters:
Ą to A,
Ś to S,
Ó to O,
ü to u,
And so on...
What is the simplest way to do it?
-[NSString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES].
All of the examples you gave are handled as you want. Looks like characters with no obvious analog, such as ☃, go to '?'.
NSString *unicode = #"Chào mừng đến với Việt Nam.";
NSString *standard = [unicode stringByReplacingOccurrencesOfString:#"đ" withString:#"d"];
standard = [standard stringByReplacingOccurrencesOfString:#"Đ" withString:#"D"];
NSData *decode = [standard dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *ansi = [[NSString alloc] initWithData:decode encoding:NSASCIIStringEncoding];
NSLog(#"ANSI: %#", ansi);
Ken answer will replace "æ" with "ae" and "ß" with "s", but won't replace ligatures œ, ij, ff, fi, fl, ffi, ffl, ſt, st, ...
An improved solution is to first insert additional lines of mapping to handle everything fine:
string = [string stringByReplacingOccurrencesOfString:#"Œ" withString:#"OE"];
string = [string stringByReplacingOccurrencesOfString:#"œ" withString:#"oe"];
string = [string stringByReplacingOccurrencesOfString:#"Đ" withString:#"D"];
string = [string stringByReplacingOccurrencesOfString:#"đ" withString:#"d"];
string = [string precomposedStringWithCompatibilityMapping];
NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *newString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
Objective C's NSASCIIEncoding only supports upto 127 , the character set you are looking for are beyond 127 in ASCII table.
NSASCIIStringEncoding
Strict 7-bit ASCII encoding within 8-bit chars; ASCII values 0…127 only.
Available in Mac OS X v10.0 and later.
Declared in NSString.h.
NSData *data = [decode dataUsingEncoding:[NSString defaultCStringEncoding]];
decode = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSUTF8StringEncoding, and [NSSring UTF8String] was not working for me under Xcode 12.2
Here is a my custom NSString Category which works for all ASCII values 0..255 in objective c
Header-fle
#import <Cocoa/Cocoa.h>
#interface NSString (ASCIIEncode)
- (const char*)ASCIIEncode;
#end
Implementation
#import "NSString+ASCIIEncode.h"
#implementation NSString (ASCIIEncode)
- (const char*)ASCIIEncode {
static char output[1024];
// https://tools.piex.at/ascii-tabelle/
// https://www.ionos.de/digitalguide/server/knowhow/ascii-american-standard-code-for-information-interchange/
NSMutableArray *ascii = [NSMutableArray new];
// Hex
// 000 Dez Hex
[ascii addObject:#"\0"]; // 000 000 NUL
[ascii addObject:#( 1)]; // 001 001 SOH
[ascii addObject:#( 2)]; // 002 002 STX
[ascii addObject:#( 3)]; // 003 003 ETX
[ascii addObject:#( 4)]; // 004 004 EOT
[ascii addObject:#( 5)]; // 005 005 ENQ
[ascii addObject:#( 6)]; // 006 006 ACK
[ascii addObject:#"\a"]; // 007 007 BEL
[ascii addObject:#"\b"]; // 008 008 BS
[ascii addObject:#( 9)]; // 009 009 TAB
[ascii addObject:#"\n"]; // 010 00A LF
[ascii addObject:#(11)]; // 011 00B VT
[ascii addObject:#(12)]; // 012 00C FF
[ascii addObject:#"\r"]; // 013 00D CR
[ascii addObject:#(14)]; // 014 00E SO
[ascii addObject:#(15)]; // 015 00F NAK
// 010
[ascii addObject:#(16)]; // 016 010 DLE
[ascii addObject:#(17)]; // 017 011 DC1
[ascii addObject:#(18)]; // 018 012 DC2
[ascii addObject:#(19)]; // 019 013 DC3
[ascii addObject:#(20)]; // 020 014 DC4
[ascii addObject:#(21)]; // 021 015 NAK
[ascii addObject:#(22)]; // 022 016 SYN
[ascii addObject:#(23)]; // 023 017 ETB
[ascii addObject:#(24)]; // 024 018 CAN
[ascii addObject:#(25)]; // 025 019 EM
[ascii addObject:#(26)]; // 026 01A SUB
[ascii addObject:#(27)]; // 027 01B ESC
[ascii addObject:#(28)]; // 028 01C FS
[ascii addObject:#(29)]; // 029 01D GS
[ascii addObject:#(30)]; // 030 01E RS
[ascii addObject:#(31)]; // 031 01F US
// 020
[ascii addObject:#" "]; // 032 020 Space
[ascii addObject:#"!"]; // 033 021
[ascii addObject:#"\""]; // 034 022
[ascii addObject:#"#"]; // 035 023
[ascii addObject:#"$"]; // 036 024
[ascii addObject:#"%"]; // 037 025
[ascii addObject:#"&"]; // 038 026
[ascii addObject:#"'"]; // 039 027
[ascii addObject:#"("]; // 040 028
[ascii addObject:#")"]; // 041 029
[ascii addObject:#"*"]; // 042 02A
[ascii addObject:#"+"]; // 043 02B
[ascii addObject:#","]; // 044 02C
[ascii addObject:#"-"]; // 045 02D
[ascii addObject:#"."]; // 046 02E
[ascii addObject:#"/"]; // 047 02F
// 030
[ascii addObject:#"0"]; // 048 030
[ascii addObject:#"1"]; // 049 031
[ascii addObject:#"2"]; // 050 032
[ascii addObject:#"3"]; // 051 033
[ascii addObject:#"4"]; // 052 034
[ascii addObject:#"5"]; // 053 035
[ascii addObject:#"6"]; // 054 036
[ascii addObject:#"7"]; // 055 037
[ascii addObject:#"8"]; // 056 038
[ascii addObject:#"9"]; // 057 039
[ascii addObject:#":"]; // 058 03A
[ascii addObject:#";"]; // 059 03B
[ascii addObject:#"<"]; // 060 03C
[ascii addObject:#"="]; // 061 03D
[ascii addObject:#">"]; // 062 03E
[ascii addObject:#"?"]; // 063 03F
// 040
[ascii addObject:#"#"]; // 064 040
[ascii addObject:#"A"]; // 065 041
[ascii addObject:#"B"]; // 066 042
[ascii addObject:#"C"]; // 067 043
[ascii addObject:#"D"]; // 068 044
[ascii addObject:#"E"]; // 069 045
[ascii addObject:#"F"]; // 070 046
[ascii addObject:#"G"]; // 071 047
[ascii addObject:#"H"]; // 072 048
[ascii addObject:#"I"]; // 073 049
[ascii addObject:#"J"]; // 074 04A
[ascii addObject:#"K"]; // 075 04B
[ascii addObject:#"L"]; // 076 04C
[ascii addObject:#"M"]; // 077 04D
[ascii addObject:#"N"]; // 078 04E
[ascii addObject:#"O"]; // 079 04F
// 050
[ascii addObject:#"P"]; // 080 050
[ascii addObject:#"Q"]; // 081 051
[ascii addObject:#"R"]; // 082 052
[ascii addObject:#"S"]; // 083 053
[ascii addObject:#"T"]; // 084 054
[ascii addObject:#"U"]; // 085 055
[ascii addObject:#"V"]; // 086 056
[ascii addObject:#"W"]; // 087 057
[ascii addObject:#"X"]; // 088 058
[ascii addObject:#"Y"]; // 089 059
[ascii addObject:#"Z"]; // 090 05A
[ascii addObject:#"["]; // 091 05B
[ascii addObject:#"\\"]; // 092 05C
[ascii addObject:#"]"]; // 093 05D
[ascii addObject:#"^"]; // 094 05E
[ascii addObject:#"_"]; // 095 05F
// 060
[ascii addObject:#"`"]; // 096 060
[ascii addObject:#"a"]; // 097 061
[ascii addObject:#"b"]; // 098 062
[ascii addObject:#"c"]; // 099 063
[ascii addObject:#"d"]; // 100 064
[ascii addObject:#"e"]; // 101 065
[ascii addObject:#"f"]; // 102 066
[ascii addObject:#"g"]; // 103 067
[ascii addObject:#"h"]; // 104 068
[ascii addObject:#"i"]; // 105 069
[ascii addObject:#"j"]; // 106 06A
[ascii addObject:#"k"]; // 107 06B
[ascii addObject:#"l"]; // 108 06C
[ascii addObject:#"m"]; // 109 06D
[ascii addObject:#"n"]; // 110 06E
[ascii addObject:#"o"]; // 111 06F
// 070
[ascii addObject:#"p"]; // 112 070
[ascii addObject:#"q"]; // 113 071
[ascii addObject:#"r"]; // 114 072
[ascii addObject:#"s"]; // 115 073
[ascii addObject:#"t"]; // 116 074
[ascii addObject:#"u"]; // 117 075
[ascii addObject:#"v"]; // 118 076
[ascii addObject:#"w"]; // 119 077
[ascii addObject:#"x"]; // 120 078
[ascii addObject:#"y"]; // 121 079
[ascii addObject:#"z"]; // 122 07A
[ascii addObject:#"{"]; // 123 07B
[ascii addObject:#"|"]; // 124 07C
[ascii addObject:#"}"]; // 125 07D
[ascii addObject:#"~"]; // 126 07E
[ascii addObject:#(127)];// 127 07F DEL
// 080
[ascii addObject:#"€"]; // 128 080
[ascii addObject:#(129)];// 129 081
[ascii addObject:#"‚"]; // 130 082
[ascii addObject:#"ƒ"]; // 131 083
[ascii addObject:#"„"]; // 132 084
[ascii addObject:#"…"]; // 133 085
[ascii addObject:#"†"]; // 134 086
[ascii addObject:#"‡"]; // 135 087
[ascii addObject:#"ˆ"]; // 136 088
[ascii addObject:#"‰"]; // 137 089
[ascii addObject:#"Š"]; // 138 08A
[ascii addObject:#"‹"]; // 139 08B
[ascii addObject:#"Œ"]; // 140 08C
[ascii addObject:#(141)];// 141 08D
[ascii addObject:#"Ž"]; // 142 08E
[ascii addObject:#(143)]; // 143 08F
// 090
[ascii addObject:#(144)];// 144 090
[ascii addObject:#"‘"]; // 145 091
[ascii addObject:#"’"]; // 146 092
[ascii addObject:#"“"]; // 147 093
[ascii addObject:#"”"]; // 148 094
[ascii addObject:#"•"]; // 149 095
[ascii addObject:#"–"]; // 150 096
[ascii addObject:#"—"]; // 151 097
[ascii addObject:#"˜"]; // 152 098
[ascii addObject:#"™"]; // 153 099
[ascii addObject:#"š"]; // 154 09A
[ascii addObject:#"›"]; // 155 09B
[ascii addObject:#"œ"]; // 156 09C
[ascii addObject:#(157)];// 157 09D
[ascii addObject:#"ž"]; // 158 09E
[ascii addObject:#"Ÿ"]; // 159 09F
// 0A0
[ascii addObject:#(160)];// 160 0A0
[ascii addObject:#"¡"]; // 161 0A1
[ascii addObject:#"¢"]; // 162 0A2
[ascii addObject:#"£"]; // 163 0A3
[ascii addObject:#"¤"]; // 164 0A4
[ascii addObject:#"¥"]; // 165 0A5
[ascii addObject:#"¦"]; // 166 0A6
[ascii addObject:#"§"]; // 167 0A7
[ascii addObject:#"¨"]; // 168 0A8
[ascii addObject:#"©"]; // 169 0A9
[ascii addObject:#"ª"]; // 170 0AA
[ascii addObject:#"«"]; // 171 0AB
[ascii addObject:#"¬"]; // 172 0AC
[ascii addObject:#(173)];// 173 0AD
[ascii addObject:#"®"]; // 174 0AE
[ascii addObject:#"¯"]; // 175 0AF
// 0B0
[ascii addObject:#"°"]; // 176 0B0
[ascii addObject:#"±"]; // 177 0B1
[ascii addObject:#"²"]; // 178 0B2
[ascii addObject:#"³"]; // 179 0B3
[ascii addObject:#"´"]; // 180 0B4
[ascii addObject:#"µ"]; // 181 0B5
[ascii addObject:#"¶"]; // 182 0B6
[ascii addObject:#"·"]; // 183 0B7
[ascii addObject:#"¸"]; // 184 0B8
[ascii addObject:#"¹"]; // 185 0B9
[ascii addObject:#"º"]; // 186 0BA
[ascii addObject:#"»"]; // 187 0BB
[ascii addObject:#"¼"]; // 188 0BC
[ascii addObject:#"½"]; // 189 0BD
[ascii addObject:#"¾"]; // 190 0BE
[ascii addObject:#"¿"]; // 191 0BF
// 0C0
[ascii addObject:#"À"]; // 192 0C0
[ascii addObject:#"Á"]; // 193 0C1
[ascii addObject:#"Â"]; // 194 0C2
[ascii addObject:#"Ã"]; // 195 0C3
[ascii addObject:#"Ä"]; // 196 0C4
[ascii addObject:#"Å"]; // 197 0C5
[ascii addObject:#"Æ"]; // 198 0C6
[ascii addObject:#"Ç"]; // 199 0C7
[ascii addObject:#"È"]; // 200 0C8
[ascii addObject:#"É"]; // 201 0C9
[ascii addObject:#"Ê"]; // 202 0CA
[ascii addObject:#"Ë"]; // 203 0CB
[ascii addObject:#"Ì"]; // 204 0CC
[ascii addObject:#"Í"]; // 205 0CD
[ascii addObject:#"Î"]; // 206 0CE
[ascii addObject:#"Ï"]; // 207 0CF
// 0D0
[ascii addObject:#"Ð"]; // 208 0D0
[ascii addObject:#"Ñ"]; // 209 0D1
[ascii addObject:#"Ò"]; // 210 0D2
[ascii addObject:#"Ó"]; // 211 0D3
[ascii addObject:#"Ô"]; // 212 0D4
[ascii addObject:#"Õ"]; // 213 0D5
[ascii addObject:#"Ö"]; // 214 0D6
[ascii addObject:#"×"]; // 215 0D7
[ascii addObject:#"Ø"]; // 216 0D8
[ascii addObject:#"Ù"]; // 217 0D9
[ascii addObject:#"Ú"]; // 218 0DA
[ascii addObject:#"Û"]; // 219 0DB
[ascii addObject:#"Ü"]; // 220 0DC
[ascii addObject:#"Ý"]; // 221 0DD
[ascii addObject:#"Þ"]; // 222 0DE
[ascii addObject:#"ß"]; // 223 0DF
// 0E0
[ascii addObject:#"à"]; // 224 0E0
[ascii addObject:#"á"]; // 225 0E1
[ascii addObject:#"â"]; // 226 0E2
[ascii addObject:#"ã"]; // 227 0E3
[ascii addObject:#"ä"]; // 228 0E4
[ascii addObject:#"å"]; // 229 0E5
[ascii addObject:#"æ"]; // 230 0E6
[ascii addObject:#"ç"]; // 231 0E7
[ascii addObject:#"è"]; // 232 0E8
[ascii addObject:#"é"]; // 233 0E9
[ascii addObject:#"ê"]; // 234 0EA
[ascii addObject:#"ë"]; // 235 0EB
[ascii addObject:#"ì"]; // 236 0EC
[ascii addObject:#"í"]; // 237 0ED
[ascii addObject:#"î"]; // 238 0EE
[ascii addObject:#"ï"]; // 239 0EF
// 0F0
[ascii addObject:#"ð"]; // 240 0F0
[ascii addObject:#"ñ"]; // 241 0F1
[ascii addObject:#"ò"]; // 242 0F2
[ascii addObject:#"ó"]; // 243 0F3
[ascii addObject:#"ô"]; // 244 0F4
[ascii addObject:#"õ"]; // 245 0F5
[ascii addObject:#"ö"]; // 246 0F6
[ascii addObject:#"÷"]; // 247 0F7
[ascii addObject:#"ø"]; // 248 0F8
[ascii addObject:#"ù"]; // 249 0F9
[ascii addObject:#"ú"]; // 250 0FA
[ascii addObject:#"û"]; // 251 0FB
[ascii addObject:#"ü"]; // 252 0FC
[ascii addObject:#"ý"]; // 253 0FD
[ascii addObject:#"þ"]; // 254 0FE
[ascii addObject:#"ÿ"]; // 255 0FF
NSInteger i;
for (i=0; i < self.length; i++) {
NSRange range;
range.location = i;
range.length = 1;
NSString *charString = [self substringWithRange:range];
for (NSInteger asciiIdx=0; asciiIdx < ascii.count; asciiIdx++) {
if ([charString isEqualToString:ascii[asciiIdx]]) {
unsigned char c = (unsigned char)asciiIdx;
output[i] = c;
break;
}
}
}
// Don't forget string termination
output[i] = 0;
return (const char*)&output[0];
}
#end
Related
Can't install current version of the chrome driver by webdriver.Chrome(ChoromeDriverManager().install())
I want to install chromedriver.exe via piece of code driver = webdriver.Chrome(ChromeDriverManager().install()), but instead of it I have obtained an error: ---------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\driver.py:45, in Driver.get_version(self) 44 try: ---> 45 return self.get_latest_release_version() 46 except Exception: File C:\Program Files\Python310\lib\site-packages\webdriver_manager\drivers\chrome.py:53, in ChromeDriver.get_latest_release_version(self) 52 def get_latest_release_version(self): ---> 53 browser_version = self.get_browser_version() 54 log(f"Get LATEST {self._name} version for {self.get_browser_type()} {browser_version}") File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\driver.py:55, in Driver.get_browser_version(self) 54 def get_browser_version(self): ---> 55 return get_browser_version_from_os(self.get_browser_type()) File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\utils.py:141, in get_browser_version_from_os(browser_type) 131 """Return installed browser version.""" 132 cmd_mapping = { 133 ChromeType.GOOGLE: { 134 OSType.LINUX: linux_browser_apps_to_cmd( 135 "google-chrome", 136 "google-chrome-stable", 137 "google-chrome-beta", 138 "google-chrome-dev", 139 ), 140 OSType.MAC: r"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version", --> 141 OSType.WIN: windows_browser_apps_to_cmd( 142 r'(Get-Item -Path "$env:PROGRAMFILES\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion', 143 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion', 144 r'(Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion', 145 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Google\Chrome\BLBeacon").version', 146 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome").version', 147 ), 148 }, 149 ChromeType.CHROMIUM: { 150 OSType.LINUX: linux_browser_apps_to_cmd("chromium", "chromium-browser"), 151 OSType.MAC: r"/Applications/Chromium.app/Contents/MacOS/Chromium --version", 152 OSType.WIN: windows_browser_apps_to_cmd( 153 r'(Get-Item -Path "$env:PROGRAMFILES\Chromium\Application\chrome.exe").VersionInfo.FileVersion', 154 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Chromium\Application\chrome.exe").VersionInfo.FileVersion', 155 r'(Get-Item -Path "$env:LOCALAPPDATA\Chromium\Application\chrome.exe").VersionInfo.FileVersion', 156 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Chromium\BLBeacon").version', 157 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Chromium").version', 158 ), 159 }, 160 ChromeType.BRAVE: { 161 OSType.LINUX: linux_browser_apps_to_cmd( 162 "brave-browser", "brave-browser-beta", "brave-browser-nightly" 163 ), 164 OSType.MAC: r"/Applications/Brave\ Browser.app/Contents/MacOS/Brave\ Browser --version", 165 OSType.WIN: windows_browser_apps_to_cmd( 166 r'(Get-Item -Path "$env:PROGRAMFILES\BraveSoftware\Brave-Browser\Application\brave.exe").VersionInfo.FileVersion', 167 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\BraveSoftware\Brave-Browser\Application\brave.exe").VersionInfo.FileVersion', 168 r'(Get-Item -Path "$env:LOCALAPPDATA\BraveSoftware\Brave-Browser\Application\brave.exe").VersionInfo.FileVersion', 169 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\BraveSoftware\Brave-Browser\BLBeacon").version', 170 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\BraveSoftware Brave-Browser").version', 171 ), 172 }, 173 ChromeType.MSEDGE: { 174 OSType.LINUX: linux_browser_apps_to_cmd( 175 "microsoft-edge", 176 "microsoft-edge-stable", 177 "microsoft-edge-beta", 178 "microsoft-edge-dev", 179 ), 180 OSType.MAC: r"/Applications/Microsoft\ Edge.app/Contents/MacOS/Microsoft\ Edge --version", 181 OSType.WIN: windows_browser_apps_to_cmd( 182 # stable edge 183 r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge\Application\msedge.exe").VersionInfo.FileVersion', 184 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge\Application\msedge.exe").VersionInfo.FileVersion', 185 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Microsoft\Edge\BLBeacon").version', 186 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Microsoft\EdgeUpdate\Clients\{56EB18F8-8008-4CBD-B6D2-8C97FE7E9062}").pv', 187 # beta edge 188 r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge Beta\Application\msedge.exe").VersionInfo.FileVersion', 189 r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge Beta\Application\msedge.exe").VersionInfo.FileVersion', 190 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge Beta\Application\msedge.exe").VersionInfo.FileVersion', 191 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Microsoft\Edge Beta\BLBeacon").version', 192 # dev edge 193 r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge Dev\Application\msedge.exe").VersionInfo.FileVersion', 194 r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge Dev\Application\msedge.exe").VersionInfo.FileVersion', 195 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge Dev\Application\msedge.exe").VersionInfo.FileVersion', 196 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Microsoft\Edge Dev\BLBeacon").version', 197 # canary edge 198 r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge SxS\Application\msedge.exe").VersionInfo.FileVersion', 199 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Microsoft\Edge SxS\BLBeacon").version', 200 # highest edge 201 r"(Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe').'(Default)').VersionInfo.ProductVersion", 202 r"[System.Diagnostics.FileVersionInfo]::GetVersionInfo((Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe').'(Default)').ProductVersion", 203 r"Get-AppxPackage -Name *MicrosoftEdge.* | Foreach Version", 204 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge").version', 205 ), 206 }, 207 "firefox": { 208 OSType.LINUX: linux_browser_apps_to_cmd("firefox"), 209 OSType.MAC: r"/Applications/Firefox.app/Contents/MacOS/firefox --version", 210 OSType.WIN: windows_browser_apps_to_cmd( 211 r'(Get-Item -Path "$env:PROGRAMFILES\Mozilla Firefox\firefox.exe").VersionInfo.FileVersion', 212 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Mozilla Firefox\firefox.exe").VersionInfo.FileVersion', 213 r"(Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe').'(Default)').VersionInfo.ProductVersion", 214 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Mozilla\Mozilla Firefox").CurrentVersion', 215 ), 216 }, 217 } 219 try: File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\utils.py:120, in windows_browser_apps_to_cmd(*apps) 119 """Create analogue of browser --version command for windows.""" --> 120 powershell = determine_powershell() 122 first_hit_template = """$tmp = {expression}; if ($tmp) {{echo $tmp; Exit;}};""" File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\utils.py:272, in determine_powershell() 271 cmd = "(dir 2>&1 *`|echo CMD);&<# rem #>echo powershell" --> 272 with subprocess.Popen( 273 cmd, 274 stdout=subprocess.PIPE, 275 stderr=subprocess.DEVNULL, 276 stdin=subprocess.DEVNULL, 277 shell=True, 278 ) as stream: 279 stdout = stream.communicate()[0].decode() File C:\Program Files\Python310\lib\subprocess.py:969, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize) 966 self.stderr = io.TextIOWrapper(self.stderr, 967 encoding=encoding, errors=errors) --> 969 self._execute_child(args, executable, preexec_fn, close_fds, 970 pass_fds, cwd, env, 971 startupinfo, creationflags, shell, 972 p2cread, p2cwrite, 973 c2pread, c2pwrite, 974 errread, errwrite, 975 restore_signals, 976 gid, gids, uid, umask, 977 start_new_session) 978 except: 979 # Cleanup if the child failed starting. File C:\Program Files\Python310\lib\subprocess.py:1438, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session) 1437 try: -> 1438 hp, ht, pid, tid = _winapi.CreateProcess(executable, args, 1439 # no special security 1440 None, None, 1441 int(not close_fds), 1442 creationflags, 1443 env, 1444 cwd, 1445 startupinfo) 1446 finally: 1447 # Child is launched. Close the parent's copy of those pipe 1448 # handles that only the child should have open. You need (...) 1451 # pipe will not close when the child process exits and the 1452 # ReadFile will hang. FileNotFoundError: [WinError 2] The system cannot find the file specified During handling of the above exception, another exception occurred: FileNotFoundError Traceback (most recent call last) Cell In[28], line 1 ----> 1 driver = webdriver.Chrome(ChromeDriverManager().install()) 2 #[WinError 2] The system cannot find the file specified File C:\Program Files\Python310\lib\site-packages\webdriver_manager\chrome.py:39, in ChromeDriverManager.install(self) 38 def install(self) -> str: ---> 39 driver_path = self._get_driver_path(self.driver) 40 os.chmod(driver_path, 0o755) 41 return driver_path File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\manager.py:26, in DriverManager._get_driver_path(self, driver) 25 def _get_driver_path(self, driver): ---> 26 binary_path = self.driver_cache.find_driver(driver) 27 if binary_path: 28 return binary_path File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\driver_cache.py:96, in DriverCache.find_driver(self, driver) 94 os_type = driver.get_os_type() 95 driver_name = driver.get_name() ---> 96 driver_version = driver.get_version() 97 browser_version = driver.get_browser_version() 98 browser_type = driver.get_browser_type() File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\driver.py:47, in Driver.get_version(self) 45 return self.get_latest_release_version() 46 except Exception: ---> 47 return self.get_browser_version() 48 return self._version File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\driver.py:55, in Driver.get_browser_version(self) 54 def get_browser_version(self): ---> 55 return get_browser_version_from_os(self.get_browser_type()) File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\utils.py:141, in get_browser_version_from_os(browser_type) 130 def get_browser_version_from_os(browser_type=None): 131 """Return installed browser version.""" 132 cmd_mapping = { 133 ChromeType.GOOGLE: { 134 OSType.LINUX: linux_browser_apps_to_cmd( 135 "google-chrome", 136 "google-chrome-stable", 137 "google-chrome-beta", 138 "google-chrome-dev", 139 ), 140 OSType.MAC: r"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version", --> 141 OSType.WIN: windows_browser_apps_to_cmd( 142 r'(Get-Item -Path "$env:PROGRAMFILES\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion', 143 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion', 144 r'(Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion', 145 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Google\Chrome\BLBeacon").version', 146 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome").version', 147 ), 148 }, 149 ChromeType.CHROMIUM: { 150 OSType.LINUX: linux_browser_apps_to_cmd("chromium", "chromium-browser"), 151 OSType.MAC: r"/Applications/Chromium.app/Contents/MacOS/Chromium --version", 152 OSType.WIN: windows_browser_apps_to_cmd( 153 r'(Get-Item -Path "$env:PROGRAMFILES\Chromium\Application\chrome.exe").VersionInfo.FileVersion', 154 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Chromium\Application\chrome.exe").VersionInfo.FileVersion', 155 r'(Get-Item -Path "$env:LOCALAPPDATA\Chromium\Application\chrome.exe").VersionInfo.FileVersion', 156 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Chromium\BLBeacon").version', 157 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Chromium").version', 158 ), 159 }, 160 ChromeType.BRAVE: { 161 OSType.LINUX: linux_browser_apps_to_cmd( 162 "brave-browser", "brave-browser-beta", "brave-browser-nightly" 163 ), 164 OSType.MAC: r"/Applications/Brave\ Browser.app/Contents/MacOS/Brave\ Browser --version", 165 OSType.WIN: windows_browser_apps_to_cmd( 166 r'(Get-Item -Path "$env:PROGRAMFILES\BraveSoftware\Brave-Browser\Application\brave.exe").VersionInfo.FileVersion', 167 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\BraveSoftware\Brave-Browser\Application\brave.exe").VersionInfo.FileVersion', 168 r'(Get-Item -Path "$env:LOCALAPPDATA\BraveSoftware\Brave-Browser\Application\brave.exe").VersionInfo.FileVersion', 169 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\BraveSoftware\Brave-Browser\BLBeacon").version', 170 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\BraveSoftware Brave-Browser").version', 171 ), 172 }, 173 ChromeType.MSEDGE: { 174 OSType.LINUX: linux_browser_apps_to_cmd( 175 "microsoft-edge", 176 "microsoft-edge-stable", 177 "microsoft-edge-beta", 178 "microsoft-edge-dev", 179 ), 180 OSType.MAC: r"/Applications/Microsoft\ Edge.app/Contents/MacOS/Microsoft\ Edge --version", 181 OSType.WIN: windows_browser_apps_to_cmd( 182 # stable edge 183 r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge\Application\msedge.exe").VersionInfo.FileVersion', 184 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge\Application\msedge.exe").VersionInfo.FileVersion', 185 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Microsoft\Edge\BLBeacon").version', 186 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Microsoft\EdgeUpdate\Clients\{56EB18F8-8008-4CBD-B6D2-8C97FE7E9062}").pv', 187 # beta edge 188 r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge Beta\Application\msedge.exe").VersionInfo.FileVersion', 189 r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge Beta\Application\msedge.exe").VersionInfo.FileVersion', 190 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge Beta\Application\msedge.exe").VersionInfo.FileVersion', 191 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Microsoft\Edge Beta\BLBeacon").version', 192 # dev edge 193 r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge Dev\Application\msedge.exe").VersionInfo.FileVersion', 194 r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge Dev\Application\msedge.exe").VersionInfo.FileVersion', 195 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge Dev\Application\msedge.exe").VersionInfo.FileVersion', 196 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Microsoft\Edge Dev\BLBeacon").version', 197 # canary edge 198 r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge SxS\Application\msedge.exe").VersionInfo.FileVersion', 199 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Microsoft\Edge SxS\BLBeacon").version', 200 # highest edge 201 r"(Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe').'(Default)').VersionInfo.ProductVersion", 202 r"[System.Diagnostics.FileVersionInfo]::GetVersionInfo((Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe').'(Default)').ProductVersion", 203 r"Get-AppxPackage -Name *MicrosoftEdge.* | Foreach Version", 204 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge").version', 205 ), 206 }, 207 "firefox": { 208 OSType.LINUX: linux_browser_apps_to_cmd("firefox"), 209 OSType.MAC: r"/Applications/Firefox.app/Contents/MacOS/firefox --version", 210 OSType.WIN: windows_browser_apps_to_cmd( 211 r'(Get-Item -Path "$env:PROGRAMFILES\Mozilla Firefox\firefox.exe").VersionInfo.FileVersion', 212 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Mozilla Firefox\firefox.exe").VersionInfo.FileVersion', 213 r"(Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe').'(Default)').VersionInfo.ProductVersion", 214 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Mozilla\Mozilla Firefox").CurrentVersion', 215 ), 216 }, 217 } 219 try: 220 cmd_mapping = cmd_mapping[browser_type][os_name()] File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\utils.py:120, in windows_browser_apps_to_cmd(*apps) 118 def windows_browser_apps_to_cmd(*apps: str) -> str: 119 """Create analogue of browser --version command for windows.""" --> 120 powershell = determine_powershell() 122 first_hit_template = """$tmp = {expression}; if ($tmp) {{echo $tmp; Exit;}};""" 123 script = "$ErrorActionPreference='silentlycontinue'; " + " ".join( 124 first_hit_template.format(expression=e) for e in apps 125 ) File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\utils.py:272, in determine_powershell() 270 """Returns "True" if runs in Powershell and "False" if another console.""" 271 cmd = "(dir 2>&1 *`|echo CMD);&<# rem #>echo powershell" --> 272 with subprocess.Popen( 273 cmd, 274 stdout=subprocess.PIPE, 275 stderr=subprocess.DEVNULL, 276 stdin=subprocess.DEVNULL, 277 shell=True, 278 ) as stream: 279 stdout = stream.communicate()[0].decode() 280 return "" if stdout == "powershell" else "powershell" File C:\Program Files\Python310\lib\subprocess.py:969, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize) 965 if self.text_mode: 966 self.stderr = io.TextIOWrapper(self.stderr, 967 encoding=encoding, errors=errors) --> 969 self._execute_child(args, executable, preexec_fn, close_fds, 970 pass_fds, cwd, env, 971 startupinfo, creationflags, shell, 972 p2cread, p2cwrite, 973 c2pread, c2pwrite, 974 errread, errwrite, 975 restore_signals, 976 gid, gids, uid, umask, 977 start_new_session) 978 except: 979 # Cleanup if the child failed starting. 980 for f in filter(None, (self.stdin, self.stdout, self.stderr)): File C:\Program Files\Python310\lib\subprocess.py:1438, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session) 1436 # Start the process 1437 try: -> 1438 hp, ht, pid, tid = _winapi.CreateProcess(executable, args, 1439 # no special security 1440 None, None, 1441 int(not close_fds), 1442 creationflags, 1443 env, 1444 cwd, 1445 startupinfo) 1446 finally: 1447 # Child is launched. Close the parent's copy of those pipe 1448 # handles that only the child should have open. You need (...) 1451 # pipe will not close when the child process exits and the 1452 # ReadFile will hang. 1453 self._close_pipe_fds(p2cread, p2cwrite, 1454 c2pread, c2pwrite, 1455 errread, errwrite) FileNotFoundError: [WinError 2] The system cannot find the file specified Therefore, I have to download into my system ditectory chromedriver.exe of 109.0.5414.74 version and activating one by code PATH = 'C:/Program Files/chromedriver/chromedriver.exe' options = Options() service = Service(PATH) driver = webdriver.Chrome(service = service, options = options). Please, help me to fix eror in automatic installing ChromeDriver via code noted above. My Chrome version is 109.0.5414.75.
This error message... FileNotFoundError Traceback (most recent call last) File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\driver.py:45, in Driver.get_version(self) 44 try: ---> 45 return self.get_latest_release_version() 46 except Exception: File C:\Program Files\Python310\lib\site-packages\webdriver_manager\drivers\chrome.py:53, in ChromeDriver.get_latest_release_version(self) 52 def get_latest_release_version(self): ---> 53 browser_version = self.get_browser_version() 54 log(f"Get LATEST {self._name} version for {self.get_browser_type()} {browser_version}") File C:\Program Files\Python310\lib\site-packages\webdriver_manager\core\driver.py:55, in Driver.get_browser_version(self) 54 def get_browser_version(self): ---> 55 return get_browser_version_from_os(self.get_browser_type()) ...implies that webdriver_manager was not able to detect the google-chrome version as FileNotFoundError was raised while the following queries were performed: --> 141 OSType.WIN: windows_browser_apps_to_cmd( 142 r'(Get-Item -Path "$env:PROGRAMFILES\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion', 143 r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion', 144 r'(Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion', 145 r'(Get-ItemProperty -Path Registry::"HKCU\SOFTWARE\Google\Chrome\BLBeacon").version', 146 r'(Get-ItemProperty -Path Registry::"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome").version', 147 ), Solution Ensure that Google Chrome is updated to the latest version and is installed at the default location i.e. in either of the following locations: PROGRAMFILES\Google\Chrome\Application\chrome.exe PROGRAMFILES (x86)\Google\Chrome\Application\chrome.exe LOCALAPPDATA\Google\Chrome\Application\chrome.exe
SQL query is not working (Error in rsqlite_send_query)
This is what the head of my data frame looks like > head(d19_1) SMZ SIZ1_diff SIZ1_base SIZ2_diff SIZ2_base SIZ3_diff SIZ3_base SIZ4_diff SIZ4_base SIZ5_diff SIZ5_base 1 1 -620 4170 -189 1347 -35 2040 82 1437 244 1533 2 2 -219 831 -57 255 -4 392 8 282 14 297 3 3 -426 834 -162 294 -134 379 -81 241 -22 221 4 4 -481 676 -142 216 -114 267 -50 158 -43 166 5 5 -233 1711 -109 584 54 913 71 624 74 707 6 6 -322 1539 -79 512 -50 799 23 532 63 576 Total_og Total_base %_SIZ1 %_SIZ2 %_SIZ3 %_SIZ4 %_SIZ5 Total_og Total_base 1 11980 12648 14.86811 14.03118 1.715686 5.706333 15.916504 11980 12648 2 2156 2415 26.35379 22.35294 1.020408 2.836879 4.713805 2156 2415 3 1367 2314 51.07914 55.10204 35.356201 33.609959 9.954751 1367 2314 4 790 1736 71.15385 65.74074 42.696629 31.645570 25.903614 790 1736 5 5339 5496 13.61777 18.66438 5.914567 11.378205 10.466761 5339 5496 6 4362 4747 20.92268 15.42969 6.257822 4.323308 10.937500 4362 4747 The datatype of the data frame is as below str(d19_1) > str(d19_1) 'data.frame': 1588 obs. of 20 variables: $ SMZ : int 1 2 3 4 5 6 7 8 9 10 ... $ SIZ1_diff : int -620 -219 -426 -481 -233 -322 -176 -112 -34 -103 ... $ SIZ1_base : int 4170 831 834 676 1711 1539 720 1396 998 1392 ... $ SIZ2_diff : int -189 -57 -162 -142 -109 -79 -12 72 -36 -33 ... $ SIZ2_base : int 1347 255 294 216 584 512 196 437 343 479 ... $ SIZ3_diff : int -35 -4 -134 -114 54 -50 16 4 26 83 ... $ SIZ3_base : int 2040 392 379 267 913 799 361 804 566 725 ... $ SIZ4_diff : int 82 8 -81 -50 71 23 36 127 46 75 ... $ SIZ4_base : int 1437 282 241 158 624 532 242 471 363 509 ... $ SIZ5_diff : int 244 14 -22 -43 74 63 11 143 79 125 ... $ SIZ5_base : int 1533 297 221 166 707 576 263 582 429 536 ... $ Total_og : int 11980 2156 1367 790 5339 4362 2027 4715 3465 4561 ... $ Total_base: int 12648 2415 2314 1736 5496 4747 2168 4464 3278 4375 ... $ %_SIZ1 : num 14.9 26.4 51.1 71.2 13.6 ... $ %_SIZ2 : num 14 22.4 55.1 65.7 18.7 ... $ %_SIZ3 : num 1.72 1.02 35.36 42.7 5.91 ... $ %_SIZ4 : num 5.71 2.84 33.61 31.65 11.38 ... $ %_SIZ5 : num 15.92 4.71 9.95 25.9 10.47 ... $ Total_og : int 11980 2156 1367 790 5339 4362 2027 4715 3465 4561 ... $ Total_base: int 12648 2415 2314 1736 5496 4747 2168 4464 3278 4375 ... When I run the below query, it is returning me the below error and I don't know why. I don't have any column in table Query d20_1 <- sqldf('SELECT *, CASE WHEN SMZ BETWEEN 1 AND 110 THEN "Baltimore City" WHEN SMZ BETWEEN 111 AND 217 THEN "Anne Arundel County" WHEN SMZ BETWEEN 218 AND 405 THEN "Baltimore County" WHEN SMZ BETWEEN 406 AND 453 THEN "Carroll County" WHEN SMZ BETWEEN 454 AND 524 THEN "Harford County" WHEN SMZ BETWEEN 1667 AND 1674 THEN "York County" ELSE 0 END Jurisdiction FROM d19_1') Error: Error in rsqlite_send_query(conn#ptr, statement) : table d19_1 has no column named <NA>
Your code works correctly for me: d19_1 <- structure(list(SMZ = 1:6, SIZ1_diff = c(-620L, -219L, -426L, -481L, -233L, -322L), SIZ1_base = c(4170L, 831L, 834L, 676L, 1711L, 1539L), SIZ2_diff = c(-189L, -57L, -162L, -142L, -109L, -79L), SIZ2_base = c(1347L, 255L, 294L, 216L, 584L, 512L), SIZ3_diff = c(-35L, -4L, -134L, -114L, 54L, -50L), SIZ3_base = c(2040L, 392L, 379L, 267L, 913L, 799L), SIZ4_diff = c(82L, 8L, -81L, -50L, 71L, 23L ), SIZ4_base = c(1437L, 282L, 241L, 158L, 624L, 532L), SIZ5_diff = c(244L, 14L, -22L, -43L, 74L, 63L), SIZ5_base = c(1533L, 297L, 221L, 166L, 707L, 576L), Total_og = c(11980L, 2156L, 1367L, 790L, 5339L, 4362L), Total_base = c(12648L, 2415L, 2314L, 1736L, 5496L, 4747L ), X._SIZ1 = c(14.86811, 26.35379, 51.07914, 71.15385, 13.61777, 20.92268), X._SIZ2 = c(14.03118, 22.35294, 55.10204, 65.74074, 18.66438, 15.42969), X._SIZ3 = c(1.715686, 1.020408, 35.356201, 42.696629, 5.914567, 6.257822), X._SIZ4 = c(5.706333, 2.836879, 33.609959, 31.64557, 11.378205, 4.323308), X._SIZ5 = c(15.916504, 4.713805, 9.954751, 25.903614, 10.466761, 10.9375), Total_og.1 = c(11980L, 2156L, 1367L, 790L, 5339L, 4362L), Total_base.1 = c(12648L, 2415L, 2314L, 1736L, 5496L, 4747L)), .Names = c("SMZ", "SIZ1_diff", "SIZ1_base", "SIZ2_diff", "SIZ2_base", "SIZ3_diff", "SIZ3_base", "SIZ4_diff", "SIZ4_base", "SIZ5_diff", "SIZ5_base", "Total_og", "Total_base", "X._SIZ1", "X._SIZ2", "X._SIZ3", "X._SIZ4", "X._SIZ5", "Total_og.1", "Total_base.1"), row.names = c(NA, -6L), class = "data.frame") library(sqldf) sqldf('SELECT *, CASE WHEN SMZ BETWEEN 1 AND 110 THEN "Baltimore City" WHEN SMZ BETWEEN 111 AND 217 THEN "Anne Arundel County" WHEN SMZ BETWEEN 218 AND 405 THEN "Baltimore County" WHEN SMZ BETWEEN 406 AND 453 THEN "Carroll County" WHEN SMZ BETWEEN 454 AND 524 THEN "Harford County" WHEN SMZ BETWEEN 1667 AND 1674 THEN "York County" ELSE 0 END Jurisdiction FROM d19_1')
What's the difference of FunctionDefHelper::Create and FunctionDefHelper::Define?
the following is from math_grad.cc line543 to line554: 543 *g = FDH::Create("_", 544 // Input defs 545 {"x:T", "i:int32", "dy:T"}, 546 // Ret val defs 547 {"dx:T", "di:int32"}, 548 // Attr defs 549 {{"T: {half, float, double}"}}, 550 // Nodes 551 nodes, 552 // Return values 553 {{"dx", "dx:output:0"}, {"di", "di:y:0"}}); 554 return Status::OK(); and the following is from math_grad.cc line593 to line615, 593 Status MinMaxGradHelper(const string& op, const AttrSlice& attrs, 594 FunctionDef* g) { 595 // clang-format off 596 *g = FDH::Define( 597 // Arg defs 598 {"x:T", "i:int32", "dy:T"}, 599 // Ret val defs 600 {"dx:T", "di:int32"}, 601 // Attr defs 602 {{"T: {half, float, double}"}}, 603 { 604 // keep_dims because we need to do x == y, which requires x 605 // and y are broadcastable. 606 {{"y"}, op, {"x", "i"}, {{"T", "$T"}, {"keep_dims", true}}}, 607 {{"mask"}, "Equal", {"x", "y"}, {{"T", "$T"}}}, 608 {{"mask_cast"}, "Cast", {"mask"}, {{"SrcT", DT_BOOL}, {"DstT", "$T"}}}, 609 {{"mask_sum"}, "Sum", {"mask_cast", "i"}, {{"T", "$T"}}}, 610 {{"norm_dy"}, "Div", {"dy", "mask_sum"}, {{"T", "$T"}}}, 611 {{"sy"}, "Shape", {"y"}, {{"T", "$T"}}}, 612 {{"norm_dy_reshaped"}, "Reshape", {"norm_dy", "sy"}, {{"T", "$T"}}}, 613 {{"dx"}, "Mul", {"mask_cast", "norm_dy_reshaped"}, {{"T", "$T"}}}, 614 {{"di"}, "ZerosLike", {"i"}, {{"T", DT_INT32}}} 615 }); I am a little confused about how does TensorFlow determine whether use FDH::Define or FDH::Create. As I know, FDH::Define is an old approch to define a FunctionDef. and I thought that FDH::Define provide less information compared with FDH::Create. So, any one can help me tell the difference? Any advice will be appreciated, thanks a lot.
Answer from a colleague: "FunctionDefs are not yet part of the public API; these are temporary mechanisms for defining functions until we have real API support for them. One of those two functions is older and mirrors the older FunctionDef format, which has now been deleted. I didn't delete the function, I just made it produce the new format; but this only works in simple cases. There was too much code using that function to migrate all of them. But the main point is that this isn't documented well because it is not part of our public API and subject to change."
Protractor - find element in iframe
in very top of my page I have call of iframe: <iframe ng-if="webpadUrl" id="webPadIframe" ng-src="http://Path/To/iFrame?sessionId=9bc9989441c8c9cfb9ff5bdc381a72ea" seamless="seamless" class="fullscreen ng-scope" src="http://Path/To/iFrame?sessionId=9bc9989441c8c9cfb9ff5bdc381a72ea"> </iframe> Inside of iframe I have something like: <svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 5845 3897"> and below that multiple <g> with different ID and so on.. <g id="30_0_80" transform="translate(420,754)" class=""> <path class="fp x80 xab active" d="M307 0 L293 15 L155 120 L87 181 L47 220 L0 277 L0 282 L14 341 L27 379 L32 386 L32 386 L74 425 L123 461 L153 480 L188 500 L238 525 L303 551 L337 563 L340 563 L381 561 L490 560 L492 557 L522 526 L591 473 L662 430 L745 383 L770 368 L785 358 L796 350 L802 343 L806 335 L809 321 L809 318 L810 295 L808 293 L806 293 L763 292 L680 277 L643 269 L590 253 L555 239 L555 239 L508 214 L452 179 L397 138 L369 115 L339 79 L325 56 L310 28 L308 23 L308 19 L310 1 L307 0 Z"></path> <path class="p x88 xc7" d="M796 296 L792 300 L736 324 L595 391 L486 455 L413 505 L349 559"></path> <path class="p x88 xc7" d="M33 372 L57 324 L82 284 L128 228 L133 222 L134 221 L164 188 L222 131 L252 102 L281 69"></path><path class="p x88 xc7" d="M9 283 L24 261 L52 221 L79 190 L88 182"></path><path class="p x88 xc7" d="M169 175 L251 97 L284 60 L295 40 L303 25"></path><path class="p x88 xc7" d="M132 214 L119 229 L88 266"></path> <path class="p x88 xc7" d="M72 287 L54 315"></path><path class="p x88 xc7" d="M47 326 L44 331 L29 360"></path> </g> What I do is trying to click <g> As it is in iframe I try something like: browser.driver.switchTo().frame(element(by.id('30_0_80'))); Unfortunately doesn't work, is there any other way how to work with this iframes? Error: NoSuchElementError: No element found using locator: By.id("30_0_80")
After sometime I find a solution how to switch to right frame, hope it help someone. browser.switchTo().frame('webPadIframe'); browser.findElement(by.id('30_0_80')).click();
How to deal with non-angular iframes using control-flow. let flow = protractor.promise.controlFlow(); flow.execute(function(){ browser.ignoreSynchronization = true; //allows you to handle non angular page browser.switchTo().frame('webPadIframe'); //switches to iframe browser.findElement(by.id('30_0_80')).click(); //action within iframe browser.switchTo().defaultContent(); //switches back to main page browser.ignoreSynchronization = false; //lets you resume handling angular )};
identifying strings within intervals, pt 2
For each row, I would like to know if the numerical string in the 6th column resides within the start and end intervals of the 3rd and 4th column. The issue for me is that identical strings in the 1st and 5th column are not always in the same row (e.g., uce-6459 is on the same line as uce-432). Input locus match start end subset pos region uce-3280 uce-3280_p1 269 388 uce-3280 222 uce-6620 uce-6620_p1 297 416 uce-6620 198 uce-6620 uce-6620_p1 297 416 uce-6620 300 uce-432 uce-432_p2 328 447 uce-432 205 uce-432 uce-432_p1 268 387 uce-6459 207 uce-6459 uce-6459_p1 210 329 uce-6459 275 uce-6459 uce-6459_p1 210 329 uce-6459 288 uce-6459 uce-6459_p1 210 329 uce-374 373 uce-374 uce-374_p2 509 628 uce-3393 327 uce-374 uce-374_p1 449 568 uce-3393 416 uce-3393 uce-3393_p1 439 558 uce-3393 712 uce-3393 uce-3393_p1 439 558 uce-1200 416 uce-3393 uce-3393_p1 439 558 uce-805 397 uce-1200 uce-1200_p3 341 460 uce-627 326 uce-805 uce-805_p1 333 452 uce-2299 340 uce-627 uce-627_p1 396 515 uce-2126 481 uce-2299 uce-2299_p1 388 507 uce-5427 562 uce-2126 uce-2126_p1 323 437 uce-5427 711 uce-5427 uce-5427_p1 509 628 uce-5893 242 uce-5427 uce-5427_p1 509 628 uce-5893 330 uce-5893 uce-5893_p1 477 582 uce-5893 398 Desired output locus match start end subset pos region uce-3280 uce-3280_p1 269 388 uce-3280 222 no uce-6620 uce-6620_p1 297 416 uce-6620 198 no uce-6620 uce-6620_p1 297 416 uce-6620 300 yes uce-432 uce-432_p2 328 447 uce-432 205 no uce-432 uce-432_p1 268 387 uce-6459 207 no uce-6459 uce-6459_p1 210 329 uce-6459 275 yes uce-6459 uce-6459_p1 210 329 uce-6459 288 yes uce-6459 uce-6459_p1 210 329 uce-374 373 no uce-374 uce-374_p2 509 628 uce-3393 327 no uce-374 uce-374_p1 449 568 uce-3393 416 no uce-3393 uce-3393_p1 439 558 uce-3393 712 no uce-3393 uce-3393_p1 439 558 uce-1200 416 yes uce-3393 uce-3393_p1 439 558 uce-805 397 yes uce-1200 uce-1200_p3 341 460 uce-627 326 no uce-805 uce-805_p1 333 452 uce-2299 340 no uce-627 uce-627_p1 396 515 uce-2126 481 no uce-2299 uce-2299_p1 388 507 uce-5427 562 yes uce-2126 uce-2126_p1 323 437 uce-5427 711 no uce-5427 uce-5427_p1 509 628 uce-5893 242 no uce-5427 uce-5427_p1 509 628 uce-5893 330 no uce-5893 uce-5893_p1 477 582 uce-5893 398 no Any help would be appreciated.
Here is a full stand-alone awk-script: #!/usr/bin/awk -f # goes through the whole file, saves boundaries of the intervals NR > 1 && NR == FNR { starts[$1] = $3 ends[$1] = $4 #print "Scanned interval: "$1" = ["starts[$1]","ends[$1]"]" } # prints the header of the table NR != FNR && FNR == 1 { print $0 } # annotates each line with "yes"/"no" FNR > 1 && NR != FNR { print $0" "(starts[$5] <= $6 && $6 <= ends[$5] ? "yes" : "no") } Depending on what OS you have and what awk you are using, you might need to adjust the first line (use which awk to find the right path). In order to make it run, you have to save it in a separate file (e.g. analyzeSnp.awk), then make it executable (e.g. chmod u+x analyzeSnp.awk), and then run it like this: ./analyzeSnp.awk inputData inputData Alternatively, you can enclose it in single quotes and paste it directly into the console like this: $ awk ' #!/usr/bin/awk -f # goes through the whole file, saves boundaries of the intervals NR > 1 && NR == FNR { starts[$1] = $3 ends[$1] = $4 #print "Scanned interval: "$1" = ["starts[$1]","ends[$1]"]" } # prints the header of the table NR != FNR && FNR == 1 { print $0 } # annotates each line with "yes"/"no" FNR > 1 && NR != FNR { print $0" "(starts[$5] <= $6 && $6 <= ends[$5] ? "yes" : "no") }' loci.txt loci.txt Important: you have to specify your input file twice, because we need a first scan to build a table with intervals, and then a second scan for actual annotation. Here is the produced output: locus match start end subset pos region uce-3280 uce-3280_p1 269 388 uce-3280 222 no uce-6620 uce-6620_p1 297 416 uce-6620 198 no uce-6620 uce-6620_p1 297 416 uce-6620 300 yes uce-432 uce-432_p2 328 447 uce-432 205 no uce-432 uce-432_p1 268 387 uce-6459 207 no uce-6459 uce-6459_p1 210 329 uce-6459 275 yes uce-6459 uce-6459_p1 210 329 uce-6459 288 yes uce-6459 uce-6459_p1 210 329 uce-374 373 no uce-374 uce-374_p2 509 628 uce-3393 327 no uce-374 uce-374_p1 449 568 uce-3393 416 no uce-3393 uce-3393_p1 439 558 uce-3393 712 no uce-3393 uce-3393_p1 439 558 uce-1200 416 yes uce-3393 uce-3393_p1 439 558 uce-805 397 yes uce-1200 uce-1200_p3 341 460 uce-627 326 no uce-805 uce-805_p1 333 452 uce-2299 340 no uce-627 uce-627_p1 396 515 uce-2126 481 no uce-2299 uce-2299_p1 388 507 uce-5427 562 yes uce-2126 uce-2126_p1 323 437 uce-5427 711 no uce-5427 uce-5427_p1 509 628 uce-5893 242 no uce-5427 uce-5427_p1 509 628 uce-5893 330 no uce-5893 uce-5893_p1 477 582 uce-5893 398 no This looks pretty close to your example snippet. A general remark: AWK is a surprisingly modern and powerful scripting language (at least for it's age: this thing is almost 40 years old!). If you want to use AWK, you are not constrained to cryptic single-liners.