コード例 #1
0
ファイル: translate.py プロジェクト: pokowaka/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]]
コード例 #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
ファイル: init2parseWords.py プロジェクト: pokowaka/pali
        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())