Exemplo n.º 1
0
from __future__ import absolute_import, unicode_literals

import os

import requests
from six.moves.urllib.request import urlopen
from pythainlp.tools import get_path_data, get_path_db
from tinydb import Query, TinyDB
from tqdm import tqdm

CORPUS_DB_URL = (
    "https://github.com/PyThaiNLP/pythainlp-corpus/raw/1.7/db.json")

# __all__ = ["thaipos", "thaiword","alphabet","tone","country","wordnet"]
path_db_ = get_path_db()


def get_file(name):
    db = TinyDB(path_db_)
    temp = Query()
    if len(db.search(temp.name == name)) > 0:
        path = get_path_data(db.search(temp.name == name)[0]["file"])
        db.close()
        if not os.path.exists(path):
            download(name)
        return path


def download_(url, dst):
    """
Exemplo n.º 2
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import,unicode_literals
from pythainlp.tools import get_path_db,get_path_data
from tinydb import TinyDB,Query
from future.moves.urllib.request import urlopen
from tqdm import tqdm
import requests
import os
import requests
#__all__ = ["thaipos", "thaiword","alphabet","tone","country","wordnet"]
path_db_=get_path_db()
def get_file(name):
    db=TinyDB(path_db_)
    temp = Query()
    if len(db.search(temp.name==name))>0:
        path= get_path_data(db.search(temp.name==name)[0]['file'])
        db.close()
        if not os.path.exists(path):
            download(name)
        return path
def download_(url, dst):
    """
    @param: url to download file
    @param: dst place to put the file
    """
    file_size = int(urlopen(url).info().get('Content-Length', -1))
    if os.path.exists(dst):
        first_byte = os.path.getsize(dst)
    else:
        first_byte = 0
    if first_byte >= file_size: