Ejemplo n.º 1
0
    def build(self, lex_file, dict_dir):
        """
           读入规则文件, 词典文件
           构建自动机和匹配引擎
        """
        ori_in = read_lex(lex_file)
        script = char_stream(ori_in)
        tokens = token_list(script).tokens
        ast_obj = ast.AST(stream(tokens))

        # 逗号分开的词典文件目录列表,  会加载目录中所有txt文件
        all_slot_entity_files = []
        if dict_dir:
            dict_dirs = dict_dir.split(",")
            for dir_path in dict_dirs:
                all_slot_entity_files.extend(glob.glob(dir_path + "/*.txt"))
        print("词典文件:", all_slot_entity_files)

        # 规则中的关键词
        keywords = ast.extract_all_atoms(ast_obj)
        ac_machine = ac.AC()
        ac_machine.make(keywords, all_slot_entity_files)

        rule_graph = parse.RuleStructure(ast_obj)
        rule_trie, rule_info = rule_graph.build()
        self.searcher = search.Searcher(rule_trie, rule_info, ac_machine)
        self.rule_info = rule_info
Ejemplo n.º 2
0
 def test_searching(self):
     f = os.path.join(os.getcwd(), "testing_to_prepare.txt")
     srchr = search.Searcher(f)
     adr = "липово, набережная улица, 30"
     exp = [(54.8199454, 18.3544725), (54.8216088, 18.351938),
            (54.8223243, 18.3508078), (54.8231284, 18.349651),
            (54.8256473, 18.3478349), (54.8239951, 18.3491378)]
     self.assertEqual(list(filter(None, srchr.search_nodes(adr))), exp)
Ejemplo n.º 3
0
def proceedSearch(inputText, maxNotes):
    searcher = search.Searcher()
    searchRes = searcher.Search(inputText, getTitleList(), getTagsList())

    maxIndex = maxNotes if len(searchRes) > maxNotes else len(searchRes)

    indexes = []
    for i in range(0, maxIndex):
        indexes.append(searchRes[i][0])
    fillSearchFrame(indexes)
Ejemplo n.º 4
0
 def post(self, request):
     form = forms.ImageUploadForm(request.POST, request.FILES)
     if form.is_valid():
         image = form.save()
         searcher = search.Searcher(image)
         searcher.run()
         return make_response(request, self.RESULT_TEMPLATE, {
             'queryImage': image,
             'searcher': searcher,
             'form': form,
         })
     else:
         # response the error form to client
         return make_response(request, self.SEARCH_TEMPLATE, {'form': form})
Ejemplo n.º 5
0
 def do_GET(self):
     parts = self.path.split('?', 1)
     if len(parts) < 2:
         self.send_error(400, "Missing query")
         return
     q = urlparse.parse_qs(parts[1])
     q = q.get("q")
     if q is None:
         self.send_error(400, "Missing q parameter")
         return
     self.send_response(200)
     self.send_header("Content-Type", "text/xml")
     self.end_headers()
     writer = codecs.getwriter('utf-8')(self.wfile)
     searcher = search.Searcher(index_path)
     searcher.query(q[0].decode('utf-8'), writer)
     writer.flush()
Ejemplo n.º 6
0
    def __init__(self, db_path='rocks.db'):
        self.db = rocksdb.DB(db_path, rocksdb.Options(), read_only=True)
        self.trace = True
        self.searcher = search.Searcher(exact=True)

        #important configs
        self.skip_artists_with_no_tracks = True
        self.simple_edges = False
        self.max_edges_per_artist = 4
        self.pop_weight = 100.00
        self.min_popularity = 30

        self.artist_blacklist = set()
        self.edge_blacklist = collections.defaultdict(set)
        self.load_blacklist()

        self.load_graph()
Ejemplo n.º 7
0
	def smartUpdate(self, id, onlineNumber):
		"""
		Compare online stored number of descendants with calculated number of descendants
		given by the advised-table.
		If numbers are equal, no mathematician has been added and no update is needed.
		"""
		self.cursor.execute("SELECT author FROM advised, dissertation WHERE student=dID AND advisor=?", (id,))
		localStudents = self.cursor.fetchall()

		print(u"Online descendants = {}".format(onlineNumber).encode('utf-8'))

		if len(localStudents) > 0:
			storedStudents = set()

			for row in localStudents:
				storedStudents.add(row["author"])

			searcher = search.Searcher(self.connector, False, False)
			calculatedNumber = searcher.numberOfDescendants(storedStudents)

			if calculatedNumber == onlineNumber:
				print(u"In local database = {}".format(calculatedNumber).encode('utf-8'))
				print(u"Skip branch!".encode('utf-8'))

				return True

			else:
				print(u"In local database >= {}".format(calculatedNumber).encode('utf-8'))

			if calculatedNumber > onlineNumber:
				print(u"Student(s) online deleted! Delete them in local database and grab this branch again.".encode('utf-8'))

				for delStudent in storedStudents:
					self.cursor.execute("DELETE FROM dissertation WHERE author=?", (delStudent,))
					# TRIGGER and CASCADE statements will delete the entries in the other tables
					self.connection.commit()

		elif len(localStudents) == 0 and onlineNumber < 2:
			print(u"In local database = 0".encode('utf-8'))

		else:
			print(u"In local database: N/A".encode('utf-8'))

		return False
Ejemplo n.º 8
0
from flask import Blueprint, jsonify, g
import search
import os

api = Blueprint("api", __name__, url_prefix="/api")
searcher = search.Searcher(api_key=os.environ["NITRO_YOUTUBE_KEY"])


@api.route("/queue", methods=["GET"])
def get_queue():
    queue = g.queue.get_queue()
    return jsonify(queue)


@api.route("/queue/add/<id>", methods=["GET"])
def add_to_queue(id):
    g.queue.add_song(id)
    return "OK"


@api.route("/search/<query>", methods=["GET"])
def get_search_results(query):
    query = query.strip().lower()
    return jsonify(searcher.query(query))
Ejemplo n.º 9
0
    output_clip.write_videofile(output_fname, audio=False)


if __name__ == '__main__':
    import os
    folder = 'output_video'
    if not os.path.isdir(folder):
        os.makedirs(folder)

    # model = 'trained_models/HSV-ss(16, 16)-hb16-o9-p8-c2-hcALL-sf1-hist1-hog1-acc99.49.p'
    # model = 'trained_models/HLS-ss(16, 16)-hb16-o9-p10-c2-hcALL-sf1-hist1-hog1-acc99.32.p'
    # model = 'trained_models/YCrCb-ss(16, 16)-hb16-o9-p8-c2-hcALL-sf1-hist1-hog1-acc99.21.p'
    model = 'trained_models/YCrCb-ss(16, 16)-hb16-o9-p8-c2-hcALL-sf1-hist1-hog1-acc99.72.p'
    (fp, clf, X_scaler) = tr.load_classifier(model)

    searcher = sr.Searcher(fp, clf, X_scaler)

    sp = sr.SearchParams.get_defaults()

    for heatmap_window_size in [10]:
        for threshold in [1.7]:
            for vehicle_window_size in [7]:
                tracker = Tracker(searcher,
                                  sp,
                                  heatmap_window_size,
                                  heatmap_threshold_per_frame=threshold,
                                  vehicle_window_size=vehicle_window_size)
                process_video(
                    'test_video.mp4',
                    'output_video/test_video_boost_heat_th{}_hw{}_vw{}.mp4'.
                    format(threshold, heatmap_window_size,
Ejemplo n.º 10
0
 def test_initializing(self):
     p = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                      'filth.txt.bz2')
     s = search.Searcher(p)
     self.assertEqual(s.file_db, p)
     self.assertDictEqual(s.address_coordinates, {})
Ejemplo n.º 11
0
    tagsOk = False
    if len(tags) == 0:
        tagsOk = True
    for t in tags:
        if t in place["types"]:
            tagsOk = True
    if not tagsOk:
        return False
    if 'rating' not in place:
        exit(1)
    r = float(place["rating"])
    return r >= rating


try:
    searcher = search.Searcher()
    location = sys.argv[1]
    pages = 1
    tags = []
    rating = 0.0
    i = 2
    while i < len(sys.argv) - 2:
        tags.append(sys.argv[i])
        i += 1
    if sys.argv[i] != 'none':
        rating = float(sys.argv[i])
    i += 1
    results = int(sys.argv[i])
    text = searcher.get_places_query(location.replace("_", " "), pages)
    data = json.loads(text)
    if len(tags) == 0 and rating == 0.0: