Skip to content

Commit

Permalink
Released v1.3.4,解決 MP_ArticutAPI 封裝後 Process Runtime 出錯的問題
Browse files Browse the repository at this point in the history
  • Loading branch information
EclairCJ committed Sep 20, 2023
1 parent e5bdec6 commit fe6853d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
34 changes: 20 additions & 14 deletions ArticutAPI/MP_ArticutAPI.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import os
import re
import time

try:
import rapidjson as json
except:
import json

try:
import requests
except Exception as e:
Expand All @@ -23,9 +14,14 @@
else:
print(e)

from multiprocessing import cpu_count, Pool
from pathlib import os, sys
from pprint import pprint

if getattr(sys, 'frozen', False):
from multiprocessing.dummy import Pool, freeze_support
else:
from multiprocessing import Pool, freeze_support

try:
from Toolkit.analyse import AnalyseManager
from Toolkit.localRE import TaiwanAddressAnalizer
Expand All @@ -37,18 +33,28 @@
from .Toolkit.toolkits import *
from .Toolkit.NER import GenericNER

import time
try:
import rapidjson as json
except:
import json

class MP_Articut:
def __init__(self, url="http://127.0.0.1", port="8964", bulkSize=20, userDefinedDictFILE=None):
def __init__(self, url="http://127.0.0.1", port="8964", bulkSize=20, userDefinedDictFILE=None, processes=-1):
freeze_support()
self.port = port
if url.startswith("http"):
self.url = "{}:{}".format(url, port)
else:
self.url = "http://{}:{}".format(url, port)
self.bulkSize = bulkSize
self.processes = cpu_count()
if self.processes > 8:
self.processes = 8
defaultProcesses = os.cpu_count()
if processes > 0 and processes <= defaultProcesses:
self.processes = processes
else:
self.processes = defaultProcesses
if self.processes > 8:
self.processes = 8

self.userDefinedDictFILE = None
self.openDataPlaceAccessBOOL=False
Expand Down
1 change: 0 additions & 1 deletion ArticutAPI/Toolkit/toolkits.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def _segIndexConverter(self, parseResultDICT, posIndexLIST):
if posLIST:
tmpLIST = []
for start, end, seg in posLIST:

posEndSTR = parseResultDICT["result_pos"][i][:start]
segEndSTR = "".join([x.group() for x in self.stripPat.finditer(posEndSTR)])
tmpLIST.append((len(segEndSTR), len(segEndSTR)+len(seg), seg))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="ArticutAPI",
version="1.3.3",
version="1.3.4",
author="Droidtown Linguistic Tech. Co. Ltd.",
author_email="info@droidtown.co",
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.",
Expand Down

0 comments on commit fe6853d

Please sign in to comment.