Exemple #1
0
def main():
    
    r = redis.Redis(host='localhost', port=6379, db=11)
    #r.flushdb()
    # A
    brain = BBRR.Brain(r,  "haha",  2)
    brain.fetchCategory("ABCD")
    brain.fetchCategory("ABCD")
    brain.fetchCategory("HIJ")
    brain.fetchCategory("KLM")
    print brain.getCategoryList()
    print brain.getCategoryScoreList()
    print brain.getCategoryNameScoreList()
    
    brain.addCategory("KLM")
    brain.addCategory("KLM")
    brain.addCategory("KLM")
    print brain.getCategoryList()
    print brain.getCategoryScoreList()
    print brain.getCategoryNameScoreList()
    #print brain.category.grp_get_score("ABCD")
    #print brain.category.grp_get_score("HIJ")
    #print brain.category.grp_get_score("KLM")
    testtxt = u"这是一个这是测试程序程序啊程序这是这是这这这。"
    brain.feed_plain_txt(testtxt, 'test',  1)
    cat = brain.fetchCategory('test')
    print utils.collection_str(cat.getAtomNameScoreList())
    print "=" * 80
    print utils.collection_str(cat.getAtomNameScoreList(n=1))
    print brain.getInfo()
def main():
    if len(sys.argv) < 4:
        print "Usage:",  sys.argv[0],  "category", "ngram" , 'grpid',  "[start] [end] \n\r"
        print "please check you parameters. current number is %d\n" % (len(sys.argv) - 1)
        print "if not sure which group to use, use 0 to get a group list"
        return

    category = sys.argv[1]
    ngram = int(sys.argv[2])
    grpid =   int(sys.argv[3])
    start = None
    end = None

    if "test" not in category:
        print "Please Check category or modify source code."
        return
        
    if len(sys.argv) >= 5:
        start = int(sys.argv[4])
    if len(sys.argv) >= 6:
        end = int(sys.argv[5])

    if start==None and end==None:
        # not show full set...since it will block interface
        end = 10
    # there is no need to check "start <= end", in fact start can be Positive, and end be Negative,  
    # redis accept it.
    

    r = redis.Redis(host='localhost', port=6379, db=11)
    brain = BBRR.Brain(r,  "abcLEX",  ngram)
   
    # brief 
    print "+" * 80
    print brain.getInfo()
    print "+" * 80
    
    cat = brain.fetchCategory(category)
    if cat:
        print utils.collection_str(cat.getAtomNameScoreList(n=grpid, start=start, end=end,  rev=True))
    print "+" * 80
def main():
    if len(sys.argv) < 3:
        print "Usage:",  sys.argv[0],  "category  type\n\r"
        print "please check you parameters. current number is %d" % (len(sys.argv) - 1)
        print "support type: rela, dist, find, seg"
        return

    category = sys.argv[1]
    type = sys.argv[2]
    
    if category != "test" and type != "find":
        print "Please Check category or modify source code."
        return

    if type not in ['rela', 'dist',  'find',  'seg']:
        print "Unsupported Type"
        return
    
    ngram = 3
    r = redis.Redis(host='localhost', port=6379, db=11)
    brain = BBRR.Brain(r,  "abcLEX",  ngram)
   
    cat = brain.fetchCategory(category)
    if cat:
        if type == 'rela':
            cat.refineRela()
        elif type =='dist':
            cat.refineDist()
        elif type == 'find':
            atom = sys.argv[3]
            print utils.collection_str(cat.findAtom(atom))
        elif type == 'seg':
            filename = sys.argv[3]
                    
            text_file = codecs.open(filename, 'rt', encoding='utf8')
            text_read = text_file.read()  
            for sentence in cat.segment_txt(text_read):
                print sentence[0]