Пример #1
0
def main():
    mongo = MongoSpider(conf.mongo_spider)
    redis_word = redis.Redis(**conf.redis_word)
    keyword = Keyword(redis_word)

    for article in mongo.article.find({
            'v.seg': {
                '$gt': 0
            }
    }).skip(1000).limit(10):
        if article is None or article['v']['seg'] <= 0:
            continue
        word = mongo.word_file.get(article['_id'])
        if word is not None:
            word = json.loads(word)

        title = article['title']
        words = word['words']
        res = keyword.make(title, words)
        if res is not None:
            print
            print
            print
            print '*' * 100
            print 'http://www.haoku.net/articles/%s.html' % article['_id']
            print_list(res['keys'], title='keys of %s' % title)
            print_dict(res['words'],
                       title='index of %s' % title,
                       cmp_key=lambda x: -x[1])
Пример #2
0
def do_fpga_image_list(args):
    """Query FPGA images of a tenant"""
    kwargs = OrderedDict()
    if args.page is not None and args.size is not None:
        kwargs['page'] = args.page
        kwargs['size'] = args.size
    elif args.page is not None and args.size is None\
            or args.page is None and args.size is not None:
        utils.print_err('Error: argument --page and --size '
                        'must exist or not exist at the same time')
        return
    utils.check_param(**kwargs)

    status_code, reason, body = rest.fpga_image_list(*_get_config(),
                                                     params=kwargs)
    if status_code != 200 or not isinstance(body, dict):
        raise FisException(_invalid_resp(status_code, reason, body))
    fi_list = body.get('fpgaimages', [])

    _do_resp(status_code, reason)
    columns = [
        'id', 'name', 'status', 'protected', 'size', 'createdAt',
        'description', 'metadata', 'message'
    ]
    utils.print_list(fi_list, columns)
Пример #3
0
 def list_assignments(self):
     course = Course(self.api_client.client, self.args.course)
     labs = [hw["name"] for hw in Lab.list(course)]
     if len(labs) == 0:
         print("Course has no labs.")
     else:
         print_list(labs)
Пример #4
0
    def do_tables(self, args):
        """Liste les tables de las base de données"""
        if not self.db:
            print('ERROR: No DB connected')
            return

        utils.print_list(self.db.tables)
Пример #5
0
def analyse_string(string, max_subjectivity):
    blob = TextBlob(string)
    np_counts = blob.np_counts
    np_counts_sorted = sorted(np_counts.items(),
                              key=operator.itemgetter(1),
                              reverse=True)
    np_counts_filtered = np_counts_sorted[:20]
    sentences = string_to_sentences(blob)
    sentences_sentiments = build_sentences_sentiments_list(sentences)

    filtered_sentences_sentiments = filter_sentences_sentiments(
        sentences_sentiments, max_subjectivity)
    sorted_sentences_sentiments = sort_sentences_sentiments(
        filtered_sentences_sentiments)

    five_most_positive = sorted_sentences_sentiments[-5:]
    five_most_negative = sorted_sentences_sentiments[:4]
    print_list(five_most_positive)
    result = {}
    result['raw_text'] = string
    result['np_counts'] = np_counts_sorted
    result['np_counts_sorted'] = np_counts_sorted
    result['np_counts_filtered'] = np_counts_filtered
    result['sentences_sentiments'] = sentences_sentiments
    result['sorted_sentences_sentiments'] = sorted_sentences_sentiments
    return result
Пример #6
0
 def describe(self, force_describe = False):
   utils.type_slow(['You are in ' + self.name])
   if force_describe or not self.visited:
     utils.type_slow(self.description)
     self.print_contents()
     utils.print_list('You can go: ', self.get_path_names())
     self.visited = True
Пример #7
0
 def print_inventory(self):
     items = []
     for i in self.inventory:
         items.append(i.get_name())
     if len(items) == 0:
         items = ['nothing']
     utils.print_list('You have: ', items)
Пример #8
0
 def print(rows, cfg):
     cfg = cfg or {}
     cols = cfg.get('cols', [])
     if cfg.get('table', False):
         print(tabulate(rows, cols, tablefmt="grid"))
     else:
         print_list([[row.get(col, None) for col in cols] for row in rows],
                    cols)
Пример #9
0
 def list_chapters(self):
     course = Course(self.api_client.client, self.args.course)
     book = Book(course, self.args.book)
     print_list(
         [
             "{}. {}".format(str(float(c["rank"])).rstrip("0").rstrip("."), c["title"])
             for c in Chapter.list(course, book)
         ]
     )
Пример #10
0
def _simpleTestHarness(no_wrap):

    import utils

    def testFormatter(event):
        return "*{}".format(event["state"])

    def buildFormatter(field, width):
        def f(dict):
            if field == 'number':
                return dict[field]
            return "{}".format(dict[field]).replace("_", " ")
        return {"formatter": f, "wrapperFormatter": width}

    set_no_wrap(no_wrap)

    field_labels = ['Time Stamp', 'State', 'Event Log ID', 'Reason Text',
                    'Entity Instance ID', 'Severity', 'Number']
    fields = ['timestamp', 'state', 'event_log_id', 'reason_text',
              'entity_instance_id', 'severity', 'number']

    formatterSpecX = {"timestamp": 10,
                      "state": 8,
                      "event_log_id": 70,
                      "reason_text": 30,
                      "entity_instance_id": 30,
                      "severity": 12,
                      "number": 4}

    formatterSpec = {}
    for f in fields:
        formatterSpec[f] = buildFormatter(f, formatterSpecX[f])

    logs = []
    for i in range(0, 30):
        log = {}
        for f in fields:
            if f == 'number':
                log[f] = i
            else:
                log[f] = "{}{}".format(f, i)
        logs.append(utils.objectify(log))

    formatterSpec = formatterSpecX

    formatters = build_wrapping_formatters(logs, fields, field_labels, formatterSpec)

    utils.print_list(logs, fields, field_labels, formatters=formatters, sortby=6,
                     reversesort=True, no_wrap_fields=['entity_instance_id'])

    print("nowrap = {}".format(is_nowrap_set()))
Пример #11
0
 def perform_scan(self, state):
     print_progress_bar(self.scan_seconds)
     clear()
     print_list(self.result_sets[self.next_scan_sensitivity_level])
     # If our scanner has another, more sensitive result set available,
     # prepare to return it on the next scan. Otherwise stick with current
     # sensitivity level.
     if (self.next_scan_sensitivity_level + 1) < len(self.result_sets):
         self.next_scan_sensitivity_level+=1
     state['scans_completed']+=1
     if state['scans_completed']==1:
         state['is_logged_in'] = False
     _user_input = input(RETURN_TO_MAIN_MENU_INSTRUCTION)
     clear()
Пример #12
0
    def services(self):
        ns_object = ["service"]
        list_of_services = []

        try:
            output = self.client.get_object(ns_object)
        except RuntimeError as e:
            msg = "Problem while trying to get list of services " \
                  "on %s.\n%s" % (self.args.host, e)
            raise RuntimeError(msg)

        for service in output['service']:
            list_of_services.append(service['name'])

        utils.print_list(sorted(list_of_services))
Пример #13
0
    def csvservers(self):
        ns_object = ["csvserver"]
        list_of_cs_vservers = []

        try:
            output = self.client.get_object(ns_object)
        except RuntimeError as e:
            msg = "Problem while trying to get list of CS vservers " \
                  "on %s.\n%s" % (self.args.host, e)
            raise RuntimeError(msg)

        for vserver in output['csvserver']:
            list_of_cs_vservers.append(vserver['name'])

        utils.print_list(sorted(list_of_cs_vservers))
Пример #14
0
    def services(self):
        ns_object = ["service"]
        list_of_services = []

        try:
            output = self.client.get_object(ns_object)
        except RuntimeError as e:
            msg = "Problem while trying to get list of services " \
                  "on %s.\n%s" % (self.args.host, e)
            raise RuntimeError(msg)

        for service in output['service']:
            list_of_services.append(service['name'])

        utils.print_list(sorted(list_of_services))
Пример #15
0
    def csvservers(self):
        ns_object = ["csvserver"]
        list_of_cs_vservers = []

        try:
            output = self.client.get_object(ns_object)
        except RuntimeError as e:
            msg = "Problem while trying to get list of CS vservers " \
                  "on %s.\n%s" % (self.args.host, e)
            raise RuntimeError(msg)

        for vserver in output['csvserver']:
            list_of_cs_vservers.append(vserver['name'])

        utils.print_list(sorted(list_of_cs_vservers))
Пример #16
0
def rodada(pages, output):
	xpaths_finais = {}
	for (xpath, weight) in main(pages, output):
			if(xpaths_finais.get(xpath, False)):
				xpaths_finais[xpath] += weight
			else:
				xpaths_finais[xpath] = weight		
	big_fat = sorted(xpaths_finais.items(), key = lambda x: x[1], reverse=True)
	if __debug__:
		utils.print_list("big_fat", big_fat)
	chooses_ones = big_fat[:5]
	#the_choose_one = utils.merge_xpaths(chooses_ones)
	#output.write("\n"+ "M>" + str(the_choose_one))
	output.write("\n"+ "N^" + str(chooses_ones[0]))

	output.write("\n" + "#"*30)
Пример #17
0
    def do_closure(self, args):
        """Calcule la fermeture d'une liste d'attributs"""
        parser = CmdParser('closure')
        parser.add_argument('attributes', nargs='*')
        try:
            args = parser.parse_args(args.split())
            if args.attributes is None or len(args.attributes) == 0:
                parser.print_help()
                return
        except ArgumentError:
            return

        att = functools.reduce(lambda a, b: str(a) + ' ' + str(b), args.attributes)
        closure = self.db.df_closure(att, self.db.list_df())

        utils.print_list(closure)
Пример #18
0
def one_round(L, D, node_dict, debug=False):
    # find the pair of nodes with the smallest distance
    temp = [(D[k], k) for k in L]
    d,t = sorted(temp)[0]
    if debug:
        print 'closest:'
        print t,d
    save_node_data(t,d,node_dict,debug=debug)
    # collapse the list
    rL = sorted(collapse(L,t))
    if debug:
        print 'elements after joining:'
        utils.print_list(rL,n=1)
    # calculate cluster distances
    for t in rL:
        if not t in D:
            D[t] = average_distance(t,D,debug=debug)
    return rL,t
Пример #19
0
def one_round(L,D,node_dict,debug=False):
    # find the pair of nodes with the smallest distance
    temp = [(D[k],k) for k in L]
    d,t = sorted(temp)[0]
    if debug:
        print 'closest:'
        print t,d
    save_node_data(t,d,node_dict,debug=debug)
    # collapse the list
    rL = sorted(collapse(L,t))
    if debug:
        print 'elements after joining:'
        utils.print_list(rL,n=1)
    # calculate cluster distances
    for t in rL:
        if not t in D:
            D[t] = average_distance(t,D,debug=debug)
    return rL,t
Пример #20
0
def do_fpga_image_relation_list(args):
    """Query FPGA image relations visible to a tenant"""
    kwargs = OrderedDict()
    if args.image_id is not None:
        kwargs['image_id'] = args.image_id
    if args.fpga_image_id is not None:
        kwargs['fpga_image_id'] = args.fpga_image_id
    if args.page is not None and args.size is not None:
        kwargs['page'] = args.page
        kwargs['size'] = args.size
    elif args.page is not None and args.size is None\
            or args.page is None and args.size is not None:
        utils.print_err('Error: argument --page and --size '
                        'must exist or not exist at the same time')
        return
    utils.check_param(**kwargs)

    status_code, reason, body = rest.fpga_image_relation_list(*_get_config(),
                                                              params=kwargs)
    if status_code != 200 or not isinstance(body, dict):
        raise FisException(_invalid_resp(status_code, reason, body))

    _do_resp(status_code, reason)
    relation_list = []
    for relations in body.get('associations', []):
        image_id = relations.get('image_id', None)
        for fpga_image in relations.get('fpgaimages', []):
            relation = {}
            relation['image_id'] = image_id
            relation.update(fpga_image)
            relation['fpga_image_id'] = relation.get('id', None)
            relation_list.append(relation)
    columns = [
        'image_id', 'fpga_image_id', 'name', 'status', 'protected', 'size',
        'createdAt', 'description', 'metadata', 'message'
    ]
    utils.print_list(relation_list, columns)

    if args.image_id is None and args.fpga_image_id is None:
        print(
            'Tips: The FPGA image relations can only be obtained if at least one of the \033[31m--fpga-image-id\033[0m and \033[31m--image-id\033[0m arguments is specified, otherwise only an empty list is returned.'
        )
Пример #21
0
    def do_super_key(self, args):
        """liste les super clefs d'une table"""
        if not self.db:
            print('ERROR: No DB connected')
            return

        try:
            parser = CmdParser('key')
            parser.add_argument('table')
            args = parser.parse_args(args.split())
        except ArgumentError:
            return

        try:
            keys = self.db.super_key(args.table)
        except funcdep.UnknownTableError:
            print('ERROR: Table not exists')
            return

        utils.print_list(keys)
Пример #22
0
    def do_list(self, args):
        """Liste les DF pour la base de données ou une table"""
        if not self.db:
            print('ERROR: No DB connected')
            return

        try:
            parser = CmdParser('list')
            parser.add_argument('table', nargs='?')
            args = parser.parse_args(args.split())
        except ArgumentError:
            return

        dfs = None
        try:
            dfs = self.db.list_table_df(args.table) if args.table else self.db.list_df()
        except funcdep.UnknownTableError:
            print('ERROR: Table not exists')
            return

        utils.print_list(dfs)
Пример #23
0
    def do_fields(self, args):
        """Liste les champs d'une table de la base de données"""
        if not self.db:
            print('ERROR: No DB connected')
            return

        try:
            parser = CmdParser('fields')
            parser.add_argument('table')
            args = parser.parse_args(args.split())
        except ArgumentError:
            return

        fields = None
        try:
            fields = self.db.get_fields(args.table)
        except (funcdep.UnknownTableError, funcdep.DFTableError):
            print('ERROR: Tables not exists')
            return

        utils.print_list(fields)
Пример #24
0
def main(*args):
    #
    #
    if len(args) == 1:
        s.main()
    elif len(args) == 2:
        if args[1] == 'c':
            equipamientos = get_equipments()
            categorias = get_equipment_categories(equipamientos)
            print_list(categorias)
        elif args[1] == 'e':
            equipamientos = get_equipments()
            print_list(equipamientos)
        else:
            s.command_help()
            exit(-1)

    elif len(args) == 3:
        if args[1] == 'f':
            equipamientos = get_equipments()
            equipamientos = filter_equipments(equipamientos, args[2])
            print_list(equipamientos)
        else:
            s.command_help()
            exit(-1)
    else:
        s.command_help()
        exit(-1)
Пример #25
0
def main():
    if len(sys.argv) < 3 or (len(sys.argv) > 1 and sys.argv[1] == "--help"):
        print_help_message()
        exit()

    file_name = sys.argv[1]
    objdump_lines = []
    try:
        f = open(file_name, 'r')
        objdump_lines = f.readlines()
        f.close()
    except IOError as e:
        print_help_message([e])
        exit()

    jump_register = sys.argv[3] if len(sys.argv) > 3 else None

    disallowed_registers = utils.build_register_list_from_pattern(sys.argv[4]) if len(sys.argv) > 4 else []

    objdump_handler.extract_functions_from_objdump_lines(objdump_lines)
    rop_gadgets = objdump_handler.search(sys.argv[2], disallowed_registers, jump_register)
    utils.print_list(rop_gadgets)
Пример #26
0
def main():
	mongo = MongoSpider(conf.mongo_spider)
	redis_word = redis.Redis(**conf.redis_word)
	keyword = Keyword(redis_word)

	for article in mongo.article.find({'v.seg':{'$gt':0}}).skip(1000).limit(10):
		if article is None or article['v']['seg'] <= 0:
			continue
		word = mongo.word_file.get(article['_id'])
		if word is not None:
			word = json.loads(word)

		title = article['title']
		words = word['words']
		res = keyword.make(title, words)
		if res is not None:
			print
			print
			print
			print '*' * 100
			print 'http://www.haoku.net/articles/%s.html' % article['_id']
			print_list(res['keys'], title='keys of %s' % title)
			print_dict(res['words'], title='index of %s' % title, cmp_key=lambda x: -x[1])
Пример #27
0
    def filter(self, max_collinearity=0.7):

        features = self._feature_metadata.get_active_features()
        self.feature_correlations_ = pd.DataFrame()

        # Perform pairwise correlation coefficient calculations
        for col_a, col_b in itertools.combinations(features, 2):
            r, p = pearsonr(self.X_[col_a], self.X_[col_b])
            cols = col_a + "__" + col_b
            d = {
                "Columns": cols,
                "A": col_a,
                "B": col_b,
                "Correlation": abs(r),
                "p-value": p
            }
            df = pd.DataFrame(data=d, index=[0])
            self.feature_correlations_ = pd.concat(
                (self.feature_correlations_, df), axis=0)

        # Select correlations above threshold
        redundancies = self.feature_correlations_[
            self.feature_correlations_["Correlation"] > max_collinearity]
        if redundancies.shape[0] > 0:
            features_to_remove = []
            print("\nFiltering Redundant Features")
            print(
                f"{redundancies.shape[0]} pairs of redundant features found.")
            print(redundancies)
            for idx, row in redundancies.iterrows():
                features_to_remove.append(
                    self._select_redundant_feature(row["A"], row["B"]))
            self._feature_metadata.exclude_features(features_to_remove)

            print("\nThe following features are excluded.")
            print_list(features_to_remove, 1)
        return self
Пример #28
0
def collapse(L,node_in,debug=False):
    node = ''.join(utils.list_elements(node_in))
    if debug:
        print 'node', node
        print 'L'
        node, utils.print_list(L, n=4)
    rL = list()
    for item in L:
        left,right = item
        if debug:
            print 'left', left, 'right', right
        for tip in left:
            if tip in node:
                left = node
        for tip in right:
            if tip in node:
                right = node
        if not left == right:
            rL.append((left,right))
    rL = sorted(list(set(rL)))
    if debug:
        print 'rL after set:'
        utils.print_list(rL)
    return rL
Пример #29
0
def collapse(L, node_in, debug=False):
    node = ''.join(utils.list_elements(node_in))
    if debug:
        print 'node', node
        print 'L'
        node, utils.print_list(L, n=4)
    rL = list()
    for item in L:
        left,right = item
        if debug:
            print 'left', left, 'right', right
        for tip in left:
            if tip in node:
                left = node
        for tip in right:
            if tip in node:
                right = node
        if not left == right:
            rL.append((left,right))
    rL = sorted(list(set(rL)))
    if debug:
        print 'rL after set:'
        utils.print_list(rL)
    return rL
Пример #30
0
            if j.val < x:
                if j != t:
                    i.next = j.next
                    s.next = j
                    s = j
                    j.next = t
                    j = i.next
                else:
                    i = j
                    j = j.next
                    s = i
                    t = j
            else:
                i = j
                j = j.next
        return fake_head.next


s = Solution()
A = [ListNode(1), ListNode(4), ListNode(3), ListNode(2), ListNode(6), ListNode(5), ListNode(2), ListNode(7)]
for i in xrange(len(A) - 1):
    A[i].next = A[i+1]
print_list(A[0])
print_list(s.partition(A[0], 3))

A = [ListNode(2), ListNode(1)]
for i in xrange(len(A) - 1):
    A[i].next = A[i+1]
print_list(A[0])
print_list(s.partition(A[0], 2))
Пример #31
0
 def test_list_process(self):
     print_list('Processes', self.node.process_list())
Пример #32
0
        :type n: int
        :rtype: ListNode
        Reverse a linked list from position m to n. Do it in-place and in one-pass.
        """
        h = ListNode(0)
        h.next, l, r, c = head, h, head, 1
        while c < m:
            l, r = r, r.next
            c += 1
        while c < n:
            # print c, l.val, r.val
            # t, l.next = l.next, r.next
            # l.next.next, r.next = t, r.next.next
            l.next, r.next.next, r.next = r.next, l.next, r.next.next  # order matters
            c += 1
            # print_list(h)
        return h.next


s = Solution()
head = ListNode(-1)
head.next = ListNode(-2)
head.next.next = ListNode(-3)
head.next.next.next = ListNode(-4)
head.next.next.next.next = ListNode(-5)
head.next.next.next.next.next = ListNode(-6)
head.next.next.next.next.next.next = ListNode(-7)
# print_list(head)
head = s.reverseBetween(head, 2, 4)
print_list(head)
Пример #33
0
    fname = fname.replace("?", "_")    
    fname = fname.replace("!", "_")
    fname = fname.replace("'", "_")
    print fname
    
    return fname + ".html" 
    
       
def crawl_url(seed): # returns list of crawled links
    
    crawled = []    
    content = urlutils.get_page(seed)    
    crawled = get_target_urls(content) 

    return crawled


# create a directory with the name of the URL if it does not exist
# if it exists, clean the files from the directory 
dir_name = urlutils.get_stem_url(URL1)
dir_name = PREFIX+dir_name 
if not os.path.exists(dir_name):
    os.mkdir(dir_name)
utils.clean_dir(dir_name)

#crawl urls 
crawled = crawl_url(URL1)
fout = open(dir_name+"//_url_list.txt",'w')    
utils.print_list(crawled, fout)    
fout.close()
Пример #34
0
from utils import Node, print_list

def get_last(head):
    current = head
    if current is None:
        return None
    while current.next is not None:
        current = current.next
        
    return current

if __name__ == '__main__':
    head = Node(1)
    second = Node(2)
    third = Node(3)
    fourth = Node(4)
    fifth = Node(5)

    head.next = second
    second.next = third
    third.next = fourth
    fourth.next = fifth
    print_list(head)

    print('\n\n')

    result = get_last(None)
    print(result)
Пример #35
0
import os
import sys

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path = [os.path.join(SCRIPT_DIR + '/../')] + sys.path

from mongojoin import MongoJoin
from mongojoin import MongoCollection
from utils import print_dict, print_list

if __name__ == "__main__":

    m_1 = MongoCollection("test", "supplier", ["supplier_id", "name"], {})

    c_1 = m_1.get_mongo_cursor()

    print "************************ COLLECTION : SUPPLIER ************************"
    c = c_1.find({})
    print_list(c)

    aggregator = MongoJoin(m_1, m_1, ["supplier_id"])

    print "\n************************ INNER JOIN **********************"
    print_dict(aggregator.inner())
    print "\n********************** LEFT OUTER JOIN **********************"
    print_dict(aggregator.left_outer())
    print "\n********************** RIGHT OUTER JOIN *********************"
    print_dict(aggregator.right_outer())
    print "\n********************** FULL OUTER JOIN *********************"
    print_dict(aggregator.full_outer())
Пример #36
0
 def do_print(self, arg):
     """Print the whole parsed/validated list or one element: print 1"""
     utils.print_list(arg)
Пример #37
0
 def list_parts(self):
     course = Course(self.api_client.client, self.args.course)
     book = Book(course, self.args.book)
     print_list(["{}. {}".format(c["rank"], c["title"]) for c in Part.list(course, book)])
Пример #38
0
 def list_books(self):
     res = self.api_client.list_books(self.args.course, all=self.args.all)
     print_list([c["label"] for c in res])
Пример #39
0
 def list_courses(self):
     print_list([c["label"] for c in Course.list(self.api_client.client)])
Пример #40
0
# 1行目を取得してmに代入
input_line_first = input().split()
m = int(input_line_first[1])

# 2行目を取得して、aというリストに代入
a_str = input().split()
a = [int(i) for i in a_str]

# 3行目以降を取得してsという2次元リストに代入
s_str = utils.get_lines_by_first_line()
s = utils.cast_int_for_two_dimensional_list(s_str)

for s_line in s:

    start = s_line[0]-1
    end = s_line[1]

    target_slice = a[start:end]
    average = numpy.average(target_slice)

    diff = 0
    if average < m:
        diff = math.ceil(m - average)

        for i, v in enumerate(a):
            if i in range(start, end):
                a[i] += diff

utils.print_list(a)