Пример #1
0
def build_db(connection, filename):
    c = connection.cursor()
    create_db(c)
    with codecs.open(filename, 'r', encoding="utf-8") as f:
        s = BMGraphDBSink(connection)
        # bmgraph.logger.setLevel(logging.DEBUG)
        bmgraph_file.logger.setLevel(logging.INFO)
        bmgraph_file.read_file(f, s)
    connection.commit()
    logger.info("%i rows in the database." % node_count(c))
    logger.info("%i node attributes in the database." % node_attribute_count(c))
    logger.info("%i edge attributes in the database." % edge_attribute_count(c))
    logger.info("%i edges in the database." % edge_count(c))
Пример #2
0
def build_db(connection, filename):
    c = connection.cursor()
    create_db(c)
    with codecs.open(filename, 'r', encoding="utf-8") as f:
        s = BMGraphDBSink(connection)
        # bmgraph.logger.setLevel(logging.DEBUG)
        bmgraph_file.logger.setLevel(logging.INFO)
        bmgraph_file.read_file(f, s)
    connection.commit()
    logger.info("%i rows in the database." % node_count(c))
    logger.info("%i node attributes in the database." %
                node_attribute_count(c))
    logger.info("%i edge attributes in the database." %
                edge_attribute_count(c))
    logger.info("%i edges in the database." % edge_count(c))
Пример #3
0
def simple_get(url):
    """
    Attempts to get the content at `url` by making an HTTP GET request.
    If the content-type of response is some kind of HTML/XML, return the
    text content, otherwise return None.
    """

    filename = "{0}.html".format(url.split("/").pop().lower())
    filepath = abspath(join(dirname(__file__), "./cache", filename))
    file_data = read_file(filepath)

    if file_data != None:
        return file_data

    try:
        print("Fetching: {0}...".format(url))
        with closing(get(url, stream=True)) as resp:
            if is_good_response(resp):
                write_cache_file(filepath, resp.content)
                return resp.content
            else:
                return None

    except RequestException as e:
        log_error('Error during requests to {0} : {1}'.format(url, str(e)))
        return None
Пример #4
0
  def get_station_bus_stops(self, station_name):
    # get the bus stop codes
    # get the interchange code (little more tricky because LTG does not provide it)

    bus_stop_codes = []

    slugified_station_name = station_name.replace(' ', '-').lower()

    r = requests.get(
        f'https://landtransportguru.net/{slugified_station_name}-station/')
    if r.status_code == 200:
      soup = BeautifulSoup(r.content, 'lxml')

      table_cell_soup = soup.find_all('td')
      for cell_soup in table_cell_soup:

        # (1) Find bus stop codes. We need to go through all table cells and see if the first 5 digits are numbers
        try:
          # checking if the first 5 digits can be ints. If yes, they are the bus stop codes
          # just for safety, we'll also check that the "–" character is present

          int(cell_soup.text[0:5])

          if "–" in cell_soup.text:
            stop_code = cell_soup.text[0:5]

            # Make sure not to add a None
            # Make sure not to add if it's already there
            if stop_code and stop_code not in bus_stop_codes:
              bus_stop_codes.append(stop_code)

              next

        except:
          pass

        # (2) Find if interchange
        a_soup = cell_soup.find('a')
        if a_soup and "interchange" in a_soup.text .lower():
          bus_stop_name = a_soup.text .lower() .replace("interchange", "int").replace(" bus", "").replace(
              "temporary", "temp").replace("bukit", "bt")  # bukit is hortened to bt in bus stop names

          # print(bus_stop_name)

          # go through temporary/all_stops_dict.json (or combined) and find the code matching the name
          all_bus_stops_dict = read_file('temp/bus', 'all_stops_dict.json')

          for bus_stop in all_bus_stops_dict.keys():
            if bus_stop_name == all_bus_stops_dict[bus_stop]['name'].lower():
              # match found :)
              stop_code = all_bus_stops_dict[bus_stop]['code']
              if stop_code not in bus_stop_codes:
                bus_stop_codes.append(stop_code)

      return bus_stop_codes
    else:
      # return empty list if error
      return []
Пример #5
0
def main(target_dir, tenant):
    print_gather_dir_info(target_dir)
    for path in list_dir(target_dir, '.js'):
        original_content = read_file(path)
        replaced_content, number_of_replace = replace_tenant(
            original_content, tenant)

        if number_of_replace > 0:
            print_replace(path, number_of_replace)
            write_file(path, replaced_content)
Пример #6
0
def RecognizeSpeechAndRemoveFile(AUDIO_FILENAME):
    #print("Recognize and remove file", AUDIO_FILENAME)

    # reading audio
    audio = read_file(AUDIO_FILENAME)

    delete_file(AUDIO_FILENAME)

    # send to WIT.AI
    recognize(audio)
Пример #7
0
def RecognizeSpeechAndRemoveFile(AUDIO_FILENAME):
    # reading audio
    audio = read_file(AUDIO_FILENAME)

    # delete useless file because is already in "audio" variable
    delete_file(AUDIO_FILENAME)

    # send to WIT.AI
    recognize(audio)

    time.sleep(3)
Пример #8
0
def insert_stock_base():
    path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    path = unicode(path, 'utf8')
    json_str = read_file(path + '/stocknum.json')
    stocks = json.loads(json_str)['hah']
    sql = ''
    startTime = datetime.datetime.now()
    logging.info("拼装插入股票基础数据sql语句开始:" + str(startTime))
    sql = LOCAL_SQL % ('stock', 'stockCode, stockName', '%s, %s')
    values = []
    for i in xrange(0, len(stocks)):
        stock = stocks[i]
        temp = (stock['stockCode'], stock['stockName'])
        values.append(temp)
        pass
    endTime = datetime.datetime.now()
    logging.info("拼装插入股票基础数据结束:" + str(endTime) + ", 共耗时:" + str((endTime - startTime).seconds))
    insert_many(sql, tuple(values))
    pass
Пример #9
0
def send_request(file_name):
    # read file
    file_content = file.read_file(file_name)
    audio_data = encode_data(file_content)

    # construct and send request
    url = "http://%s:%s%s" % (host, port, path)
    body = {"audio_data": audio_data}
    raw_response = requests.post(url, data=json.dumps(body), headers=headers, timeout=180)

    # handle response
    json_response = None
    try:
        json_response = raw_response.json()
    except Exception as e:
        print("file [%s] error: " % file_name, e)

    if (json_response["success"]):
        return json_response["result"]
    else:
        print("file [%s] failed, message: %s, request_id: %s: " % (file_name, json_response["message"]["global"], json_response["request_id"]))
Пример #10
0
else:
    print "Usage: python generate.py -font <font name> -l <language> -s <size> -a <input alphabet directory>"
    exit()

if (sys.argv[3] == "-l"):
    lang = sys.argv[4]
else:
    print "Usage: python generate.py -font <font name> -l <language> -s <size> -a <input alphabet directory>"
    exit()

if (sys.argv[5] == "-s"):
    font_size = sys.argv[6]
else:
    print "Usage: python generate.py -font <font name> -l <language> -s <size> -a <input alphabet directory>"
    exit()

if (sys.argv[7] == "-a"):
    alphabet_dir = sys.argv[8]
else:
    print "Usage: python generate.py -font <font name> -l <language> -s <size> -a <input alphabet directory>"
    exit()

font_string = font_name + " " + lang + " " + font_size

#begin training
draw(font_string, int(font_size), lang, file.read_file(
    alphabet_dir))  #reads all fonts in the directory font_dir and trains

train.train(lang)
#training ends
Пример #11
0
#Comment
try:
    answer = 1
    while answer < 3 and answer > 0:

        answer = int(input("What would you like to do? \n(1) Simple Calculator \n(2) Create / Edit / Read a File \n(3) Nothing \nAnswer: "))

        if answer == 1:
            print("\nYou chose '1'.")
            num1 = float(input("First number: "))
            num2 = float(input("Second number: "))
            operator = input ("What to do with it: ")
            calculator.simple_calculator(num1,num2,operator)

        elif answer == 2:
            print("\nYou chose '2'.")
            option = input("Create, Edit, or Read a file: ")
            if option.lower() == "create":
                file.create_file()
            elif option.lower() == "edit":
                file.edit_file()
            elif option.lower() == "read":
                file.read_file()
            else:
                print("That is not an option.\n")

        else:
            print("\nYou chose '3' or a number that is out of range. Bye.")

except:
    print("\nYou have entered an invalid answer. Bye.")
Пример #12
0
from sklearn.feature_extraction.text import TfidfTransformer
from pprint import pprint
from pymongo import MongoClient
import operator
import math
import os
import file

folder_path = os.path.dirname(os.path.realpath(__file__)) + '/pos_terms'
result = {}
raw_datas = []
datas = []
for f in os.listdir(folder_path):
    path = os.path.join(folder_path, f)
    if os.path.isfile(path) and '.json' in path:
        raw_datas += file.read_file(path)
for raw_data in raw_datas:
    concat = []
    concat = ' '.join(raw_data)
    datas.append(concat)

corpus = []
for data in raw_datas:
    corpus.append(' '.join(data))

vectorizer = CountVectorizer()
x = vectorizer.fit_transform(corpus)
word = vectorizer.get_feature_names()
transformer = TfidfTransformer()
tfidf = transformer.fit_transform(x)
word = vectorizer.get_feature_names()
Пример #13
0
    exit()
       
if(sys.argv[3]=="-l"):
    lang=sys.argv[4]
else:
    print "Usage: python generate.py -font <font name> -l <language> -s <size> -a <input alphabet directory>"
    exit()
   
if(sys.argv[5]=="-s"):
    font_size=sys.argv[6]
else:
    print "Usage: python generate.py -font <font name> -l <language> -s <size> -a <input alphabet directory>"
    exit()

if(sys.argv[7]=="-a"):
    alphabet_dir=sys.argv[8]
else:
    print "Usage: python generate.py -font <font name> -l <language> -s <size> -a <input alphabet directory>"
    exit()

font_string=font_name+" "+lang+" "+font_size


#begin training    
draw(font_string,int(font_size),lang,file.read_file(alphabet_dir))#reads all fonts in the directory font_dir and trains

train.train(lang)
#training ends


Пример #14
0
    exit()
        
if(sys.argv[3]=="-l"):
    lang=sys.argv[4]
else:
    print "Usage: python generate.py -fd <font directory> -l <language> -a <input alphabet directory>"
    exit()
    
if(sys.argv[5]=="-a"):
    alphabet_dir=sys.argv[6]
else:
    print "Usage: python generate.py -fd <font directory> -l <language> -a <input alphabet directory>"
    exit()
    


       


#begin training    
#font_dir="/usr/share/fonts/truetype/ttf-bengali-fonts/"
for t in os.walk(font_dir):
        for f in t[2]:
            if(f.split('.')[1]=="ttf"):
                font_file=font_dir+f
                print font_file
                draw(lang,f,font_file,40,file.read_file(alphabet_dir))#reads all fonts in the directory font_dir and trains

train.train(lang)
#training ends
Пример #15
0
def all_encoding_stats(file_name):
    """output with default file_name:
Test file: cyphesis_atlas_XML_2000-03-27_no_obj.log
Msg count: 228
            uncompressed    gzip -9   bzip2 -9
XML               954.97      47.93      33.95
XML2_test         727.00      45.92      34.03
Packed            384.41      36.79      30.84
Bach_beta         478.61      39.11      31.35
Binary1_beta      380.54      38.58      32.26
Binary2_test      236.12      35.22      30.78


Test file: CyphesisClient_fromServerViewpoint2_no_obj.log
Msg count: 716
            uncompressed    gzip -9   bzip2 -9
XML               832.77      36.76      23.82
XML2_test         632.11      35.03      23.94
Packed            284.41      28.88      23.20
Bach_beta         373.68      31.91      23.28
Binary1_beta      277.63      30.53      24.04
Binary2_test      156.22      28.31      23.62


Test file: cyphesis_atlas_Packed_2001-07-13.log
Msg count: 4768
            uncompressed    gzip -9   bzip2 -9
XML              1250.59      27.39      14.17
XML2_test         910.63      23.97      13.20
Packed            405.12      17.34      12.67
Bach_beta         544.18      18.72      12.21
Binary1_beta      441.45      22.03      14.34
Binary2_test      260.30      19.02      13.23
    """
    print()
    print()
    print("Test file:",file_name)
    global all_msg
    xml_codec = codec.get_XML()
    #all_msg = xml_codec.decode(open(file_name).read())
    all_msg = file.read_file(file_name)
    print("Msg count:",len(all_msg))

    all_stats = []
    #XML size
    all_stats.append(calculate_stats(all_msg,xml_codec))

    #XML2 size
    all_stats.append(calculate_stats(all_msg,codec.get_XML2_test()))

    #Packed size
    all_stats.append(calculate_stats(all_msg,codec.get_Packed()))

    #Bach size
    all_stats.append(calculate_stats(all_msg,codec.get_Bach_beta()))

    #Binary1_beta size
    all_stats.append(calculate_stats(all_msg,codec.get_Binary1_beta()))

    #Binary2_test size
    all_stats.append(calculate_stats(all_msg,codec.get_Binary2_test()))

##    for name in binary2.attribute_type_dict.keys():
##        print name
##        binary2.discard_name = name
##        all_stats.append(calculate_stats(all_msg,codec.get_Binary2_test()))
##        all_stats[-1][0] = list(all_stats[-1][0])
##        all_stats[-1][0][0] = name
##    all_stats.sort(lambda e1,e2:cmp(e1[2][2],e2[2][2]))

    print()
    filter_types = ("uncompressed", "gzip -9", "bzip2 -9")
    print("            %10s %10s %10s" % filter_types)
    for stat in all_stats:
        print("%-13s %10.2f %10.2f %10.2f" % (
            stat[0][0], stat[0][2], stat[1][2], stat[2][2]))
Пример #16
0
def cam_setup(camidx=0,
              roi=None,
              flatf=None,
              darkf=None,
              maskshape='all',
              procd=32,
              usecam=True,
              outdir='./',
              verb=0):
    """
	Setup IEEE1394 camera using Python's binding for OpenCV. Setup will be 
	stored in global CAM_CFG dictionary for use by cam_getimage().

	@param camidx Camera index
	@param roi Region of Interest to use, as (x, y, width, height)
	@param flatf Flatfield image to use [file]
	@param darkf Darkfield image to use [file]
	@param maskshape Shape for processing mask, 'circ' or 'all'
	@param procd Bitdepth to process images at (32 or 64)
	@param outdir Directory to store stuff to
	@param verb Verbosity
	"""

    global CAM_CFG

    if (verb & VERB_M > L_INFO): print "Setting up camera..."

    if (procd == 64):
        npdtype = np.float64
        cvdtype = cv.IPL_DEPTH_64F
    else:
        npdtype = np.float32
        cvdtype = cv.IPL_DEPTH_32F

    if (darkf and os.path.isfile(darkf)):
        if (verb & VERB_M > L_DEBG): print "Processing dark frames..."
        # Hard-link to used files for new cache
        newdarkf = pjoin(outdir, CAM_DARKFIELD)
        if (os.path.exists(newdarkf)):
            os.unlink(newdarkf)
        os.link(darkf, newdarkf)
        darkim = file.read_file(darkf).astype(npdtype)
        CAM_CFG['dark'] = cv.fromarray(darkim)
    if (flatf and os.path.isfile(flatf)):
        if (verb & VERB_M > L_DEBG): print "Processing flat frame(s)..."
        newflatf = pjoin(outdir, CAM_FLATFIELD)
        if (os.path.exists(newflatf)):
            os.unlink(newflatf)
        os.link(flatf, newflatf)
        flatim = file.read_file(flatf).astype(npdtype)
        CAM_CFG['flat'] = cv.fromarray(flatim)
        if (CAM_CFG.has_key('dark')):
            cv.Sub(CAM_CFG['flat'], CAM_CFG['dark'], CAM_CFG['flat'])

    if (verb & VERB_M > L_XNFO): print "Configuring camera..."

    if (not CAM_CFG.has_key('window')):
        CAM_CFG['window'] = 'cam_live'
    cv.NamedWindow(CAM_CFG['window'], cv.CV_WINDOW_AUTOSIZE)
    cv.NamedWindow("cam_histogram", cv.CV_WINDOW_AUTOSIZE)
    CAM_CFG['idx'] = camidx
    CAM_CFG['roi'] = roi

    if (usecam):
        CAM_CFG['handle'] = cv.CaptureFromCAM(camidx)
        #cv.GetCaptureProperty(CAM_CFG['handle'], cv.CV_CAP_PROP_FPS)
        cv.SetCaptureProperty(CAM_CFG['handle'], cv.CV_CAP_PROP_FPS, 60)
    else:
        CAM_CFG['handle'] = None

    if (roi):
        CAM_CFG['dshape'] = (roi[2], roi[3])
    elif (usecam):
        # GetSize returns (width, h), NumPy arrays expect (height, w)
        rawframe = cv.QueryFrame(CAM_CFG['handle'])
        CAM_CFG['dshape'] = cv.GetSize(rawframe)[::-1]
    else:
        raise ValueError("Need ROI or camera to determine data shape.")

    CAM_CFG['frame'] = cv.CreateImage(CAM_CFG['dshape'][::-1], cvdtype, 1)

    if (maskshape == 'circ'):
        CAM_CFG['mask'] = im.mk_rad_mask(*CAM_CFG['dshape']) < 1
    else:
        CAM_CFG['mask'] = np.ones(CAM_CFG['dshape']).astype(np.bool)
    CAM_CFG['imask'] = (CAM_CFG['mask'] == False)

    file.store_file(pjoin(outdir, CAM_APTMASK),
                    CAM_CFG['mask'].astype(np.uint8),
                    clobber=True)

    if (verb & VERB_M > L_INFO): print "Camera setup complete..."

    cam_getimage(show=True)
Пример #17
0
from post_details import post_details

browser = webdriver.Chrome('chromedriver.exe')
file = 'main.txt'

username = '******'
password = '******'

url_page = 'https://www.instagram.com/tarbiate_jensi1/'

#login(browser,username,password)
go_to_page(browser, url_page)
print("go_to_page")

if post_of_page(browser, file):
    list_of_post = read_file('main.txt')
    lenght_of_list = int(len(list_of_post) / 3)

    for i in range(lenght_of_list):
        print("i= ", i)
        counter = 3 * i
        load_comments(browser, list_of_post[counter + 1])

        post_details(browser, list_of_post[counter], list_of_post[counter + 1],
                     list_of_post[counter + 2])

    print("done")

else:
    print("post of page is not find!")
Пример #18
0
    tkn = tag[1].replace('[','').replace(']','').split('\',')
    if len(tkn) > 3:
        continue
    ltype = set()
    for t in tkn:
        # type-to-tag
        typ = t.replace('\'','').strip()
        ltag = type2tag.setdefault(typ, set())
        ltag.add(ptag)
        type2tag[typ] = ltag
        # tag-to-type
        ltype.add (typ)
    tag2type[ptag] = ltype
        
# tag - group
sgroup = ufile.read_file ('app/resources/semantic-groups.txt')
if sgroup is None:
    log.error ('impossible to load the semantic categories - interrupting')
    sys.exit()
group2tag = {}
group2type = {}
tag2group = {}
for sg in sgroup:
	tkn = sg.strip().split('|')
        grp = tkn[0].strip()
        typ = tkn[2].strip().lower()
        if typ not in type2tag:
            continue
        # group-to-tag
        if typ in type2tag:
            ltag = group2tag.setdefault (grp, set())
Пример #19
0
def cam_setup(camidx=0, roi=None, flatf=None, darkf=None, maskshape='all', procd=32, usecam=True, outdir='./', verb=0):
	"""
	Setup IEEE1394 camera using Python's binding for OpenCV. Setup will be 
	stored in global CAM_CFG dictionary for use by cam_getimage().

	@param camidx Camera index
	@param roi Region of Interest to use, as (x, y, width, height)
	@param flatf Flatfield image to use [file]
	@param darkf Darkfield image to use [file]
	@param maskshape Shape for processing mask, 'circ' or 'all'
	@param procd Bitdepth to process images at (32 or 64)
	@param outdir Directory to store stuff to
	@param verb Verbosity
	"""

	global CAM_CFG

	if (verb&VERB_M > L_INFO):  print "Setting up camera..."

	if (procd == 64): 
		npdtype = np.float64
		cvdtype = cv.IPL_DEPTH_64F
	else: 
		npdtype = np.float32
		cvdtype = cv.IPL_DEPTH_32F

	if (darkf and os.path.isfile(darkf)):
		if (verb&VERB_M > L_DEBG): print "Processing dark frames..."
		# Hard-link to used files for new cache
		newdarkf = pjoin(outdir, CAM_DARKFIELD)
		if (os.path.exists(newdarkf)):
			os.unlink(newdarkf)
		os.link(darkf, newdarkf)
		darkim = file.read_file(darkf).astype(npdtype)
		CAM_CFG['dark'] = cv.fromarray(darkim)
	if (flatf and os.path.isfile(flatf)):
		if (verb&VERB_M > L_DEBG): print "Processing flat frame(s)..."
		newflatf = pjoin(outdir, CAM_FLATFIELD)
		if (os.path.exists(newflatf)):
			os.unlink(newflatf)
		os.link(flatf, newflatf)
		flatim = file.read_file(flatf).astype(npdtype)
		CAM_CFG['flat'] = cv.fromarray(flatim)
  		if (CAM_CFG.has_key('dark')):
  			cv.Sub(CAM_CFG['flat'], CAM_CFG['dark'], CAM_CFG['flat'])

	if (verb&VERB_M > L_XNFO):  print "Configuring camera..."

	if (not CAM_CFG.has_key('window')):
		CAM_CFG['window'] = 'cam_live'
	cv.NamedWindow(CAM_CFG['window'], cv.CV_WINDOW_AUTOSIZE)
	cv.NamedWindow("cam_histogram", cv.CV_WINDOW_AUTOSIZE)
	CAM_CFG['idx'] = camidx
	CAM_CFG['roi'] = roi
	
	if (usecam): 
		CAM_CFG['handle'] = cv.CaptureFromCAM(camidx)
		#cv.GetCaptureProperty(CAM_CFG['handle'], cv.CV_CAP_PROP_FPS)
		cv.SetCaptureProperty(CAM_CFG['handle'], cv.CV_CAP_PROP_FPS, 60)
	else:
		CAM_CFG['handle'] = None

	if (roi):
		CAM_CFG['dshape'] = (roi[2], roi[3])
	elif (usecam):
		# GetSize returns (width, h), NumPy arrays expect (height, w)
		rawframe = cv.QueryFrame(CAM_CFG['handle'])
		CAM_CFG['dshape'] = cv.GetSize(rawframe)[::-1]
	else:
		raise ValueError("Need ROI or camera to determine data shape.")

	CAM_CFG['frame'] = cv.CreateImage(CAM_CFG['dshape'][::-1], cvdtype, 1)

	if (maskshape == 'circ'):
		CAM_CFG['mask'] = im.mk_rad_mask(*CAM_CFG['dshape']) < 1
	else:
		CAM_CFG['mask'] = np.ones(CAM_CFG['dshape']).astype(np.bool)
	CAM_CFG['imask'] = (CAM_CFG['mask'] == False)

	file.store_file(pjoin(outdir, CAM_APTMASK), CAM_CFG['mask'].astype(np.uint8), clobber=True)

	if (verb&VERB_M > L_INFO):  print "Camera setup complete..."

	cam_getimage(show=True)
Пример #20
0
#!/bin/python

import sys
from OutWritter import OutWritter
from file import read_file
from PySide2.QtWidgets import QApplication
from PySide2.QtQuick import QQuickView
from PySide2.QtCore import QUrl, QTimer

app = QApplication([])
writter = OutWritter()
view = QQuickView()
url = QUrl("components/list_view.qml")

view.setResizeMode(QQuickView.SizeRootObjectToView)
view.setSource(url)

timer = QTimer()
timer.timeout.connect(lambda: None)
timer.start(100)

list = view.rootObject()
list.setProperty('entries', read_file("./config/bookmarks"))

context = view.rootContext()
context.setContextProperty("out", writter)

view.show()

sys.exit(app.exec_())
Пример #21
0
def all_encoding_stats(file_name):
    """output with default file_name:
Test file: cyphesis_atlas_XML_2000-03-27_no_obj.log
Msg count: 228
            uncompressed    gzip -9   bzip2 -9
XML               954.97      47.93      33.95
XML2_test         727.00      45.92      34.03
Packed            384.41      36.79      30.84
Bach_beta         478.61      39.11      31.35
Binary1_beta      380.54      38.58      32.26
Binary2_test      236.12      35.22      30.78


Test file: CyphesisClient_fromServerViewpoint2_no_obj.log
Msg count: 716
            uncompressed    gzip -9   bzip2 -9
XML               832.77      36.76      23.82
XML2_test         632.11      35.03      23.94
Packed            284.41      28.88      23.20
Bach_beta         373.68      31.91      23.28
Binary1_beta      277.63      30.53      24.04
Binary2_test      156.22      28.31      23.62


Test file: cyphesis_atlas_Packed_2001-07-13.log
Msg count: 4768
            uncompressed    gzip -9   bzip2 -9
XML              1250.59      27.39      14.17
XML2_test         910.63      23.97      13.20
Packed            405.12      17.34      12.67
Bach_beta         544.18      18.72      12.21
Binary1_beta      441.45      22.03      14.34
Binary2_test      260.30      19.02      13.23
    """
    print
    print
    print "Test file:",file_name
    global all_msg
    xml_codec = codec.get_XML()
    #all_msg = xml_codec.decode(open(file_name).read())
    all_msg = file.read_file(file_name)
    print "Msg count:",len(all_msg)

    all_stats = []
    #XML size
    all_stats.append(calculate_stats(all_msg,xml_codec))

    #XML2 size
    all_stats.append(calculate_stats(all_msg,codec.get_XML2_test()))

    #Packed size
    all_stats.append(calculate_stats(all_msg,codec.get_Packed()))

    #Bach size
    all_stats.append(calculate_stats(all_msg,codec.get_Bach_beta()))

    #Binary1_beta size
    all_stats.append(calculate_stats(all_msg,codec.get_Binary1_beta()))

    #Binary2_test size
    all_stats.append(calculate_stats(all_msg,codec.get_Binary2_test()))

##    for name in binary2.attribute_type_dict.keys():
##        print name
##        binary2.discard_name = name
##        all_stats.append(calculate_stats(all_msg,codec.get_Binary2_test()))
##        all_stats[-1][0] = list(all_stats[-1][0])
##        all_stats[-1][0][0] = name
##    all_stats.sort(lambda e1,e2:cmp(e1[2][2],e2[2][2]))

    print
    filter_types = ("uncompressed", "gzip -9", "bzip2 -9")
    print "            %10s %10s %10s" % filter_types
    for stat in all_stats:
        print "%-13s %10.2f %10.2f %10.2f" % (
            stat[0][0], stat[0][2], stat[1][2], stat[2][2])
Пример #22
0
    tkn = tag[1].replace('[', '').replace(']', '').split('\',')
    if len(tkn) > 3:
        continue
    ltype = set()
    for t in tkn:
        # type-to-tag
        typ = t.replace('\'', '').strip()
        ltag = type2tag.setdefault(typ, set())
        ltag.add(ptag)
        type2tag[typ] = ltag
        # tag-to-type
        ltype.add(typ)
    tag2type[ptag] = ltype

# tag - group
sgroup = ufile.read_file('app/resources/semantic-groups.txt')
if sgroup is None:
    log.error('impossible to load the semantic categories - interrupting')
    sys.exit()
group2tag = {}
group2type = {}
tag2group = {}
for sg in sgroup:
    tkn = sg.strip().split('|')
    grp = tkn[0].strip()
    typ = tkn[2].strip().lower()
    if typ not in type2tag:
        continue
# group-to-tag
    if typ in type2tag:
        ltag = group2tag.setdefault(grp, set())
Пример #23
0
 def test_read_file(self):
     self.assertEqual('Hogehoge\nFoobar\n',
                      file.read_file("../file/read_file.txt"))
Пример #24
0
import file
import json

a = file.read_file()
b = file.add_json(a, 'test')
Пример #25
0
    for v in votes:
        votesPerc.append(v / X)
    votesMissing = []

    sumDif = 0
    for vp in votesPerc:
        dif = votesPerc[indMax] - vp
        votesMissing.append(dif)
        sumDif += dif

    return maxEle, sumDif, votesMissing


if __name__ == '__main__':
    lines = file.read_file('A-large.in')
    i = 0
    write = []
    for line in lines:
        if i != 0:
            line = line.split(" ")
            N = line[0]
            votes1 = line[1:]
            votes = []
            for j in votes1:
                votes.append(float(j))
            X = sum(votes)

            maxEle, sumDif, votesMissing = greaterThan1(votes, X)

            if sumDif <= 1: