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

Increase the characteristics of the specified language during the run #69

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion langid/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .langid import classify, rank, set_languages
from .langid import classify, rank, set_languages, classify_with_language
23 changes: 23 additions & 0 deletions langid/langid.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ def classify(instance):

return identifier.classify(instance)


def classify_with_language(instance, langs):
"""
Convenience method using a global identifier instance with the default
model included in langid.py. Identifies the language that a string is
written in.

@param instance a text string. Unicode strings will automatically be utf8-encoded
param langs. Increase the characteristics of the specified language during the run
@returns a tuple of the most likely language and the confidence score
"""
global identifier
if identifier is None:
load_model()

return identifier.classify_with_language(instance, langs)


def rank(instance):
"""
Convenience method using a global identifier instance with the default
Expand Down Expand Up @@ -288,6 +306,11 @@ def nb_classprobs(self, fv):
pd = pdc + self.nb_pc
return pd

def classify_with_language(self, text, langs):
self.set_languages(langs=langs)

return self.classify(text)

def classify(self, text):
"""
Classify an instance.
Expand Down