Skip to content

Commit

Permalink
Reordered classes
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Oct 28, 2024
1 parent 0c23138 commit 0d5c489
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions sklearn2pmml/preprocessing/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@ def matches(self, x):
def replace(self, replacement, x):
raise NotImplementedError()

class REEngine(RegExEngine):

def __init__(self, pattern):
import re

super(REEngine, self).__init__(pattern)
self.pattern_ = re.compile(pattern)

warnings.warn("Using Python's built-in Regular Expressions (RE) engine instead of Perl Compatible Regular Expressions (PCRE) engine. Transformation results might not be reproducible between Python and PMML environments when using more complex patterns", Warning)

def matches(self, x):
return self.pattern_.search(x)

def replace(self, replacement, x):
return self.pattern_.sub(replacement, x)

class PCREEngine(RegExEngine):

def __init__(self, pattern):
Expand Down Expand Up @@ -60,6 +44,22 @@ def matches(self, x):
def replace(self, replacement, x):
return self.pattern_.substitute(replacement, x)

class REEngine(RegExEngine):

def __init__(self, pattern):
import re

super(REEngine, self).__init__(pattern)
self.pattern_ = re.compile(pattern)

warnings.warn("Using Python's built-in Regular Expressions (RE) engine instead of Perl Compatible Regular Expressions (PCRE) engine. Transformation results might not be reproducible between Python and PMML environments when using more complex patterns", Warning)

def matches(self, x):
return self.pattern_.search(x)

def replace(self, replacement, x):
return self.pattern_.sub(replacement, x)

def make_regex_engine(pattern, re_flavour):
if re_flavour == "pcre":
return PCREEngine(pattern)
Expand Down

0 comments on commit 0d5c489

Please sign in to comment.