Skip to content

Commit fe6853d

Browse files
committed
Released v1.3.4,解決 MP_ArticutAPI 封裝後 Process Runtime 出錯的問題
1 parent e5bdec6 commit fe6853d

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

ArticutAPI/MP_ArticutAPI.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
#!/usr/bin/env python3
22
# -*- coding:utf-8 -*-
33

4-
import os
5-
import re
6-
import time
7-
8-
try:
9-
import rapidjson as json
10-
except:
11-
import json
12-
134
try:
145
import requests
156
except Exception as e:
@@ -23,9 +14,14 @@
2314
else:
2415
print(e)
2516

26-
from multiprocessing import cpu_count, Pool
17+
from pathlib import os, sys
2718
from pprint import pprint
2819

20+
if getattr(sys, 'frozen', False):
21+
from multiprocessing.dummy import Pool, freeze_support
22+
else:
23+
from multiprocessing import Pool, freeze_support
24+
2925
try:
3026
from Toolkit.analyse import AnalyseManager
3127
from Toolkit.localRE import TaiwanAddressAnalizer
@@ -37,18 +33,28 @@
3733
from .Toolkit.toolkits import *
3834
from .Toolkit.NER import GenericNER
3935

36+
import time
37+
try:
38+
import rapidjson as json
39+
except:
40+
import json
4041

4142
class MP_Articut:
42-
def __init__(self, url="http://127.0.0.1", port="8964", bulkSize=20, userDefinedDictFILE=None):
43+
def __init__(self, url="http://127.0.0.1", port="8964", bulkSize=20, userDefinedDictFILE=None, processes=-1):
44+
freeze_support()
4345
self.port = port
4446
if url.startswith("http"):
4547
self.url = "{}:{}".format(url, port)
4648
else:
4749
self.url = "http://{}:{}".format(url, port)
4850
self.bulkSize = bulkSize
49-
self.processes = cpu_count()
50-
if self.processes > 8:
51-
self.processes = 8
51+
defaultProcesses = os.cpu_count()
52+
if processes > 0 and processes <= defaultProcesses:
53+
self.processes = processes
54+
else:
55+
self.processes = defaultProcesses
56+
if self.processes > 8:
57+
self.processes = 8
5258

5359
self.userDefinedDictFILE = None
5460
self.openDataPlaceAccessBOOL=False

ArticutAPI/Toolkit/toolkits.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def _segIndexConverter(self, parseResultDICT, posIndexLIST):
6262
if posLIST:
6363
tmpLIST = []
6464
for start, end, seg in posLIST:
65-
6665
posEndSTR = parseResultDICT["result_pos"][i][:start]
6766
segEndSTR = "".join([x.group() for x in self.stripPat.finditer(posEndSTR)])
6867
tmpLIST.append((len(segEndSTR), len(segEndSTR)+len(seg), seg))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="ArticutAPI",
8-
version="1.3.3",
8+
version="1.3.4",
99
author="Droidtown Linguistic Tech. Co. Ltd.",
1010
author_email="info@droidtown.co",
1111
description="Articut NLP system provides not only finest results on Chinese word segmentaion (CWS), Part-of-Speech tagging (POS) and Named Entity Recogintion tagging (NER), but also the fastest online API service in the NLP industry.",

0 commit comments

Comments
 (0)