mirror of
https://github.com/fxsjy/jieba.git
synced 2025-07-10 00:01:33 +08:00
更新
This commit is contained in:
parent
dce353f88b
commit
6024497917
@ -2,7 +2,7 @@ import jieba
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from analyzer import ChineseAnalyzer
|
from .analyzer import ChineseAnalyzer
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ def load_model():
|
|||||||
if sys.platform.startswith("java"):
|
if sys.platform.startswith("java"):
|
||||||
start_P, trans_P, emit_P = load_model()
|
start_P, trans_P, emit_P = load_model()
|
||||||
else:
|
else:
|
||||||
import prob_start,prob_trans,prob_emit
|
from . import prob_start,prob_trans,prob_emit
|
||||||
start_P, trans_P, emit_P = prob_start.P, prob_trans.P, prob_emit.P
|
start_P, trans_P, emit_P = prob_start.P, prob_trans.P, prob_emit.P
|
||||||
|
|
||||||
def viterbi(obs, states, start_p, trans_p, emit_p):
|
def viterbi(obs, states, start_p, trans_p, emit_p):
|
||||||
|
@ -56,7 +56,7 @@ def load_model(f_name,isJython=True):
|
|||||||
if sys.platform.startswith("java"):
|
if sys.platform.startswith("java"):
|
||||||
char_state_tab_P, start_P, trans_P, emit_P, word_tag_tab = load_model(jieba.get_abs_path_dict())
|
char_state_tab_P, start_P, trans_P, emit_P, word_tag_tab = load_model(jieba.get_abs_path_dict())
|
||||||
else:
|
else:
|
||||||
import char_state_tab, prob_start, prob_trans, prob_emit
|
from . import char_state_tab, prob_start, prob_trans, prob_emit
|
||||||
char_state_tab_P, start_P, trans_P, emit_P = char_state_tab.P, prob_start.P, prob_trans.P, prob_emit.P
|
char_state_tab_P, start_P, trans_P, emit_P = char_state_tab.P, prob_start.P, prob_trans.P, prob_emit.P
|
||||||
word_tag_tab = load_model(jieba.get_abs_path_dict(),isJython=False)
|
word_tag_tab = load_model(jieba.get_abs_path_dict(),isJython=False)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from whoosh.index import create_in,open_dir
|
|||||||
from whoosh.fields import *
|
from whoosh.fields import *
|
||||||
from whoosh.qparser import QueryParser
|
from whoosh.qparser import QueryParser
|
||||||
|
|
||||||
from jieba.analyse.analyzer import ChineseAnalyzer
|
from jieba.analyse import ChineseAnalyzer
|
||||||
|
|
||||||
analyzer = ChineseAnalyzer()
|
analyzer = ChineseAnalyzer()
|
||||||
|
|
||||||
@ -18,31 +18,31 @@ ix = create_in("tmp", schema) # for create new index
|
|||||||
writer = ix.writer()
|
writer = ix.writer()
|
||||||
|
|
||||||
writer.add_document(
|
writer.add_document(
|
||||||
title="document1",
|
title="document1",
|
||||||
path="/a",
|
path="/a",
|
||||||
content="This is the first document we’ve added!"
|
content="This is the first document we’ve added!"
|
||||||
)
|
)
|
||||||
|
|
||||||
writer.add_document(
|
writer.add_document(
|
||||||
title="document2",
|
title="document2",
|
||||||
path="/b",
|
path="/b",
|
||||||
content="The second one 你 中文测试中文 is even more interesting! 吃水果"
|
content="The second one 你 中文测试中文 is even more interesting! 吃水果"
|
||||||
)
|
)
|
||||||
|
|
||||||
writer.add_document(
|
writer.add_document(
|
||||||
title="document3",
|
title="document3",
|
||||||
path="/c",
|
path="/c",
|
||||||
content="买水果然后来世博园。"
|
content="买水果然后来世博园。"
|
||||||
)
|
)
|
||||||
|
|
||||||
writer.add_document(
|
writer.add_document(
|
||||||
title="document4",
|
title="document4",
|
||||||
path="/c",
|
path="/c",
|
||||||
content="工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作"
|
content="工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作"
|
||||||
)
|
)
|
||||||
|
|
||||||
writer.add_document(
|
writer.add_document(
|
||||||
title="document4",
|
title="document4",
|
||||||
path="/c",
|
path="/c",
|
||||||
content="咱俩交换一下吧。"
|
content="咱俩交换一下吧。"
|
||||||
)
|
)
|
||||||
@ -55,7 +55,7 @@ for keyword in ("水果世博园","你","first","中文","交换机","交换"):
|
|||||||
print("result of ",keyword)
|
print("result of ",keyword)
|
||||||
q = parser.parse(keyword)
|
q = parser.parse(keyword)
|
||||||
results = searcher.search(q)
|
results = searcher.search(q)
|
||||||
for hit in results:
|
for hit in results:
|
||||||
print(hit.highlights("content"))
|
print(hit.highlights("content"))
|
||||||
print("="*10)
|
print("="*10)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user