<commit_before>import sys
import os
sys.path.append(os.path.abspath('../'))
import qudt4dt
reload(sys) 
sys.setdefaultencoding( "utf-8" ) 
def get_all_unit_symbol():
    bara = qudt4dt.Barbara("http://localhost:3030")
    unitList = bara.list_all_units()
    result = {}
    for u in unitList:
        symbol = bara.get_SI_symbol(u)
        vec = bara.get_SI_vector(symbol)
        result[u] = vec
    return result

if __name__ == '__main__':
    for (k, v) in get_all_unit_symbol().items():
        print '%s\n %s\n' %(k,v)
<commit_msg>done a sample script to convert qudt unit to mdao<commit_after># -*- coding:utf-8 -*-
import sys
import os
sys.path.append(os.path.abspath('../'))
reload(sys) 
sys.setdefaultencoding( "utf-8" ) 


import re
import qudt4dt
bara = qudt4dt.Barbara("http://localhost:3030")
baseUnit = {u'L':u'm', u'M':u'kg',
            u'T':u's', u'I':u'A',
            u'N':u'mol',u'J':u'cd',
            u'\u0398': u'K', u'U':u'rad'}

def symbol_lex_token(symbolString):
    if symbolString == '':
        return []
    else:
        token = re.compile(ur'^([LMNJTIU\u0398])-?\d*',re.UNICODE)
        result = re.match(token,symbolString)
        point = len(result.group(0))
        power = result.group(0)[len(result.group(1)):]
        pair = (result.group(1), power)
        return symbol_lex_token(symbolString[point:]) + [pair]
        
def tokens_to_unit(tokens):
    r = ''
    for (i,j) in tokens:
        if j == '':
            r += '*{sym}'.format(sym = baseUnit[i])
        else:
            r += '*{sym}**{pow}'.format( sym = baseUnit[i], pow =j)
    return r[1:]

def get_all_unit_symbol():
    unitList = bara.list_all_units()
    result = {}
    for u in unitList:
        symbol = bara.get_SI_symbol(u)

        if not symbol == None:
            print u
            si = re.match(r'http://qudt.org/vocab/dimension#Dimension_SI_(.+)$',symbol).group(1)
            print si
            print tokens_to_unit(symbol_lex_token(si))
            print ('\n')
       # vec = bara.get_SI_vector(symbol)
       # print vec

if __name__ == '__main__':
    # print u'\u0398'
    get_all_unit_symbol()
    #print tokens_to_unit(symbol_lex_token(u'ϴ-1'))
   # print bara.get_unit_class('http://qudt.org/vocab/unit#SquareCentimeterMinute')
   # print bara.get_units_in_same_class('http://qudt.org/vocab/unit#SquareCentimeterMinute')
{'fraction_non_alphanumeric': 0.1663131098854476, 'fraction_numerical': 0.014425116673737802, 'mean_word_length': 2.784911717495987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4110944', 'n_tokens_mistral': 901, 'n_tokens_neox': 872, 'n_words': 157}