Пример #1
0
def updateProductLocal():
    test_searcher = searcher(settings.FULLTEXT_DIR)
    csvfile = csv.writer(open('product_hits.csv', 'wb')  )
    count = 0    
    with open('../../../data/products.csv', 'rU') as csvinputfile:
        spamreader = csv.reader(csvinputfile)
        for row in spamreader:
            count = count + 1
            
            print count
            hits = getHits(test_searcher, row[0].strip())
            if len(hits) > 1:
                csvfile.writerow([row[0].strip(), "; ".join(hits), len(hits)])
            '''cur1 = db.cursor() 
Пример #2
0
 def test6():
     b = chessboard()
     b.loads(
         '1:CJ 2:DJ 1:dk 1:DL 1:EH 1:EI 2:EJ 2:EK 2:FH 2:FI 2:FJ 1:FK 2:FL 1:FM 2:GF 1:GG 2:GH 2:GI 2:GJ 1:GK 1:GL 2:GM 1:HE 2:HF 2:HG 2:HH 2:HI 1:HJ 2:HK 2:HL 1:IF 1:IG 1:IH 2:II 1:IJ 2:IL 2:JG 1:JH 1:JI 1:JJ 1:JK 2:JL 1:JM 1:KI 2:KJ 1:KL 1:LJ 2:MK'
     )
     #b.loads('1:HH,1:HI,1:HJ,1:HK')
     s = searcher()
     s.board = b.board()
     t = time.time()
     score, row, col = s.search(2, 3)
     t = time.time() - t
     b[row][col] = 2
     print b
     print score, t
     print chr(ord('A') + row) + chr(ord('A') + col)
Пример #3
0
def main():
	while( True ):
		# input
		print "Please input the Image:"
		curName = raw_input()
		if int(curName) > 1000 or int(curName) < 0:
			break
		# search
		imgs = sr.getImgs()
		imgNameArr,resDetial,checkRate = sr.searcher( "images/"+curName+".jpg", 'images/', curName, 1000, 100, imgs )
		startGUI( imgNameArr )
		print "==========================================="
		print "The check rate of image "+curName+".jpg is:"
		print checkRate
		print "==========================================="
	print "Exit"
Пример #4
0
    def __init__(self):

        self.SIZE = 13  # The number of locations/cross-points in row or column
        self.TEXT = '  A B C D E F G H I J K L M'

        self.b = chessboard(SIZE=self.SIZE, TEXT=self.TEXT)
        self.s = searcher(self.SIZE)
        self.s.board = self.b.board()

        self.turn = 2
        self.history = []
        # self.undo = False

        # 设置难度
        self.DEPTH = 2
        # speed up
        self._psyco_speedup()
Пример #5
0
 def test7():
     b = chessboard()
     s = searcher()
     s.board = b.board()
     b.loads('2:HH 1:JF')
     turn = 2
     while 1:
         score, row, col = s.search(2, 2)
         print 'robot move %s%s (%d)' % (chr(ord('A') + row),
                                         chr(ord('A') + col), score)
         b[row][col] = 2
         if b.check() == 2:
             print b
             print b.dumps()
             print 'you lose !!'
             return 0
         while 1:
             print b
             print 'your move (pos):',
             text = raw_input().strip('\r\n\t ')
             if len(text) == 2:
                 tr = ord(text[0].upper()) - ord('A')
                 tc = ord(text[1].upper()) - ord('A')
                 if tr >= 0 and tc >= 0 and tr < 15 and tc < 15:
                     if b[tr][tc] == 0:
                         row, col = tr, tc
                         break
                     else:
                         print 'can not move there'
                 else:
                     print 'bad position'
             elif text.upper() == 'Q':
                 print b.dumps()
                 return 0
         b[row][col] = 1
         if b.check() == 1:
             print b
             print b.dumps()
             print 'you win !!'
             return 0
     return 0
Пример #6
0
def updateProduct():
    test_searcher = searcher(settings.FULLTEXT_DIR)
    csvfile = csv.writer(open('product_hits.csv', 'wb')  )
        
    db = dbconnector().getNewCon("product")
    cur = db.cursor() 
    cur.execute("select product from products  ")
    count = 0 
    for (product, ) in cur :
            count = count + 1
            print count
            hits = getHits(test_searcher, product)
            csvfile.writerow([product, "; ".join(hits), len(hits)])
            '''cur1 = db.cursor() 
            insert_query = ("update  products set hits = %s , num_hits = %s where product = %s")
            data_query = ("; ".join(hits), len(hits), product)
            cur1.execute(insert_query, data_query)
            cur1.close() 
            db.commit()'''
    cur.close()
    db.close()
Пример #7
0
def searcherLoad():
    pm = persistenceManager()
    tokenSet = set(pm.csv2map(term_count_csv_path, ['term', 'count']).keys())
    ids = np.load(id_mat_path)
    q = 'bitcoin cryptocurrency speculation bubble wallstreet bank dollar'

    idfMat = np.load(idf_vec_mat_path)
    sr = searcher(tokenSet, idfMat, ids)
    r = sr.query(q, 1)
    print(r)
    gc.collect()

    lrma50 = np.load('d:/db/persistence5k/lrma50.npy')
    sr = searcher(tokenSet, lrma50, ids)
    r = sr.query(q, 1)
    print(r)
    gc.collect()

    lrma100 = np.load('d:/db/persistence5k/lrma100.npy')
    sr = searcher(tokenSet, lrma100, ids)
    r = sr.query(q, 1)
    print(r)
    gc.collect()

    lrma200 = np.load('d:/db/persistence5k/lrma200.npy')
    sr = searcher(tokenSet, lrma200, ids)
    r = sr.query(q, 1)
    print(r)
    gc.collect()

    lrma500 = np.load('d:/db/lrma500.npy')
    sr = searcher(tokenSet, lrma500, ids)
    r = sr.query(q, 1)
    print(r)
    gc.collect()

    lrma750 = np.load('d:/db/persistence5k/lrma750.npy')
    sr = searcher(tokenSet, lrma750, ids)
    r = sr.query(q, 1)
    print(r)
    gc.collect()
Пример #8
0
def gamemain():
    b = chessboard()
    s = searcher()
    s.board = b.board()
 
    opening = [
        '1:HH 2:II',
        #'2:IG 2:GI 1:HH',
        '1:IH 2:GI',
        '1:HG 2:HI',
        #'2:HG 2:HI 1:HH',
        #'1:HH 2:IH 2:GI',
        #'1:HH 2:IH 2:HI',
        #'1:HH 2:IH 2:HJ',
        #'1:HG 2:HH 2:HI',
        #'1:GH 2:HH 2:HI',
    ]
 
    import random
    openid = random.randint(0, len(opening) - 1)
    b.loads(opening[openid])
    turn = 2
    history = []
    undo = False
 
    # 设置难度
    DEPTH = 1
 
    if len(sys.argv) > 1:
        if sys.argv[1].lower() == 'hard':
            DEPTH = 2
 
    while 1:
        print ''
        while 1:
            print '<ROUND %d>'%(len(history) + 1)
            b.show()
            print 'Your move (u:undo, q:quit):',
            text = raw_input().strip('\r\n\t ')
            if len(text) == 2:
                tr = ord(text[0].upper()) - ord('A')
                tc = ord(text[1].upper()) - ord('A')
                if tr >= 0 and tc >= 0 and tr < 15 and tc < 15:
                    if b[tr][tc] == 0:
                        row, col = tr, tc
                        break
                    else:
                        print 'can not move there'
                else:
                    print 'bad position'
            elif text.upper() == 'U':
                undo = True
                break
            elif text.upper() == 'Q':
                print b.dumps()
                return 0
         
        if undo == True:
            undo = False
            if len(history) == 0:
                print 'no history to undo'
            else:
                print 'rollback from history ...'
                move = history.pop()
                b.loads(move)
        else:
            history.append(b.dumps())
            b[row][col] = 1
 
            if b.check() == 1:
                b.show()
                print b.dumps()
                print ''
                print 'YOU WIN !!'
                return 0
 
            print 'robot is thinking now ...'
            score, row, col = s.search(2, DEPTH)
            cord = '%s%s'%(chr(ord('A') + row), chr(ord('A') + col))
            print 'robot move to %s (%d)'%(cord, score)
            b[row][col] = 2
 
            if b.check() == 2:
                b.show()
                print b.dumps()
                print ''
                print 'YOU LOSE.'
                return 0
 
    return 0
 
 
#----------------------------------------------------------------------
# testing case
#----------------------------------------------------------------------
Пример #9
0
import crawler
import searcher
import sys

reload(searcher)
e = searcher.searcher('searchindex.db')

# e.getmatchrows('get set')


# e.query( 'get set')

# e.calculatepagerank()

cur = e.con.execute( 'select * from pagerank order by score desc' )
# for i in range( 10 ): print cur.next()

e.query( 'get set')



# e.geturlname( )

Пример #10
0
import searcher
import data_load
import indexer
import WEBcrawler
import weather

weather.weather()
visit_url.visit_url()
indexer.indexer()
searcher.searcher()
data_load.traverser()
d = indexer.indexer("raw_data.pickle","shelve")
searcher.search(d)
Пример #11
0
def edit(data):

	
	content = ""
	
	while content != "end":
		content = input("id: ")
		
		if content == "end":
			continue
		if content[:2] == "ls":
			ls(content, data)
			continue

		if content == "search":
			se = ""
			while se != "end":
				se = input("search: ")
				if se == "end":
					continue
				if isint(se):
					from mapper import reload
					get(data, reload(data), id = int(se))
				for n in searcher(se, data):
					print(str(n.id) + ": " + n.title)
			continue
		try:
			id = int(content)
		except ValueError:
			print("INVALID ID")
			continue
		
		cur_node = data[id]
		cur = ""
		while cur != "end":
			cur = input(str(id) + ": ")
			if cur == "end":
				continue
			if cur == "ls":
				cur_node.printNode()
			if cur == "description":

				new_descr = input("\n" + str(id) + ".description: " + str(cur_node.description) + "\n")
				if new_descr == "end":
					continue
				else:
					if "+a" == cur[:-2]:
				 		new_descr = cur_node.description + ". " + new_descr
					cur_node.description = new_descr
					print("\n" + str(id) + ".description: " + str(cur_node.description) + "\n")
			if cur == "past":
				p = ""
				print("\npast: " + str(cur_node.past) + "\n")
				while p != "end":

					p = input()
					if p == "end":
						continue
					if p[:2] == "ls":
						print("\npast: " + str(cur_node.past) + "\n")
						ls(p, data)
						continue
					
					if p == "search":
						se = ""
						while se != "end":
							se = input("search: ")
							if se == "end":
								continue
							if isint(se):
								from mapper import reload
								get(data, reload(data), id = int(se))
							for n in searcher(se, data):
								print(str(n.id) + ": " + n.title)
						continue
					try:
						ind = p[0]
						newID = int(p[1:])
					except:
						print("INVALID ID")
						p = input("\npast: " + str(cur_node.past) + "\n")
						continue
					
					if ind == "-":
						cur_node.past.remove(newID)
						data[newID].future.remove(id)
						print("past: " + str(cur_node.past) + "\n")
					if ind == "+":
						cur_node.past.append(newID)
						data[newID].future.append(id)
						print("past: " + str(cur_node.past) + "\n")
			if cur == "future":

				p = ""
				print("\nfuture: " + str(cur_node.future) + "\n")
				while p != "end":

					p = input()
					if p == "end":
						continue
					if p[:2] == "ls":
						print("\nfuture: " + str(cur_node.future) + "\n")
						ls(p, data)
						continue
					
					if p == "search":
						se = ""
						while se != "end":
							se = input("search: ")
							if se == "end":
								continue
							if isint(se):
								from mapper import reload
								get(data, reload(data), id = int(se))
							for n in searcher(se, data):
								print(str(n.id) + ": " + n.title)
						continue
					try:
						ind = p[0]
						newID = int(p[1:])
					except:
						print("INVALID ID")
						print("\nfuture: " + str(cur_node.future) + "\n")
						continue
					
					if ind == "-":
						cur_node.future.remove(newID)
						data[newID].past.remove(id)
						print("future: " + str(cur_node.future) + "\n")
					if ind == "+":
						cur_node.future.append(newID)
						data[newID].past.append(id)
						print("future: " + str(cur_node.future) + "\n")
			if cur == "related":
				pa = ""
				while pa != "end":

					pa = input("\nid: " + str(id) + "\n" + ", ".join(cur_node.related) + "\n\n: ")
					if pa == "end":
						continue
					
					p = list(pa)
					if p[0] == "-":
						cur_node.related.remove(p[1])
						data[int(p[1])].related.remove(p[1])
					if p[0] == "+":
						cur_node.related.append(p[1])
						data[int(p[1])].related.append(p[1])
					print("\nid: " + str(id) + "\n" + ", ".join(cur_node.related))
			if cur == "keywords":

				pa = ""
				while pa != "end":

					pa = input("\nid: " + str(id) + "\n" + ", ".join(cur_node.keywords) + "\n\n: ")
					if pa == "end":
						continue
					
					p = list(pa)
					if p[0] == "-":
						cur_node.keywords.remove(p[1])
					if p[0] == "+":
						cur_node.keywords.append(p[1])	
					print("\nid: " + str(id) + "\n" + ", ".join(cur_node.keywords))
			if "title" in cur:
				
				titleNew = input("\n" + str(id) + ".title: " + cur_node.title + "\n")
				if titleNew == "end":
					continue
				else:
					if "+a" == cur[:-2]:
						titleNew = cur_node.title + ". " + titleNew
					cur_node.title = titleNew	
				print("\n" + str(id) + ".title: " + cur_node.title + "\n")
# 			if cur == "type":
# 
# 				typeNew = input("\nid: " + str(id) + "\n" + cur_node.type + "\n\n: ")
# 				if descrNew == "end":
# 					continue
# 				else:
# 					cur_node.description = descrNew	
# 				print "\nid: " + str(id) + "\n" + cur_node.type
				
	return data
				
Пример #12
0
import crawler
import searcher

pages = ['https://www.codechef.com/']

C = crawler.crawler('codechef.db')
C.createindextables()

print "Crawling :: \n"
C.crawl(pages)

print "Ranking Pages :: \n"
C.calculatepagerank()

S = searcher.searcher('codechef.db')

searchQuery = 'Saturday'
S.query(searchQuery)
Пример #13
0
        test_y[i][j] *= (1 + np.random.uniform(-1 * noise_level, noise_level, len(test_x)))

#Run the tests and characterize the results
fits = []
guesses = []
degrees = []

for i in range(0, len(test_functions)):
    print(" ")
    print("Test: " + str(i) + " | f(x) = " + test_names[i])  
    tStart = time.time()
    fits.append([])
    guesses.append([])
    degrees.append([])
    for j in range(0,n_tests_per_function):
        fit, guess, degree  = searcher(test_functions[i], test_x, test_y[i][j], p_min, p_max)
        fits[i].append(fit)
        guesses[i].append(guess)
        degrees[i].append(degree)
    print("DEBUG: time taken =  " + str(time.time() - tStart) + " s")
    for j in range(0, n_tests_per_function):
        print("True parameters: " + str(test_parameters[i][j]))
        print("Best fit parameters: " + str(fits[i][j][0]))
        print("Guessed parameters: " + str(guesses[i][j]) + " | Degree: " + str(degrees[i][j]))
        pl.plot(test_x,test_y[i][j],'bo',alpha=0.2,label="Original data ")
        pl.plot(test_x,test_functions[i](test_x, *(fits[i][j][0])), 'g-', label="Best fit" )
        pl.plot(test_x,test_functions[i](test_x, *(guesses[i][j])),'m-', 
                label="Best guess," + " degree = " + str(degrees[i][j]))
        pl.legend(loc=2)
        pl.suptitle("f(x) = " + str(test_names[i]))
        pl.title("Goodness of guess = " 
Пример #14
0
"""
URL redirection
"""

import BaseHTTPServer
from SocketServer import ThreadingMixIn
import time

# import threading
from searcher import searcher

search = searcher(50)


class searchHandler(BaseHTTPServer.BaseHTTPRequestHandler, searcher):
    def do_HEAD(self):
        searchQuery = self.path
        print searchQuery
        try:
            a, b = search.search(searchQuery, 20, 10)
        except:
            a, b = [], []
        print a, b
        # clusters = open('/opt/bitnami/apache2/cgi-bin/clusters.csv','w')
        clusters = open("../../data/clusters.csv", "w")
        for t in a:
            try:
                clusters.write(t + "\n")
            except:
                pass
Пример #15
0
            DG = reload(data)

        #WRITING CONTENT
        if start == "write":
            writer(topic)
            data = reader(topic)
            DG = init(data)
            DG = cleanPred(data, DG)

        if start == "search":
            se = ""
            while se != "end":
                if se == "end":
                    continue
                se = input("search: ")
                for n in searcher(se, data):
                    print(str(n.id) + ": " + n.title)

        if start == "ls":
            for n in data:
                if isinstance(n, int):
                    continue
                print(str(n.id) + ": " + str(n.title))

        if start == "graph":
            draw_all(data, DG)

        #summarize data
        #degree centrality, pred nodes, suc nodes (page rank)
        if start == "summarize":
            size = int(len(DG.nodes()) / 10)
Пример #16
0
def interface(init_topic=""):
    from mapper import reload
    topic = ""
    while topic != "end":
        #loading topic
        if init_topic == "":
            topic = input("topic: ")

            if topic == "end":
                continue
            if topic == "ls":
                for n in [
                        n.replace(".json", "") for n in os.listdir("../data/")
                        if ".json" in n
                ]:
                    print(n)
                continue
            if len(searcher(topic, list(os.listdir("../data/")))) > 0:
                print()
                for n in [
                        n.replace(".json", "")
                        for n in searcher(topic, list(os.listdir("../data/")))
                        if ".json" in n
                ]:
                    print(n)
        else:
            topic = init_topic
        file = "../data/" + topic + ".json"

        if topic + ".json" not in set(os.listdir("../data/")):
            print("NEW")
            conf = input("confirm: ")
            #need a confirm option
            if conf == "y" or conf == "yes":
                with open(file, "w+") as cur_file:
                    cur_file.write(json.dumps([]))
            else:
                continue

        start = ""
        data = reader(topic)
        DG = reload(data)
        #for the purpose of recording changes to length of dataset
        preLen = len(data)
        path = ""
        walker = 0
        SET_OF_COMMANDS = ["end", "print", "edit", "write", "search"]
        #actions
        while start != "end":
            start = input(topic + ": ")
            if start == "end":
                continue

            #print the new data? useless method because it writes to file everytime
            if start == "print":
                for i in range(preLen + 1, len(data)):
                    print(str(data[i].id) + ": " + data[i].title)

                print(data)
                conf = input("confirm?: ")
                if conf == "y" or conf == "yes":
                    writeToFile(file, data)
                else:
                    continue

            if start == "edit":
                data = edit(data)
                writeToFile(file, data)
                DG = reload(data)

            #WRITING CONTENT
            if start == "write":
                writer(topic)
                data = reader(topic)
                DG = reload(data)

            if start == "search":
                se = ""
                while se != "end":
                    se = input("search: ")
                    if se == "end":
                        continue
                    if isint(se):
                        get(data, DG, id=int(se))
                    for n in searcher(se, data):
                        print(str(n.id) + ": " + n.title)

            if isint(start):
                get(data, DG, id=int(start))

            if start[:2] == "ls":
                ls(start, data)
                continue

            if start == "graph":
                draw_all(data, DG)

            #summarize data
            #degree centrality, pred nodes, suc nodes (page rank)
            if start == "summarize":
                size = int(len(DG.nodes()) / 10)
                print("Size = " + str(size))
                centralnodes = [
                    n[0] for n in most_degree_centrality(DG, limit=size)
                ]

                suc = mostPopularSuc(data, DG, limit=size)
                pred = mostPopularPred(data, DG, limit=size)

                totalNodes = []
                totalNodes.extend(centralnodes)
                totalNodes.extend(suc)
                totalNodes.extend(pred)

                print("Pred Nodes: ")
                print()
                for n in pred:
                    print(str(n.id) + ": " + str(n.title))
                print()
                print("Central Nodes: ")
                print()
                for n in centralnodes:
                    print(str(n.id) + ": " + str(n.title))
                print()
                print("Suc Nodes: ")
                print()
                for n in suc:
                    print(str(n.id) + ": " + str(n.title))

                p = input("plot? ")
                if p == "y" or p == "yes":
                    subDG = DG.subgraph(totalNodes)
                    labels = labeler(data)
                    pos = nx.spring_layout(subDG)
                    labelDict = {
                        n: lab
                        for n, lab in labels.items() if n in pos
                    }
                    nx.draw(subDG,
                            pos,
                            with_labels=True,
                            font_size=12,
                            labels=labelDict)
                    plt.draw()
                    plt.show()

            if start == "get":
                get(data, DG)

            if start == "axioms":
                leaves = [n for n, d in DG.out_degree() if d == 0]
                print(len(leaves))
                dprint(leaves)

            if start == "cycle":
                isCycle(DG)

            if start == "project":
                get_project(data, DG)

            if start == "branch":
                branch(data, DG)

            if start == "pyvis":
                from net_vis import net_vis
                net_vis(data)

            if start == "load":
                from load import file_finder, term_text_editor, pdf_loader, txt_loader
                if len(path) > 0:
                    s = input("LOADED PATH: " + path + "\n")
                    if s == "new":
                        path = file_finder()
                        if ".txt" in path:
                            t_data = txt_loader(path)
                        elif ".pdf" in path:
                            t_data = pdf_loader(path)
                        else:
                            print("NO VALID FILE")
                        term_text_editor(path, from_topic=topic)
                        data = reader(topic)
                        DG = reload(data)
                    else:
                        walker = term_text_editor(t_data,
                                                  init_index=walker,
                                                  from_topic=topic)
                        data = reader(topic)
                        DG = reload(data)
                else:
                    path = file_finder()
                    if ".txt" in path:
                        t_data = txt_loader(path)
                    elif ".pdf" in path:
                        t_data = pdf_loader(path)
                    else:
                        print("NO VALID FILE")
                    walker = term_text_editor(t_data, from_topic=topic)
                    data = reader(topic)
                    DG = reload(data)
Пример #17
0
import crawler
import searcher
import sys

reload(searcher)
e = searcher.searcher('searchindex.db')

# e.getmatchrows('get set')

# e.query( 'get set')

# e.calculatepagerank()

cur = e.con.execute('select * from pagerank order by score desc')
# for i in range( 10 ): print cur.next()

e.query('get set')

# e.geturlname( )
Пример #18
0
def term_text_editor(data, init_index=0, from_topic=""):
    from writer import writer

    from searcher import searcher

    i = ""

    walker = init_index
    return_string = ""
    if walker == 0:
        print("LOADING")
        print("PRESS ENTER TO CONTINUE")
        input()

    while i != "end" or (walker > 0 and walker < len(data)):
        cur_sentence = str(data[walker])
        i = input(cur_sentence + '.' + '\n')
        if i == "end":
            continue
        if "add" in i:
            if i[:-1] == "-":
                return_string = cur_sentence + return_string + ". "
            else:
                return_string += cur_sentence + ". "
            print("ADDED")
            print()
            walker += 1

        if i == "" or "+" in i:
            try:
                num = int(i.replace("+", ""))
            except:
                num = 1

            walker += num
            continue
        if i == "-" or i == "back":
            try:
                num = int(i.replace("+", ""))
            except:
                num = 1
            walker -= num
            print()
            continue
        if i == "ls":
            print(return_string)
            print()

        if i == "search":
            search = input("search: ")
            list_search = searcher(search, data, index=True)
            if len(list_search) > 0:
                print(str(len(list_search)) + " ITEMS FOUND")
                for n in list_search:
                    s = input(data[n] + ": \n")
                    if s == "jump":
                        walker = n
                        break
                    if s == "end":
                        break

        if i == "write":
            if from_topic == "":
                topic = input("topic: ")
                writer(topic, init_description=return_string)
            else:
                writer(from_topic, init_description=return_string)
            continue
        if i == "interface" or i == "map":
            break

    return walker
Пример #19
0
def file_finder():
    from searcher import searcher
    import os

    SUPPORTED_FILE_TYPES = ['.pdf', '.txt']
    w = ""
    path = os.getcwd()

    def reload_dir(path):
        with os.scandir(path) as dire:
            cur_directory = [n for n in dire]
        return cur_directory

    cur_directory = reload_dir(path)

    def aprint(array, tab='\t'):
        for n in array:
            if isinstance(n, os.DirEntry):
                print(tab + n.name)
            else:
                print(tab + n)

    while w != "end":
        w = input("load: ")
        if w == "end":
            continue

        if w == "ls":
            aprint(cur_directory)
            continue

        if w == "":
            cur_directory = reload_dir(path)
            aprint(cur_directory)
            continue

        if w in SUPPORTED_FILE_TYPES:
            file_type = w
            cur_directory = [n for n in cur_directory if file_type in n.name]
            aprint(cur_directory)
            continue

        if "cd .." == w or ".." == w:
            arr = path.split('/')
            if len(arr) > 1:
                path = "/".join(arr[:-1])
                print(path)
                cur_directory = reload_dir(path)
                aprint(cur_directory)
            else:
                aprint(cur_directory)
            continue
        if "cd" in w:

            if w[3:] in [n.name for n in cur_directory]:
                path += "/" + w[3:]
                cur_directory = reload_dir(path)
                aprint(cur_directory)
            else:
                print("/" + w[3:] + " NOT IN DIRECTORY")
            continue

        if w == "path":
            print(path)
            continue

        else:
            s = searcher(w, [n.name for n in cur_directory])
            if len(s) == 0:
                print("NO SIMILAR FILES")
                aprint(cur_directory)
                continue
            cur_directory = [n for n in cur_directory if n.name in s]
            if len(s) > 1:
                cur_directory = [n for n in cur_directory if n.name in s]
                aprint(cur_directory)
            elif cur_directory[0].is_file():
                aprint(cur_directory)
                i = input("load? ")
                if i == "y" or i == "yes":
                    path = cur_directory[0].path
                    break
                    #term_text_editor(path, from_topic = "")
            else:
                path = cur_directory[0].path
                cur_directory = reload_dir(path)
                aprint(cur_directory)
    return path
Пример #20
0
def writer(topic, data=0, init_description=""):
    from writer import writeToFile, isint

    #cleaning function making sure each node is properly linked
    def clean(data, curNode):
        for n in curNode.future:
            if n >= len(data):
                continue
            pastArray = data[n].past
            if n not in pastArray:
                data[n].flashback(curNode.id)
        for n in curNode.past:
            if n >= len(data):
                continue
            futureArray = data[n].future
            if n not in futureArray:
                data[n].flashforward(curNode.id)
        for n in curNode.related:
            if n >= len(data):
                continue
            relatedArray = data[n].related
            if n not in relatedArray:
                data[n].relate(curNode.id)

    file = "../data/" + topic + ".json"

    data = reader(topic)
    DG = init(data)
    DG = cleanPred(data, DG)
    max = len(data)

    content = ""
    summary = init_description
    print(topic + ".write: " + summary)

    while content != "end":
        content = input("")

        if content == "end":
            continue
        #summary function
        if content == "ls":
            print(summary)
            continue
        #enter
        if content == "\n":
            summary += "\n"
            continue
        #premature break
        if content == "break":
            break
        #writing the actual content
        summary += content + " "

    #premature break
    if content == "break":
        return ""
    #connecting the content

    #get title
    print("Title: ")
    title = input("")
    if title == "up":
        title = summary

    print("Type: ")
    type = []
    t = ""
    while t != "end":
        t = input("")
        if t == "end":
            continue
        type.append(t)

    print("Past: ")
    past_temp = ""
    back = []
    while past_temp != "end":
        past_temp = input("")
        if past_temp == "end":
            continue
        if past_temp[:2] == "ls":
            ls(past_temp, data)
            continue
        if past_temp == "search":
            se = ""
            while se != "end":
                se = input("search: ")
                if se == "end":
                    continue
                if isint(se):
                    get(data, DG, id=int(se))
                for n in searcher(se, data):
                    print(str(n.id) + ": " + n.title)
            continue
        if past_temp == "suc":
            for n in mostPopularSuc(data, DG, limit=10):
                print(str(n.id) + ": " + n.title)
            continue
        if past_temp == "pre":
            for n in mostPopularPred(data, DG, limit=10):
                print(str(n.id) + ": " + n.title)
            continue
        if past_temp == "cen":
            for n in most_degree_centrality(DG, limit=10):
                print(str(n[0].id) + ": " + n[0].title)
            continue
        if past_temp == "project":
            get_project(data, DG)
            continue
        if past_temp == "branch":
            branch(data, DG)
            continue
        if past_temp == "get":
            get(data, DG)
            continue
        if isint(past_temp):
            result = int(past_temp)
            back.append(result)
        else:
            print([
                str(n.id) + ": " + str(n.title)
                for n in searcher(past_temp, data)
            ])
        print(back)

    print("Future: ")
    future_temp = ""
    future = []
    while future_temp != "end":
        future_temp = input("")
        if future_temp == "end":
            continue
        if future_temp[:2] == "ls":
            if future_temp[:2] == "ls":
                ls(future_temp, data)
            continue
        if future_temp == "search":
            se = ""
            while se != "end":
                se = input("search: ")
                if se == "end":
                    continue
                if isint(se):
                    get(data, DG, id=int(se))
                for n in searcher(se, data):
                    print(str(n.id) + ": " + n.title)
            continue
        if future_temp == "suc":
            for n in mostPopularSuc(data, DG, limit=10):
                print(str(n.id) + ": " + n.title)
        if future_temp == "pre":
            for n in mostPopularPred(data, DG, limit=10):
                print(str(n.id) + ": " + n.title)
        if future_temp == "cen":
            for n in most_degree_centrality(DG, limit=10):
                print(str(n[0].id) + ": " + n[0].title)
        if future_temp == "get":
            get(data, DG)
        if isint(future_temp):
            result = int(future_temp)
            future.append(result)
        else:
            print([
                str(n.id) + ": " + str(n.title)
                for n in searcher(future_temp, data)
            ])
        print(future)

    #simplify things, break things up into if you want to add related
    c = ""
    related = []
    keyword = []
    while c != "end":
        c = input("")
        if c == "end":
            continue
        if c == "break":
            break
        #if you want to add related
        if c == "related":
            print("Related: ")
            r_temp = ""
            while r_temp != "end":
                r_temp = input("")
                if r_temp == "end":
                    continue
                if isint(r_temp):
                    result = int(r_temp)
                    related.append(result)
                else:
                    print([
                        str(n.id) + ": " + str(n.title)
                        for n in searcher(r_temp, data)
                    ])
                print(related)
        #if you want to add keywords
        if c == "keywords":
            print("Keywords: ")
            k_temp = ""
            while k_temp != "end":
                k_temp = input("")
                if k_temp == "end":
                    continue
                keyword.append(k_temp)
        if c == "edit":
            data = edit(data)
    if c == "break":
        return ""
    print(title)
    print(type)
    print(summary)

    #CLEANING

    current_Node = Node(title, type, summary, keyword, back, future, related,
                        max)
    clean(data, current_Node)
    data.append(current_Node)
    max += 1

    #WRITING BACK TO TXT FILE
    writeToFile(file, data)
Пример #21
0
#!/usr/bin/env python

import sys

from searcher import searcher

if __name__ == "__main__":
    if len(sys.argv) > 1:
        searchQuery = " ".join(sys.argv[1:])
    else:
        print "Please specify Search Query"
        exit()

    search = searcher(200, "/home/bitnami/8Q/")

    print searchQuery
    try:
        a, b = search.search(searchQuery, 20, 10)
    except:
        a, b = [], []

    print "Papers = %d, Clusters = %d" % (len(a), len(b))
    clusters = open("/opt/bitnami/apache2/cgi-bin/clusters.csv", "w")
    # clusters = open('../../data/clusters.csv','w')
    for i, cluster in enumerate(b):
        for s in cluster:
            try:
                clusters.write(s)
            except:
                pass
        if i < len(b) - 1: