示例#1
0
def extractOneDicExps(dicIndex, dicId):
  with open(getDictWordsCSV1Path(), 'r') as f:
    wordreader = csv.reader(f, delimiter=',', quotechar='"')
    for row in wordreader:
      if len(row) != 7:
        raise Exception('len(row) != 7')
      if row[0] == 'db_id': continue

      word = row[4].decode('utf-8').lower()
      if row[2] == dicId:
        yield [word, row[6]]

  with open(getDictWordsCSV2Path(), 'r') as f:
    wordreader = csv.reader(f, delimiter=',', quotechar='"')
    for row in wordreader:
      if len(row) != 7:
        raise Exception('len(row) != 7')
      if row[0] == 'db_id': continue

      word = row[4].decode('utf-8').lower()
      if row[2] == dicId:
        yield [word, row[6]]
示例#2
0
文件: translate.py 项目: sup6/pali
def extractOneDicExps(dicIndex, dicId):
    with open(getDictWordsCSV1Path(), 'r') as f:
        wordreader = csv.reader(f, delimiter=',', quotechar='"')
        for row in wordreader:
            if len(row) != 7:
                raise Exception('len(row) != 7')
            if row[0] == 'db_id': continue

            word = row[4].decode('utf-8').lower()
            if row[2] == dicId:
                yield [word, row[6]]

    with open(getDictWordsCSV2Path(), 'r') as f:
        wordreader = csv.reader(f, delimiter=',', quotechar='"')
        for row in wordreader:
            if len(row) != 7:
                raise Exception('len(row) != 7')
            if row[0] == 'db_id': continue

            word = row[4].decode('utf-8').lower()
            if row[2] == dicId:
                yield [word, row[6]]
示例#3
0
                else:
                    data.append([row[2], row[6]])

                with open(path, 'w') as f:
                    f.write(json.dumps(data))
            else:
                # create new data file
                if dicIndex[row[2]][0] == 'zh':
                    # convert simplified chinese to traditional chinese
                    data = [[row[2], jtof(row[6])]]
                else:
                    data = [[row[2], row[6]]]

                with open(path, 'w') as f:
                    f.write(json.dumps(data))


if __name__ == '__main__':
    # read index of dictionary books
    with open(getDictBooksJsonPath(), 'r') as f:
        dicIndex = json.loads(f.read())

    if os.path.exists(getDictWordsJsonDir()):
        shutil.rmtree(getDictWordsJsonDir())
        os.makedirs(getDictWordsJsonDir())
    else:
        os.makedirs(getDictWordsJsonDir())

    processWordCSV(getDictWordsCSV1Path(), dicIndex, getDictWordsJsonDir())
    processWordCSV(getDictWordsCSV2Path(), dicIndex, getDictWordsJsonDir())
示例#4
0
        else:
          data.append([row[2], row[6]])

        with open(path, 'w') as f:
          f.write(json.dumps(data))
      else:
        # create new data file
        if dicIndex[row[2]][0] == 'zh':
          # convert simplified chinese to traditional chinese
          data = [ [row[2], jtof(row[6])] ]
        else:
          data = [ [row[2], row[6]] ]

        with open(path, 'w') as f:
          f.write(json.dumps(data))


if __name__ == '__main__':
  # read index of dictionary books
  with open(getDictBooksJsonPath(), 'r') as f:
    dicIndex = json.loads(f.read())

  if os.path.exists(getDictWordsJsonDir()):
    shutil.rmtree(getDictWordsJsonDir())
    os.makedirs(getDictWordsJsonDir())
  else:
    os.makedirs(getDictWordsJsonDir())

  processWordCSV(getDictWordsCSV1Path(), dicIndex, getDictWordsJsonDir())
  processWordCSV(getDictWordsCSV2Path(), dicIndex, getDictWordsJsonDir())