Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if the hashtag or word is in all caps, lower it #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ekphrasis/classes/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def handle_hashtag_match(self, m):
text = m.group()[1:]

# todo:simplify routine
expanded = self.segmenter.segment(text)
if text.islower():
expanded = self.segmenter.segment(text)
expanded = " ".join(expanded.split("-"))
expanded = " ".join(expanded.split("_"))
# print(m.group(), " - ", expanded)
Expand All @@ -145,7 +145,6 @@ def handle_hashtag_match(self, m):

else:
# split words following CamelCase convention
expanded = self.regexes["camel_split"].sub(r' \1', text)
expanded = expanded.replace("-", "")
expanded = expanded.replace("_", "")
# print(m.group(), " - ", expanded)
Expand Down
2 changes: 2 additions & 0 deletions ekphrasis/classes/segmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def find_segment(self, text, prev='<S>'):
# if you don't have enough RAM lower the maxsize
@lru_cache(maxsize=65536)
def segment(self, word):
if word.isupper() or (word[0].isupper() and word[1:].islower()):
word = word.lower()
if word.islower():
return " ".join(self.find_segment(word)[1])
else:
Expand Down
2 changes: 1 addition & 1 deletion ekphrasis/tools/generate_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy
from tqdm import tqdm

REGEX_TOKEN = re.compile(r'(?<![#@])\b[a-z]{1,15}\b')
REGEX_TOKEN = re.compile(r'(?<![#@])\b[a-z\u00C0-\u00FF0-9]{1,15}\b')
REGEX_URL = re.compile(
r"(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})")
SEPARATOR = "_"
Expand Down