Hofmann Posted March 5, 2011 at 04:58 AM Report Posted March 5, 2011 at 04:58 AM In the midst of making 平水韻 flashcards for Anki, I'm stuck. I've got an Excel file at this point, where the rhyme is in column A and the character is in column B. Of course, there are some homographs, so some characters appear more than once in column B, but with a different rhyme. For example, the character 參 has the rhymes 下平聲十二侵, 下平聲十三覃, and 去聲二十八勘. I'd like to combine them such that a cell in column A has "下平聲十二侵, 下平聲十三覃, 去聲二十八勘" and the corresponding cell in column B has "參" but I'm lost on how to do that. I'm not doing that manually because there are thousands of homographs. Quote
creamyhorror Posted March 5, 2011 at 05:36 AM Report Posted March 5, 2011 at 05:36 AM It would be easier and more flexible to make a new table from your existing data: structure: [ Character | Tone 1 | Tone 2 | etc. ] (Characters are unique, not to be repeated; tone columns are to be filled with boolean YES/NO values) For each cell in the tone columns, use a LOOKUP or similar function to check for the character-tone pair in the original dataset. If true, put a "YES" in the cell; otherwise leave it blank. edit: Sorry, looks like the MATCH function is more appropriate You can then format and use this table directly. If you want the format you initially requested (2 columns only), you can use CONCATENATE functions in the columns directly to the right of the table to add successive tone names together to give you what you want. I only have OpenOffice on my computer but I can do it for you if you want. Quote
cababunga Posted March 5, 2011 at 05:51 AM Report Posted March 5, 2011 at 05:51 AM (edited) Here, I made you a tab separated file. I'm sure you can import it in Excel. Hmm... Are attachments suppose to show up anywhere? Ok, put it here: http://www.mediafire.com/?2ettwuk2h679dga Edited March 5, 2011 at 06:00 AM by cababunga 2 Quote
creamyhorror Posted March 5, 2011 at 06:06 AM Report Posted March 5, 2011 at 06:06 AM Damn, OpenOffice's MATCH function can't do what Excel can. Fail. Anyway I guess the problem's solved. Quote
Hofmann Posted March 5, 2011 at 06:06 AM Author Report Posted March 5, 2011 at 06:06 AM Damn! May I bother you to explain how you did that? Quote
cababunga Posted March 5, 2011 at 06:28 AM Report Posted March 5, 2011 at 06:28 AM Sure. First I saved your spreadsheet as a tab-separated values and then in interactive Python session did the following: from collections import defaultdict d=defaultdict(list) for x in open('平水韻 flashcards.txt'): r, c = x.split('\t') d[c].append(r) f=open('平水韻 flashcards.tab', 'w') for c, r in sorted(d.iteritems()): print >>f, "%s\t%s" % (' '.join(r), c), 1 Quote
imron Posted March 5, 2011 at 06:54 AM Report Posted March 5, 2011 at 06:54 AM I was going to make one in Vim using regexes, but it looks like cababunga beat me to it Quote
Hofmann Posted March 5, 2011 at 06:31 PM Author Report Posted March 5, 2011 at 06:31 PM It looks like there are no problems. It's a shared deck named 平水韻 Pingshuiyun. Thanks for the help. Quote
Recommended Posts
Join the conversation
You can post now and select your username and password later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.