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

Code 2 #8

Open
stestagg opened this issue Sep 7, 2017 · 0 comments
Open

Code 2 #8

stestagg opened this issue Sep 7, 2017 · 0 comments

Comments

@stestagg
Copy link

stestagg commented Sep 7, 2017

import json
import operator
from collections import defaultdict

from detect import get_top_bigrams, parse_sample


def check_common_bigrams(bigrams, bigram_data):
    langs = {}
    for lang, lang_bigram in bigram_data.items():
        match = 0
        for bigram in bigrams:
            if bigram in lang_bigram:
                match += 1
        langs[lang] = match
    return langs


def main(sample):
    counts = defaultdict(int)
    parse_sample(counts, text=sample)
    bigrams = get_top_bigrams(counts)
    trained = json.load(open('output.json'))

    results = (check_common_bigrams(bigrams, trained))
    print(sorted(results.items(), key=operator.itemgetter(1), reverse=True)[0], repr(sample))


if __name__ == "__main__":
    for line in open("test_100.json"):
        main(json.loads(line)['text'])
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

1 participant