todo: functors
This commit is contained in:
		
							parent
							
								
									40f6aea2e7
								
							
						
					
					
						commit
						8a3d6f0a5a
					
				| @ -95,8 +95,9 @@ def api_register(): | |||||||
|         email == "" |         email == "" | ||||||
|     ): |     ): | ||||||
|         return "ERR" |         return "ERR" | ||||||
|  |     email_hash = hashlib.sha256(email.encode("utf-8")).hexdigest() | ||||||
|     existing = list(valdb[USERS_COLL].find({ |     existing = list(valdb[USERS_COLL].find({ | ||||||
|         "$or": [{"username": username}, {"email": email}] |         "$or": [{"username": username}, {"email": email_hash}] | ||||||
|     })) |     })) | ||||||
|     if len(existing) > 0: |     if len(existing) > 0: | ||||||
|         return "ERR: Username or email already exists." |         return "ERR: Username or email already exists." | ||||||
| @ -104,8 +105,7 @@ def api_register(): | |||||||
|         "username": username, |         "username": username, | ||||||
|         "hpass": hashlib.sha256( |         "hpass": hashlib.sha256( | ||||||
|             password.encode("utf-8")).hexdigest(), |             password.encode("utf-8")).hexdigest(), | ||||||
|         "email": hashlib.sha256( |         "email": email_hash | ||||||
|             email.encode("utf-8")).hexdigest() |  | ||||||
|     } |     } | ||||||
|     valdb[USERS_COLL].insert(entry) |     valdb[USERS_COLL].insert(entry) | ||||||
|     return "OK" |     return "OK" | ||||||
| @ -264,20 +264,19 @@ def api_get_frames(): | |||||||
|     if hw is None: |     if hw is None: | ||||||
|         return json.dumps({"error": "Required argument: hw (headword)."}) |         return json.dumps({"error": "Required argument: hw (headword)."}) | ||||||
| 
 | 
 | ||||||
|     rf_name = request.args.get("rf", "reduce_0")  # 2nd is default |     rf_name = request.args.get("rf", "reduce_0") | ||||||
|     RF = reduce_functions[rf_name]["f"] |     RF = reduce_functions[rf_name]["f"] | ||||||
| 
 | 
 | ||||||
|     corpus = request.args.get("cor") |     corpus = request.args.get("cor") | ||||||
|     if corpus not in CORPORA: |     if corpus not in CORPORA: | ||||||
|         return json.dumps({"error": "cor={kres,ssj}"}) |         return json.dumps({"error": "cor={kres,ssj}"}) | ||||||
| 
 | 
 | ||||||
|     # entry = vallex.entries[hw]  # TODO  hw -> [Frame,] |  | ||||||
|     cur = valdb[corpus].find({"headwords": hw}) |     cur = valdb[corpus].find({"headwords": hw}) | ||||||
|     frames = [] |     frames = [] | ||||||
|     for ent in cur: |     for ent in cur: | ||||||
|         # TODO: maybe filter by hw? |  | ||||||
|         frames += frames_from_db_entry(ent)  # pre-process this step for prod TODO |         frames += frames_from_db_entry(ent)  # pre-process this step for prod TODO | ||||||
| 
 | 
 | ||||||
|  |     # filter by relevant hw | ||||||
|     frames = [x for x in frames if x.hw == hw] |     frames = [x for x in frames if x.hw == hw] | ||||||
| 
 | 
 | ||||||
|     ret_frames = RF(frames, valdb[SENSEMAP_COLL]) |     ret_frames = RF(frames, valdb[SENSEMAP_COLL]) | ||||||
| @ -290,10 +289,21 @@ def api_get_functor_frames(): | |||||||
|     functor = request.args.get("functor") |     functor = request.args.get("functor") | ||||||
|     if functor is None: |     if functor is None: | ||||||
|         return json.dumps({"error": "Missing argument: functor."}) |         return json.dumps({"error": "Missing argument: functor."}) | ||||||
|     rf_name = request.args.get("rf", "reduce_0")  # 2nd is default | 
 | ||||||
|  |     rf_name = request.args.get("rf", "reduce_0") | ||||||
|     RF = reduce_functions[rf_name]["f"] |     RF = reduce_functions[rf_name]["f"] | ||||||
|     raw_frames = vallex.functors_index[functor]  # TODO | 
 | ||||||
|     ret_frames = RF(raw_frames, vallex) |     corpus = request.args.get("cor") | ||||||
|  |     if corpus not in CORPORA: | ||||||
|  |         return json.dumps({"error": "cor={kres,ssj}"}) | ||||||
|  | 
 | ||||||
|  |     cur = valdb[corpus].find({"functors": functor}) | ||||||
|  |     frames = [] | ||||||
|  |     for ent in cur: | ||||||
|  |         frames += frames_from_db_entry(ent)  # pre-process this step for prod TODO | ||||||
|  | 
 | ||||||
|  |     # raw_frames = vallex.functors_index[functor]  # TODO | ||||||
|  |     ret_frames = RF(frames, valdb[SENSEMAP_COLL]) | ||||||
|     return prepare_frames(ret_frames) |     return prepare_frames(ret_frames) | ||||||
| 
 | 
 | ||||||
| # FRAMES ----------------------------^ | # FRAMES ----------------------------^ | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user