Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Mimino666/langdetect
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: samurous/langdetect
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Oct 4, 2017

  1. Copy the full SHA
    b7a33f7 View commit details
  2. Copy the full SHA
    5a15294 View commit details
  3. Copy the full SHA
    171c22f View commit details
Showing with 33 additions and 1 deletion.
  1. +1 −1 langdetect/__init__.py
  2. +19 −0 langdetect/detector.py
  3. +13 −0 langdetect/detector_factory.py
2 changes: 1 addition & 1 deletion langdetect/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .detector_factory import DetectorFactory, PROFILES_DIRECTORY, detect, detect_langs
from .detector_factory import DetectorFactory, PROFILES_DIRECTORY, detect, detect_langs, get_detector
19 changes: 19 additions & 0 deletions langdetect/detector.py
Original file line number Diff line number Diff line change
@@ -111,6 +111,25 @@ def append(self, text):
self.text += ch
pre = ch

def reset_text(self):
""" Reset the target text to an empty string.
"""
self.text = ''

def reset_langprob(self):
""" Reset the target text to an empty string.
"""
self.langprob = None

def reset(self):
""" Reset the instance so it will redetect language for a new string appended.
"""
self.reset_text()
self.reset_langprob()

def cleaning_text(self):
'''Cleaning text to detect
(eliminate URL, e-mail address and Latin sentence if it is not written in Latin alphabet).
13 changes: 13 additions & 0 deletions langdetect/detector_factory.py
Original file line number Diff line number Diff line change
@@ -117,12 +117,14 @@ def get_lang_list(self):
PROFILES_DIRECTORY = path.join(path.dirname(__file__), 'profiles')
_factory = None


def init_factory():
global _factory
if _factory is None:
_factory = DetectorFactory()
_factory.load_profile(PROFILES_DIRECTORY)


def detect(text):
init_factory()
detector = _factory.create()
@@ -135,3 +137,14 @@ def detect_langs(text):
detector = _factory.create()
detector.append(text)
return detector.get_probabilities()


def get_detector():
""" Return a new Detector instance.
:return: a new Detector instance.
:rtype: Detector
"""
global _factory
init_factory()
return _factory.create()