Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -137,9 +137,10 @@ def encode_text_fragment(text):
|
|
137 |
def generate_citation_hash(author, year, url, fragment_text, cited_text, username, task_name, current_date, current_time):
|
138 |
# Normalise hyphens for consistent hash generation
|
139 |
normalised_fragment_text = normalise_hyphens(fragment_text)
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
143 |
return hashlib.sha256(data.encode('utf-8')).hexdigest()
|
144 |
|
145 |
def format_citation_html(url, fragment_text, author, year, scc_hash):
|
@@ -451,20 +452,21 @@ with tabs[1]:
|
|
451 |
hash_base_url, hash_fragment = parse_url(hash_url)
|
452 |
# Parse metadata from hash URL fragment
|
453 |
username, task_name, date, time = parse_metadata(hash_fragment)
|
454 |
-
|
455 |
if not all([author, year, citation_base_url, citation_fragment, scc_hash, hash_base_url, username, task_name, date, time]):
|
456 |
st.error("Invalid input format. Ensure the citation text, URLs, and SCC index text are correctly pasted from the generated output.")
|
457 |
elif citation_base_url != hash_base_url:
|
458 |
st.error("The citation URL and SCC index URL must point to the same base URL.")
|
459 |
else:
|
460 |
-
# Normalise hyphens for hash recomputation
|
461 |
normalised_citation_fragment = normalise_hyphens(citation_fragment)
|
|
|
462 |
normalised_task_name = normalise_hyphens(task_name)
|
463 |
# Recompute hash
|
464 |
recomputed_hash = generate_citation_hash(
|
465 |
-
author, year, citation_base_url, normalised_citation_fragment,
|
466 |
)
|
467 |
-
|
468 |
if recomputed_hash == scc_hash:
|
469 |
st.markdown("""
|
470 |
<div class="success-box">
|
|
|
137 |
def generate_citation_hash(author, year, url, fragment_text, cited_text, username, task_name, current_date, current_time):
|
138 |
# Normalise hyphens for consistent hash generation
|
139 |
normalised_fragment_text = normalise_hyphens(fragment_text)
|
140 |
+
# Use the longest segment for the cited text to align with citation link
|
141 |
+
selected_cited_text = select_longest_segment(cited_text)
|
142 |
+
normalised_cited_text = normalise_hyphens(selected_cited_text)
|
143 |
+
data = f"{author}, {year} | {url} | {normalised_fragment_text} | {normalised_cited_text} | {username} | {normalise_hyphens(task_name)} | {current_date} | {current_time}"
|
144 |
return hashlib.sha256(data.encode('utf-8')).hexdigest()
|
145 |
|
146 |
def format_citation_html(url, fragment_text, author, year, scc_hash):
|
|
|
452 |
hash_base_url, hash_fragment = parse_url(hash_url)
|
453 |
# Parse metadata from hash URL fragment
|
454 |
username, task_name, date, time = parse_metadata(hash_fragment)
|
455 |
+
|
456 |
if not all([author, year, citation_base_url, citation_fragment, scc_hash, hash_base_url, username, task_name, date, time]):
|
457 |
st.error("Invalid input format. Ensure the citation text, URLs, and SCC index text are correctly pasted from the generated output.")
|
458 |
elif citation_base_url != hash_base_url:
|
459 |
st.error("The citation URL and SCC index URL must point to the same base URL.")
|
460 |
else:
|
461 |
+
# Normalise hyphens and select longest segment for hash recomputation
|
462 |
normalised_citation_fragment = normalise_hyphens(citation_fragment)
|
463 |
+
selected_citation_fragment = select_longest_segment(normalised_citation_fragment)
|
464 |
normalised_task_name = normalise_hyphens(task_name)
|
465 |
# Recompute hash
|
466 |
recomputed_hash = generate_citation_hash(
|
467 |
+
author, year, citation_base_url, normalised_citation_fragment, selected_citation_fragment, username, normalised_task_name, date, time
|
468 |
)
|
469 |
+
|
470 |
if recomputed_hash == scc_hash:
|
471 |
st.markdown("""
|
472 |
<div class="success-box">
|