Skip to content

Commit 1af43e4

Browse files
authored
Merge pull request #199 from Loop3D/fix/regex_support
Fix/regex support
2 parents edd771f + c6d0b7a commit 1af43e4

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

map2loop/mapdata.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,17 @@ def parse_fault_map(self) -> tuple:
995995
# crop
996996
faults = faults.loc[faults.geometry.length >= self.minimum_fault_length]
997997

998-
if config["structtype_column"] in self.raw_data[Datatype.FAULT]:
998+
if config["structtype_column"] in self.raw_data[Datatype.FAULT]:
999999
faults["FEATURE"] = self.raw_data[Datatype.FAULT][config["structtype_column"]]
1000-
faults = faults[faults["FEATURE"].astype(str).str.contains(config["fault_text"])]
1000+
# Check if the string contains commas indicating multiple substrings
1001+
if ',' in config["fault_text"]:
1002+
import re
1003+
fault_text = config["fault_text"].split(',')
1004+
search_terms = [term.strip().strip("'").strip('"') for term in fault_text]
1005+
escaped_terms = [re.escape(term) for term in search_terms]
1006+
# Combine the escaped terms using the pipe '|' symbol for alternation
1007+
fault_text_pattern = '|'.join(escaped_terms)
1008+
faults = faults[faults["FEATURE"].astype(str).str.contains(fault_text_pattern, case=False, regex=True, na=False)]
10011009
if self.verbose_level > VerboseLevel.NONE:
10021010
if len(faults) < len(self.raw_data[Datatype.GEOLOGY]) and len(faults) == 0:
10031011
msg = f"Fault map reduced to 0 faults as structtype_column ({config['structtype_column']}) does not contains as row with fault_text \"{config['fault_text']}\""
@@ -1132,9 +1140,16 @@ def parse_fold_map(self) -> tuple:
11321140
folds[config["structtype_column"]] = self.raw_data[Datatype.FOLD][
11331141
config["structtype_column"]
11341142
]
1135-
folds = folds[
1136-
folds[config["structtype_column"]].astype(str).str.contains(config["fold_text"])
1137-
]
1143+
if ',' in config["fold_text"]:
1144+
import re
1145+
fold_text = config["fold_text"].split(',')
1146+
search_terms = [term.strip().strip("'").strip('"') for term in fold_text]
1147+
escaped_terms = [re.escape(term) for term in search_terms]
1148+
# Combine the escaped terms using the pipe '|' symbol for alternation
1149+
fold_text_pattern = '|'.join(escaped_terms)
1150+
folds = folds[
1151+
folds[config["structtype_column"]].astype(str).str.contains(fold_text_pattern, case=False, regex=True, na=False)
1152+
]
11381153
if self.verbose_level > VerboseLevel.NONE:
11391154
if len(folds) < len(self.raw_data[Datatype.GEOLOGY]) and len(folds) == 0:
11401155
msg = f"Fold map reduced to 0 folds as structtype_column ({config['structtype_column']}) does not contains any row with fold_text \"{config['fold_text']}\""

0 commit comments

Comments
 (0)