當前位置: 首頁>>代碼示例>>Python>>正文


Python article.Article方法代碼示例

本文整理匯總了Python中article.Article方法的典型用法代碼示例。如果您正苦於以下問題:Python article.Article方法的具體用法?Python article.Article怎麽用?Python article.Article使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在article的用法示例。


在下文中一共展示了article.Article方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_data

# 需要導入模塊: import article [as 別名]
# 或者: from article import Article [as 別名]
def load_data(self, path, is_dir=False):

        data = []
        filename = None

        if is_dir:
            filenames = [name for name in os.listdir(path) if not name.startswith.(".")]
        else:
            filenames = [path]

        for filename in filenames:
            with open(os.path.join(path, filename),'r', encoding="utf-8") as data:
                tp = json.load(data)
                for article in tp:
                    try:
                        self.corpus.append(Article(article))
                    except:
                        print("? %s ???????????" % filename) 
開發者ID:thisray,項目名稱:PTTChatBot_DL2017,代碼行數:20,代碼來源:corpus.py

示例2: crawl

# 需要導入模塊: import article [as 別名]
# 或者: from article import Article [as 別名]
def crawl(url,username,full_articles=True):
    articles = list()
    d = feedparser.parse(url)


    for entry in d["entries"]:
        if 'published_parsed' in entry:
            pubdate = pytz.utc.localize(datetime.fromtimestamp(mktime(entry['published_parsed'])))
        else:
            pubdate = pytz.utc.localize(datetime.fromtimestamp(mktime(entry['updated_parsed'])))

        articles.append(Article(
            title=entry['title'],
            url= entry['link'],
            body=entry["content"][0]["value"] if 'content' in entry else entry["summary"],
            username=username,
            pubdate=pubdate,
        ))

    return articles 
開發者ID:naggie,項目名稱:dsblog,代碼行數:22,代碼來源:feed.py

示例3: read_parses

# 需要導入模塊: import article [as 別名]
# 或者: from article import Article [as 別名]
def read_parses(parse_path, relations_dict=None):
        parses = [json.loads(x) for x in open(parse_path)]
        for doc_id in parses[0]:
            print >> logs, "Doc ID:%s" % doc_id
            doc = parses[0][doc_id]
            sentences = []
            for sid, sen in enumerate(doc['sentences']):
                parse_tree = sen['parsetree']
                dep_tree = sen['dependencies']
                words = sen['words']
                # provided by kong
                if sid == 0 and words[0][1]['CharacterOffsetBegin'] < 8:
                    words[0][1]['CharacterOffsetBegin'] += 6
                sentences.append(Sentence(sid, parse_tree, dep_tree, words))
            if relations_dict is not None:
                relations = relations_dict[doc_id]
            else:
                relations = []
            params = {'sens': sentences, 'rels':relations}
            yield Article(doc_id, params) 
開發者ID:qcl6355,項目名稱:conll2016,代碼行數:22,代碼來源:corpus.py

示例4: read_parses

# 需要導入模塊: import article [as 別名]
# 或者: from article import Article [as 別名]
def read_parses(parse_path, relations_dict=None):
        parses = [json.loads(x) for x in open(parse_path)]
        for doc_id in parses[0]:
            print >> logs, "Doc ID:%s" % doc_id
            doc = parses[0][doc_id]
            sentences = []
            for sid, sen in enumerate(doc['sentences']):
                parse_tree = sen['parsetree']
                dep_tree = sen['dependencies']
                words = sen['words']
                sentences.append(Sentence(sid, parse_tree, dep_tree, words))
            if relations_dict is not None:
                relations = relations_dict[doc_id]
            else:
                relations = []
            params = {'sens': sentences, 'rels':relations}
            yield Article(doc_id, params) 
開發者ID:qcl6355,項目名稱:conll2016,代碼行數:19,代碼來源:corpus.py

示例5: _get_article_list

# 需要導入模塊: import article [as 別名]
# 或者: from article import Article [as 別名]
def _get_article_list(self):
        """ ?????????????html????
        """
        article = Article()
        article_list = []
        for i in range(self.zhuanlan_dict['post_count']):
            url = 'https://zhuanlan.zhihu.com/api/columns/{0}/posts?limit=1&offset={1}'.format(self.slug, i)
            article_list.append(article.get_article_html(url=url))

        return article_list 
開發者ID:shimachao,項目名稱:zhihuzhuanlan2pdf,代碼行數:12,代碼來源:zhuanlan.py

示例6: predict

# 需要導入模塊: import article [as 別名]
# 或者: from article import Article [as 別名]
def predict(input_dir):
    '''
    Get genre probabilities for each text document in input directory.
    '''
    clf = joblib.load('model.pkl')

    with open('results.csv', 'wb') as fh:
        writer = csv.writer(fh, delimiter='\t')
        writer.writerow(['Filename'] + [utilities.genres[g][0].split('/')[0]
            for g in utilities.genres])

        for filename in [f for f in os.listdir(input_dir) if f.endswith('.txt')]:
            with open(input_dir + os.sep + filename) as ifh:
                print('Processing file: ' + filename)

                row = []
                row.append(filename)

                # Read input file
                doc = ifh.read().decode('utf-8')

                # Create article object and calculate features
                art = article.Article(text=doc)
                features = [art.features[f] for f in utilities.features]

                # Get probability for each genre
                proba = clf.predict_proba([features])[0]

                # Save results
                for g in utilities.genres:
                    row.append(str(proba[g - 1])[:6])
                writer.writerow(row)
                print(row[1:]) 
開發者ID:jlonij,項目名稱:genre-classifier,代碼行數:35,代碼來源:predict.py

示例7: index

# 需要導入模塊: import article [as 別名]
# 或者: from article import Article [as 別名]
def index():
    '''
    Return the probability for each genre.
    '''
    if not (request.query.text or request.query.url):
        return 'invoke with ?text= or ?url='

    if request.query.text:
        art = article.Article(text=request.query.text)
    elif request.query.url:
        art = article.Article(url=request.query.url)

    example = [art.features[f] for f in utilities.features]

    abs_path = os.path.dirname(os.path.realpath(__file__))
    clf = joblib.load(abs_path + os.sep + 'model.pkl')
    proba = clf.predict_proba([example])[0]

    resp = {}
    for i, p in enumerate(proba):
        resp[utilities.genres[i + 1][0].split('/')[0]] = str(proba[i])[:6]
    resp = json.dumps(resp)

    if request.query.callback:
        resp = request.query.callback + '(' + resp + ')'

    return resp 
開發者ID:jlonij,項目名稱:genre-classifier,代碼行數:29,代碼來源:web.py

示例8: generate_training

# 需要導入模塊: import article [as 別名]
# 或者: from article import Article [as 別名]
def generate_training(self, path):
        '''
        Generate training data from a list of labeled articles.
        '''
        with open(path, 'rU') as fh:
            db = csv.DictReader(fh, delimiter='\t')

        with open('data/training.txt', 'wb') as fh:
            fieldnames = ['url', 'label'] + utilities.features
            writer = csv.DictWriter(fh, fieldnames=fieldnames,
                delimiter='\t')
            writer.writeheader()

            for i, row in enumerate(db):

                # Get url
                url = None
                if row['Identifier']:
                    url = row['Identifier']
                elif (row['Prediction'] != 'None' and
                        float(row['Confidence']) > 0.675):
                    url = row['Prediction']
                else:
                    continue
                if not url.endswith(':ocr'):
                    url += ':ocr'

                # Get label
                label = None
                for g in utilities.genres:
                    if row['Genre'] in utilities.genres[g]:
                        label = g
                        break
                if not label:
                    continue

                # If valid training instance found, create new article
                try:
                    art = article.Article(url=url)

                    # Save results
                    fields = {'label': label, 'url': url}
                    for f in utilities.features:
                        fields[f] = art.features[f]
                    writer.writerow(fields)

                except (IOError, AssertionError) as e:
                    print('Error processsing article ' + url + ': '
                        + repr(e)) 
開發者ID:jlonij,項目名稱:genre-classifier,代碼行數:51,代碼來源:data.py


注:本文中的article.Article方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。