本文整理匯總了Python中philologic.OHCOVector.Record.attrib[column+"_norm"]方法的典型用法代碼示例。如果您正苦於以下問題:Python Record.attrib[column+"_norm"]方法的具體用法?Python Record.attrib[column+"_norm"]怎麽用?Python Record.attrib[column+"_norm"]使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類philologic.OHCOVector.Record
的用法示例。
在下文中一共展示了Record.attrib[column+"_norm"]方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: smash_these_unicode_columns
# 需要導入模塊: from philologic.OHCOVector import Record [as 別名]
# 或者: from philologic.OHCOVector.Record import attrib[column+"_norm"] [as 別名]
def smash_these_unicode_columns(loader_obj, text):
tmp_file = open(text["sortedtoms"] + ".tmp", "w")
for line in open(text["sortedtoms"]):
type, word, id, attrib = line.split('\t')
id = id.split()
record = Record(type, word, id)
record.attrib = loads(attrib)
for column in columns:
if column in record.attrib:
# print >> sys.stderr, repr(record.attrib)
col = record.attrib[column].decode("utf-8")
col = col.lower()
smashed_col = [c for c in unicodedata.normalize("NFKD", col) if not unicodedata.combining(c)]
record.attrib[column + "_norm"] = ''.join(smashed_col).encode("utf-8")
print(record, file=tmp_file)
tmp_file.close()
os.remove(text["sortedtoms"])
os.rename(text["sortedtoms"] + ".tmp", text["sortedtoms"])