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

Can i just specify languages that i want to detect, such as only detect en, ja and zh-cn? #71

Open
maliho0803 opened this issue Apr 20, 2020 · 2 comments

Comments

@maliho0803
Copy link

can i just specify languages that i want to detect, such as only detect en, ja and zh-cn?

@Zsub
Copy link

Zsub commented May 18, 2020

You can do this by instantiating the detector yourself:

import csv
import html
import langdetect

with open('rawdata.csv', newline='', encoding="UTF-8") as rawdata:
    rawreader = csv.reader(rawdata, delimiter=',', quotechar='"')

    # instantiate the DetectorFactory
    factory = langdetect.detector_factory.DetectorFactory()
    factory.load_profile(langdetect.detector_factory.PROFILES_DIRECTORY)

    for row in rawreader:
        # this re-creates the detector each time
        detector = factory.create()
        # or whatever your text probabilities are.
        detector.set_prior_map({"en": 0.5, "de": 0.5})
        # give the detector the text to run on
        detector.append(row[column])
        # let the detector run!
        print(detector.detect())

@batara666
Copy link

@Mimino666 can we just ignore specified language ?, and isn't be nice to have that as method ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants