Exemple #1
0
def upload():
    file1=request.files['i1']
    file2=request.files['i2']
    delete('uploads/*')
    delete('query/*')


    if file1 and file2 and allowed_file(file1.filename) and allowed_file(file2.filename):
        filename1=secure_filename(file1.filename)
        filename2=secure_filename(file2.filename)
        
        file1.save(os.path.join(app.config['UPLOAD_FOLDER'],filename1))
        file2.save(os.path.join(app.config['QUERY'],filename2))
        f1= os.path.join(app.config['UPLOAD_FOLDER'],filename1)
        f2=os.path.join(app.config['QUERY'],filename2)
        index(app.config['UPLOAD_FOLDER'])
        i,r=matcher(app.config['UPLOAD_FOLDER'],os.path.join(app.config['QUERY'],filename2))
        match1=i
        match2=r
        match3=match(f1,f2) 
        match3=round(match3,4)*100
        print(match3)
        maximum=find_max(match1,match2,match3)
        return render_template('result.html',match1=match1,match2=match2,match3=match3,maximum=maximum) 

    return "<h1 style='color:red'> Error on input files. </h1>"
Exemple #2
0
def final(seedURL, pageLimit, directory, searchAlg):
    crawler(seedURL, pageLimit, directory, searchAlg)  #runs the crawler
    index(directory,
          "index.dat")  #indexes all the files that the cralwer found
    webGraphFile = open("webGraph.dat",
                        "rb")  #opens the webGraph that the crawler made
    webGraph = pickle.load(webGraphFile)
    pageRank(webGraph)  #runs pagerank on the web graph
    return "Done"
Exemple #3
0
 def __init__(self, parserchain=None):
     if parserchain:
         self._parserchain = parserchain
     if not self._parserchain or len(self._parserchain)<1:
         #self._parserchain.append(css(os.path.dirname(__file__) + './css_googlenews.json'))
         #self._parserchain.append(css(os.path.dirname(__file__) + './css_baidunews.json'))
         self._parserchain.append(paper())
         self._parserchain.append(cx())
         self._parserchain.append(index())
import index
x = 'abcdefghi'
"""y = x[2:-2]
print (y)
"""
start = index(x, c)
Exemple #5
0
# -*- coding: utf-8 -*-
#!/usr/local/bin/python3.4

import os, sys, inspect
from pathlib import Path
config_index = Path('output/index.json')
config_corpus = Path('output/corpus.json')
currentdir = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))
srcdir = currentdir + "/src"
sys.path.insert(0, srcdir)
from index import *
from query import *

index = index()
if config_corpus.is_file() & config_index.is_file():
    answer = input(
        "A previous corpus is already saved. Do you want to use it? Y/N: ")
    if answer == "Y":
        #dowload the previous index and corpus
        state = (index.load_index(currentdir + "/output/index.json",
                                  currentdir + "/output/corpus.json"), 1)
    else:
        answer = input(
            "Do you want to use the corpus in the input folder (Y)? Or another (N)? "
        )
        if answer == "Y":
            #dowload input corpus
            state = (index.load_files("input/*"), 2)
        else:
            path = input(
 def test_accept_parameters(self, application_request):
     d = index(application_request)
     assert d['text'] == 'whee!'
Exemple #7
0
def test_index():
    db = load_workbook("data/system.xlsx")
    index(db, 'user', 'username')
Exemple #8
0
def update_index(table_name, column_name):
    index(using_db, table_name, column_name)
config_index = Path('output/index_image.json')
config_corpus = Path('output/corpus_image.json')
currentdir = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))
srcdir = currentdir + "/src"
sys.path.insert(0, srcdir)
from index import *
from query import *
from text import *
imgdir = currentdir + "/SearchEngineProject2/clustering"
sys.path.insert(0, imgdir)
from create_clusters import *
from request import *

# Create index
ind = index()
folder_name = 'SearchEngineProject2/clustering/image_dataset_descriptors/'
saving_path = 'SearchEngineProject2/clustering/saved_kmeans'
result = dataset_handling(folder_name, saving_path)
ind.load_images(result)

# Create request
name_dataset_file = 'SearchEngineProject2/clustering/image_dataset_descriptors/dataset_imagesall_souls.json'
image_name = 'all_souls_000091'

req = request_handling(folder_name, saving_path, name_dataset_file, image_name)
result = list(HandleImageQuery(req, ind))
result.reverse()

# print result in order
for r in result:
Exemple #10
0
You are given a string S. Each character of S is either ‘a’, or ‘b’. You wish to reverse exactly one sub-string of S such that the new string is lexicographically smaller than all the other strings that you can get by reversing exactly one sub-string. 
For example, given ‘abab’, you may choose to reverse the substring ‘ab’ that starts from index 2 (0-based). This gives you the string ‘abba’. But, if you choose the reverse the substring ‘ba’ starting from index 1, you will get ‘aabb’. There is no way of getting a smaller string, hence reversing the substring in the range [1, 2] is optimal. 

Input: 
First line contains a number T, the number of test cases. 
Each test case contains a single string S. The characters of the string will be from the set { a, b }. 

Output: 
For each test case, print two numbers separated by comma; 
for example “x,y” (without the quotes and without any additional whitespace). 
“x,y” describe the starting index (0-based) and ending index respectively of the 
substring that must be reversed in order to acheive the smallest lexicographical string. If there are multiple possible answers, print the one with the smallest ‘x’. If there are still multiple answers possible, print the one with the smallest ‘y’. 

Constraints: 
1 ? T ? 100 
1 ? length of S ? 1000 

Sample Input: 
5 
abab 
abba 
bbaa 
aaaa 
babaabba 

Sample Output: 
1,2 
1,3 
0,3 
0,0 
0,4
Exemple #11
0
 def run(self):
     index().run()
The list() Constructor
It is also possible to use the list() constructor to make a new list.

Example
Using the list() constructor to make a List:

thislist = list(("apple", "banana", "cherry")) # note the double round-brackets
print(thislist)
List Methods
Python has a set of built-in methods that you can use on lists.

Method	Description
append()	Adds an element at the end of the list
clear()	Removes all the elements from the list
copy()	Returns a copy of the list
count()	Returns the number of elements with the specified value
extend()	Add the elements of a list (or any iterable), to the end of the current list
index()	Returns the index of the first element with the specified value
insert()	Adds an element at the specified position
pop()	Removes the element at the specified position
remove()	Removes the item with the specified value
reverse()	Reverses the order of the list
sort()	Sorts the list
Test Yourself With Exercises
Exercise:
Print the second item in the fruits list.

fruits = ["apple", "banana", "cherry"]
print(
)