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


Python Doc.read_bytes方法代碼示例

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


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

示例1: test_read_write

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc import read_bytes [as 別名]
def test_read_write(EN):
    doc1 = EN(u'This is a simple test. With a couple of sentences.')
    doc2 = EN(u'This is another test document.')

    with open('/tmp/spacy_docs.bin', 'wb') as file_:
        file_.write(doc1.to_bytes())
        file_.write(doc2.to_bytes())

    with open('/tmp/spacy_docs.bin', 'rb') as file_:
        bytes1, bytes2 = Doc.read_bytes(file_)
        r1 = Doc(EN.vocab).from_bytes(bytes1)
        r2 = Doc(EN.vocab).from_bytes(bytes2)

    assert r1.string == doc1.string
    assert r2.string == doc2.string
開發者ID:prashiyn,項目名稱:spaCy,代碼行數:17,代碼來源:test_io.py

示例2: test_read_write

# 需要導入模塊: from spacy.tokens import Doc [as 別名]
# 或者: from spacy.tokens.Doc import read_bytes [as 別名]
def test_read_write(EN):
    doc1 = EN(u'This is a simple test. With a couple of sentences.')
    doc2 = EN(u'This is another test document.')

    try:
        tmp_dir = tempfile.mkdtemp()
        with open(os.path.join(tmp_dir, 'spacy_docs.bin'), 'wb') as file_:
            file_.write(doc1.to_bytes())
            file_.write(doc2.to_bytes())

        with open(os.path.join(tmp_dir, 'spacy_docs.bin'), 'rb') as file_:
            bytes1, bytes2 = Doc.read_bytes(file_)
            r1 = Doc(EN.vocab).from_bytes(bytes1)
            r2 = Doc(EN.vocab).from_bytes(bytes2)

        assert r1.string == doc1.string
        assert r2.string == doc2.string
    finally:
        shutil.rmtree(tmp_dir)
開發者ID:Arttii,項目名稱:spaCy,代碼行數:21,代碼來源:test_io.py


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