Christopher Román Jaimes commited on
Commit ·
ac89c56
1
Parent(s): e2740ad
feat: add extract a valid string number left dotted.
Browse files32 unmodified lines3334353637383940414243444546119 unmodified lines16616716816917017177 unmodified lines24925025125225325432 unmodified lines.sort_values("score", ascending = False)\.drop_duplicates(subset = "label", keep = "first")# Add Columns Label for Text and Probabilityprediction_df["label_text"] = prediction_df["label"].apply(lambda x: f"pred_{x}")prediction_df["label_prob"] = prediction_df["label"].apply(lambda x: f"prob_{x}")# Format Predictionsentities = prediction_df.set_index("label_text")["text"].to_dict()entities_probs = prediction_df.set_index("label_prob")["score"].to_dict()predictions_formatted = {**entities, **entities_probs}return predictions_formattedelse:119 unmodified linesreturn None# Cleaningclean_functions_dict = {"SUPERFICIE_TERRAZA": extract_surface_from_string,77 unmodified lines# Format Prediction Entitiesentities_formatted = format_gliner_predictions(entities)# Clean Entitiesentities_names = list({c.replace("pred_", "").replace("prob_", "") for c in list(entities_formatted.keys())})entities_cleaned = dict()32 unmodified lines33343536373839404142434445464748495051119 unmodified lines17117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021177 unmodified lines28929029129229329429529629729829932 unmodified lines.sort_values("score", ascending = False)\.drop_duplicates(subset = "label", keep = "first")# Add Position Columnprediction_df["position"] = prediction_df.apply(lambda x: (x["start"], x["end"]) ,axis = 1)# Add Columns Label for Text and Probabilityprediction_df["label_text"] = prediction_df["label"].apply(lambda x: f"pred_{x}")prediction_df["label_prob"] = prediction_df["label"].apply(lambda x: f"prob_{x}")prediction_df["label_position"] = prediction_df["label"].apply(lambda x: f"pos_{x}")# Format Predictionsentities = prediction_df.set_index("label_text")["text"].to_dict()entities_probs = prediction_df.set_index("label_prob")["score"].to_dict()entities_positions = prediction_df.set_index("label_position")["position"].to_dict()predictions_formatted = {**entities, **entities_probs, **entities_positions}return predictions_formattedelse:119 unmodified linesreturn Nonedef extract_valid_string_left_dotted(string, text, pos):if isinstance(string, str):# String Positionleft_pos, rigth_pos = pos# Verify if the Left Position is not too close to the beginning of the text.if left_pos < 5:return Noneif string[0].isdigit():# 1. Take a subtext with 5 more characters to the left of the string.sub_text = text[left_pos - 5: rigth_pos]# 2. If the string has no dots to the left, return the original string.if text[left_pos - 1] == ".":# 3. If the string has a left dot but no preceding digit, return the original string.if text[left_pos - 2].isdigit():# 4. If the string has a left dot, with 3 left digits, and the fourth left value isn't ',', '.', or "''", it returns the new string.pattern = r'^(?![\d.,])\D*\d{1,3}\.' + re.escape(string)match = re.search(pattern, sub_text)if match:return match.group(0)else:return Noneelse:return stringelse:return stringelse:return stringelse:return None# Cleaningclean_functions_dict = {"SUPERFICIE_TERRAZA": extract_surface_from_string,77 unmodified lines# Format Prediction Entitiesentities_formatted = format_gliner_predictions(entities)# Extract valid string left dottedfeature_surfaces = ['SUPERFICIE_BALCON', 'SUPERFICIE_TERRAZA', 'SUPERFICIE_JARDIN', 'SUPERFICIE_TERRENO', 'SUPERFICIE_HABITABLE']for feature_name in feature_surfaces:entities_formatted[f"pred_{feature_name}"] = extract_valid_string_left_dotted(entities_formatted[f"pred_{feature_name}"], text, entities_formatted[f"pos_{feature_name}"])# Clean Entitiesentities_names = list({c.replace("pred_", "").replace("prob_", "") for c in list(entities_formatted.keys())})entities_cleaned = dict()
app.py+46-1