TiberiuCristianLeon commited on
Commit
3e517ad
·
verified ·
1 Parent(s): ab4ca2e

Normalize results to percent values

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -26,7 +26,7 @@ class Detect():
26
  docs = Document([], text=self.text)
27
  nlp = Pipeline(lang="multilingual", processors="langid")
28
  nlp(docs)
29
- return [docs.lang, 1.00]
30
  def langdetect(self) -> list[str, float]:
31
  from langdetect import detect, detect_langs
32
  from langdetect import DetectorFactory
@@ -49,8 +49,8 @@ class Detect():
49
  "te", "th", "tl", "tr", "ug", "uk", "ur", "vi", "vo", "wa", "xh", "zh", "zu"]
50
  import py3langid
51
  lang, prob = py3langid.classify(self.text) # unpack the result tuple in variables
52
- return [lang, abs(round(number=prob, ndigits=2))]
53
- def lingua(self) -> list[str, float]:
54
  from lingua import Language, LanguageDetectorBuilder
55
  detector: LanguageDetector = LanguageDetectorBuilder.from_all_languages().with_preloaded_language_models().build()
56
  confidence_values: List[ConfidenceValue] = detector.compute_language_confidence_values(self.text)
@@ -131,7 +131,7 @@ def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, st
131
  if 'py3langid' in used_libraries:
132
  detections.append(['py3langid'] + detectinstance.py3langid())
133
  if 'lingua-py' in used_libraries:
134
- detections.append(['lingua-py'] + detectinstance.lingua())
135
  if 'pycld2' in used_libraries:
136
  detections.append(['pycld2'] + detectinstance.pycld2())
137
  if 'fastlangdetect' in used_libraries:
 
26
  docs = Document([], text=self.text)
27
  nlp = Pipeline(lang="multilingual", processors="langid")
28
  nlp(docs)
29
+ return [docs.lang, 100]
30
  def langdetect(self) -> list[str, float]:
31
  from langdetect import detect, detect_langs
32
  from langdetect import DetectorFactory
 
49
  "te", "th", "tl", "tr", "ug", "uk", "ur", "vi", "vo", "wa", "xh", "zh", "zu"]
50
  import py3langid
51
  lang, prob = py3langid.classify(self.text) # unpack the result tuple in variables
52
+ return [lang, abs(round(number=prob * 100, ndigits=2))]
53
+ def linguapy(self) -> list[str, float]:
54
  from lingua import Language, LanguageDetectorBuilder
55
  detector: LanguageDetector = LanguageDetectorBuilder.from_all_languages().with_preloaded_language_models().build()
56
  confidence_values: List[ConfidenceValue] = detector.compute_language_confidence_values(self.text)
 
131
  if 'py3langid' in used_libraries:
132
  detections.append(['py3langid'] + detectinstance.py3langid())
133
  if 'lingua-py' in used_libraries:
134
+ detections.append(['lingua-py'] + detectinstance.linguapy())
135
  if 'pycld2' in used_libraries:
136
  detections.append(['pycld2'] + detectinstance.pycld2())
137
  if 'fastlangdetect' in used_libraries: