Skip to content

Commit

Permalink
move rules to different folder, use importlib-resources
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
asdofindia committed Feb 19, 2024
1 parent cfb21ec commit ab88a01
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graft rules
9 changes: 3 additions & 6 deletions libindic/normalizer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

import codecs
import os
import re
import string
from importlib_resources import files


class Normalizer:

def __init__(self):
self.rules_file = os.path.join(
os.path.dirname(__file__), "normalizer_ml.rules")
self.rules_file = files('rules').joinpath('normalizer_ml.rules')
self.rulesDict = self.LoadRules()
pattern = "|".join(map(re.escape, self.rulesDict.keys()))
self.regex = re.compile(pattern)
Expand All @@ -46,8 +44,7 @@ def LoadRules(self):
rules_dict = dict()
line = []
line_number = 0
rules_file = codecs. open(
self.rules_file, encoding='utf-8', errors='ignore')
rules_file = self.rules_file.open()
while True:
line_number = line_number + 1
text_raw = rules_file.readline()
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ classifiers = [
"Intended Audience :: Information Technology",
"Programming Language :: Python",
]
dependencies = [
"importlib-resources"
]

[project.urls]
Homepage = "https://libindic.org/normalizer"


[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"


[tool.setuptools.package-data]
"*" = ["*.rules"]
[tool.setuptools.packages.find]
where = ["libindic"]

[project.entry-points."libindic.api.rest"]
normalize = "normalizer.expose:normalize"
Expand Down
File renamed without changes.

0 comments on commit ab88a01

Please sign in to comment.