SHARE
TWEET

Untitled

rcompton Mar 28th, 2013 39 Never
  1. #!/usr/bin/python2.6
  2.  
  3. import argparse
  4. import random
  5. import langid
  6. import sys,os
  7.  
  8. if len(sys.argv) < 2:
  9.     sys.exit(0)
  10.    
  11. id = sys.argv[1]
  12.    
  13. parser = argparse.ArgumentParser(description='Run langid classifier on command line text')
  14. parser.add_argument('text', type=str, nargs="+")
  15. args = parser.parse_args(sys.argv[2:])
  16.    
  17. args.text = ' '.join(args.text)
  18. (lang,prob) = langid.classify(args.text)
  19. print "%s\t%s" %(id,lang)
  20. sys.exit(0)
RAW Paste Data
Top